module name vs '.'

Dave Angel d at davea.name
Mon Jun 18 09:44:49 EDT 2012


On 06/18/2012 09:19 AM, Neal Becker wrote:
> Am I correct that a module could never come from a file path with a '.' in the 
> name?
>
No.
Simple example: Create a directory called src.directory
In that directory, create two files
::neal.py::
import becker
print becker.__file__
print becker.hello()
::becker.py::
def hello():
 print "Inside hello"
 return "returning"
Then run neal.py, from that directory;
davea at think:~/temppython/src.directory$ python neal.py
/mnt/data/davea/temppython/src.directory/becker.pyc
Inside hello
returning
davea at think:~/temppython/src.directory$
Observe the results of printing __file__
Other approaches include putting a directory path containing a period
into sys.path
-- 
DaveA


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /