glob.glob output

Discussion in 'Python' started by Hitesh, Mar 12, 2007.

  1. Hitesh

    Hitesh Guest

    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
    Hitesh, Mar 12, 2007
    #1
    1. Advertising

  2. Hitesh

    Hitesh Guest

    On Mar 12, 1:58 pm, "Hitesh" <> wrote:
    > 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.
    Hitesh, Mar 12, 2007
    #2
    1. Advertising

  3. Hitesh

    Hitesh Guest

    On Mar 12, 2:12 pm, "Hitesh" <> wrote:
    > On Mar 12, 1:58 pm, "Hitesh" <> wrote:
    >
    >
    >
    >
    >
    > > 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
    Hitesh, Mar 12, 2007
    #3
  4. 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.
    Bruno Desthuilliers, Mar 12, 2007
    #4
  5. Hitesh

    Hitesh Guest

    On Mar 12, 4:33 pm, Bruno Desthuilliers
    <> wrote:
    > 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
    Hitesh, Mar 13, 2007
    #5
  6. Hitesh a écrit :
    > On Mar 12, 4:33 pm, Bruno Desthuilliers
    > <> wrote:
    >> 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 !-)
    Bruno Desthuilliers, Mar 13, 2007
    #6
  7. Hitesh

    Hitesh Guest

    On Mar 13, 11:00 am, Bruno Desthuilliers <bruno.
    > wrote:
    > Hitesh a écrit :
    >
    > > On Mar 12, 4:33 pm, Bruno Desthuilliers
    > > <> wrote:
    > >> 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
    Hitesh, Mar 13, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    714
    Tim Roberts
    Dec 1, 2003
  2. Tim Peters
    Replies:
    1
    Views:
    350
    Duncan Booth
    Dec 1, 2003
  3. Sean Berry

    Question about glob.glob <--newbie

    Sean Berry, May 4, 2004, in forum: Python
    Replies:
    3
    Views:
    342
    David M. Cooke
    May 4, 2004
  4. Elbert Lev

    glob.glob unicode bug or feature

    Elbert Lev, Jul 31, 2004, in forum: Python
    Replies:
    5
    Views:
    383
    Neil Hodgson
    Aug 2, 2004
  5. billiejoex

    glob.glob standardization

    billiejoex, Jun 27, 2007, in forum: Python
    Replies:
    3
    Views:
    261
    Tim Roberts
    Jun 29, 2007
Loading...

Share This Page