469,579 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Nested os.path.join()'s


Today, I needed to concatenate a bunch of directory paths and files
together based on user input to create file paths. I achieved this
through nested os.path.join()'s which I am unsure if this is a good
thing or not.

example:

if os.path.exists(os.path.join(basedir,picdir)) == True :
blah blah

Question is, is there a better way of doing this? The above *works* but
it looks kinda hackish...

--Paul
All Email originating from UWC is covered by disclaimer
http://www.uwc.ac.za/portal/public/p...disclaimer.htm

Jun 27 '08 #1
2 1497
On 2008-05-05, Paul Scott <ps****@uwc.ac.zawrote:
Today, I needed to concatenate a bunch of directory paths and files
together based on user input to create file paths. I achieved this
through nested os.path.join()'s which I am unsure if this is a good
thing or not.

example:

if os.path.exists(os.path.join(basedir,picdir)) == True :
blah blah
That's not an example of nested os.path.join()'s.
Question is, is there a better way of doing this?
I don't think so.
The above *works* but it looks kinda hackish...
What about it do you think looks hackish?

I supposed you could do this instead:

path = os.path.join(basedir,picdir)
if os.path.exists(path) == True :
blah blah

But I don't really see why that's any better.

--
Grant Edwards grante Yow! Like I always say
at -- nothing can beat
visi.com the BRATWURST here in
DUSSELDORF!!
Jun 27 '08 #2
Paul Scott wrote:
... example:
if os.path.exists(os.path.join(basedir,picdir)) == True :
blah blah

Question is, is there a better way of doing this? The above *works* but
it looks kinda hackish...
You've had the joining addressed elsewhere, but note that:
if os.path.exists(os.path.join(basedir, picdir)):
blah blah
is a lot better than comparing to True.

--Scott David Daniels
Sc***********@Acm.Org
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tcs | last post: by
1 post views Thread by tsuraan | last post: by
2 posts views Thread by Gigs_ | last post: by
reply views Thread by Jean-Paul Calderone | last post: by
8 posts views Thread by kj | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.