Страница 4 из 4

Добавлено: Пн, 2 апреля 2018, 19:00:13
dyvniy
Константы
const in python
http://code.activestate.com/recipes/65207-constants-in-python/?in=user-97991

Код: Выделить всё

# Put in const.py...:
class _const:
    class 
ConstError(TypeError): pass
    def __setattr__
(self,name,value):
        if 
self.__dict__.has_key(name):
            
raise self.ConstError"Can't rebind const(%s)"%name
        self
.__dict__[name]=value
import sys
sys
.modules[__name__]=_const()

# that's all -- now any client-code can
import const
# and bind an attribute ONCE:
const.magic 23
# but NOT re-bind it:
const.magic 88      # raises const.ConstError
# you may also want to add the obvious __delattr__ 

Добавлено: Пт, 27 апреля 2018, 15:13:01
dyvniy
Память в питоне
https://psutil.readthedocs.io/en/latest/#psutil.Process.memory_info
Самые важные:
rss - сколько оперативки ест процесс
vms - сколько места в файле подкачки он занимает

Добавлено: Пт, 15 июня 2018, 18:20:15
dyvniy
Module can be reload
https://stackoverflow.com/questions/961162/reload ... ror-name-reload-is-not-defined
in python 3.5+ :

Код: Выделить всё

import importlib
importlib
.reload(pymodule