473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem with join

hi
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them

folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)

now when i print the filenameslist i find that it looks like

['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']

is there some problem with the way i use join? why do i get \\ infront
of the basename?
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',

can anyone pls help
gordon
Mar 7 '08 #1
6 1583
On Mar 7, 9:12 am, nodrogbrown <nodrogbr...@gmail.comwrote:
hi
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them

folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)

now when i print the filenameslist i find that it looks like

['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']

is there some problem with the way i use join? why do i get \\ infront
of the basename?
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',

can anyone pls help
gordon
see path.join in the os library.
Mar 7 '08 #2
nodrogbrown wrote:
hi
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them

folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)

now when i print the filenameslist i find that it looks like

['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']

is there some problem with the way i use join? why do i get \\ infront
of the basename?
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',
os.path.join()
http://docs.python.org/lib/module-os.path.html#l2h-2185

vs.

string.join()
http://docs.python.org/lib/node42.html#l2h-379

RB
Mar 7 '08 #3
nodrogbrown wrote:
hi
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them

folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)

now when i print the filenameslist i find that it looks like

['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']

is there some problem with the way i use join? why do i get \\ infront
of the basename?
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',
You've got a couple of options. Your "folder" to start
with is in the unixy form a/b/c and the .join function
doesn't do anything to change that, merely uses os.pathsep
to append the parts to each other.

You can either set your folder to be r"f:\brown\code..."
in the first case or use os.path.normpath or os.path.abspath
on the result.

TJG
Mar 7 '08 #4
On Mar 7, 9:33 am, corynis...@gmail.com wrote:
On Mar 7, 9:12 am, nodrogbrown <nodrogbr...@gmail.comwrote:
hi
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them
folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)
now when i print the filenameslist i find that it looks like
['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']
is there some problem with the way i use join? why do i get \\ infront
of the basename?
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',
can anyone pls help
gordon

see path.join in the os library.
Upon further examination... it looks like you are using windows and
os.path.join.

The separator for windows is a '\'. In python, you have to escape
that character with another '\'. That's why you see '\\'.

That being said, I think what you have will still work to access a
file. Windows is usually smart enough to deal with a front slash here
and there.

Mar 7 '08 #5
En Fri, 07 Mar 2008 13:12:13 -0200, nodrogbrown <no*********@gmail.com>
escribi�:
i am using python on WinXP..i have a string 'folder ' that i want to
join to a set of imagefile names to create complete qualified names so
that i can create objects out of them

folder='F:/brown/code/python/fgrp1'
filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist=[]
for x in filenms:
myfile=join(folder,x)
filenameslist.append(myfile)

now when i print the filenameslist i find that it looks like

['F:/brown/code/python/fgrp1\\amber1.jpg',
'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
\amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']

is there some problem with the way i use join? why do i get \\ infront
of the basename?
join is fine. "\\" is a single character. \ is used as the escape
character, and has to be doubled when representing itself. Print an
individual element to see the effect:

print filenameslist[0]
F:/brown/code/python/fgrp1\amber1.jpg

(a list uses repr() on its elements instead of str()).
i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',
If the string is only used to open a file, and never shown to the user,
what you prefer is irrelevant, isn't it?
What is important here is what Windows prefers, and that's a backslash,
although many times / is accepted too. You can convert the file names to
their preferred spelling using os.path.normpath

Back to your code, try this:

from os.path import join, normpath
folder = 'F:/brown/code/python/fgrp1'
names = ['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist = [normpath(join(folder, name)) for name in names]

--
Gabriel Genellina

Mar 7 '08 #6
If the string is only used to open a file, and never shown to the user,
what you prefer is irrelevant, isn't it?
guess thats right..
Back to your code, try this:

from os.path import join, normpath
folder = 'F:/brown/code/python/fgrp1'
names = ['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
filenameslist = [normpath(join(folder, name)) for name in names]

thanks Gabriel..
gordon
Mar 7 '08 #7

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

Similar topics

16
by: Ling Lee | last post by:
Hello. I'm trying to write a small program that lets you put in a number as an integer and then it tells you the textuel representation of the number. Like if your input is 42, it will say...
2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
1
by: Keith | last post by:
I have created a view to test some of the data in my database. I am relatively new to SQL so may have caused this problem by doing something wrong. I have a table called SYS_Individual which...
14
by: signaturefactory | last post by:
I am trying the following query in and oleDbCommand: SELECT PartLocations.LocationName, Sum(PartsJournal.Quantity) AS SumOfQuantity, PartsJournal.PartsLotNumber FROM PartLocations INNER JOIN...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
27
by: John Salerno | last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's turning out to be quite a pain to wrap my mind around. It's from a puzzle game. It will help if you look at this image: ...
1
by: imranpariyani | last post by:
Hi i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated.. the view is: CREATE OR REPLACE VIEW thsn.trade_view AS SELECT...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
3
by: Anila | last post by:
Hi Friends, My problem with Inner join is ... first i joined two tables and i got the result. after that iam trying to join one more table its giving syn tax error in JOIN condition. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...

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.