472,373 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Confusion over calling a nested function inside a parent function

Expand|Select|Wrap|Line Numbers
  1. class WORK:
  2. def getwork(self):
  3. def choosetable(self):pass
  4. choosetable() #TypeError: choosetable() takes exactly 1
  5. #argument (0 given)
  6.  
Calling choosetable() at the above location gives me the error
described above.
Dec 22 '06 #1
5 1086

Pyenos wrote:
Expand|Select|Wrap|Line Numbers
  1. class WORK:
  2.     def getwork(self):
  3.         def choosetable(self):pass
  4.         choosetable() #TypeError: choosetable() takes exactly 1
  5.                       #argument (0 given)
  6.  

Calling choosetable() at the above location gives me the error
described above.
Although choosetable is a memeber of an instance method, it is not one
itself. It should not have self as it's first formal parameter.

Dec 22 '06 #2
Pyenos <py****@pyenos.orgwrote:
Expand|Select|Wrap|Line Numbers
  1. class WORK:
  2.     def getwork(self):
  3.         def choosetable(self):pass
  4.         choosetable() #TypeError: choosetable() takes exactly 1
  5.                       #argument (0 given)
  6.  

Calling choosetable() at the above location gives me the error
described above.

A function defined inside a method is just a function, it's only when a
function is retrieved from the class dictionary (whether it was defined
there or assigned to the class later) that it becomes a method.

Just leave the self parameter off the choosetable function: you can still
access self from the outer scope of getwork.
Dec 22 '06 #3
"MacDonald" <cr*******@gmail.comwrites:
Pyenos wrote:
Expand|Select|Wrap|Line Numbers
  1.  class WORK:
  2.      def getwork(self):
  3.          def choosetable(self):pass
  4.          choosetable() #TypeError: choosetable() takes exactly 1
  5.                        #argument (0 given)
  6.  
Calling choosetable() at the above location gives me the error
described above.

Although choosetable is a memeber of an instance method, it is not one
itself. It should not have self as it's first formal parameter.
Expand|Select|Wrap|Line Numbers
  1. class WORK:
  2. def getwork(self):
  3. def choosetable():pass
  4. choosetable()
  5.  
like this? thank you! ;-)
Dec 22 '06 #4
MacDonald a écrit :
Pyenos wrote:
>>
Expand|Select|Wrap|Line Numbers
  1. class WORK:
  2.    def getwork(self):
  3.        def choosetable(self):pass
  4.        choosetable() #TypeError: choosetable() takes exactly 1
  5.                      #argument (0 given)

Calling choosetable() at the above location gives me the error
described above.


Although choosetable is a memeber of an instance method,
s/is a member of/is defined in/

Dec 23 '06 #5
Pyenos a écrit :
[code]
You already got the answer - just a pair of stylistic advices:
class WORK:
1/ By convention, ALL_UPPER names denote (pseudo) symbolic constants.
The convention for class names is CamelCase.

2/ better to use new-style classes.

=>
class Work(object):
...
Dec 23 '06 #6

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

Similar topics

6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
6
by: Marc Hoeijmans | last post by:
How is it possible to us a property from a nested class. Example: namespace MyApp { public class MaxLength { public class Project {
37
by: Tim N. van der Leeuw | last post by:
Hi, The following might be documented somewhere, but it hit me unexpectedly and I couldn't exactly find this in the manual either. Problem is, that I cannot use augmented assignment operators...
12
by: Peter Cranz | last post by:
hello, I've got the following problem: I have a construct similar like this: namespace A { class X {
16
by: Alan Jones | last post by:
Hello everyone, any help would be greatly appreciated. :) What I'm trying to do may not be advisable, but here goes... I want a page named signature.php to appear conditionally as an include...
0
by: Brian Lowe | last post by:
I'm in a web page and I have hierarchical data so I'm using 2 nested DataList controls. DataList1 is using a data source with rows of , , and where MoreData is a list. DataList1 has an...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.