I'm trying to instaniate (not sure if thats correct spelling lol) one of my classes but even though i've spelt the name correctly i keep getting a NameError:

main:

import os
import os.path
import shutil

print "#######################################################################"
print "#                    FOLDER SORTER - VERSION 0.1 Beta                 #"
print "#    This is a small utility which should sort all your rag-tag       #"
print "#    files into folders of the same name.                             #"
print "#######################################################################"
print "#    For a Full List of Commands type help at the prompt              #"
print "#######################################################################"

pf = PathFinder.init()

pathfinder:

class PathFinder:
    
    u_dir = ""
    
    def init(self):
        self.get_dir()
        
    def get_dir(self):
        self.u_dir = raw_input("Please Enter A Default Path: ")
        self.check_dir(u_dir)
        
    def check_dir(self,u_dir):
        if os.path.exists(u_dir):
            self.list_dir(u_dir)
        else:
            print "Sorry, The Path You Entered Could Not Be Found."

    def list_dir(self,u_dir):
        print "The following files and folders where found at the"
        print "location you specified\n"

        for names in sorted(os.listdir(u_dir)):
            if os.path.splitext(names) [1] == '':
                print "Folder: ", names
            else:
                print "File: ", names

and i get this error:

Traceback (most recent call last):
File "E:\python\folder_sorter_version_02\Main.py", line 15, in <module>
pf = PathFinder.init()
NameError: name 'PathFinder' is not defined

I'm pretty sure i'm missing something simple but i just cant see it, so i would greatly appreciate any help anyone has to offer.

You never imported your class... as I'm assuming that 'PathFinder' is not in your Main.py ... let's say it's in PF.py .... from PF import PathFinder That should do it

Hi Jlm, thanks for taking the time to reply. I tried importing my class using this....

import PathFinder

... But all i get is an error message telling me that the module is not callable.

Also i did not realize that I had to import my classes even if their in the same directory as the Main application file.

Please read my last post.

It worked ! Thank you very much jlm, your help is very much appreciated :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.