python - Simple class definition giving "missing 1 required positional argument" in ipython -


here class file (called myclasses.py):

class wave:     def __init__(self, name = "", xdelta = 1)         self.name = name         self.xdelta = xdelta      def loadbinary(bpath):         print(bpath) 

for i've stripped out other details (loading binary file code, etc.) this, , when run following i'm getting error output:

import myclasses = myclasses.wave a.loadbinary('test') 

the error:

typeerror: loadbinary() missing 1 required positional argument: 'bpath' 

i've tried changing loadbinary definition "loadbinary(self, bpath)" gives same error. i've tried replacing "print" code "pass" have nothing, still gives me error. i've tried running following:

a.loadbinary(bpath='test') 

...but changes error read: loadbinary() missing 1 required positional argument: 'self'

at point, i'm not sure going on. class definition basic, , not inherit other classes, , can tell following code in python documentation classes shown here: https://docs.python.org/2/tutorial/classes.html

i'm using python 3.4.3, , happens in ipython 3.1.0, running in pycharm 4.5.1. if run in ipython 3.1.0 directly @ command prompt (os x terminal) following error output:

unbound method loadbinary() must called wave instance first argument (got str instance instead) 

you never instantiated class. instead:

class wave:     def __init__(self, name = "", xdelta = 1)         self.name = name         self.xdelta = delta      def loadbinary(self, bpath):         print(bpath) 

or...

class wave:     def __init__(self, name = "", xdelta = 1)         self.name = name         self.xdelta = delta      @staticmethod     def loadbinary(bpath):         print(bpath) 

then...

import myclasses = myclasses.wave() # brackets instantiate class a.loadbinary('test') 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -