473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3276
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd ...
5
by: Elbert Lev | last post by:
#Here is the script #Python 2.3 on W2K import glob name = glob.glob(u"./*.mp3") print type(name) name = glob.glob(u"*.mp3") print type(name)
4
by: Python Dunce | last post by:
I've run into an issue with glob and matching filenames with brackets '' in them. The problem comes when I'm using part of such a filename as the path I'm passing to glob. Here's a trimmed down...
2
by: Zain Homer | last post by:
Someone please let me know if I'm sending this to the wrong email alias... I'm wondering why we can't use the glob module to glob with curly brackets like we can from the command line (at least...
8
by: mark.bergman | last post by:
I am porting from Digital Unix to Linux (RHEL 4), and am seeing a difference in the return value of glob(). Given a non-existant directory "/tmp/a", and the following line of code: result =...
3
by: billiejoex | last post by:
os.listdir(path) return a list of file names independently if the path- argument used is absolute or relative: '/home/user' glob.glob, instead, return file names only if given path is...
1
by: crybaby | last post by:
when I do this in my python code and run it in windows xp, it creates ctemp/..../.../.../../ so on and creates file t. Not file starting with the name complist and ending with .txt...
5
by: jo3c | last post by:
hi everyone happy new year! im a newbie to python i have a question by using linecache and glob how do i read a specific line from a file in a batch and then insert it into database? because...
2
by: Franz Marksteiner | last post by:
Hi folks, is there a way to negate a glob() pattern? What I want is to get a tree structure, e.g. all .php files *and* all directories. How would I start here? -- Freundliche Grüße, Franz...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.