python是基于哪个系统的_python能检测到它运行的是哪个操作系统?
python可以檢測操作系統,然后為文件系統構造一個if / else語句。
我需要用FileSys字符串替換Fn字符串中的C: CobaltRCX 。import os.path, csv
from time import strftime
if os.path.?????:## Windows
FileSys = r"C:working"
else: ##linux
FileSys = r"working"
y=(strftime("%y%m%d"))
Fn = (r"C:workingSetup%s.csv" %y)
我通常只是使用這個:import os
if os.name == 'nt':
pass # Windows
else:
pass # other (unix)
編輯:
希望對您的評論作出回應:from time import strftime
import os
if os.name == 'nt': # Windows
basePath = 'C:working'
else:
basePath = '/working/'
Fn = '%sSetup%s.csv' % ( basePath, strftime( '%y%m%d' ) )
使用sys.platform 。 你可以在http://docs.python.org/library/platform.html找到更多信息
是。>>> import os
>>> os.uname()
('Linux', 'ubuntu', '2.6.32-27-generic', '#49-Ubuntu SMP Thu Dec 2 00:51:09 UTC 2010', 'x86_64')
>>> system = os.uname()
>>> print system[0] + '/' + system[1]
Linux/ubuntu
>>>
鏈接地址: http://www.djcxy.com/p/3375.html
總結
以上是生活随笔為你收集整理的python是基于哪个系统的_python能检测到它运行的是哪个操作系统?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 处理机调度实验总结_计算机系统结构总结
- 下一篇: ipynb和py文件一样吗_文件描述符了