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. >

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

2009-07-10 Thread Nick
On Jul 9, 8:22 pm, Paul Rubin wrote: > Nick 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 garble

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, Nick wrote: > >>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 in

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

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

2009-07-09 Thread Paul Rubin
Nick 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

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, Nick wrote: >    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 has changed in the

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 the

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 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 know what all the buil

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 Richard Brodie
"Tom Kermode" 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 programmer who > do

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 which

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 wrote: > Previously, I wrote: > >> P.S. While this is a fairly obvious problem it's usually a good > >

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 ma

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 l

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]) n

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

2009-07-09 Thread Nick
On Jul 9, 10:02 am, "Richard Brodie" wrote: > "Nick" 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 firs

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

2009-07-09 Thread Richard Brodie
"Nick" 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 practice. S

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 g

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