glob.glob output

H

Hitesh

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)

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.... 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...

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

No luck here either.

Seems like I am doing here something reallt silly mistake..

Thank you,
hj
 
H

Hitesh

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)

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.... 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...

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

No luck here either.

Seems like I am doing here something reallt silly mistake..

Thank you,
hj


I am using pythonWin and command line means Interactive Shell.
 
H

Hitesh

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)
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.... 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...
xtRec = []
for l in lineLog:
path1 = "\\\\" + l + "\\server*\\*\\xtRec*"
xtrec = glob.glob(path1)
print xtRec
No luck here either.
Seems like I am doing here something reallt silly mistake..
Thank you,
hj

I am using pythonWin and command line means Interactive Shell.- Hide quoted text -

- Show quoted text -

all right seems like I got it.. it's the looping part. I need to
append the list.

hj
 
B

Bruno Desthuilliers

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.
 
H

Hitesh

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.


Thank you for your reply.
From the return value I am trying to figure out whether the file
xtRec* exist or not.
I am newbie so exuse my ignorance... still learning.
Somehow when I tried your solution, it takes 10mins to scan 200 plus
servers but when I tried my code, it takes less then 2 mins.
This is a puzzle for me, I gotta figure it out.

hj
 
B

Bruno Desthuilliers

Hitesh a écrit :
(snip)
Thank you for your reply.
From the return value I am trying to figure out whether the file
xtRec* exist or not.

Yes, I had understood this !-)

What I wanted to point out was the fact you were discarding this value.
I am newbie so exuse my ignorance... still learning.

Been here, done that... Don't worry. We're all still learning.
Somehow when I tried your solution, it takes 10mins to scan 200 plus
servers but when I tried my code,

Which one ? The original one, or the one where you first store glob
results in a list ?
it takes less then 2 mins.
This is a puzzle for me, I gotta figure it out.

i/o are usually expansive, so the difference may comes from the repeated
print. Also, I'm doing a bit of formatting, which is not your case.

FWIW, my own snippet was just an example of the idiomatic way to read a
text file line by line. Doing TheRightThing(tm) for your actual problem
is your responsability !-)
 
H

Hitesh

Hitesh a écrit :


Yes, I had understood this !-)

What I wanted to point out was the fact you were discarding this value.


Been here, done that... Don't worry. We're all still learning.


Which one ? The original one, or the one where you first store glob
results in a list ?


i/o are usually expansive, so the difference may comes from the repeated
print. Also, I'm doing a bit of formatting, which is not your case.

FWIW, my own snippet was just an example of the idiomatic way to read a
text file line by line. Doing TheRightThing(tm) for your actual problem
is your responsability !-)

Thank you :). I understand that now!

hj
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top