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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值