glob.glob output

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Mar 12 16:33:43 EDT 2007


Hitesh a écrit :
> import string
> import os
> 
> f = open ("c:\\servername.txt", 'r')
> linelist = f.read()
> 
> lineLog = string.split(linelist, '\n')
> lineLog = lineLog [:-1]
> #print lineLog
> for l in lineLog:
>     path1 = "\\\\" + l + "\\server*\\*\\xtRec*"
>     glob.glob(path1)

And ? What are you doing then with return value of glob.glob ?


BTW, seems like an arbitrarily overcomplicated way to do:

from glob import glob
source = open(r"c:\\servername.txt", 'r')
try:
   for line in source:
     if line.strip():
       found = glob(r"\\%s\server*\*\xtRec*" % line)
       print "\n".join(found)
finally:
   source.close()

> When I run above from command line python, It prints the output of
> glob.glob
> but when I run it as a script, it does not print
> anything....

Not without an explicit print statement. This behaviour is useful in the 
interactive python shell, but would be really annoying in normal use.

> I know that there are files like xtRec* inside those
> folders.. and glob.glob does spits the path if run from python command
> line.
> 
> I tried something like this but did not work:
> for l in lineLog:
>     path1 = "\\\\" + l + "\\server*\\*\\xtRec*"
>     xtRec = glob.glob(path1)
>     print xtRec
> 
> No results...

With the same source file, on the same filesystem ? Unless your xtRec* 
files have been deleted between both tests you should have something here.

> xtRec = []
> for l in lineLog:
>     path1 = "\\\\" + l + "\\server*\\*\\xtRec*"
>     xtrec = glob.glob(path1)

You're rebinding xtRec each turn. This is probably not what you want.



More information about the Python-list mailing list