Вопрос

This is the code, the problem I am having is that while everything works as expected, the desired perl script cannot be called unless I specify the full file path (as in "s"), even though they are all in the same directory (Desktop). Any help would be appreciated.

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
Это было полезно?

Решение

Are you invoking the script like C:\>python myscript.py? If so, then your script will actually be running under the python program, which means its location will be wherever your python executable it, not the script. You can verify this by importing os and running os.getcwd(), which will probably show something like 'C:\\Python33'.

To fix this, either invoke your script directly by doing C:\myscript.py (this works just finel; Windows knows which interpreter to use based off of the extension), use os.chdir() to fix your location in the file system, or just use absolute pathing.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top