请教一个怪问题

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

请教一个怪问题

fuyu0123456789

各位

又碰到一个怪问题,请看下面的3Python文件

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’]}

 

请问是怎么回事啊???

 
 
 



美利山开盘3000人抢购!440套售罄,加推300套17号开始登记!
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请教一个怪问题

Zoom.Quiet
2008/1/23 fuyu0123456789 <[hidden email]>:
>
>
> 各位
>
> 又碰到一个怪问题,请看下面的3个Python文件
>
> main.py:
>

from a import Host as AH
from b import Host as BH
print BH

表,玩自个儿就好

> 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']}
>
>
>
> 请问是怎么回事啊???
>
>
>
>
>  ________________________________
>  美利山开盘3000人抢购!440套售罄,加推300套17号开始登记!
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



--
'''Time is unimportant, only life important!
过程改进乃是开始催生可促生靠谱的人的组织!
'''http://zoomquiet.org
博 @ http://blog.zoomquiet.org/pyblosxom/
维 @ http://wiki.woodpecker.org.cn/moin/ZoomQuiet
豆 @ http://www.douban.com/people/zoomq/
看 @ http://zoomq.haokanbu.com/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip.  http://7-zip.org
You can get the truely Freedom 4 software.
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请教一个怪问题

Lich_Ray
In reply to this post by fuyu0123456789
把 import 的过程去掉,直接在 Python 解释器里执行:
>>> Host = "http://www.163.com"
>>> Hosts = {"site":[Host,]}
>>> Host =" http://www.google.com"
>>> Hosts
{'site': ['http://www.163.com']}
然后想想为什么。

在08-1-23, fuyu0123456789 <[hidden email]> 写道:

各位

又碰到一个怪问题,请看下面的3Python文件

main.py:

from a import *

from b import *

 

a.py:

Host = "<a href="http://www.163.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.163.com"

Hosts = {"site":[Host,]}

 

b.py

Host =" <a href="http://www.google.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://www.google.com"

 

Shell环境下执行下列代码

import main

main.Hosts

 

但是输出结果是

{'site': ['http://www.163.com']}

 

按我的理解应该是

{'site':['<a href="http://www.google.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://www.google.com']}

 

请问是怎么回事啊???

 
 
 



美利山开盘3000人抢购!440套售罄,<a style="font-size: 12px; line-height: 15px; color: blue; text-decoration: underline;" href="http://popme.163.com/link/003865_0118_1005.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> 加推300套17号开始登记!
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese



--
Ray Stinger, nickname Lich_Ray
God is in his heaven, all's right with the world.
-------------------------------------------------
let focus = 'computing' in where:
http://lichray.javaeye.com
let focus = 'computing' in here:
http://inblogs.net/let-in
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请教一个怪问题

Yongchao Lao
In reply to this post by fuyu0123456789
其��就是�}�u和引用的���}把,Hosts�e面是保存了Host的副本。
 
後面import了b文件的host以後,�m然覆�w了之前的�量,也�]能改�之前的值。�@�e是假�O後�淼�host覆�w原先的host--即�r是�@�樱�也是不可以改�hosts�e面的副本。但是���H情�r是�纱蔚�host���是在不同的地址,�H�H是名字一�佣�已(�@�拥脑�,就不能用host�@��名字�L��之前在a文件�O立的host�量了)。
 
 
2008-01-23

fluke.l

发件人: fuyu0123456789
发送时间: 2008-01-23  20:13:59
收件人: python-chinese
抄送:
主题: [python-chinese]请教一个怪问题

各位

又碰到一个怪问题,请看下面的3Python文件

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’]}

 

请问是怎么回事啊???

 
 
 



美利山开盘3000人抢购!440套售罄,加推300套17号开始登记!

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请教一个怪问题

Jiahua Huang
In reply to this post by fuyu0123456789
2008/1/23 fuyu0123456789 <[hidden email]>:

>
> 各位
> 又碰到一个怪问题,请看下面的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 [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese