Mer*_*lin 6 python linux windows
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:\\working\\Setup%s.csv" %y)
Run Code Online (Sandbox Code Playgroud)
pok*_*oke 16
我通常只使用这个:
import os
if os.name == 'nt':
pass # Windows
else:
pass # other (unix)
Run Code Online (Sandbox Code Playgroud)
希望回应您的意见:
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' ) )
Run Code Online (Sandbox Code Playgroud)
小智 6
请参阅此处:https ://stackoverflow.com/a/58689984/3752715
import platform
plt = platform.system()
if plt == "Windows": print("Your system is Windows")
elif plt == "Linux": print("Your system is Linux")
elif plt == "Darwin": print("Your system is MacOS")
else: print("Unidentified system")
Run Code Online (Sandbox Code Playgroud)
你可以看到我的github仓库https://github.com/sk3pp3r/PyOS并使用pyos.py脚本
| 归档时间: |
|
| 查看次数: |
12891 次 |
| 最近记录: |