Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '16,': 0.03; 'attribute': 0.05; 'result,': 0.05; 'exception.': 0.07; 'subject:question': 0.08; 'python': 0.09; '__future__': 0.09; 'ide': 0.09; 'imports': 0.09; 'interpreter,': 0.09; 'pep': 0.09; 'subject:module': 0.09; 'cc:addr:python-list': 0.10; '328': 0.16; 'calendar': 0.16; 'modules,': 0.16; 'wing': 0.16; 'wrote:': 0.17; 'library,': 0.17; 'pfxlen:0': 0.17; 'module': 0.19; 'sort': 0.21; 'import': 0.21; '2.x': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'absolute': 0.23; 'thus': 0.24; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; 'module.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'chris': 0.28; 'piece': 0.29; 'searches': 0.29; 'included': 0.29; 'skip:& 10': 0.29; 'this.': 0.29; 'skip:& 30': 0.30; 'code': 0.31; 'problem.': 0.32; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'print': 0.32; 'traceback': 0.33; 'weeks': 0.33; 'skip:& 20': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'problem,': 0.35; 'there': 0.35; 'except': 0.36; 'thank': 0.36; 'bad': 0.37; 'resolve': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'instead': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'leading': 0.61; 'different': 0.63; 'due': 0.66; '8bit%:24': 0.84; 'sender:addr:chris': 0.84; 'to:addr:bigpond.com': 0.84; 'url:rebertia': 0.84; 'phil': 0.91; 'adventures': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=ZOFBcfotMxyaue4H8KmWcWuDq4lZZJSxwDwymrVLgJk=; b=dbNOSOz87lgwieD7Tiur9Nb0rNutzeGS4PFwiPLTlytTj0iIKkBcgMBWU0+9Gp48cv 1WR/W0/+nQ/NxAfQgWnlGdwmiBC1AdkCvg1j2JiGePQlrK1e0QmnZfv+aagPbWMdfbfj H2gjS83qaSjWcqHQZE7Lzz29hg5ppJgT0pcd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=ZOFBcfotMxyaue4H8KmWcWuDq4lZZJSxwDwymrVLgJk=; b=EU0DY8G4NsEQEHD5h6NPvDMg/WM3HaqDlzmdZ8pKoi6Ysu5fw3M6yt971pL6569Ys8 u6adte+OFL38EXN7RfENpH0mElKD1hUGMWGkMYKeNC0dm2qYzQc0UpqyP2oGUx/6kv1F BREqYV8c9BokYKCt442woGI37KjsrOB1cpNlfzcz9AupBZtYtMvSRM3M9BdGMCNZb95H af05jgFa9YdhP/RjCg3d44CMVr5qCPxfWcrHC0Wv3Gl7mxNCn94ajlt/inF5u31f7iEs cMPboez+PuuO7mhrp0JNUr+dJrV8Tjlg2Jg1m2uL+m11mfRInKJrJFDNGyCltf+mOGsi X4UA== MIME-Version: 1.0 X-Received: by 10.50.56.139 with SMTP id a11mr5373734igq.86.1361090365911; Sun, 17 Feb 2013 00:39:25 -0800 (PST) Sender: chris@rebertia.com In-Reply-To: <51208B03.2070404@bigpond.com> References: <51208B03.2070404@bigpond.com> Date: Sun, 17 Feb 2013 00:39:25 -0800 X-Google-Sender-Auth: hlySg0H2Zu3u78xf_hdySZU_0i0 Subject: Re: Calendar module question From: Chris Rebert To: Phil Content-Type: multipart/alternative; boundary=f46d0401f449c4730204d5e78b93 X-Gm-Message-State: ALoCoQn642cVMBVx+hDdSTH9tZMbTdbwCVBn+EYrmP/CRhx0wpUjCHOiudjV4bhTbWXTmCSsshHu Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 88 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361090374 news.xs4all.nl 6947 [2001:888:2000:d::a6]:39525 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39019 --f46d0401f449c4730204d5e78b93 Content-Type: text/plain; charset=UTF-8 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 > import calendar > File "/home/phil/calendar.py", line 3, in > 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 --f46d0401f449c4730204d5e78b93 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 t= ried many IDEs. The following piece of code fails under all IDEs, and the i= nterpreter, except under the Wing IDE.

Why would this code work under the Wing IDE and nowhere else? Could there b= e a different calendar module included with Wing?

import calendar

cal =3D calendar.prcal(2013)
print cal

Traceback (most recent call last):
=C2=A0 File "calendar.py", line 1, in <module>
=C2=A0 =C2=A0 import calendar
=C2=A0 File "/home/phil/calendar.py", line 3, in <module> =C2=A0 =C2=A0 cal =3D calendar.prcal(2013)
AttributeError: 'module' object has no attribute 'prcal'

You named=C2=A0your own=C2=A0script=C2=A0f= ile "calendar.py". As a result, when you did=C2=A0`import calenda= r`, due to the way Python 2.x searches=C2=A0for modules, it imports your fi= le instead of the `calendar` module in the standard library, thus leading t= o the above exception. Because of this sort=C2=A0of problem, it is/was cons= idered bad practice to give a module/package the same name as any std lib m= odule.

However, if you are running a recent-ish=C2=A0version o= f Python, adding `from __future__ import absolute_import` may resolve the p= roblem. See PEP 328 for details. Absolute imports were thankfully=C2=A0made the default in Python 3.


--
Cheers,
Chris
--
http://rebertia.com
--f46d0401f449c4730204d5e78b93--