Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Imported functions missing arguments

Still a little green? Ask your beginner's questions here

Imported functions missing arguments

Postby CorbinWhite » Mon Aug 12, 2019 4:39 pm

I have some Python code with two classes - PyMaha() and MixerCL() - that I'm using in a Touch project. I'm getting the text into Touch via a filein DAT named "pymaha", and then in a chop execute DAT I have the line
Code: Select all
 from pymaha import MixerCL as cl


All of that seems to be fine, but when I call functions I'm getting an error that I'm missing a required positional argument. Here's one of the functions as defined in the class MixerCL()
Code: Select all
def setChanOn( self , chan , on ):
     self.chan = str(chan)
     self.on = str(on)

     command = ("string command {} 0 {}".format(self.chan , self.on)).encode()

#the following function is defined in PyMaha()
#PyMaha() is imported into MixerCL() in the __init__ function as self.py
   
     self.py.sendCommand(command)


in the chop execute DAT in the onValueChange() function I simply have the following

Code: Select all
cl.setChanOn( channel , val )


This returns an error telling me I'm missing the required positional argument "on"

I thought I would avoid all the weirdness of extensions and be able to write a single big of source code for use within and outside of Touch, that's why I'm trying this import method, but clearly I'm missing something here.
CorbinWhite
 
Posts: 128
Joined: Sun Aug 16, 2015 2:49 pm

Re: Imported functions missing arguments

Postby malcolm » Mon Aug 12, 2019 5:00 pm

If cl is a class definition, you need to create an instance of the class to use it. You can't call a function on the definition like this.
User avatar
malcolm
Staff
 
Posts: 4423
Joined: Tue Nov 13, 2007 1:11 am

Re: Imported functions missing arguments

Postby CorbinWhite » Mon Aug 12, 2019 7:35 pm

got it. seems that import line I had doesn't actually do what I thought it would.

I replaced it with the following, and now it's all working. thanks!
Code: Select all
import pymaha
cl = pymaha.MixerCL()
CorbinWhite
 
Posts: 128
Joined: Sun Aug 16, 2015 2:49 pm


Return to Beginners

Who is online

Users browsing this forum: No registered users and 20 guests