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? 7 3327 mi**********@gmail.com wrote:
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?
You have told split to split on single blank space not whitespace.
To split on whitespace use .split() (e.g. no arguments)
-Larry
En Wed, 11 Apr 2007 16:13:42 -0300, <mi**********@gmail.comescribió:
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
On Apr 11, 4:10 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Wed, 11 Apr 2007 16:13:42 -0300, <mike.aldr...@gmail.comescribió:
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'
En Wed, 11 Apr 2007 17:15:48 -0300, <mi**********@gmail.comescribió:
The file contents have leading whitespace, then a number:
123456 \n
I expect to return '123456'
And nothing following the number?
pyline = " 123456 \n"
pyprint line.strip()
123456
--
Gabriel Genellina
On Apr 11, 4:20 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Wed, 11 Apr 2007 17:15:48 -0300, <mike.aldr...@gmail.comescribió:
The file contents have leading whitespace, then a number:
123456 \n
I expect to return '123456'
And nothing following the number?
pyline = " 123456 \n"
pyprint line.strip()
123456
--
Gabriel Genellina
That works fine if I am using the interpreter, but I get 'cannot open
file' when i try to read from an archive..
Does that make sense? Sorry, this is my 2nd python script.
En Fri, 13 Apr 2007 08:59:30 -0300, <mi**********@gmail.comescribió:
That works fine if I am using the interpreter, but I get 'cannot open
file' when i try to read from an archive..
Does that make sense? Sorry, this is my 2nd python script.
Try a small, failing example and post the code and the full error
traceback - else it's hard to tell what's happening.
--
Gabriel Genellina
On Apr 11, 1:13 pm, mike.aldr...@gmail.com wrote:
Hi folks,
The first line in the file I am examining will be a number followed by
more whitespace. Looks like I cannot split by whitespace?
but I get 'cannot open
file' when i try to read from an archive..
....and that led you to conclude that you cannot split by whitespace? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lumpierbritches |
last post by:
Thank you in advance for any and all assistance, it is GREATLY appreciated. I
was wondering if there is a way to tell Access 97 to compare the first line
with other textboxes using the...
|
by: Amit Kulkarni |
last post by:
Hi,
I have small problem.
I want to truncate a line in a text file using C file handling
functions and write new line in place of it. How do I do it?
e.g.
"example.txt"
Line 1: This is a...
|
by: shekharpati |
last post by:
hi all,
I,m trying to read a space delimited file with the use of formated
input through fscanf. But surprisingly i am able to read all the 4999
lines of data except the "first line" which is...
|
by: News |
last post by:
Hi Everyone,
The attached code creates client connections to websphere queue managers
and then processes an inquiry against them.
The program functions when it gets options from the command...
|
by: tshad |
last post by:
I have a program that is reading a .csv file into a dataset and works fine
except that it is dropping the first line. I assume that is because it is
dropping the header. The problem is the first...
|
by: aboxylica |
last post by:
I have a file which contains something like this
>ref|NC_001133|
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACA
CATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTT...
|
by: arnuld |
last post by:
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read...
|
by: friend.blah |
last post by:
i have a text file lets say in this format
abc abs ajfhg agjfh
fhs ghg jhgjs fjhg
dj djk djghd dkfdf
....
....
......
i want to read the first line at certain time for eg : at 10clk
|
by: lilyumestar |
last post by:
I have project I have to do for class. We have to write 4 different .java files.
Project2.java
HouseGUI.java
House.java
HouseSorting.java
I already finish House.java and I need to work on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |