Ulsa Minor Ulsa Minor - 5 months ago 11
Python Question

I have written two separate files, one containing classes and the other calling them but calling one makes object of all. Why?

separate.py

class foo():
print 'a bunch of time consuming work'

class tryme():
print 'try me'*


main.py

from separate import *

foo()


It however printed both:

a bunch of time consuming work
try me

Answer

You should write an init for your classes then it wont happen anymore!

class foo():
  def __init__(self):
    print('a bunch of time consuming work')

class tryme():
  def __init__(self):
    print ('try me')
Comments