Python论坛  - 讨论区

标题:[python-chinese] 请教一个怪问题

2008年01月23日 星期三 20:11

fuyu0123456789 fuyu0123456789在163.com
星期三 一月 23 20:11:40 HKT 2008

各位

又碰到一个怪问题,请看下面的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’]}

 

请问是怎么回事啊???

 
 
-------------- 涓嬩竴閮ㄥ垎 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20080123/c34d1ea0/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月23日 星期三 20:34

Zoom.Quiet zoom.quiet在gmail.com
星期三 一月 23 20:34:44 HKT 2008

2008/1/23 fuyu0123456789 <fuyu0123456789在163.com>:
>
>
> 各位
>
> 又碰到一个怪问题,请看下面的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 python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> 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.

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]
zy

zy

2008年01月23日 星期三 20:36

Lich_Ray solo.lich在gmail.com
星期三 一月 23 20:36:21 HKT 2008

°Ñ 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 <fuyu0123456789在163.com> дµÀ£º
>
> ¸÷λ
>
> ÓÖÅöµ½Ò»¸ö¹ÖÎÊÌ⣬Çë¿´ÏÂÃæµÄ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']}
>
>
>
> ÇëÎÊÊÇÔõô»ØÊ°¡£¿£¿£¿
>
>
>
>
>
> ------------------------------
> ÃÀÀûɽ¿ªÅÌ3000ÈËÇÀ¹º£¡440Ì×ÊÛóÀ£¬¼ÓÍÆ300Ì×17ºÅ¿ªÊ¼µÇ¼Ç£¡<http://popme.163.com/link/003865_0118_1005.html>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: 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
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080123/9fb3c108/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月23日 星期三 21:23

fluke.l fluke.l在gmail.com
星期三 一月 23 21:23:57 HKT 2008

Æ䌍¾ÍÊÇÑ}ÑuºÍÒýÓõƖî}°Ñ£¬HostsÑeÃæÊDZ£´æÁËHostµÄ¸±±¾¡£

ááÃæimportÁËbÎļþµÄhostÒÔáᣬëmÈ»¸²ÉwÁË֮ǰµÄ׃Á¿£¬Ò²›]ÄܸÄ׃֮ǰµÄÖµ¡£ß@ÑeÊǼÙÔOááíµÄhost¸²ÉwÔ­ÏȵÄhost--¼´•rÊÇß@˜Ó£¬Ò²ÊDz»¿ÉÒÔ¸Ä׃hostsÑeÃæµÄ¸±±¾¡£µ«Ênjë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]Çë½ÌÒ»¸ö¹ÖÎÊÌâ 
 
¸÷λ
ÓÖÅöµ½Ò»¸ö¹ÖÎÊÌ⣬Çë¿´ÏÂÃæµÄ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¡¯]}
 
ÇëÎÊÊÇÔõô»ØÊ°¡£¿£¿£¿







ÃÀÀûɽ¿ªÅÌ3000ÈËÇÀ¹º£¡440Ì×ÊÛóÀ£¬¼ÓÍÆ300Ì×17ºÅ¿ªÊ¼µÇ¼Ç£¡ 
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080123/4d9bbd3b/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月24日 星期四 10:32

Jiahua Huang jhuangjiahua在gmail.com
星期四 一月 24 10:32:12 HKT 2008

2008/1/23 fuyu0123456789 <fuyu0123456789 at 163.com>:
>
> 各位
> 又碰到一个怪问题,请看下面的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 里边 字符串可是 不可变对象,
不能作为"引用" 来用

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号