list.append和list.append .__ doc__的地址 [英] the address of list.append and list.append.__doc__

查看:83
本文介绍了list.append和list.append .__ doc__的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题,我使用的是Python 2.4.2


> > a = [1,2,3]
id(a.append)



19167152#1


>> id(list.append)



11306608#1


1. a.append和list.append的地址不同,我可以得到

来自a.append的list.append的地址?


>> id(a.append .__ doc__)



19162720


>> id(a.appen d .__ doc__)



19162336

< blockquote class =post_quotes>
>> id(a.append .__ doc__)



19162592


>> id(a.append .__ doc__)



19162720


> ;> id(list.append .__ doc__)



19162336


>> id(list.append .__ doc__)



19162720


>> id(list.append .__ doc__)



19162592


>> id(list.append .__ doc__)



19162336

2.为什么a.append .__ doc__和list.append .__ doc__的地址发生变化,

这意味着__doc__不是普通字符串,但是返回一个

字符串。

解决方案

HYRY写道:


我有以下问题,我使用的是Python 2.4.2


>>> a = [1,2,3]
id(a.append)



19167152#1


>>> i d(list.append)



11306608#1


1. a.append的地址和list.append是不同的,我可以从a.append获取list.append的

地址吗?



编号a.append是绑定方法 - 一个已经有一个

关联实例的方法,它将作为

方法调用的第一个参数提供。绑定方法是即时创建的。


>


>>> id(a.append .__ doc__)



19162720


>>> id(a.append .__ doc__)



19162336


>>> id( a.append .__ doc__)



19162592


>>> id(a.append .__ doc__)



19162720


>>> id(list.append .__ doc__)



19162336
< blockquote class =post_quotes>


>>> id(list.append .__ doc__)



19162720


>>> id(list.append .__ doc__)



19162592


>>> id(list.append。 __doc__)



19162336

2.为什么a.append .__ doc__和list.append .__ doc__的地址发生变化,

这意味着__doc__不是普通的字符串,但是返回一个

字符串。

不知道。 WJFFM on 2.5.1:


>> id(list。追加.__ doc__)



2146574752

< blockquote class =post_quotes>
>> id(list.append .__ doc__)



2146574752


>> id(list.append .__ doc__)



2146574752


> ;> id(list.append .__ doc__)



2146574752


>>>



问候

Steve

-

Steve Holden +1 571 484 6266 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://del.icio.us/steve.holden


对不起,狗吃了我的.sigline


否。 a.append是一种绑定方法。 - 一个已经有


关联实例的方法,它将作为

方法调用的第一个参数提供。绑定方法是即时创建的。



这是否意味着没有方法可以从

获取原始方法创建的方法在运行中?


我安装了python 2.4.4并再次尝试了id(list.append .__ doc__),这里

是结果,只有id(list.append .__ doc__)发生了变化,这很奇怪,

并且只发生在命令行中。因为我正在做一些在命令行中使用此id的
程序。有人可以帮我在你的电脑上试试这个吗?我想知道哪个是问题:这个版本的

python,还是我的电脑。


