Найти - Пользователи
Полная версия: Как называет правильно такая штука "<bound method Test.test of <__main__.Test instance at 0x02A61350>>"
Начало » Python для новичков » Как называет правильно такая штука "<bound method Test.test of <__main__.Test instance at 0x02A61350>>"
1
0xAbort
import random
# Если мы создадим несколько функции
def t1(): pass
def t2(): pass
def t3(): pass
# Положим их в список
l = [t1, t2, t3]
# То как назвать правильно переменую t
t = random.choice(l)
print(t) # Выведется "<function t1 at 0x0237F930>"


И как вообще такая штука называется. Сигнатура? Адрес?
Shaman
repr(object)

Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method.
ayb
Чтобы было понятнее :

>>> class Foo():
...     def __repr__(self):
...         return('Foo')
... 
>>> foo = Foo()
>>> foo
Foo
>>> class Bar():
...     pass
... 
>>> bar = Bar()
>>> bar
<__main__.Bar object at 0xb71077ec>
>>> 
py.user.next
0xAbort
И как вообще такая штука называется. Сигнатура? Адрес?
t - имя, привязанное к объекту. (В питоне функции являются объектами.)

>>> def f(): pass
... 
>>> f
<function f at 0xb74b93d4>
>>> id(f)
3075183572
>>> hex(id(f))
'0xb74b93d4'
>>>
>>> 1
1
>>> hex(id(1))
'0x4cba34a0'
>>>

У каждого объекта есть адрес. Имя просто привязывается к объекту через его адрес.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB