Problem with os.path

D

Daya Kiran Sunkara

Hi All,

I have a program which fetches the list of files inside a directory.
For fetching this list I am making use of the glob.glob method which
takes path as a parameter.
For building the path I am making use of os.path.join. My code looks
somewhat like this:
-----------------------------------------------------------------------
import glob
import os
path = 'E:\mktrisk\service\marketdata\da'
for filename in glob.glob(os.path.join(path,'*.java')):
datafile = open(filename,'r').readlines()
----------------------------------------------------------------------

this program works fine when the string 'path' is not too long. When I
pass a longer string as path, the program doesn't work. Now I am not
sure whether its a limitation with the string class or with os.path. I
am passing a valid path to the program and I am running this on Python
2.4.2 on Windows XP.

Any help will be greatly appreciated.

regards,
Daya
 
P

Pelmen

sorry? if i'm wrong? but i'm think you have to use double slash, to
prevent escape-interpreting as '\n' for example
 
S

Scott David Daniels

Daya said:
...
path = 'E:\mktrisk\service\marketdata\da'
You should use:
path = r'E:\mktrisk\service\marketdata\da'
if you want to use backslashes regularly (for regexps and paths).
You do know you could also use:
path = 'E:/mktrisk/service/marketdata/da'
even on windows.

--Scott David Daniels
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,052
Latest member
EvaW192252

Latest Threads

Top