473,702 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ba sedir,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 1641
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(ba sedir,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(ba sedir,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(ba sedir,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(ba sedir, picdir)):
blah blah
is a lot better than comparing to True.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4105
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the results, then doing a self left join with those results, etc. What puzzles me is that the time required for the query seems to grow exponentially as I add additional left joins, which I didn't expect. I expected the inner select to return about 25...
3
6467
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
2
2060
by: smauldin | last post by:
Why does the execution plan have a nested loop join for a simple select with an UDF in the where clause? Here is the query: select * from test_plan where vCol = my_udf('test') Here is the table definition: create table test_plan(iCol integer, vCol varchar(20))
12
3985
by: coosa | last post by:
Dear all, I have table called CATEGORY, which is defined as follows: CREATE TABLE CATEGORY ( CATEGORY_ID INTEGER IDENTITY(1,1) NOT NULL, CATEGORY_NAME VARCHAR(40) NOT NULL CONSTRAINT UC__CATEGORY__CATEGORY_NAME UNIQUE, PARENT_CATEGORY_ID INTEGER,
1
1806
by: tsuraan | last post by:
Supposing that I have a directory tree like so: a/ __init__.py b/ __init__.py c.py and b.py has some method (let's call it d) within it. I can, from python, do:
2
1209
by: Gigs_ | last post by:
i have this function. def f(start): stack = def f1(start): for fname in os.listdir(startDir): path = os.path.join(startDir, fname) if os.path.isfile(path): stack.append(path) else:
1
1830
by: crybaby | last post by:
when I do this in my python code and run it in windows xp, it creates ctemp/..../.../.../../ so on and creates file t. Not file starting with the name complist and ending with .txt (complist*.txt). Any idea why this may be? glob only works in *nix not on windows? os.renames(glob.glob('complist*.txt') ,r'temp/'.join(glob.glob('complist*.txt')))
0
1365
by: Jean-Paul Calderone | last post by:
On Mon, 05 May 2008 16:28:33 +0200, Paul Scott <pscott@uwc.ac.zawrote: How about not nesting the calls? True Jean-Paul
8
2676
by: kj | last post by:
How can a script know its absolute path? (__file__ only gives the path it was used to invoke the script.) Basically, I'm looking for the Python equivalent of Perl's FindBin. The point of all this is to make the scripts location the reference point for the location of other files, as part of a self-contained distribution. TIA!
0
8738
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7829
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6575
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.