469,609 Members | 1,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

glob.glob output

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

Mar 12 '07 #1
6 3155
On Mar 12, 1:58 pm, "Hitesh" <hitesh...@gmail.comwrote:
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.
Mar 12 '07 #2
On Mar 12, 2:12 pm, "Hitesh" <hitesh...@gmail.comwrote:
On Mar 12, 1:58 pm, "Hitesh" <hitesh...@gmail.comwrote:


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

Mar 12 '07 #3
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.
Mar 12 '07 #4
On Mar 12, 4:33 pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
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
Mar 13 '07 #5
Hitesh a écrit :
On Mar 12, 4:33 pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
>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 !-)
Mar 13 '07 #6
On Mar 13, 11:00 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Hitesh a écrit :
On Mar 12, 4:33 pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
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 !-)
Thank you :-). I understand that now!

hj

Mar 13 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Georgy Pruss | last post: by
5 posts views Thread by Elbert Lev | last post: by
4 posts views Thread by Python Dunce | last post: by
2 posts views Thread by Zain Homer | last post: by
3 posts views Thread by billiejoex | last post: by
5 posts views Thread by jo3c | last post: by
2 posts views Thread by Franz Marksteiner | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.