Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39019 > unrolled thread
| Started by | Chris Rebert <clp2@rebertia.com> |
|---|---|
| First post | 2013-02-17 00:39 -0800 |
| Last post | 2013-02-17 00:39 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Calendar module question Chris Rebert <clp2@rebertia.com> - 2013-02-17 00:39 -0800
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2013-02-17 00:39 -0800 |
| Subject | Re: Calendar module question |
| Message-ID | <mailman.1885.1361090374.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Saturday, February 16, 2013, Phil wrote: > Thank you for reading this. > > My adventures with Python have just begun and during the few weeks I have > tried many IDEs. The following piece of code fails under all IDEs, and the > interpreter, except under the Wing IDE. > > Why would this code work under the Wing IDE and nowhere else? Could there > be a different calendar module included with Wing? > > import calendar > > cal = calendar.prcal(2013) > print cal > > Traceback (most recent call last): > File "calendar.py", line 1, in <module> > import calendar > File "/home/phil/calendar.py", line 3, in <module> > cal = calendar.prcal(2013) > AttributeError: 'module' object has no attribute 'prcal' > You named your own script file "calendar.py". As a result, when you did `import calendar`, due to the way Python 2.x searches for modules, it imports your file instead of the `calendar` module in the standard library, thus leading to the above exception. Because of this sort of problem, it is/was considered bad practice to give a module/package the same name as any std lib module. However, if you are running a recent-ish version of Python, adding `from __future__ import absolute_import` may resolve the problem. See PEP 328 for details. Absolute imports were thankfully made the default in Python 3. -- Cheers, Chris -- http://rebertia.com
Back to top | Article view | comp.lang.python
csiph-web