Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Lie Ryan
Friðrik Már Jónsson wrote: Hi Rhodri, It's only really a pitfall if you try to use the built-in after you've redefined it. That's the thing to keep an eye open for. You're right, but in cases where you're editing a codebase which you didn't author entirely by yourself you may not be

Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Lie Ryan
Simon Forman wrote: On Thu, Jul 9, 2009 at 9:42 AM, Nicknleio...@gmail.com wrote: snip fields = line.split() for i in range(len(fields)): fields[i] = float(fields[i]) instead of the above code you could say: fields = [float(n) for n in in line.split()] Have fun getting

Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Nick
On Jul 9, 8:22 pm, Paul Rubin http://phr...@nospam.invalid wrote: Nick nleio...@gmail.com writes: text = file.readlines() len = len(text) fields = text[1].split() Is that intended to split the first line of the file? Remember that arrays in python begin at index 0. no the '1st line' is

Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 13:53 +, Friðrik Már Jónsson wrote: Look at: len = len(text) You're overriding `len` (a built-in method), with an integer (`len(text)`). You then call: for i in range(len(fields)): But `len` is no longer a callable, but merely an integer.

gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Nick
I've seen a lot of posts on this problem, but none seems to help. Here is the code: /code file = open(prefix1) text = file.readlines() len = len(text) fields = text[1].split() num_rows = int(fields[1]) num_cols = int(fields[2]) U1_matrix = [] print fields print repr(fields) print len(fields)

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Lutz Horn
Hi, Nick schrieb: I've seen a lot of posts on this problem, but none seems to help. Could you please post a sample input file and the exact error message? Thanks Lutz -- Strike Out ⇒ http://www.fourmilab.ch/documents/strikeout -- http://mail.python.org/mailman/listinfo/python-list

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Friðrik Már Jónsson
Look at: len = len(text) You're overriding `len` (a built-in method), with an integer (`len(text)`). You then call: for i in range(len(fields)): But `len` is no longer a callable, but merely an integer. Regards, Friðrik Már P.S. While this is a fairly obvious problem it's usually a

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Richard Brodie
Nick nleio...@gmail.com wrote in message news:e54c4461-c0b7-42fb-8542-cefd7bf5f...@h18g2000yqj.googlegroups.com... file = open(prefix1) text = file.readlines() len = len(text) You have redefined two built-in functions file and len in the first three lines. This is usually considered poor

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Nick
On Jul 9, 10:02 am, Richard Brodie r.bro...@rl.ac.uk wrote: Nick nleio...@gmail.com wrote in message news:e54c4461-c0b7-42fb-8542-cefd7bf5f...@h18g2000yqj.googlegroups.com... file = open(prefix1) text = file.readlines() len = len(text) You have redefined two built-in functions file and

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Bruno Desthuilliers
Nick a écrit : I've seen a lot of posts on this problem, but none seems to help. Here is the code: /code file = open(prefix1) shadows the builtin 'file' type. text = file.readlines() len = len(text) shadows the builtin 'len' function. fields = text[1].split() num_rows = int(fields[1])

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Dave Angel
Nick wrote: I've seen a lot of posts on this problem, but none seems to help. Here is the code: /code file = open(prefix1) text = file.readlines() len = len(text) fields = text[1].split() num_rows = int(fields[1]) num_cols = int(fields[2]) U1_matrix = [] print fields print repr(fields) print

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Friðrik Már Jónsson
Previously, I wrote: P.S. While this is a fairly obvious problem it's usually a good idea to post working code and a traceback when requesting help. Nick wrote: thanks for spotting the obvious errors, its my 2nd day programming python in about 3 years. I'm sorry, my saying it was obvious

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Nick
no problem, i understand, i haven't coded anything in literally 2 years, but it was a simple and pretty obvious mistake. thanks for all your help, nick On Jul 9, 11:30 am, Friðrik Már Jónsson frid...@pyth.net wrote: Previously, I wrote: P.S. While this is a fairly obvious problem it's

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Tom Kermode
Hi, Do you know a good way to avoid running into this problem? It makes sense to suggest not calling variables the same names as built-in functions, but that's hard for a new python programmer who doesn't already know what all the built-in functions are. Over time a programmer will learn

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Richard Brodie
Tom Kermode tkerm...@gmail.com wrote in message news:mailman.2903.1247155607.8015.python-l...@python.org... Do you know a good way to avoid running into this problem? It makes sense to suggest not calling variables the same names as built-in functions, but that's hard for a new python

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Friðrik Már Jónsson
Tom Kermode wrote: Do you know a good way to avoid running into this problem? It makes sense to suggest not calling variables the same names as built-in functions, but that's hard for a new python programmer who doesn't already know what all the built-in functions are. One way is using a code

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Rhodri James
On Thu, 09 Jul 2009 17:06:45 +0100, Tom Kermode tkerm...@gmail.com wrote: Hi, Do you know a good way to avoid running into this problem? It makes sense to suggest not calling variables the same names as built-in functions, but that's hard for a new python programmer who doesn't already

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Friðrik Már Jónsson
Hi Rhodri, It's only really a pitfall if you try to use the built-in after you've redefined it. That's the thing to keep an eye open for. You're right, but in cases where you're editing a codebase which you didn't author entirely by yourself you may not be aware of that. That said, if

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Simon Forman
On Thu, Jul 9, 2009 at 9:42 AM, Nicknleio...@gmail.com wrote: snip    fields = line.split()    for i in range(len(fields)):        fields[i] = float(fields[i]) instead of the above code you could say: fields = [float(n) for n in in line.split()] Have fun getting back into python! :] (A lot

Re: gett error message: TypeError: 'int' object is not callable

2009-07-09 Thread Paul Rubin
Nick nleio...@gmail.com writes: text = file.readlines() len = len(text) fields = text[1].split() Is that intended to split the first line of the file? Remember that arrays in python begin at index 0. -- http://mail.python.org/mailman/listinfo/python-list