Python 2.4.4(#71,2006年10月18日,08:34:43)[MSC v.1310 32位(英特尔)]
win32上


键入help,copyright,credit等。或许可证或欲获得更多信息。


>> id(list .__ doc__)



11674984


> ;> id(list .__ doc__)



11674984


>> id(list .__ doc__)



11674984


>> id(list.append .__ doc__)



11747168


>> id(list.append .__ doc__)



11824352


> ;> id(list.append .__ doc__)



11747168


>> id(list.append .__ doc__)



11824352


>> id(list.append .__ doc__)



11747168


>> id(list.append .__ doc__)



11824352


>> id(list.count .__ doc__)



11863968


>> id(list.count .__ doc__)



11863968


>> id (list.count .__ doc__)



11863968


>> id(list.count .__ doc__)



11863968


En Wed,2007年9月26日01:22:37 -0300,HYRY< ru ******* @ gmail.comescribi? ??:


我安装了python 2.4.4并再次尝试了id(list.append .__ doc__),这里

是结果,只有id(list.append .__ doc__)更改,这很奇怪,

并且只发生在命令行中。因为我正在做一些在命令行中使用此id的
程序。有人可以帮我在你的电脑上试试这个吗?我想知道问题出在哪里:这个版本的

python,还是我的电脑。



问题?

也许如果你解释一下你真正想做什么,有人可以认为

这样做的方式,很可能*不*使用id()


> ;>> id(list.count .__ doc__)



11863968


>>> id(list.count .__ doc__)



11863968


>>> id(list.count .__ doc__)



11863968


>>> id(list.count .__ doc __)



11863968



这种行为是一个意外。实际的doc字符串存储为定义列表类型的C结构中的C / $
以null结尾的字符串。

当您请求list.append .__ doc __时,Python字符串对象必须是

建立指向原始C字符串。在调用id()之后,没有人

引用该字符串对象,并且它是垃圾收集的。下次你要求b $ b请求相同的东西,取决于内存如何分配器工作的细节,它可能会或可能不会重复使用相同的内存地址。尝试使用

打印hello在这些id电话之间。


-

Gabriel Genellina


I have the following questions, I am using Python 2.4.2

>>a = [1,2,3]
id(a.append)

19167152 #1

>>id(list.append)

11306608 #1

1. the address of a.append and list.append is different, can I get the
address of list.append from a.append?

>>id(a.append.__doc__)

19162720

>>id(a.append.__doc__)

19162336

>>id(a.append.__doc__)

19162592

>>id(a.append.__doc__)

19162720

>>id(list.append.__doc__)

19162336

>>id(list.append.__doc__)

19162720

>>id(list.append.__doc__)

19162592

>>id(list.append.__doc__)

19162336
2. why the address of a.append.__doc__ and list.append.__doc__ change,
this means __doc__ is not a normal string, but something return a
string.

解决方案

HYRY wrote:

I have the following questions, I am using Python 2.4.2

>>>a = [1,2,3]
id(a.append)

19167152 #1

>>>id(list.append)

11306608 #1

1. the address of a.append and list.append is different, can I get the
address of list.append from a.append?

No. a.append is a "bound method" - a method that already has an
associated instance, that will be provided as the first argument to the
method call. Bound methods are created "on the fly".

>

>>>id(a.append.__doc__)

19162720

>>>id(a.append.__doc__)

19162336

>>>id(a.append.__doc__)

19162592

>>>id(a.append.__doc__)

19162720

>>>id(list.append.__doc__)

19162336

>>>id(list.append.__doc__)

19162720

>>>id(list.append.__doc__)

19162592

>>>id(list.append.__doc__)

19162336
2. why the address of a.append.__doc__ and list.append.__doc__ change,
this means __doc__ is not a normal string, but something return a
string.
Don''t know. WJFFM on 2.5.1:

>>id(list.append.__doc__)

2146574752

>>id(list.append.__doc__)

2146574752

>>id(list.append.__doc__)

2146574752

>>id(list.append.__doc__)

2146574752

>>>

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline


No. a.append is a "bound method" - a method that already has an

associated instance, that will be provided as the first argument to the
method call. Bound methods are created "on the fly".

Does this means there is no method to get the original methods from
the Bound methods created "on the fly"?

I installed python 2.4.4 and tried id(list.append.__doc__) again, here
is the result, only id(list.append.__doc__) changes, this is strange,
and only happened in the command line. Because I am doing something
program that use this id in the command line. Can someone help me try
this on your PC, I want to know which is the problem: this version of
python, or my PC.

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

>>id(list.__doc__)

11674984

>>id(list.__doc__)

11674984

>>id(list.__doc__)

11674984

>>id(list.append.__doc__)

11747168

>>id(list.append.__doc__)

11824352

>>id(list.append.__doc__)

11747168

>>id(list.append.__doc__)

11824352

>>id(list.append.__doc__)

11747168

>>id(list.append.__doc__)

11824352

>>id(list.count.__doc__)

11863968

>>id(list.count.__doc__)

11863968

>>id(list.count.__doc__)

11863968

>>id(list.count.__doc__)

11863968


En Wed, 26 Sep 2007 01:22:37 -0300, HYRY <ru*******@gmail.comescribi???:

I installed python 2.4.4 and tried id(list.append.__doc__) again, here
is the result, only id(list.append.__doc__) changes, this is strange,
and only happened in the command line. Because I am doing something
program that use this id in the command line. Can someone help me try
this on your PC, I want to know which is the problem: this version of
python, or my PC.

"the problem"?
Perhaps if you explain what you really want to do, someone can think the
way to do that, most likely *not* using id()

>>>id(list.count.__doc__)

11863968

>>>id(list.count.__doc__)

11863968

>>>id(list.count.__doc__)

11863968

>>>id(list.count.__doc__)

11863968

This behavior is an accident. The actual doc strings are stored as C
null-terminated strings inside the C structures defining the list type.
When you request list.append.__doc__, a Python string object has to be
built pointing to the original C string. After the call to id(), nobody
references that string object, and it is garbage collected. Next time you
request the same thing, depending on the details on how the memory
allocator works, it may or may not reuse the same memory address. Try with
some print "hello" in between those id calls.

--
Gabriel Genellina


这篇关于list.append和list.append .__ doc__的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