2004年08月25日 星期三 10:13
我想知道的是给定变量a, 如何得到字符串'a'? 这是一个有些神秘的事情,不知道Python是否能做到。 > -----Original Message----- > From: python-chinese-bounces at lists.python.cn > [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Xie Yanbo > Sent: 2004年8月25日 09:59 > To: python-chinese at lists.python.cn > Subject: Re: [python-chinese] 有什么办法可以判断一个变量是否被定义过 > > On 2004-08-25 09:54:1093398840 +0800, Alex Dong wrote: > > Dir() 返回的是所有已经定义的变量的名字,比如: > > >>> a = 3 > > >>> b = 4 > > >>> dir() > > ['__builtins__', '__doc__', '__name__', 'a', 'b'] > > >>> str(a) > > 3 > > 但是怎么能得到一个变量的名字呢? 一个奇怪又有趣的问题。 > > 什么叫“得到一个变量的名字”?你在执行 dir() 之后不是已经 > 都得到了吗?你是不是想通过得到的变量名字 'a' 取得 a 的值? > 如果是,这样试试: > > eval('a') > > 或者 > > eval(dir()[3]) > > 也能得到。 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > >
2004年08月25日 星期三 10:14
dreamingk(天成),您好!
opener.addheaders = [
("User-agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3"),
("Accept", "text/html, image/jpeg, image/png, text/*, image/*, */*")]
我用的winxp ie6 这一段应该怎么写?这个header必须要写吗?
======= 2004-08-25 10:11:08 您在来信中写道:=======
>Xie Yanbo,您好!
> cookie=ClientCookie.CookieJar()
> cookie.save(... )
> AttributeError: CookieJar instance has no attribute 'save'
>
>======= 2004-08-25 10:01:58 您在来信中写道:=======
>
>>On 2004-08-25 09:57:1093399068 +0800, dreamingk(天成) wrote:
>>> Xie Yanbo,您好!
>>>
>>> hehe 我正想呢,我看了半天lib ref,从来没见到过ClientCookie呢。。。
>>
>>建议现在就开始学习 cookielib, 毕竟 python2.4 正式版已经近在咫尺了
>>
>> http://www.python.org/dev/doc/devel/whatsnew/whatsnew24.html
>>
>>再过几天你就可以在正式版的 lib reference 里面看到它了。
>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>>
>
>= = = = = = = = = = = = = = = = = = = =
>
>
> 致
>礼!
>
>
> dreamingk(天成)
> dreamingker at 163.com
> 2004-08-25
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
dreamingk(天成)
dreamingker at 163.com
2004-08-25
2004年08月25日 星期三 10:17
Alex Dong,您好!
好象不可以这样吧!
可以通过给定字符串来得到相应的变量的值。逆操作应该不可以吧!
======= 2004-08-25 10:13:38 您在来信中写道:=======
>我想知道的是给定变量a, 如何得到字符串'a'?
>
>这是一个有些神秘的事情,不知道Python是否能做到。
>
>> -----Original Message-----
>> From: python-chinese-bounces at lists.python.cn
>> [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Xie Yanbo
>> Sent: 2004年8月25日 09:59
>> To: python-chinese at lists.python.cn
>> Subject: Re: [python-chinese] 有什么办法可以判断一个变量是否被定义过
>>
>> On 2004-08-25 09:54:1093398840 +0800, Alex Dong wrote:
>> > Dir() 返回的是所有已经定义的变量的名字,比如:
>> > >>> a = 3
>> > >>> b = 4
>> > >>> dir()
>> > ['__builtins__', '__doc__', '__name__', 'a', 'b']
>> > >>> str(a)
>> > 3
>> > 但是怎么能得到一个变量的名字呢? 一个奇怪又有趣的问题。
>>
>> 什么叫“得到一个变量的名字”?你在执行 dir() 之后不是已经
>> 都得到了吗?你是不是想通过得到的变量名字 'a' 取得 a 的值?
>> 如果是,这样试试:
>>
>> eval('a')
>>
>> 或者
>>
>> eval(dir()[3])
>>
>> 也能得到。
>>
>> _______________________________________________
>> python-chinese list
>> python-chinese at lists.python.cn
>> http://python.cn/mailman/listinfo/python-chinese
>>
>>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
= = = = = = = = = = = = = = = = = = = =
致
礼!
dreamingk(天成)
dreamingker at 163.com
2004-08-25
2004年08月25日 星期三 11:51
On 2004-08-25 10:13:1093400018 +0800, Alex Dong wrote: > 我想知道的是给定变量a, 如何得到字符串'a'? > > 这是一个有些神秘的事情,不知道Python是否能做到。 恐怕不可以。和其他高级语言一样,Python 可以在运行时探测某个 变量的数据类型,这是有意义的;但运行时探测变量的名字真的有 意义吗?从实质上来说,变量名实际上代表的是一个引用,几个不同 的变量名可以实际指向的是一个变量,你只要能引用到这个变量中 的数据就可以了,有必要知道这个引用的名字吗? 我没有研究过源代码,不过我估计 Python 里得不到你想要的功能。
Zeuux © 2025
京ICP备05028076号