On Apr 11, 4:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 11 Apr 2007 16:13:42 -0300, <[EMAIL PROTECTED]> escribió: > > > > > > > Hi folks, > > I am trying to read the first occurence of non-whitespace in a file, > > within a zipfile. Here is my code: > > > zipnames = glob.glob("<search_dir>*") > > for zipname in zipnames: > > z = zipfile.ZipFile(zipname, "r") > > for filename in z.namelist(): > > count = len(z.read(filename).split('\n')) > > if fnmatch.fnmatch(filename, "*AUDIT*"): > > test = filename.split(' ') > > print 'File:', test[0], > > bytes = z.read(filename) > > print 'has', len(bytes), 'bytes' > > print 'and', count, 'lines' > > > The first line in the file I am examining will be a number followed by > > more whitespace. Looks like I cannot split by whitespace? > > Your code does nothing with the first line on the file; you only split the > *filename* on whitespace. And you extract the file twice. > You don't even try to find "the first occurence of non-whitespace". Surely > an example of file contents and what output you really expect from it > would be adequate. > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text -
The file contents have leading whitespace, then a number: 123456 \n I expect to return '123456' -- http://mail.python.org/mailman/listinfo/python-list