Best viewed with LeechCraft on Microsoft Linux. Войти !bnw Сегодня Клубы
Привет, TbI — HRWKA! 1235.0 пользователей не могут ошибаться!
?6912
прекрасное6424
говно5887
говнорашка5512
хуита4695
anime3056
linux2645
music2625
bnw2589
рашка2561
log2337
ололо2114
pic1814
дунч1734
сталирасты1488
украина1437
быдло1434
bnw_ppl1371
дыбр1237
гімно1158

## module M1.py
a = 'First Message'
def printer(): print 'Hello from M1:', a

>>> import M1
>>> M1pr = M1.printer
>>> M1pr()

Hello from M1: First Message
>>> # Change printer and message ...
>>> reload(M1)

<module 'M1' from 'M1.py'>
>>> M1pr() # still using old printer

Hello from M1: Second Message # surprise message is changed
>>> M1pr = M1.printer
>>> M1pr()

Hello from second printer: Second Message # as expected
>>> M1.a = 'Third Message'
>>> M1pr()

Hello from second printer: Third Message

The surprise here is that we didn&#39;t expect any changes after the reload, because we are still using the old M1pr(). The reason we get a new message in this case is that the old printer(), which is defined in module M1, implicitly uses M1.a as its message, and M1.a is updated with a reload of M1. To say this in another way, when printer() is defined in module M1, it points to the name a in the M1 dictionary, not to an object in memory. When M1.a is redefined, the old printer function gets the new message. The third test above makes this clear.

http://www2.engr.arizona.edu/~edatools/Python/Reload.htm
// заебался вчера искать, почему один дочерний класс не видит изменений переменной класса родителя, сделанных другим дочерним класом; оказалось, что после релоада они начинают ссылаться на разные классы с одинаковым названием

#5R5DRF (4+1) / @kogda / 2892 дня назад
ipv6 ready BnW для ведрофона BnW на Реформале Викивач Котятки

Цоперайт © 2010-2016 @stiletto.