import module as new name

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
tll
Posts: 5
Joined: Fri Feb 07, 2020 10:16 am

import module as new name

Post by tll » Fri Feb 07, 2020 10:32 am

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

Online
User avatar
Roberthh
Posts: 1840
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: import module as new name

Post by Roberthh » Fri Feb 07, 2020 10:52 am

Because TTGO-T4-Pins is an expression and not a name. Try using TTGO_T4_Pins or the like.

tll
Posts: 5
Joined: Fri Feb 07, 2020 10:16 am

Re: import module as new name

Post by tll » Fri Feb 07, 2020 2:29 pm

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

User avatar
pythoncoder
Posts: 3925
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: import module as new name

Post by pythoncoder » Sun Feb 09, 2020 3:12 pm

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.
Peter Hinch

tll
Posts: 5
Joined: Fri Feb 07, 2020 10:16 am

Re: import module as new name

Post by tll » Mon Feb 10, 2020 12:49 pm

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

Post Reply