0

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()
Bach
  • 6,145
  • 7
  • 36
  • 61
yepoo
  • 3
  • 2
  • doesnt matter he is trying to import when he is in the same file as the class – Joran Beasley May 07 '14 at 00:27
  • Note that using two leading underscores (`__foo`) for class member names will trigger [name mangling](http://stackoverflow.com/a/1301369/1599111), which is most likely not the desired behavior if you plan to subclass `Puhallin`. – Lukas Graf May 07 '14 at 00:43
  • @LukasGraf ... since they are all have getter/setters I would assume that is the desired behaviour (closest thing to private variables python has) – Joran Beasley May 07 '14 at 14:33

1 Answers1

0
#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

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • Now it says: Traceback (most recent call last): File "C:/Python33/program.py", line 44, in main() File "C:/Python33/program.py", line 41, in main oma_puhallin = puhallin.Puhallin() NameError: global name 'puhallin' is not defined – yepoo May 07 '14 at 00:28
  • yeah my bad ... forgot to get rid of that ... now its fixed – Joran Beasley May 07 '14 at 00:31
  • TypeError: __init__() missing 4 required positional arguments: 'nopeus', 'halkaisija', 'vari', and 'paalla' that's what it says now. – yepoo May 07 '14 at 00:34
  • it takes arguments in its init method (that you apparently defined) ... (edited my answer to include them?) ... – Joran Beasley May 07 '14 at 00:39