Page 1 of 1

import module as new name

Posted: Fri Feb 07, 2020 10:32 am
by tll
I have been lurking for a while, trying to figure out if I can tackle a project with MP on SP32. MP beginner. I guess is time to start with a silly questions...

Why does this work

>>> import os as ox
>>> ox.listdir()

but I get syntax error on

>>> import TTGO-T4-Pins as pinmap
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax

Re: import module as new name

Posted: Fri Feb 07, 2020 10:52 am
by Roberthh
Because TTGO-T4-Pins is an expression and not a name. Try using TTGO_T4_Pins or the like.

Re: import module as new name

Posted: Fri Feb 07, 2020 2:29 pm
by tll
microPython... microCobol... aren't they similar? :lol:

I just took a piece of a github package as the name... Now it likes it and what is more, with a couple of tweaks, the board is working!

Thank you

Re: import module as new name

Posted: Sun Feb 09, 2020 3:12 pm
by pythoncoder
I know nothing of Cobol but Python interprets "-" as an operator. Consequently, as @Roberthh says, "TTGO-T4-Pins" is interpreted as an expression and not a name.

Re: import module as new name

Posted: Mon Feb 10, 2020 12:49 pm
by tll
Thank you Peter, many other languages do to... Just as a COBOL curiosity tidbit, variables are commonly a string of hyphenated words, a bit on the verbose side. Operators have to be space separated from variables.

Thank you again
Tony