Форум сайта python.su
for elem in g.doc.select("//a[@class='mainHitsSection catalogLvl2ItemHd']"):
print "Категория: " + elem.attr("href")
from twisted.internet import protocol, reactor import time import threading import redis host = 'localhost' port = 9879 class ListenRedis(threading.Thread): def __init__(self): threading.Thread.__init__(self) print("Init redis") self.redis = redis.Redis() self.pubsub = self.redis.pubsub() self.pubsub.subscribe("test_sub") self.runing = True def run(self): for item in self.pubsub.listen(): self.work(item) def work(self, item): if item["type"] != "message": return print(item) factory.send_data(item["data"]) class Twist_client(protocol.Protocol): def dataReceived(self, data): print (data.decode()) if data.decode() == "OK": print("Server say say OK") class Twist_Factory(protocol.ClientFactory): protocol = Twist_client client = Twist_client() def clientConnectionFailed(self, connector, reason): print( '1connection failed:', reason.getErrorMessage()) time.sleep(2) connector.connect() def buildProtocol(self, addr): print ('Connected.') return Twist_client() def clientConnectionLost(self, connector, reason): print( '2connection lost:', reason.getErrorMessage()) time.sleep(2) connector.connect() def send_data(self, data): re.transport.write(data) print("Start") lis = ListenRedis() lis.start() factory = Twist_Factory() re = reactor.connectTCP(host, port, factory) reactor.run()
t ['ABC' ]={'test_value1':1,'test_value2':2}
easy_install tarantool
>>> import tarantool >>> help(tarantool)
def get(arg): attributes['__table_args__'] = {'extend_existing': True, # allows create same objects at one runtime 'prefixes': ["TEMPORARY"]} # always creating temporary table return type(result.name, (Base,), attributes) # returns new class with Properties of Object instance
>>> from app import get, engine >>> from sqlalchemy.schema import CreateTable >>> sim = get('sim_number') >>> sim = get('sim_number') # допустим, понадобилось создать ещё один экземпляр /usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/clsregistry.py:167: SAWarning: This declarative base already contains a class with the same class name and module name as bill_classes.sim_number, and will be replaced in the string-lookup table. existing.add_item(cls) Traceback (most recent call last): File "/usr/lib/python3.4/code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 1, in <module> File "/media/spicin/7EB7608F698AE718/beeapi/bill_classes.py", line 139, in get return type(result.name, (Base,), attributes) # returns new class with Properties of Object instance File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/api.py", line 55, in __init__ _as_declarative(cls, classname, cls.__dict__) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/base.py", line 254, in _as_declarative **table_kw) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 396, in __new__ table._init_existing(*args, **kw) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 548, in _init_existing self._extra_kwargs(**kwargs) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 552, in _extra_kwargs self._validate_dialect_kwargs(kwargs) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/base.py", line 282, in _validate_dialect_kwargs "named <dialectname>_<argument>, got '%s'" % k) TypeError: Additional arguments should be named <dialectname>_<argument>, got 'prefixes'
def send_text(msg): text["state"]='normal' text.delete(1.0, END) text.insert("end", msg.decode('866')) text.update() text["state"]='disable' ... cmd='call export.bat' proba=subprocess.check_output(cmd, stderr=subprocess.STDOUT) while True: s = proba.stdout.readline() if not s: break send_text(s)
cmd='bat\\Helpful information\\' + a proba=subprocess.check_output(cmd, stderr=subprocess.STDOUT) send_text(proba)
#!/usr/bin/python # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui, QtOpenGL from Webcam import Ui_MainWindow import sys, cv, cv2, numpy class Web(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) class MyView(QtGui.QGraphicsView): def __init__(self,*args): QtGui.QGraphicsView.__init__(self,*args) self.scene = QtGui.QGraphicsScene() self.scene.addPixmap('1.png') view = MyView(self.scene) capture = cv.CaptureFromCAM(-1) while True: img = cv.QueryFrame(capture) cv.ShowImage("WEB-camera", img) if cv.WaitKey(10) == 27: break cv.DestroyWindow("WEB-camera") if __name__ == '__main__': app = QtGui.QApplication(sys.argv) MainApp = Web() MainApp.show() sys.exit(app.exec_())