python - importing an external Class and creating an object , accessing the functions of the object -


in main.py have put

from carnum import * vehicleid =0 vehicleid = carnum() print ("object created") 

here carnum class

class carnum:    def __init__(self):       speedlist = [] 

but when run getting 'module' object not callable

thank in advance hope guys can me out

import can used import modules, may contain classes functions , other stuff, , not import classes. in python can put multiple classes in same file, main program. example can put in main.py (which module), following:

class carnum(object):     def __init__(self):         # initialize attribute         self.speedlist = []  myobject = carnum() print("object created") 

i left out part:

vehicleid =0 vehicleid = carnum() vehicleid = vehicleid + 1 

since me doesn't make sense.

you can put cardnum class separate module (i.e: cardnum.py) , import in main module (i.e: main.py) using:

from cardnum import cardnum 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -