Ulsa Minor Ulsa Minor - 2 years ago 69
Python Question

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


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

class tryme():
print 'try me'*


from separate import *


It however printed both:

a bunch of time consuming work
try me

Answer Source

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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download