Problem with os.path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daya Kiran Sunkara

    #1

    Problem with os.path

    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\ser vice\marketdata \da'
    for filename in glob.glob(os.pa th.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
  • Pelmen

    #2
    Re: Problem with os.path

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

    Comment

    • Scott David Daniels

      #3
      Re: Problem with os.path

      Daya Kiran Sunkara wrote:[color=blue]
      > ...
      > path = 'E:\mktrisk\ser vice\marketdata \da'[/color]
      You should use:
      path = r'E:\mktrisk\se rvice\marketdat a\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
      scott.daniels@a cm.org

      Comment

      Working...