473,242 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

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 1525
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 =...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.