11.4 SYS模塊
阿新 • • 發佈:2018-03-31
Python SYS模塊 SYS模塊
os模塊是在跟操作系統進行交互,sys模塊是在跟python解釋器進行交互
import sys
# -*-coding:utf-8 -*- __author__ = ‘xiaojiaxin‘ __file_name__ = ‘sys模塊‘ print(sys.argv) #[‘C:/Users/xiaojiaxin/PycharmProjects/fullstack1/week3/day11/ramdom模塊.py‘] #sys.argv的第一個元素永遠是文件名 在cmd中操作: #添加如下代碼 if sys.argv[1]=="post": print("upload") else: print("download")
#退出程序,正常退出時exit(0)
#sys.exit()
#獲取Python解釋器的基本信息
print(sys.version)
# 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
print(sys.maxsize)
#9223372036854775807
#很重要,返回模塊的搜索路徑 print(sys.path) # [‘C:\\Users\\xiaojiaxin\\PycharmProjects\\fullstack1\\week3\\day12‘, ‘C:\\Users\\xiaojiaxin\\PycharmProjects\\fullstack1‘, ‘C:\\Users\\xiaojiaxin\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip‘, ‘C:\\Users\\xiaojiaxin\\AppData\\Local\\Programs\\Python\\Python36\\DLLs‘, ‘C:\\Users\\xiaojiaxin\\AppData\\Local\\Programs\\Python\\Python36\\lib‘, ‘C:\\Users\\xiaojiaxin\\AppData\\Local\\Programs\\Python\\Python36‘, ‘C:\\Users\\xiaojiaxin\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages‘] #添加模塊查找路徑 #sys.path.append(path)
#返回操作系統平臺名稱,重要
print(sys.platform)
# win32
#sys.platform的應用
import os
if sys.platform=="win32":
os.system("dir")
else:
os.system("ls")
11.4 SYS模塊