Message234590
| Author |
ethan.furman |
| Recipients |
barry, docs@python, eli.bendersky, ethan.furman, mark |
| Date |
2015年01月24日.02:41:39 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1422067300.58.0.303835573631.issue23292@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Currently the way to add an Enum's members to a module's namespace is:
globals().update(MyEnumeration.__members__)
but that seems quite ugly. Is there anywhere else that the user is required to use __xxx__ methods for common functionality?
I think a new method, export_to(), would solve the problem much more nicely:
@classmethod
def export_to(cls, namespace):
try:
# assume a dict-like namespace
namespace.update(cls.__members__)
except AttributeError:
# or an object-like namespace
for name, member in cls.__members__.items():
setattr(namespace, name, member) |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015年01月24日 02:41:40 | ethan.furman | set | recipients:
+ ethan.furman, barry, mark, eli.bendersky, docs@python |
| 2015年01月24日 02:41:40 | ethan.furman | set | messageid: <1422067300.58.0.303835573631.issue23292@psf.upfronthosting.co.za> |
| 2015年01月24日 02:41:40 | ethan.furman | link | issue23292 messages |
| 2015年01月24日 02:41:39 | ethan.furman | create |
|