import behaviour on Mac and Unix

Mark Jackson mjackson at wc.eso.mc.xerox.com
Tue Aug 8 09:57:49 EDT 2000


igorr at ifi.uio.no (Igor V. Rafienko) writes:

> It seems to me that import behaves differently on Unix (Linux) and
> Mac.
>
> I have a code that looks approximately like this (this is simplified,
> of course):
> 
> file: bar.py
> #!/usr/bin/env python
> 
> def foo():
>     print "I'm foo!\n"
> 
> 
> When I start the interpreter and load module bar, dir() reports that
> foo is present in that module. This is the behaviour on Unix, and this
> is, AFAIK, the expected behaviour.
> 
> However, on Mac, the *exactly* same file (except perhaps for
> tranformation of Unix style newlines into Mac style newlines)

Hold that parenthetical thought.

> can be
> imported, *but* module bar contains nothing but __doc__, __file__ and
> __builtins__. There is *no* reference to foo.

Are you *sure* the line termination is right on the Mac?  The behavior
you report would result if the Mac version of Python were seeing bar.py
as one long line (which starts with "#". . .).

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
    I arise in the morning torn between a desire to improve (or save)
    the world and a desire to enjoy (or savor) the world.  This makes
    it hard to plan the day.		- E. B. White





More information about the Python-list mailing list