Error method name not found

0

Error:

  

Traceback (most recent call last): File   "C: \ Python27 \ data \ listener.py", line 94, in       back_dir (os.getcwd ()) NameError: name 'back_dir' is not defined

Class that I am using:

class back():
    def back_dir(self,current_path):
                    c=current_path.split('\')
                    new_path=''
                    i=0
                    while i<len(c)-1:
                            if i!=0:
                                    new_path=new_path+"\"+c[i]
                            else:
                                    new_path=c[i]
                            i+=1
                    os.chdir(new_path)

Part of the code where I get the error:

back_dir(os.getcwd())

However, should it work? You can help me.

    
asked by Perl 01.08.2016 в 22:20
source

1 answer

1

There are several errors in your code. In the definition of the class you would not need to use parentheses unless you are inheriting from another. By convention, classes are defined using CamelCase, ...

When instances the class can access its methods. For example:

b = back()
b.back_dir(os.getcwd())
    
answered by 01.08.2016 в 22:32