how to get the path of a module (myself) ?

Robert Kern robert.kern at gmail.com
Tue Jun 2 19:19:41 EDT 2009


On 2009-06-02 18:00, Stef Mientki wrote:
> Robert Kern wrote:
>> On 2009-06-02 14:24, Stef Mientki wrote:
>>>
>>>> The same rule applies for your modules. As a general rule, NEVER say:
>>>>
>>>> execfile('mymodule.py')
>>>>
>>>> instead do:
>>>>
>>>> import mymodule
>>>> mymodule.some_function()
>>>> mymodule.another_function()
>>>>
>>>>
>>>> (There are exceptions, but if you need to ask what they are, you're
>>>> not ready to learn them! *wink*)
>>>>
>>>>
>>> hi Steven,
>>> maybe you hit the nail right on his head.
>>> But I finally want to release my program, with or without proper
>>> imports, but working correctly.
>>> And I'll leave the "import details" to some other guru.
>>
>> Getting the "import details" right is how you get it to work correctly.
>>
> Sorry,
> but I realy don't understand the difference between the documents on my
> desk and a python file in a subpath.

I really don't understand what relevance you think that has to writing correct 
Python programs. Yes, Python files are, indeed, files. But the correct way to 
write Python programs in multiple Python files is to organize them into modules 
and packages and use Python's import mechanism to make them reference each 
other. Please read the tutorial:

   http://docs.python.org/tutorial/modules.html

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list