'from ... import *' woes...

Michael Lauer mickey at sirius.tm.informatik.uni-frankfurt.de
Fri May 11 03:35:21 EDT 2001


Good morning,

I have a strange problem...

Consider the following program which implements a stack:

-------------------------------
#!/usr/bin/env python
Stack = []
 
def push(data):
    global Stack
    Stack = [data] + Stack
 
 
def pop():
    global Stack
    top, Stack = Stack[0], Stack[1:]
    return top
------------------------------

When I use this program via 'import', it functions as follows:

------------------------------------------
Python 2.1 (#1, Apr 21 2001, 03:38:10)
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import stack
>>> stack.Stack
[]
>>> stack.push("Hallo")
>>> stack.Stack
['Hallo']
>>> stack.pop()
'Hallo'
>>> stack.Stack
[]
>>>
-------------------------------------------

Ok, this is what I did expect. Now please see what happens if I use from ... import *

-------------------------------------------
Python 2.1 (#1, Apr 21 2001, 03:38:10)
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from stack import *
>>> Stack
[]
>>> push("Hallo")
>>> Stack
[]
>>> pop()
'Hallo'
>>> 
--------------------------------------------

So... what is happening here ? Why is the Stack display as an empty list although
a value is 'pushed' and I can 'pop' that value... ?

Yours,

:M:




More information about the Python-list mailing list