John Machin wrote:
>> 'sed' is not recognized as an internal or external command,
>> operable program or batch file.
>
> aarrbejaysus #2: Download the installer from
>
> http://gnuwin32.sourceforge.net/packages/sed.htm
in a way, this kind of advice reminds me of
http://thedailywtf.co
On 16/07/2006 5:16 PM, Fredrik Lundh wrote:
> Bill Pursell wrote:
>
>> Some might argue that this is not really doing
>> it in Python. In fact, I would argue that! But if
>> you're at a command prompt and you want to
>> see line 7358, it's much easier to type
>> % sed -n 7358p
aarrbejaysus #1:
In message <[EMAIL PROTECTED]>, Yi Xing
wrote:
> I want to read specific lines of a huge txt file (I know the line #).
> Each line might have different sizes. Is there a convenient and fast
> way of doing this in Python? Thanks.
file("myfile.txt").readlines()[LineNr]
Convenient, yes. Fast, n
In message <[EMAIL PROTECTED]>, Fredrik
Lundh wrote:
> Bill Pursell wrote:
>
>> Some might argue that this is not really doing
>> it in Python. In fact, I would argue that! But if
>> you're at a command prompt and you want to
>> see line 7358, it's much easier to type
>> % sed -n 7358p
>> than
Bill Pursell wrote:
> Some might argue that this is not really doing
> it in Python. In fact, I would argue that! But if
> you're at a command prompt and you want to
> see line 7358, it's much easier to type
> % sed -n 7358p
> than it is to write the python one-liner.
'sed' is not recognized as
On 16/07/2006 2:54 PM, Nick Vatamaniuc top-posted:
> Yi,
> Use the linecache module.
Yi, *don't* use the linecache module without carefully comparing the
documentation and the implementation with your requirements.
You will find that you have the source code on your computer -- mine
(Windows bo
Yi,
Use the linecache module. The documentation states that :
"""
The linecache module allows one to get any line from any file, while
attempting to optimize internally, using a cache, the common case where
many lines are read from a single file.
>>> import linecache
>>> linecache.getline('/etc/pas
Pierre Quentel:
> If the line number of the first line is 0 :
> source=open('afile.txt')
> for i,line in enumerate(source):
> if i == line_num:
> break
> print line
I don't know if something like this can be called an improvement:
from itertools import islice
afile = file('data.txt')
In <[EMAIL PROTECTED]>, Yi Xing wrote:
> I want to read specific lines of a huge txt file (I know the line #).
> Each line might have different sizes. Is there a convenient and fast
> way of doing this in Python? Thanks.
Don't know how efficient the `linecache` module in the standard library is
Yi Xing wrote:
> Hi All,
>
> I want to read specific lines of a huge txt file (I know the line #).
> Each line might have different sizes. Is there a convenient and fast
> way of doing this in Python? Thanks.
>
> Yi Xing
I once had to do a lot of random access of lines in a multi gigabyte
log file
Yi Xing wrote:
> I want to read specific lines of a huge txt file (I know the line #).
> Each line might have different sizes. Is there a convenient and fast
> way of doing this in Python? Thanks.
#!/usr/bin/env python
import os,sys
line = int(sys.argv[1])
path = sys.argv[2]
os.system("sed -n %d
> Yi Xing <[EMAIL PROTECTED]> (YX) wrote:
>YX> Hi All,
>YX> I want to read specific lines of a huge txt file (I know the line #). Each
>YX> line might have different sizes. Is there a convenient and fast way of
>YX> doing this in Python? Thanks.
Not fast. You have to read all preceding lines.
If the line number of the first line is 0 :
source=open('afile.txt')
for i,line in enumerate(source):
if i == line_num:
break
print line
Pierre
--
http://mail.python.org/mailman/listinfo/python-list
Hi All,
I want to read specific lines of a huge txt file (I know the line #).
Each line might have different sizes. Is there a convenient and fast
way of doing this in Python? Thanks.
Yi Xing
--
http://mail.python.org/mailman/listinfo/python-list
14 matches
Mail list logo