473,725 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Module name conflict with standard library

Hi!

I want to create a module myproject.ui.cu rses, which needs to import the
curses library.

However, if I just write ``import curses``, the module imports *itself*
instead of the standard library's curses module.

Is there any (reliable) way to access a module of the standard library
if the names conflict as in this case?

Thank you in advance,
Felix Wiemann

--
http://www.ososo.de/
Jul 18 '05 #1
8 5227
Felix Wiemann <Fe***********@ gmx.net> wrote in message news:<87******* *****@news2.oso so.de>...
Hi!

I want to create a module myproject.ui.cu rses, which needs to import the
curses library.

However, if I just write ``import curses``, the module imports *itself*
instead of the standard library's curses module.

Is there any (reliable) way to access a module of the standard library
if the names conflict as in this case?

Thank you in advance,
Felix Wiemann


Dunno. I guess that when PEP328 will be fully implemented (this is NOT the
case in 2.4.a3)

from __future__ import absolute_import
import curses

will do the right thing, importing the standard library module and not
itself (which should happen with "import .curses").

Am I correct? I do really really like PEP328 since I was bitten by
this kind of problems myself in the past. Will it be implemented fully
in time for 2.4.b1?
Michele Simionato
Jul 18 '05 #2
On 5 Sep 2004 00:32:38 -0700, Michele Simionato
<mi************ ***@gmail.com> wrote:
Am I correct? I do really really like PEP328 since I was bitten by
this kind of problems myself in the past. Will it be implemented fully
in time for 2.4.b1?


It seems doubtful, unfortunately, unless someone steps forward Real
Soon to champion the PEP and get it done.
Jul 18 '05 #3
Anthony Baxter wrote:
On 5 Sep 2004 00:32:38 -0700, Michele Simionato
<mi************ ***@gmail.com> wrote:
Am I correct? I do really really like PEP328 since I was bitten by
this kind of problems myself in the past. Will it be implemented fully
in time for 2.4.b1?


It seems doubtful, unfortunately, unless someone steps forward Real
Soon to champion the PEP and get it done.

In the mean time,

http://hkn.eecs.berkeley.edu/~dyoo/python/__std__

can help at least some of the problems.

--
Nigel Rowe
A pox upon the spammers that make me write my address like..
rho (snail) swiftdsl (stop) com (stop) au
Jul 18 '05 #4
On Sun, Sep 05, 2004 at 02:41:35AM +0200, Felix Wiemann wrote:
Hi!

I want to create a module myproject.ui.cu rses, which needs to import the
curses library.

However, if I just write ``import curses``, the module imports *itself*
instead of the standard library's curses module.

Is there any (reliable) way to access a module of the standard library
if the names conflict as in this case?


not now. I think your best bet is to call your module 'Curses'.

--
John Lenton (jo**@grulic.or g.ar) -- Random fortune:
Civilization is the limitless multiplication of unnecessary necessities.
-- Mark Twain

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBOyFLgPq u395ykGsRAl6TAJ 9uwPbvKbILgRV/m24Mw0QAsLdz5QC ffy1/
hcoRxXzAzrNPcch jNiBncy4=
=CYIX
-----END PGP SIGNATURE-----

Jul 18 '05 #5
Nigel Rowe wrote:
In the mean time [until PEP 328 is implemented],

http://hkn.eecs.berkeley.edu/~dyoo/python/__std__

can help at least some of the problems.


This doesn't always work:

$ cat random.py
from __std__ import random

$ python random.py # this works

$ cat curses.py
from __std__ import curses

$ python curses.py # this does not work
Traceback (most recent call last):
File "curses.py" , line 1, in ?
from __std__ import curses
File "/usr/lib/python2.3/curses/__init__.py", line 16, in ?
from curses.wrapper import wrapper <--- Uh-oh
File "/var/home/felix/tmp/curses.py", line 1, in ?
from __std__ import curses
ImportError: cannot import name curses

So I hope that absolute imports will get implemented in Python 2.4. I
think I'll name my module 'Curses', as John suggested (even if that's
asking for trouble on Windows systems).

--
Felix Wiemann -- http://www.ososo.de/
Jul 18 '05 #6
Felix Wiemann <Fe***********@ gmx.net> writes:
Nigel Rowe wrote:
In the mean time [until PEP 328 is implemented],

http://hkn.eecs.berkeley.edu/~dyoo/python/__std__

can help at least some of the problems.


This doesn't always work:

$ cat random.py
from __std__ import random

$ python random.py # this works

$ cat curses.py
from __std__ import curses

$ python curses.py # this does not work
Traceback (most recent call last):
File "curses.py" , line 1, in ?
from __std__ import curses
File "/usr/lib/python2.3/curses/__init__.py", line 16, in ?
from curses.wrapper import wrapper <--- Uh-oh
File "/var/home/felix/tmp/curses.py", line 1, in ?
from __std__ import curses
ImportError: cannot import name curses

So I hope that absolute imports will get implemented in Python 2.4. I
think I'll name my module 'Curses', as John suggested (even if that's
asking for trouble on Windows systems).


Do you really need to use the same name? How about something like
"mCurses" (myCurses) or "oCurses" (own Curses), etc. ?

It avoids the name clash on Windows and states that you are really not
referring to the standar curses module.

Avoiding to use an already existing name is good and it is even better
when you are using a name tha tis available at the standard library.
Not following this might cause more harm than good in the long run (or
short run, as you've noticed already).
Be seeing you,
--
Godoy. <go***@ieee.org >
Jul 18 '05 #7
Jorge Godoy wrote:
Felix Wiemann writes:
So I hope that absolute imports will get implemented in Python 2.4. I
think I'll name my module 'Curses', as John suggested (even if that's
asking for trouble on Windows systems).
Do you really need to use the same name? How about something like
"mCurses" (myCurses) or "oCurses" (own Curses), etc. ?


Hmmm, yes. Or maybe "ncurses" (even though it's actually wrong, but at
least it's obvious).
It avoids the name clash on Windows and states that you are really not
referring to the standar curses module.


True.

--
Felix Wiemann -- http://www.ososo.de/
Jul 18 '05 #8
On Sun, Sep 05, 2004 at 05:07:23PM +0200, Felix Wiemann wrote:

So I hope that absolute imports will get implemented in Python 2.4. I
think I'll name my module 'Curses', as John suggested (even if that's
asking for trouble on Windows systems).


what kind of trouble, other than not being able to put it in the same
directory as curses.py ?

--
John Lenton (jo**@grulic.or g.ar) -- Random fortune:
No hay peor sordo que el que no quiere oir.
-- Refrán.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBPFyrgPq u395ykGsRAgezAK CD3PnoY1TuAQp2I HCv2oSWcr0Y3ACe Id/n
tfnu9fpblUbWcsx 1TrKlSyw=
=Ha8b
-----END PGP SIGNATURE-----

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2153
by: sdhyok | last post by:
Here is my situation. To add more functionalities to a standard library(datetime) in python, I am implementing my own code called vp.datetime (directory structure, vp/datetime.py). To make it clear the file extends functions of the standard datetime, I like to use the same name with its standard library. The problem is that I have to use the standard library inside my extended code. But, whenever I try "import datetime", it assumes my...
2
1281
by: plb | last post by:
All: I am struggling with an import problem... In my package, myapp, I have a module, logging.py. That module, naturally, imports the library module logging with an 'import logging' statement. However, when I use 'import myapp.logging' in my script, the myapp.logging module tries to import itself rather than the library logging module.
18
3047
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
17
2042
by: Jacob Page | last post by:
I have created what I think may be a useful Python module, but I'd like to share it with the Python community to get feedback, i.e. if it's Pythonic. If it's considered useful by Pythonistas, I'll see about hosting it on Sourceforge or something like that. Is this a good forum for exposing modules to the public, or is there somewhere more-acceptable? Does this newsgroup find attachments acceptable? -- Jacob
70
4097
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the Python standard library, and Reinhold Birkenfeld started a discussion on it in python-dev <http://mail.python.org/pipermail/python-dev/2005-June/054438.html>. The upshot of the discussion was that many python-dev'ers wanted path added to the...
2
1841
by: Kenneth McDonald | last post by:
I'd like to propose a new PEP , for a standard library module that deals with files and file paths in an object oriented manner. I believe this module should be included as part of the standard Python distribution. Background ========== Some time ago, I wrote such a module for myself, and have found it extremely useful. Recently, I found a reference to a similar module, http://www.jorendorff.com/articles/python/path/ by Jeff Orendorff.
16
3593
by: Vadim Biktashev | last post by:
Hello all I would like to give a certain name to a certain global variable. Unfortunately, this name is already used in math.h for a mathematical function. Worse, I do need to use maths library and therefore have to include math.h. Thus my compiler reports conflicting declarations of the same name. Does anyone know any reasonably elegant way to resolve this conflict? I understand that I can give up and choose another name, but somehow not...
10
1908
by: Ron | last post by:
Hello, The following code works in a Form class module but not a standard module: Dim d1 As DateTime Format(d1, "MMMM") In a standard module I get a squigly line saying that an argument has not been specified for parameter format... So I tried this:
14
2087
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in python. It's free at http://pnk.com and it is a web timesheet for project accounting
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.