Search code examples
pythonclassimporttraceback

Import related error, simple program


Okay, so I friend of mine asked me to help with this little program. I can't really code anything, tried coding Python a bit last year. So when I try to run the program it says

Traceback (most recent call last):
   File "C:/Python33/program.py", line 38, in module
      import example1
ImportError: No module named 'example1'

Here's the program:


class example1:



    def __init__(self, nopeus, halkaisija, vari, paalla):
        self.__nopeus = nopeus
        self.__halkaisija = halkaisija
        self.__vari = vari
        self.__paalla = paalla

    def set_nopeus(self, nopeus):
        self.__nopeus = 'nopeus'

    def set_halkaisija(self, halkaisija):
        self.__halkaisija = 'halkaisija'

    def set_vari(self, vari):
        self.__vari = 'vari'

    def set_paalla(self, paalla):
        self.__paalla = 'paalla'

    def get_nopeus(self):
        return self.__nopeus

    def get_halkaisija(self):
        return self.__halkaisija

    def get_vari(self):
        return self.__vari

    def get_paalla(self):
        return self.__paalla



import Example1

def main():
    oma_example1 = example1.Example1()
    print (oma_puhallin.get_nopeus)

main()

Solution

  • #import Puhallin
    
    def main():
        oma_puhallin = Puhallin("nopeus", "halkaisija", "vari", "paalla")
        print (oma_puhallin.get_nopeus() ) #this is a method not a variable
    
    main()
    

    you dont need to import if you are in the same file