glob problem...

Simon Brunning SBrunning at trisystems.co.uk
Fri Sep 15 11:45:01 EDT 2000


I'm having a bit of a problem with glob. (I'm using Python 2.0b1 and
PythonWin build 134 on WinNT.)

The following all seems to work as expected interactivly:

¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸
>>> import getopt, glob, operator
>>> arguments = ('-h', 'c:\\temp\\lit\\*.txt')
>>> options, arguments = getopt.getopt(arguments, '?h')
>>> arguments = reduce(operator.add, map(glob.glob, arguments))
>>> for option, value in options:
... 	if option[-1] in '?h':
... 		print 'help'
... 
help
>>> for argument in arguments:
... 	        print argument
... 	       
c:\temp\lit\0DDCC10.TXT
c:\temp\lit\1DFRE10.TXT
c:\temp\lit\1EPOE10.TXT
etc.
¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸

But when I try the following script:

¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸
import sys

def main(*arguments):
    import getopt, glob, operator
    options, arguments = getopt.getopt(arguments, '?h')
    arguments = reduce(operator.add, map(glob.glob, arguments))
    for option, value in options:
        if option[-1] in '?h':
            print 'help'
    for argument in arguments:
        # Process file
        print argument

if __name__ == '__main__':
    main(sys.argv[1:])
¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸

I get:

¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸
Traceback (most recent call last):
  File "C:\Python\Pythonwin\pywin\framework\scriptutils.py", line 301, in
RunScript
    exec codeObject in __main__.__dict__
  File "H:\SBrunning\Python\template.py", line 15, in ?
    main(sys.argv[1:])
  File "H:\SBrunning\Python\template.py", line 6, in main
    arguments = reduce(operator.add, map(glob.glob, arguments))
  File "C:\Python\lib\glob.py", line 14, in glob
    if not has_magic(pathname):
  File "C:\Python\lib\glob.py", line 56, in has_magic
    return magic_check.search(s) is not None
TypeError: expected string or buffer
¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø
,¸

Any ideas?

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list