这是代码,我遇到的问题是,虽然一切都按预期工作,但是除非我指定完整的文件路径(如“s”中),否则无法调用所需的perl脚本,即使它们都在同一目录(桌面)。任何帮助将不胜感激。
import subprocess
status = ['s', 'mj', 'ms', 'h','q']
while(1):
while(1):
print("Compute income tax: \n")
print("\ts = single \n")
print("\tmj = married and filing jointly \n")
print("\tms = married and filing seperately \n")
print("\th = head of household \n")
print("\tq = quit \n")
#get user input for status
choice=raw_input("Enter status: ")
if (choice in status):
print("58")
break
else:
print("Unknown status!")
if (choice=='q'):
break
else:
if (choice=="s"):
subprocess.call('perl C:/Users/Username/Desktop/single.pl')
elif(choice=='mj'):
subprocess.call('perl marriedJointly.pl')
elif(choice=='ms'):
subprocess.call('perl marriedSeperately.pl')
elif(choice=='h'):
subprocess.call('perl head.pl')
#and so on
答案 0 :(得分:0)
您是否正在调用C:\>python myscript.py
这样的脚本?如果是这样,那么你的脚本实际上将在python程序下运行,这意味着它的位置将是你的python可执行文件的位置,而不是脚本。您可以导入os
并运行os.getcwd()
来验证这一点,这可能会显示'C:\\Python33'
。
要解决此问题,请通过执行C:\myscript.py
直接调用您的脚本(这可以很好地工作; Windows知道根据扩展名使用哪个解释器),使用os.chdir()
来修复您的位置文件系统,或者只是使用绝对路径。