第一個python 程序

      網友投稿 677 2025-04-04

      #!/usr/bin/env Python

      # -*- encoding: utf-8 -*-

      # 獲取系統基本信息

      import sys

      import psutil

      import time

      import os

      #獲取當前時間

      time_str =? time.strftime( "%Y-%m-%d", time.localtime( ) )

      file_name = "./" + time_str + ".log"

      if os.path.exists ( file_name ) == False :

      os.mknod( file_name )

      handle = open ( file_name , "w" )

      else :

      handle = open ( file_name , "a" )

      #獲取命令行參數的個數

      if len( sys.argv ) == 1 :

      print_type = 1

      else :

      print_type = 2

      def isset ( list_arr , name ) :

      if name in list_arr :

      return True

      else :

      第一個python 程序

      return False

      print_str = "";

      #獲取系統內存使用情況

      if ( print_type == 1 ) or isset( sys.argv,"mem" )? :

      memory_convent = 1024 * 1024

      mem = psutil.virtual_memory()

      print_str +=? " 內存狀態如下:\n"

      print_str = print_str + "? ?系統的內存容量為: "+str( mem.total/( memory_convent ) ) + " MB\n"

      print_str = print_str + "? ?系統的內存以使用容量為: "+str( mem.used/( memory_convent ) ) + " MB\n"

      print_str = print_str + "? ?系統可用的內存容量為: "+str( mem.total/( memory_convent ) - mem.used/( 1024*1024 )) + "MB\n"

      print_str = print_str + "? ?內存的buffer容量為: "+str( mem.buffers/( memory_convent ) ) + " MB\n"

      print_str = print_str + "? ?內存的cache容量為:" +str( mem.cached/( memory_convent ) ) + " MB\n"

      #獲取cpu的相關信息

      if ( print_type == 1 ) or isset( sys.argv,"cpu" ) :

      print_str += " CPU狀態如下:\n"

      cpu_status = psutil.cpu_times()

      print_str = print_str + "? ?user = " + str( cpu_status.user ) + "\n"

      print_str = print_str + "? ?nice = " + str( cpu_status.nice ) + "\n"

      print_str = print_str + "? ?system = " + str( cpu_status.system ) + "\n"

      print_str = print_str + "? ?idle = " + str ( cpu_status.idle ) + "\n"

      print_str = print_str + "? ?iowait = " + str ( cpu_status.iowait ) + "\n"

      print_str = print_str + "? ?irq = " + str( cpu_status.irq ) + "\n"

      print_str = print_str + "? ?softirq = " + str ( cpu_status.softirq ) + "\n"

      print_str = print_str + "? ?steal = " + str ( cpu_status.steal ) + "\n"

      print_str = print_str + "? ?guest = " + str ( cpu_status.guest ) + "\n"

      #查看硬盤基本信息

      if ( print_type == 1 ) or isset ( sys.argv,"disk" ) :

      print_str +=? " 硬盤信息如下:\n"

      disk_status = psutil.disk_partitions()

      for item in disk_status :

      print_str = print_str + "? ?"+ str( item ) + "\n"

      #查看當前登錄的用戶信息

      if ( print_type == 1 ) or isset ( sys.argv,"user" ) :

      print_str +=? " 登錄用戶信息如下:\n "

      user_status = psutil.users()

      for item in? user_status :

      print_str = print_str + "? ?"+ str( item ) + "\n"

      print_str += "---------------------------------------------------------------\n"

      print ( print_str )

      handle.write( print_str )

      handle.close()

      Python

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:設置雙層下劃線(單元格設置雙下劃線)
      下一篇:【MySQL】Explain字段的解釋
      相關文章
      国产成人毛片亚洲精品| 亚洲91精品麻豆国产系列在线| 亚洲麻豆精品国偷自产在线91| 亚洲电影一区二区三区| 亚洲av无码天堂一区二区三区 | 亚洲综合色丁香麻豆| 精品国产亚洲一区二区在线观看| 日韩精品电影一区亚洲| 久久亚洲国产最新网站| 日韩亚洲AV无码一区二区不卡| 国产亚洲成人久久| a级亚洲片精品久久久久久久 | 亚洲AV无码一区二区三区电影| 亚洲婷婷综合色高清在线| 亚洲国产精品特色大片观看完整版 | 国产亚洲一区二区三区在线不卡| 伊人久久综在合线亚洲91| 久久久亚洲精品蜜桃臀| 中文字幕亚洲日韩无线码| 亚洲精品无码不卡在线播HE| 亚洲成A∨人片天堂网无码| 亚洲免费日韩无码系列| 亚洲综合无码AV一区二区| 国产aⅴ无码专区亚洲av| 香蕉蕉亚亚洲aav综合| 亚洲va久久久噜噜噜久久 | 亚洲人成电影在线播放| 日韩国产精品亚洲а∨天堂免| 极品色天使在线婷婷天堂亚洲 | 亚洲熟女综合一区二区三区| 亚洲小说区图片区| 亚洲综合久久精品无码色欲| 亚洲av无码一区二区三区在线播放 | 国产偷国产偷亚洲高清日韩 | 亚洲国产精品无码久久| 亚洲色偷偷色噜噜狠狠99| 亚洲伊人色一综合网| 亚洲喷奶水中文字幕电影| 亚洲字幕AV一区二区三区四区| WWW国产亚洲精品久久麻豆| 亚洲男人av香蕉爽爽爽爽|