-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All modules should automatically be from module import * #88
Comments
snek doesn't actually support python modules, the whole hack with the math functions is that they really are named |
I understand that the modules are faked, but I think it should work as if this had been in a Python3 file before the rest of the program:
I.e. the most common modules should be from-imported last in order to override earlier names. stdscr is an auto created object in the Snek case. GPIO functions, e.g. talkto() and on(), are moduleless and temperature() also. |
62 names (from the math module) seem a bit much, IMHO it’s cleaner and closer to Python to have only |
It's standard on graphing calculators with Python to from-import |
An alternative could be to allow shorter module names. It would be as if the following had been done:
Then one wouldn't need to type a lot and one could fit larger programs in flash.
|
I've just posted PR #90 which would allow us to include 'from math import *' in source files. With that, we could |
I'd probably remove |
I believe this would be an improvement since |
Check out PR #99 and see what you think. I've left curses, stdscr and eeprom out of this patch because they're much less common. The eeprom functions can't be changed without also fixing the mu editor upstream. |
It works as expected from my small tests e.g. using this program:
I have not yet tested on Arduino UNO. |
Thanks for testing. I think I'll go see if I can add an option to leave the old names in place while also providing the new names on targets large enough for that. Tiny targets will want to save the space, I suspect. |
It would be easier if
from math import *
was used because it would save people from having to typemath.
before every math function. All modules are auto imported, and I suggest all modules should also be autofrom
-imported. That means you could use all functions without a module name prefix. You could still use the fully qualified name if you want or need to. If one name shadows another you have to use the fully qualified name except for the lastfrom
-imported module.The modules could be auto
from
-imported in an order so that the most used modules are imported last.from ANYTHING import *
should be ignored likeimport ANYTHING
is ignored now.I think this would be helpful for beginners, since you don't have to type many module prefixes. This means Snek would be more competitive as a first computer language. This would also make Snek programs shorter in flash memory.
E.g.
stdscr.refresh()
would still needstdscr.
sincestdscr
is an object and not a module.The text was updated successfully, but these errors were encountered: