Re: seek operation in python

2015-04-30 Thread Larry Hudson
On 04/30/2015 01:50 PM, Cecil Westerhof wrote: Op Thursday 30 Apr 2015 21:38 CEST schreef Larry Hudson: On 04/30/2015 01:06 AM, Cecil Westerhof wrote: [snip] I wrote a module where I have: def get_indexed_message(message_filename, index): """ Get index message from a file, where 0 gets the fi

Re: seek operation in python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 21:38 CEST schreef Larry Hudson: > On 04/30/2015 01:06 AM, Cecil Westerhof wrote: > [snip] > >> I wrote a module where I have: >> def get_indexed_message(message_filename, index): >> """ >> Get index message from a file, where 0 gets the first message >> """ >> >> return op

Re: seek operation in python

2015-04-30 Thread Larry Hudson
On 04/30/2015 01:06 AM, Cecil Westerhof wrote: [snip] I wrote a module where I have: def get_indexed_message(message_filename, index): """ Get index message from a file, where 0 gets the first message """ return open(expanduser(message_filename), 'r').r

Re: seek operation in python

2015-04-30 Thread Cecil Westerhof
Op Wednesday 29 Apr 2015 20:08 CEST schreef siva sankari R.: > file=open("input","r") > line=file.seek(7) > print line > > The above code is supposed to print a line but it prints "none". I > don't know where the mistake is. Help.! You could use my module: https://github.com/CecilWesterhof/P

Re: seek operation in python

2015-04-30 Thread Chris Angelico
On Thu, Apr 30, 2015 at 7:06 PM, Cecil Westerhof wrote: > I already done it. I thought it not to much work. And it even makes > some code shorter: > -marshal_file= open(expanduser(marshal_filename), 'r') > -not_list= load(marshal_file) > -marshal_file.close() > -return

Re: seek operation in python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 10:31 CEST schreef Dave Angel: > On 04/30/2015 04:06 AM, Cecil Westerhof wrote: >> Op Thursday 30 Apr 2015 09:33 CEST schreef Chris Angelico: >> >>> On Thu, Apr 30, 2015 at 4:27 PM, Cecil Westerhof wrote: > with open("input.cpp") as f: > lines = f.readlines() >

Re: seek operation in python

2015-04-30 Thread Dave Angel
On 04/30/2015 04:06 AM, Cecil Westerhof wrote: Op Thursday 30 Apr 2015 09:33 CEST schreef Chris Angelico: On Thu, Apr 30, 2015 at 4:27 PM, Cecil Westerhof wrote: with open("input.cpp") as f: lines = f.readlines() print(lines[7]) Is the following not better: print(open('input.cpp', 'r').read

Re: seek operation in python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 09:33 CEST schreef Chris Angelico: > On Thu, Apr 30, 2015 at 4:27 PM, Cecil Westerhof wrote: >>> with open("input.cpp") as f: >>> lines = f.readlines() >>> print(lines[7]) >> >> Is the following not better: >> print(open('input.cpp', 'r').readlines()[7]) >> >> Time is the

Re: seek operation in python

2015-04-30 Thread Chris Angelico
On Thu, Apr 30, 2015 at 4:27 PM, Cecil Westerhof wrote: >> with open("input.cpp") as f: >> lines = f.readlines() >> print(lines[7]) > > Is the following not better: > print(open('input.cpp', 'r').readlines()[7]) > > Time is the same (about 25 seconds for 100.000 calls), but I find this > more

Re: seek operation in python

2015-04-29 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 02:33 CEST schreef Chris Angelico: > On Thu, Apr 30, 2015 at 4:08 AM, siva sankari R > wrote: >> file=open("input","r") >> line=file.seek(7) >> print line >> >> The above code is supposed to print a line but it prints "none". I >> don't know where the mistake is. Help.! >

Re: seek operation in python

2015-04-29 Thread Chris Angelico
On Thu, Apr 30, 2015 at 4:08 AM, siva sankari R wrote: > file=open("input","r") > line=file.seek(7) > 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 w

Re: seek operation in python

2015-04-29 Thread Steven D'Aprano
On Thu, 30 Apr 2015 06:53 am, Mark Lawrence wrote: > The only good top poster is a dead top poster, except for... Since you just top posted, at least you're being honest. Mark, I'm fairly sure you were trying to be funny, but I think you just crossed a line from "funny and mean" to "just mean bu

Re: seek operation in python

2015-04-29 Thread Mark Lawrence
The only good top poster is a dead top poster, except for... On 29/04/2015 19:42, Billy Earney wrote: if your filename is input.cpp, you first line of code should be: file=open("input*.cpp*","r") On Wed, Apr 29, 2015 at 1:26 PM, siva sankari R wrote: There is a file named "input.cpp"(c++ fi

Re: seek operation in python

2015-04-29 Thread John Gordon
In <8b2bd328-08a6-4211-85c4-8d117d1aa...@googlegroups.com> siva sankari R writes: > file=open("input","r") > line=file.seek(7) > print line > The above code is supposed to print a line but it prints "none". > I don't know where the mistake is. Help.! The seek() function doesn't return any data

Re: seek operation in python

2015-04-29 Thread MRAB
On 2015-04-29 19:08, siva sankari R wrote: file=open("input","r") line=file.seek(7) print line The above code is supposed to print a line but it prints "none". I don't know where the mistake is. Help.! 'seek' will seek to position 7 in the file. It doesn't read. That's what 'read' is for! :-)

Re: seek operation in python

2015-04-29 Thread Billy Earney
if your filename is input.cpp, you first line of code should be: file=open("input*.cpp*","r") On Wed, Apr 29, 2015 at 1:26 PM, siva sankari R wrote: > There is a file named "input.cpp"(c++ file) that contains some 80 lines of > code. > -- > https://mail.python.org/mailman/listinfo/python-list >

Re: seek operation in python

2015-04-29 Thread siva sankari R
There is a file named "input.cpp"(c++ file) that contains some 80 lines of code. -- https://mail.python.org/mailman/listinfo/python-list

Re: seek operation in python

2015-04-29 Thread Joel Goldstick
On Wed, Apr 29, 2015 at 2:08 PM, siva sankari R wrote: > file=open("input","r") > line=file.seek(7) > print line > > The above code is supposed to print a line but it prints "none". I don't know > where the mistake is. Help.! > -- > https://mail.python.org/mailman/listinfo/python-list What is in

seek operation in python

2015-04-29 Thread siva sankari R
file=open("input","r") line=file.seek(7) print line The above code is supposed to print a line but it prints "none". I don't know where the mistake is. Help.! -- https://mail.python.org/mailman/listinfo/python-list