seek operation in python
Cecil at decebal.nl
Thu Apr 30 08:27:29 CEST 2015
Op Thursday 30 Apr 2015 02:33 CEST schreef Chris Angelico:
> On Thu, Apr 30, 2015 at 4:08 AM, siva sankari R <buddingrose11 at gmail.com> wrote:
>> print line
>> The above code is supposed to print a line but it prints "none". I
>> don't know where the mistake is. Help.!
> Going right back to the beginning... Are you aware that 'seek' works
> with byte positions? On a text file, you can't even do this, and
> even on a byte file, it won't give you the seventh line.
> If, as you say, it's only some eighty lines of code, the best
> solution is probably the simplest: read the whole file into memory.
> with open("input.cpp") as f:
> lines = f.readlines()
Is the following not better:
Time is the same (about 25 seconds for 100.000 calls), but I find this
Senior Software Engineer
More information about the Python-list