By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
# sm******@gmail.com / 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
Jul 19 '05 #2

P: n/a
On 4/22/05, Roman Neuhauser <ne******************************@sigpipe.cz> 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,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.