Форум сайта python.su
0
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>"
Отредактировано 0xAbort (Июль 5, 2015 16:21:31)
Офлайн
88
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.
Офлайн
24
Чтобы было понятнее :
>>> class Foo(): ... def __repr__(self): ... return('Foo') ... >>> foo = Foo() >>> foo Foo >>> class Bar(): ... pass ... >>> bar = Bar() >>> bar <__main__.Bar object at 0xb71077ec> >>>
Офлайн
857
0xAbortt - имя, привязанное к объекту. (В питоне функции являются объектами.)
И как вообще такая штука называется. Сигнатура? Адрес?
>>> def f(): pass ... >>> f <function f at 0xb74b93d4> >>> id(f) 3075183572 >>> hex(id(f)) '0xb74b93d4' >>> >>> 1 1 >>> hex(id(1)) '0x4cba34a0' >>>
Отредактировано py.user.next (Июль 6, 2015 03:02:51)
Офлайн