frame

what should I add to the python running on Zerynth?

Hi! I had a quick refresher of python language on codecademy website before starting to program my processor with Zerynth studio.
On codecademy I learned to use - print "what you want to be printed" - while on zerynth examples I see that print is used with brackets - print ("what you want to print") - this is of course a minor problem, but I guess I was probably learning on a slightly different version of python.
Then I defined a class like - class NewClassName(object): -, where I set object between brackets in order to inherit the generic characteristics of "object" class; but when I press "verify", Z.studio gives an error, not recognizing the syntax. I'm wondering that I should probably import some library at the beginning of the code (like I do when I write "import streams").

Thank you for your attention and help.

Comments

  • anbaanba Member
    Hi KikiCS,
    you guessed right about python version: Zerynth scripts are developed in Python 3.4, as reported by Zerynth documentation.
    This means that, for example, you must use parentheses to pass arguments to "print". This example shows how to use print in a Zerynth script.

    To define a class in Zerynth you do not need to explicit the ineheritance from "object". You do not even need it in Python 3. But while in Python 3 "class NewClassName:" and "class NewClassName(object):" are equivalent, in
    Zerynth the latter is not allowed because, to save resources, "object" is not defined.

    Another difference between Zerynth and Python 3 that concerns classes is that, in Zerynth, "super" is not defined.
    So in your derived class you have to call explicitly the base class's methods:
    import i2c
    ...
    class MAX30101(i2c.I2C):
        def __init__(self, drvname, addr=MAX30101_I2CADDR, clk=400000):
            i2c.I2C.__init__(self, drvname, addr, clk)




    Andrea Baù
    Zerynth Support Team
  • KikiCS Member
    Thank you very much!
Sign In or Register to comment.

ZERYNTH Community

@ 2016 Zerynth.com, all rights reserved.