Re: Converting argv to variable
newDirectory = str(sys.argv[1:]) [cut] Now, in a perfect universe I would get an output something like the following (if I run the script with the argument 'python': /Volumes/Home/myuser/python However, Python still hangs on to all the fluff and prints out something else: /Volumes/Home/myuser/['python'] Your newDirectory = ... line is asking for a slice of a list, which returns a list. Python then dutifully converts that list to a string representation and tacks that onto your string/path. What you want is sys.argv[1] (the first argument) not sys.argv[1:] (a list of all but the first argv--namely, all the arguments as [0] is the name of your python script) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting argv to variable
Tom skrev: newDirectory = str(sys.argv[1:]) Try newDir = '/'.join(sys.argv[1:]) or newDir = sys.argv[1] or for newDir in sys.argv[1:]: : or something along those lines, depending on how you wish to interpret the commandline. Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting argv to variable
tgiles [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] (now that I've posted in the wrong flipping newsgroup the first thing, here's my question to the lovely python folks) I've taken a year off (or so) using Python and the first thing I run into utterly stumped me. Been too long and none of the searches I've done seems to have helped any. Basically, I'm trying to create a little script which will make a new directory, using the argument passed to it to give the directory a name: #!/usr/bin/python import sys, os newDirectory = str(sys.argv[1:]) If you are only going to make one dir at a time, newDir = sys.argv[1] currentPath = str(os.getcwd()) create = currentPath + '/' + newDirectory os.path has platform-independent function to do this tjr -- http://mail.python.org/mailman/listinfo/python-list