Converting argv to variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tgiles

    Converting argv to variable

    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:])

    currentPath = str(os.getcwd() )

    create = currentPath + '/' + newDirectory

    print create

    # os.mkdir(create )

    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']

    I know there must be some way to convert the argument to a 'normal'
    variable, but it escapes me how to do so. Any pointers?

    Thanks!

    tom

  • Janwillem Borleffs

    #2
    Re: Converting argv to variable

    tgiles wrote:
    I know there must be some way to convert the argument to a 'normal'
    variable, but it escapes me how to do so. Any pointers?
    >
    Perhaps try a python newsgroup? PHP != Python...


    JW


    Comment

    • tgiles

      #3
      Re: Converting argv to variable

      Janwillem Borleffs wrote:
      tgiles wrote:
      I know there must be some way to convert the argument to a 'normal'
      variable, but it escapes me how to do so. Any pointers?
      >
      Perhaps try a python newsgroup? PHP != Python...
      >
      >
      JW
      This is the wrong newsgroup. My apologies.

      Cheers,

      tom

      Comment

      Working...