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
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
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
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.
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)
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
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
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
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
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])
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
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
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
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
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
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
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
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
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
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
20 matches
Mail list logo