Import from .py trouble - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Import from .py trouble (/thread-22814.html) |
Import from .py trouble - michael1789 - Nov-27-2019 I'm trying to split my code into separate modules: sprites.py, setting.py, etc. I'm clearly missing something. from settings import * print(tile_size)This doesn't work, though I think it should. If I spell the file wrong, like "sttings", I get I have all the python files in the same directory and setting.py's first line is "tile_size = 50" Python can see that the file exists but "import" doesn't make it visible.
RE: Import from .py trouble - ichabod801 - Nov-27-2019 Could there be another settings.py file that it could be getting confused with? Try renaming settings something weird like 'blargoraftical,' and try 'import blargoraftical'. RE: Import from .py trouble - michael1789 - Nov-27-2019 Files are now in own folder and I renamed everything. from blargoraftical import * print(tile_size)and import blargoraftical print(tile_size) Same result in 2 editors. I have other programs that run fine. I'll try a restart.
RE: Import from .py trouble - Ray - Nov-27-2019 It is possible the directory where settings.py is located to be different from the running file. I can reproduce a similar error if I do so. RE: Import from .py trouble - michael1789 - Nov-27-2019 Got it. Human error. Confused about two files named "settings". I'll catch that next time, Thank-you. |