adding more files .py to project


#1

Hi there,

I’ve been playing with the Viper IDE and a Photon, so far with nice results.
However, now that I want to go a bit further I was wondering if it’s in any way possible to import additional .py files?
So, for example let’s say I write some lengthy code to read a particular sensor and want to store that in sensor.py (with one or more functions defined inside).
Can I do that, and if so how?
I tried creating “new.py” and in “main.py” calling “from new import func” but that just threw a fit and didn’t compile…

Thanks,
Andi


#2

Hi @AndiB 

you don’t need the “from”  :wink:

example:

create a new file called functions.py with the following code where two new functions are defined:

def HelloPrint():
    print(“Hello Viper!”)    

def MySpecialFunction(a,b):
    print(“Parameter a is:”,a,“parameter b is:”,b)
<p>in the main.py you write:</p><pre class=" CodeBlock">import functions<br>a=0<br>b=0<br>while True:<br>&nbsp; &nbsp; functions.HelloPrint()<br>&nbsp; &nbsp; a+=1<br>&nbsp; &nbsp; b+=10<br>&nbsp; &nbsp; functions.MySpecialFunction(a,b)<br>&nbsp; &nbsp; sleep(1000)



#3

Thanks @floyd !