in a .py file I have the following:
class avgbox:
def __init__(self,t,n,a):
self.t = t
self.n = n
self.a = a
def add(x):
self.t += x
self.n += 1
self.a = t/n
Now when I do the from file.py import * in the interactive python shell run from the ubuntu command line, it shows no error. Then when do a = avgbox(0,0,0) it says NameError: name 'avgbox' is not defined. Any ideas? What am I doing wrong here? Thanks!
from foo import *is nearly always a bad idea.from file import avgboxselfas the first argument in theaddmethod!from file.py import *should be throwing an error. Tryfrom file import *.avgbox. Tryfrom file import avgbox, and if this doesn't work, restart your interactive interpreter.