Modules and files
So far we've seen examples of using lager python
with an individual python script (e.g. lager python myscript.py
). You can also pass a directory to lager python
instead of a file (e.g. lager python my_script_dir
). Doing so will zip up all the files in the directory and send them to your gateway, and use main.py
as your entry point. Furthermore, any dependencies listed in your (optional) requirements.txt will be installed. Let's say you had a directory structure that looks like this:
my_script_dir/
├── files/
│ ├── my_first_file.txt
├── main.py
├── requirements.txt
We'll use our requirements.txt
file to install texttable, a library for creating simple ASCII-art tables. We'll also read from a file - this will become especially useful when we want use lager python to programmatically flash our DUT.
from texttable import Texttable
def make_table():
table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_dtype(['t', # text
'f', # float (decimal)
'e', # float (exponent)
'i', # integer
'a']) # automatic
table.set_cols_align(["l", "r", "r", "r", "l"])
table.add_rows([["text", "float", "exp", "int", "auto"],
["abcd", "67", 654, 89, 128.001],
["efghijk", 67.5434, .654, 89.6, 12800000000000000000000.00023],
["lmn", 5e-78, 5e-78, 89.4, .000000000000128],
["opqrstu", .023, 5e+78, 92., 12800000000000000000000]])
return table
def main():
with open('files/my_first_file.txt') as f:
print(f.read())
table = make_table()
print(table.draw())
if __name__ == '__main__':
main()
Hello, world! This is a file.
texttable==1.6.2
➜ lager python my_script_dir
Hello, world! This is a file.
text float exp int auto
==============================================
abcd 67.000 6.540e+02 89 128.001
efghijk 67.543 6.540e-01 90 1.280e+22
lmn 0.000 5.000e-78 89 0.000
opqrstu 0.023 5.000e+78 92 1.280e+22