Self made python class -
i defined 2 class in separated file (which name myclass.py
) main program , trying include it. class definition follows:
class myclass: tn="" def _init_(self,tn): self.tn=tn
while main program follows
import myclass mc obj=mc.myclass("hello") print(obj.tn)
and when try launch following message appear: "name 'team_class 'is not defined"
. makes me think doesn't import class correctly don't seem understand reason.
at first, class' __init__()
method wrong. don't know if copied here wrong, try this:
class myclass: # __init__() magic method , needs 2 underscores, not 1 def __init__(self, tn=''): # giving default value in __init__() method # more straightforward way of doing # more pythonic name variables in snake_case self.tn = tn
then in main file:
import myclass mc obj = mc.myclass('hello') print(obj.tn) # hello
but can show team_class
used in order resolve error?
Comments
Post a Comment