【发布时间】:2020-06-21 11:03:23
【问题描述】:
我的 python 脚本在 Windows 上运行没有任何问题。但是同样的脚本也必须在 Linux 机器上运行。运行时提示指定路径不存在。请注意,变量“path”指向云服务器
后来在浏览了一些论坛后尝试了os.path.join功能,也失败了
import os
import re
import sys
#List .xlsx files followed by the string ESC
path = '\\\\cloudnetworkonlinuxserver'
path2 = 'DBX'
path3 = 'SrcFiles'
path4 = 'MEBilling'
path5 = 'ParmFiles'
filenames = os.listdir(os.path.join(path, path2, path3, path4))
for filename in filenames:
getdate = re.search('(?<=ESC_)\w+', filename)
#Replace '_' with '-'
if getdate:
date = getdate.group(0).replace('_', '-')
print('The following ESC file has date', date)
#Create .prm file with following body
f = open(os.path.join(path, path2, path5, "wf_SC_Monthend_Billing_XLS" + "." + "prm"), 'w')
#f.write cannot take more than one argument. Write variables such
a = '$$WF_PERIOD='
b = date
#Write in body of file
f.write("[Global]\n")
f.write('%s%s' % (a,b,))
#Close writing process
f.close
还有哪些其他方法可以指定与这两种操作系统兼容的路径?
【问题讨论】:
标签: python import path operating-system