Re: Question about Reading from text file with Python's Array class

2011-12-18 Thread Tim Chase
On 12/18/11 12:33, traveller3141 wrote: To test this, I made a small sample file (sillyNums.txt) as follows; 109 345 2 1234556 f=open("sillyNums.txt","r") data = array.array('i') data.fromstring(f.read(data.itemsize* bufferSize)) print data The output was nonsense: array('i', [171520049, 171258

Re: Question about Reading from text file with Python's Array class

2011-12-18 Thread Peter Otten
traveller3141 wrote: > I've been trying to use the Array class to read 32-bit integers from a > file. There is one integer per line and the integers are stored as text. > For problem specific reasons, I only am allowed to read 2 lines (2 32-bit > integers) at a time. > > To test this, I made a sm

Question about Reading from text file with Python's Array class

2011-12-18 Thread traveller3141
I've been trying to use the Array class to read 32-bit integers from a file. There is one integer per line and the integers are stored as text. For problem specific reasons, I only am allowed to read 2 lines (2 32-bit integers) at a time. To test this, I made a small sample file (sillyNums.txt) as

Re: Reading from text

2009-03-08 Thread Steve Holden
Aahz wrote: > In article , > Tim Chase wrote: >>> Assuming this is a real task and not a homework problem, then >>> I'd do it this way: >>> >>> $ cd [directory containing 50 test files] >>> $ (for file in *; do head -n11 $file | tail -n5; done) >>> >/path/to/results-file.txt >> I'd use sed:

Re: Reading from text

2009-03-06 Thread Paul McGuire
On Feb 17, 11:03 am, oamram wrote: > Hi All, > new to python. i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another file(one file > that will contain all lines). > import glob file("output.txt","w")

Re: Reading from text

2009-03-06 Thread Aahz
In article , Tim Chase wrote: >> Assuming this is a real task and not a homework problem, then >> I'd do it this way: >> >> $ cd [directory containing 50 test files] >> $ (for file in *; do head -n11 $file | tail -n5; done) >> >/path/to/results-file.txt > >I'd use sed: > > sed -ns 7,11p /

Re: Reading from text

2009-02-17 Thread Grant Edwards
On 2009-02-17, Tim Chase wrote: >> Assuming this is a real task and not a homework problem, then >> I'd do it this way: >> >> $ cd [directory containing 50 test files] >> $ (for file in *; do head -n11 $file | tail -n5; done) >> >/path/to/results-file.txt > > I'd use sed: > >sed -ns 7,11

Re: Reading from text

2009-02-17 Thread Tim Chase
Assuming this is a real task and not a homework problem, then I'd do it this way: $ cd [directory containing 50 test files] $ (for file in *; do head -n11 $file | tail -n5; done) >/path/to/results-file.txt I'd use sed: sed -ns 7,11p /source/path/*.txt >/path/to/results.txt hard to get

Re: Reading from text

2009-02-17 Thread Grant Edwards
On 2009-02-17, oamram wrote: > i have a directory with about 50 text file and i need to > iterate through them and get line 7 to 11 from each file and > write those lines into another file(one file that will contain > all lines). Assuming this is a real task and not a homework problem, then I'd

Re: Reading from text

2009-02-17 Thread MRAB
bearophileh...@lycos.com wrote: oamram: i have a directory with about 50 text file and i need to iterate through them and get line 7 to 11 from each file and write those lines into another file(one file that will contain all lines). Files can be iterated line-by-line, so this idiom: for line

Re: Reading from text

2009-02-17 Thread bearophileHUGS
oamram: > i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another > file(one file that will contain all lines). Files can be iterated line-by-line, so this idiom: for line in file: ... will give you

Re: Reading from text

2009-02-17 Thread JB
oamram a écrit : Hi All, new to python. i have a directory with about 50 text file and i need to iterate through them and get line 7 to 11 from each file and write those lines into another file(one file that will contain all lines). First create a function that read and parse one file Then cre

Reading from text

2009-02-17 Thread oamram
-from-text-tp22061427p22061427.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading from text file

2008-08-26 Thread Fredrik Lundh
A. Joseph wrote: I want to read from text file, 25 lines each time i press enter key, just like the python documentation. you can use pydoc's pager from your program: import pydoc text = open(filename).read() pydoc.pager(text) -- http://mail.python.org/mailman/listinfo/python-

Reading from text file

2008-08-26 Thread A. Joseph
I want to read from text file, 25 lines each time i press enter key, just like the python documentation. i`m using Python 2.5, Windows XP Thank you -- http://mail.python.org/mailman/listinfo/python-list