Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Noobie Question: Using strings and paths in mkdir (os.mkdir("/test/"a))

Reply
Thread Tools

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

 
 
Shaun
Guest
Posts: n/a
 
      04-22-2005
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
 
Reply With Quote
 
 
 
 
Roman Neuhauser
Guest
Posts: n/a
 
      04-22-2005
# http://www.velocityreviews.com/forums/(E-Mail Removed) / 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
 
Reply With Quote
 
 
 
 
Simon Brunning
Guest
Posts: n/a
 
      04-22-2005
On 4/22/05, Roman Neuhauser <neuhauser+python-list#(E-Mail Removed)> 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,
(E-Mail Removed),
http://www.brunningonline.net/simon/blog/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[trunk/r14273] File.mkdir() -> Dir.mkdir() in enc/make_encma Ollivier Robert Ruby 0 12-17-2007 03:48 PM
Paths, gentleman, paths Ohad Lutzky Ruby 2 11-07-2006 02:15 AM
Relative Paths (noobie question) maharg@cinci.rr.com C++ 3 08-24-2006 07:20 PM
noobie mkdir problem/question ProvoWallis Python 5 03-26-2006 04:15 AM
Convert between Windows style paths and POSIX style paths Noah Python 5 07-11-2003 09:25 PM



Advertisments