[Python-Dev] import succeeds on second try?

Ka-Ping Yee ping@lfw.org
Sat, 10 Feb 2001 17:42:49 -0800 (PST)


This is weird:

    localhost[1118]% ll spam*
    -rw-r--r--   1 ping     users          69 Feb 10 17:40 spam.py
    localhost[1119]% ll eggs*
    /bin/ls: eggs*: No such file or directory
    localhost[1120]% cat spam.py
    a = 1
    print 'hello'
    import eggs # no such file
    print 'goodbye'
    b = 2
    localhost[1121]% python
    Python 2.1a2 (#22, Feb 10 2001, 16:15:14) 
    [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
    Type "copyright", "credits" or "license" for more information.
    >>> import spam
    hello
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "spam.py", line 3, in ?
        import eggs # no such file
    ImportError: No module named eggs
    >>> import spam
    >>> dir(spam)
    ['__builtins__', '__doc__', '__file__', '__name__', 'a']
    >>>
    localhost[1122]% ll spam*
    -rw-r--r--   1 ping     users          69 Feb 10 17:40 spam.py
    -rw-r--r--   1 ping     users         208 Feb 10 17:41 spam.pyc
    localhost[1123]% ll eggs*
    /bin/ls: eggs*: No such file or directory

Why did Python write spam.pyc after the import failed?



-- ?!ng

Happiness comes more from loving than being loved; and often when our
affection seems wounded it is is only our vanity bleeding. To love, and
to be hurt often, and to love again--this is the brave and happy life.
    -- J. E. Buchrose