function name is undefined in python class

aceminer

I am relatively new to python and i am experiencing some issues with namespacing.

class a:
    def abc(self):
        print "haha" 
    def test(self):
        abc()

b = a()
b.abc() #throws an error of abc is not defined. cannot explain why is this so
Paul Lo

Since test() doesn't know who is abc, that msg NameError: global name 'abc' is not defined you see should happen when you invoke b.test() (calling b.abc() is fine), change it to:

class a:
    def abc(self):
        print "haha" 
    def test(self):
        self.abc()  
        # abc()

b = a()
b.abc() #  'haha' is printed
b.test() # 'haha' is printed

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Parameterize function name in Python

From Dev

Undefined reference to a private function of the class

From Dev

Python: Dynamically adding function to a class, whose name is contained in a string

From Dev

Class name as a variable in python

From Dev

class name as argument in a public function

From Dev

undefined method `model_name' for Address:Class

From Dev

Class instance has no attribute 'function_name' for passing object outside class- python

From Dev

Python Class Name as Class Variable

From Dev

Parse Python Function's Class Name

From Dev

Calling a function by class file name

From Dev

How can use variable class name and function in Python

From Dev

Undefined reference to class_name<template_argument>function_name(variable)?

From Dev

class name as variable in python

From Dev

Undefined reference to "function name from external library"

From Dev

JavaScript: is it possible to get the attempted name of an undefined function?

From Dev

undefined function or variable in class

From Dev

Python Class is Undefined?

From Dev

Python: isinstance() undefined global name

From Dev

Parse Python Function's Class Name

From Dev

Undefined reference to 'class::function'?

From Dev

How to pass function name of child class as parameter to parent class method in python?

From Dev

"If statement" within for loop class name undefined

From Dev

Call to undefined function in Class

From Dev

Python Function Undefined

From Dev

Python 3: Choosing the name of a class returned from a function

From Dev

This is undefined in function inside class function

From Dev

Python class in function that use function params throw NameError: name 'x' is not defined

From Dev

Python call class function without reffering class name

From Dev

Python standard (PEP) name to unknown class instance in function call

Related Related

  1. 1

    Parameterize function name in Python

  2. 2

    Undefined reference to a private function of the class

  3. 3

    Python: Dynamically adding function to a class, whose name is contained in a string

  4. 4

    Class name as a variable in python

  5. 5

    class name as argument in a public function

  6. 6

    undefined method `model_name' for Address:Class

  7. 7

    Class instance has no attribute 'function_name' for passing object outside class- python

  8. 8

    Python Class Name as Class Variable

  9. 9

    Parse Python Function's Class Name

  10. 10

    Calling a function by class file name

  11. 11

    How can use variable class name and function in Python

  12. 12

    Undefined reference to class_name<template_argument>function_name(variable)?

  13. 13

    class name as variable in python

  14. 14

    Undefined reference to "function name from external library"

  15. 15

    JavaScript: is it possible to get the attempted name of an undefined function?

  16. 16

    undefined function or variable in class

  17. 17

    Python Class is Undefined?

  18. 18

    Python: isinstance() undefined global name

  19. 19

    Parse Python Function's Class Name

  20. 20

    Undefined reference to 'class::function'?

  21. 21

    How to pass function name of child class as parameter to parent class method in python?

  22. 22

    "If statement" within for loop class name undefined

  23. 23

    Call to undefined function in Class

  24. 24

    Python Function Undefined

  25. 25

    Python 3: Choosing the name of a class returned from a function

  26. 26

    This is undefined in function inside class function

  27. 27

    Python class in function that use function params throw NameError: name 'x' is not defined

  28. 28

    Python call class function without reffering class name

  29. 29

    Python standard (PEP) name to unknown class instance in function call

HotTag

Archive