I'm working on a project which allows the user to set a path to upload files to by adding the necessary argument but for whatever reason, the upload_destination variable is always empty! Here's my code
def main():
global listen
global port
global execute
global command
global upload_destination
global target
if not len(sys.argv[1:]):
usage()
try:
opts, args = getopt.getopt(sys.argv[1:], "hle:t:p:cu", ["help", "listen", "execute", "target", "port", "command", "upload"])
except getopt.GetoptError as err:
print str(err)
usage()
for o,a in opts:
if o in ("-h", "--help"):
usage()
elif o in ("-l", "--listen"):
listen = True
elif o in ("-e", "--execute"):
execute = True
elif o in ("-c", "--commandshell"):
command = True
elif o in ("-u", "--upload"):
#Here's the problem, a is empty even though I include a path
upload_destination = a
elif o in ("-t", "--target"):
target = a
elif o in ("-p", "--port"):
port = int(a)
else:
assert False, "Unhandled Option"
if not listen and len(target) and port > 0:
buffer = sys.stdin.read()
client_sender(buffer)
if listen:
server_loop()
I call the programm by entering
C:\Users\Asus\Desktop\PythonTest>python test.py -l -c -p 3500 -u C:\Users\Asus\Desktop\Test
argparse
(docs.python.org/3/library/argparse.html)? – linusg May 13 '16 at 13:51s = "something/new"
, it'd end up ass = "something(newline)ew"
– Peter May 13 '16 at 13:56elif
block is executing at all? If you put aprint("about to change upload destination")
on the line beforeupload_destination = a
, does it get printed? – Kevin May 13 '16 at 14:00