Re: 请教一个怪问题

"Jiahua Huang" <[email protected]> Thu, 24 Jan 2008 10:32:12 +0800
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
2008/1/23 fuyu0123456789 <[email protected]>:
>
> 各位
> 又碰到一个怪问题,请看下面的3个Python文件
> main.py:
> from a import *
> from b import *
>
> a.py:
> Host = "http://www.163.com"
> Hosts = {"site":[Host,]}
>
> b.py
> Host =" http://www.google.com"
>
> 在Shell环境下执行下列代码
> import main
> main.Hosts
>
> 但是输出结果是
>
> {'site': ['http://www.163.com']}
>
> 按我的理解应该是
>
> {'site':['http://www.google.com']}
>

> 请问是怎么回事啊???
>


有什么不对么,

你的 Hosts = {"site":[Host,]}  后,
修改 Host 会改变 Hosts ?

Python 里边 字符串可是 不可变对象,
不能作为"引用" 来用
_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese