How to split a python script into several for GM862 ?

Hi,

My script is getting larger and for thoroughly commenting it became bulky. Now, I think I should split the script into several scripts (like classes in C++ or java).

But while I was trying simple import script2 or import script2.py then those were not working.

How to split a large script into several scripts and call those in other script?

Thanks in advance.

Hi,

Fireball003, if you want to split your scripts you have to write them as differents scripts, by example:

#my large dummy script
#
import MDM
#
while 1:
   Tx="at#gpio=4,1,0\r"
   res=MDM.send(Tx,0)
   Tx="at#gpio=6,1,0\r"  
   res=MDM.send(Tx,0)
   Tx="at#gpio=7,1,1\r"
   res=MDM.send(Tx,0)

we’re going to split into 3 differents scripts, with functions inside them, named scr1.py, scr2.py and guess what…scr3.py

#scr1.py, a dummy script
#
import MDM
def GPIO_CONF4:
   Tx="at#gpio=4,1,0\r"
   res=MDM.send(Tx,0)
   return
#scr2.py, another dummy script
#
import MDM
def GPIO_CONF6:
   Tx="at#gpio=6,1,0\r"  
   res=MDM.send(Tx,0)
   return
#scr3.py, and my last dummy script
#
import MDM
def GPIO_CONF7:
   Tx="at#gpio=7,1,1\r"
   res=MDM.send(Tx,0)
   return

Ok, we have 3 differents scripts with their functions.

Now we write our main script, named obviously main.py

#main dummy script
#
import scr1
import scr2
import scr3
#
while 1:
   scr1.GPIO_CONF4
   scr2.GPIO_CONF6
   scr3.GPIO_CONF7

after that, we have to compile main.py, scr1.py, scr2.py and scr3.py and download it into telit modem, enable main and voila!!

Try with your codes

:wink:

Hi cherreram,

Thanks for your reply.

Yes, I got it after scratching my head for hours. And the confusion came ONLY because of the example in Easy_script_python (pagee 66). There in the screenshot you see they only imported the other python file, but didn’t put script.method() . And I stupidly tried that in several ways thinking if I am doing something wrong.

Anyway, finally I got it.

Now we write our main script, named obviously main.py

NOO! … writing main.py is not obvious. You can write any_name.py . Only you need to enable the main (not necessarily the name to be ‘main.py’) script using AT#ESCRIPT=‘name_script.py’

Yes, you’re right, it’s not necessary to name your principal script as “main.py”, it was only a common name, for ilustration purposes only.

Whatever, don’t forget that a script never can start with a number and its max. lenght is 16 char.

If you want to put numbers into the name, you must put a letter first. By ex. “c12345.py” or “C12345.py”.

Another thing, telit python core is case sensitive, so those scripts are differents ones for it.

cheers

PS: Sometimes Telit’s pdfs sucks…and we have to learn on the run.

:wink: