[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Importing "Modules"
From:       "David Fisher" <python () rose164 ! wuh ! wustl ! edu>
Date:       1999-03-21 16:37:41
[Download RAW message or body]

----- Original Message -----
From: "Adrian Eyre" <a.eyre@optichrome.com>
To: "JJ" <joacim@home.se>; <python-list@python.org>
Sent: Tuesday, March 21, 2000 5:45 AM
Subject: RE: Importing "Modules"

> > Constants.pyc
> > [snip]
>
> Call this file "Constants.py". The .pyc will be generated for you.
>

Nothing wrong with having the module be a .pyc (assuming it really is a
complied module).  Python will import a .pyc without a .py file present.

> > Test.py
> > -----------------------------------------------------------
> > import constants
>
> This needs to be "import Constants". Python is case-sensistive.
>

Actually, while Python is case-sensitive, theWin98 file system isn't (I
don't know about NT).  This will let you do such horrific things as this:

>>> import os
>>> import OS
>>> import Os
>>> import oS
>>> dir()
['OS', 'Os', 'PyShell', '__builtins__', '__doc__', '__name__', 'oS', 'os']
>>>

So import constants should work too.

>
> I have a lot of String contants and want them in a separate file. Then
> import the file in nessesary scripts.
>
> I have the scripts in directory C:\Python\Scripts\ and my contants in
> C:\Python\Scripts\Contants\Const.pyc
>
> How can I import 'Constants.pyc' in C:\Python\Scripts\Test.py ?

I think the real problem is that the module is called Const.pyc in the
Constants directory.  One way to fix this is to make the Constants directory
a package.  You do that by adding a file to the Constants directory called
"__init__.py".  The file can be empty.  It's the name that Python needs to
treat the directory as a package.  Once you have the file you can do this
from the scripts directory:

import Constants.Const.strBil1

or

from Constants.Const import strBil1

and both of the above should also work with lower-case constants.const on a
windows box.  (I think, once again I haven't played with a NT box and
Python)


-- 
http://www.python.org/mailman/listinfo/python-list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic