robertlugg / easygui

easygui for Python
http://easygui.readthedocs.org/en/master/
BSD 3-Clause "New" or "Revised" License
457 stars 116 forks source link

__init__.py namespace error #121

Open makew0rld opened 7 years ago

makew0rld commented 7 years ago

I have made a mistake, and the errors I talk about here occur in the older version of easygui, 0.97

I downloaded easygui and put it in my site-packages folder. When I typed import easygui into IDLE I got this error: Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> import easygui File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/easygui/__init__.py", line 3, in <module> __all__ = easygui.__all__ NameError: name 'easygui' is not defined

So I went into the init.py and I think I found the error. In the first line it says from easygui import * which means that you don't have to put easygui. in front of easygui functions. But then in the third line it says __all__ = easygui.__all__ Python looks for easygui.all when we don't have that namespace because of the way easygui was imported. But when I change the first line to say import easygui python gives me the error that module 'easygui' has no attribute '__all__' What's going on?

EDIT: I think I figured how to fix it. I changed the script to this: import easygui pass __all__ = [easygui]

EDIT 2: This has been changed it this version, it is only a problem in the older versions that you are suggested to download here, version 0.97 When will those ones be updated?

zadacka commented 7 years ago

Try using 'from easygui import *' instead of 'import easygui', and you should import everything. Alternatively, use 'from easygui import <specific thing you want to import>' in order to keep your namespace clean.

Attributes like 'all' are private and get name mangled. As a general rule of thumb you don't want to access things like that. You can still access private attributes if you really want. Does that help?

makew0rld commented 7 years ago

Ok thanks, but is there an issue with my fix?

zadacka commented 7 years ago

Short answer - use v0.98 from GitHub (here!) or from PIP. I'll update SourceForge to point people here. Longer answer - I'm curious about what wasn't working and how your fix works and want to look into it. When I get the chance I'll try to reproduce it and understand how this works.

makew0rld commented 7 years ago

@zadacka Okay, but make sure to tell people to isolate the easygui folder from the .zip file that gets downloaded, it was a little confusing at first. Thanks!