Noobie Question: Using strings and paths in mkdir (os.mkdir("/test/"a))

Discussion in 'Python' started by Shaun, Apr 22, 2005.

  1. Shaun

    Shaun Guest

    Hello!

    I can't seem to get paths and variables working together:

    import os
    a = 'books'
    os.chdir( '/test')
    os.mkdir("/test/"a)

    the last line does not seem to work. os.mkdir(a) makes the directory
    books, but i want this directory as a subdirectory of test.

    I also tried: os.mkdir("/test/",a), and trying to make b = 'test' and
    then os.mkdir(a b).

    Does someone have any ideas or a link they can give me, I looked under
    strings in the python tutorial and library manual but I guess not in
    the right spot.

    Thanks for your help!

    Shaun
     
    Shaun, Apr 22, 2005
    #1
    1. Advertising

  2. Re: Noobie Question: Using strings and paths in mkdir(os.mkdir("/test/"a))

    # / 2005-04-22 00:13:05 -0700:
    > Hello!
    >
    > I can't seem to get paths and variables working together:
    >
    > import os
    > a = 'books'
    > os.chdir( '/test')
    > os.mkdir("/test/"a)
    >
    > the last line does not seem to work. os.mkdir(a) makes the directory
    > books, but i want this directory as a subdirectory of test.
    >
    > I also tried: os.mkdir("/test/",a), and trying to make b = 'test' and
    > then os.mkdir(a b).
    >
    > Does someone have any ideas or a link they can give me, I looked under
    > strings in the python tutorial and library manual but I guess not in
    > the right spot.


    http://docs.python.org/ref/string-catenation.html

    --
    How many Vietnam vets does it take to screw in a light bulb?
    You don't know, man. You don't KNOW.
    Cause you weren't THERE. http://bash.org/?255991
     
    Roman Neuhauser, Apr 22, 2005
    #2
    1. Advertising

  3. Re: Noobie Question: Using strings and paths in mkdir(os.mkdir("/test/"a))

    On 4/22/05, Roman Neuhauser <neuhauser+python-list#> wrote:
    > > import os
    > > a = 'books'
    > > os.chdir( '/test')
    > > os.mkdir("/test/"a)
    > >
    > > the last line does not seem to work. os.mkdir(a) makes the directory
    > > books, but i want this directory as a subdirectory of test.

    > http://docs.python.org/ref/string-catenation.html


    For this job, os.path.join() might be better. See
    <http://docs.python.org/lib/module-os.path.html>.

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Apr 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    351
  2. Noah
    Replies:
    5
    Views:
    846
  3. ProvoWallis

    noobie mkdir problem/question

    ProvoWallis, Mar 25, 2006, in forum: Python
    Replies:
    5
    Views:
    338
    Dennis Lee Bieber
    Mar 26, 2006
  4. Replies:
    3
    Views:
    391
    huntedsnark
    Aug 24, 2006
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    223
    David Vallner
    Nov 7, 2006
Loading...

Share This Page