473,467 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

why is this failing?

I've looked at this so long that I must be looking right past it. This
code:

class Page:
################################################## ########
def write(self, value, row=None, col=None, len=None):
print isinstance(value, str)

# error occurs on this line
print len(value)

################################################## ######
if __name__ == "__main__":
p = Page()

p.write("banana")

is throwing this error:


True
Traceback (most recent call last):
File "P2.py", line 13, in ?
p.write("banana")
File "P2.py", line 7, in write
print len(value)
TypeError: 'NoneType' object is not callable
What am I missing?

Jul 18 '05 #1
7 1530
Chris Curvey wrote:
I've looked at this so long that I must be looking right past it.
This
code:

class Page:
################################################## ########
def write(self, value, row=None, col=None, len=None): ^^^ print isinstance(value, str)

# error occurs on this line
print len(value)


You are overriding the name len, so this is equivalent to writing

None(value)

which is obviously an error.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ God is love, but get it in writing.
\__/ Gypsy Rose Lee
Jul 18 '05 #2
Chris Curvey wrote:

I've looked at this so long that I must be looking right past it. This
code:

class Page:
################################################## ########
def write(self, value, row=None, col=None, len=None):
print isinstance(value, str)

# error occurs on this line
print len(value)

################################################## ######
if __name__ == "__main__":
p = Page()

p.write("banana")

is throwing this error:

True
Traceback (most recent call last):
File "P2.py", line 13, in ?
p.write("banana")
File "P2.py", line 7, in write
print len(value)
TypeError: 'NoneType' object is not callable


Reading the error more closely, and examining the line that is failing,
you can see that the only call being made is to len(), but the error is
telling you that the name "len" is actually bound to None! How could
that happen? Check your list of arguments to the write() method...

Don't use names of builtins and your life will be easier. :-)

-Peter
Jul 18 '05 #3
In article <3F***************@engcorp.com>, Peter Hansen wrote:
Don't use names of builtins and your life will be easier. :-)


And the easiest way to do that is to use an editor with a
Python mode. Make sure it shows builtins in a distinct color.
You will then know immediately (while editing) when you
accidentally redefine a builtin.

--
Grant Edwards grante Yow! I call it a "SARDINE
at ON WHEAT"!
visi.com
Jul 18 '05 #4

Chris> def write(self, value, row=None, col=None, len=None):

You overrode the len() builtin in your function signature ^^^.

Skip

Jul 18 '05 #5
gr****@visi.com (Grant Edwards) writes:
In article <3F***************@engcorp.com>, Peter Hansen wrote:
Don't use names of builtins and your life will be easier. :-)


And the easiest way to do that is to use an editor with a
Python mode. Make sure it shows builtins in a distinct color.
You will then know immediately (while editing) when you
accidentally redefine a builtin.


You wouldn't happen to know how to do this for python-mode?

emacs-illiterate-ly y'rs,
John
Jul 18 '05 #6
Erik Max Francis <ma*@alcyone.com> writes:
"John J. Lee" wrote:
You wouldn't happen to know how to do this for python-mode?


The latest versions will do it automatically.


Just to check (I'm using a patched version, so it's a bit of a pain to
switch): the latest versions from the python-mode SF project highlight
builtins like "len" and "list", not just keywords like "print"?
John
Jul 18 '05 #7

John> Just to check (I'm using a patched version, so it's a bit of a
John> pain to switch): the latest versions from the python-mode SF
John> project highlight builtins like "len" and "list", not just
John> keywords like "print"?

I'm running 4.38. Here are the keywords it knows about:

"and" "assert" "break" "class"
"continue" "def" "del" "elif"
"else" "except" "exec" "for"
"from" "global" "if" "import"
"in" "is" "lambda" "not"
"or" "pass" "print" "raise"
"return" "while" "yield"

So, no, the builtins are not colored, just the keywords. You could easily
extend the list though.

Skip
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Stewart | last post by:
Has anyone else experience of imagecreatefromjpeg failing with an error message about memory even though the size of the image being uploaded is nothing like the space available to the script? ...
0
by: Dinesh | last post by:
Hi, I want to check the maximum size of the Data Set my Application can retain without failing.(max no of records that the Data Set can hold) How to do that? regards, Dinesh.
2
by: Per Bergland | last post by:
I have a system service written in C#. For some reason it fails to start on our external web server (running a tightened Windows 2000). If I try to start the services after logging on, it works...
2
by: Dung Ping | last post by:
I have questions on a long code. Do I just place its url, or have to paste the whole code, in my message to this forum? Thanks. Dung Ping
1
by: Frank Rizzo | last post by:
Hello, I have a bunch of thread in my app doing variuos things. One of them is failing at some point in the app and I can't (actually don't know how) figure out which one it is. Is there a way to...
7
by: Jim Carlock | last post by:
Does a SELECT element (listbox) need to be inside a FORM element? The code I'm playing with: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
6
by: Adam Honek | last post by:
Can anyone spot why the below function is failing? It returns true but when looking inside the INI file there's no new added section. ****CODE**** Public Function WriteINIFileSection(ByVal...
0
by: Valentin Guggiana | last post by:
Hi all I build MySQL 5.0.24 as follows: setenv PREFIX /data/mysql-5.0.24 setenv CFLAGS "-O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" setenv CXXFLAGS "$CFLAGS -felide-constructors...
6
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 with Apahce 2.2 on Fedora Core 5 Linux. I'm having trouble figuring out why an ftp_put call is failing. Is there a way I can get an exact reason other than checking...
0
by: meethari1984 | last post by:
Hi All, The below sample of code is failing in MSWord 2007 in windows vista 64 bit but the same is fine with the application Windows Photo Gallery Viewer. CDC objDC; objDC.m_hDC =...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.