Форум сайта python.su
#!/usr/bin/python # -*- coding: UTF-8 -*- import netsnmp COMMUNITY='public' ip='10.0.0.2' oid_snmp_name='iso.3.6.1.2.1.1.5.0' name=netsnmp.snmpget(oid_snmp_name,Version=2,Community=COMMUNITY,DestHost=ip)[0] print '--------------------------------------------------------' print 'ip : '+ip print 'snmp_sys_name : '+name print '--------------------------------------------------------'
print netsnmp.snmpset(netsnmp.Varbind("1.3.6.1.2.1.1.5.0","123","STRING"),Version=2,Community=COMMUNITY,DestHost=ip)
def run(self, edit): for region in self.view.sel(): if region.empty(): line = self.view.line(region) line_contents = self.view.substr(line) + '\n' self.view.insert(edit, line.begin(), line_contents) else: self.view.insert(edit, region.begin(), self.view.substr(region))
def generate_workers(module_name, class_name, num_threads): while True: yield (module_name, class_name, num_threads) pool = multiprocessing.Pool(cfg.get('num_processes', 1)) pool.map(run_worker, generate_workers(cfg['module'], cfg['worker_class_name'], cfg['num_threads']))
a =6 # размер доски u = 36 # сколько клеток заполнить xx = 0 #начальные условия yy = 0 #начальные условия spis_popitok = [[xx,yy]] # список уже заполненных клеток / nтут первый ход коня def sledhodi(a,i,j,spis_popitok): # метод возвращает список возможных след. ходов для данной клетки vozm = [] hod = [] spis_hodov=[] if (i-2)>=0 and j+1<=a-1: #1 hod=[i-2,j+1] vozm.append(hod) if (i-1)>=0 and j+2<=a-1: #2 hod=[i-1,j+2] vozm.append(hod) if (i+1)<=a-1 and j+2<=a-1: #3 hod=[i+1,j+2] vozm.append(hod) if (i+2)<=a-1 and j+1<=a-1: #4 hod=[i+2,j+1] vozm.append(hod) if (i+2)<=a-1 and j-1>=0: #5 hod=[i+2,j-1] vozm.append(hod) if (i+1)<=a-1 and j-2>=0: #6 hod=[i+1,j-2] vozm.append(hod) if (i-1)>=0 and j-2>=0: #7 hod=[i-1,j-2] vozm.append(hod) if (i-2)>=0 and j-1>=0: #8 hod=[i-2,j-1] vozm.append(hod) for x in range(0,len(vozm)): if vozm[x] not in spis_popitok: spis_hodov.append(vozm[x]) return spis_hodov def main(a,i,j,spis_popitok): # if len(spis_popitok)==u:# print(spis_popitok) else: b =sledhodi(a,i,j,spis_popitok) # список возможных ходов текущего положения for x in range(len(b)): c = [[],[]] c[0] = b[x][0] c[1] = b[x][1] if len(b)>0: # если список возможных ходов пуст, то возвращаемся назад, если длина больше нуля углубляемся дальше main(a,c[0],c[1],spis_popitok+[c]) # берем со списка след. клетку, полученную от итератора for и добавляем ее координаты в список уже использованных main(a,xx,yy,spis_popitok)
from PyQt4 import QtSql, QtGui def createConnection(): db = QtSql.QSqlDatabase.addDatabase('QSQLITE') db.setDatabaseName(':memory:') if not db.open(): QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information " "how to build it.\n\n" "Click Cancel to exit."), QtGui.QMessageBox.Cancel) return False query = QtSql.QSqlQuery() query.exec_("create table person(id int primary key, " "firstname varchar(20), lastname varchar(20))") query.exec_("insert into person values(101, 'Danny', 'Young')") query.exec_("insert into person values(102, 'Christine', 'Holand')") query.exec_("insert into person values(103, 'Lars', 'Gordon')") query.exec_("insert into person values(104, 'Roberto', 'Robitaille')") query.exec_("insert into person values(105, 'Maria', 'Papadopoulos')") query.exec_("create table offices (id int primary key," "imagefile int," "location varchar(20)," "country varchar(20)," "description varchar(100))"); query.exec_("insert into offices " "values(0, 0, 'Oslo', 'Norway'," "'Oslo is home to more than 500 000 citizens and has a " "lot to offer.It has been called \"The city with the big " "heart\" and this is a nickname we are happy to live up to.')") query.exec_("insert into offices " "values(1, 1, 'Brisbane', 'Australia'," "'Brisbane is the capital of Queensland, the Sunshine State, " "where it is beautiful one day, perfect the next. " "Brisbane is Australia''s 3rd largest city, being home " "to almost 2 million people.')") query.exec_("insert into offices " "values(2, 2, 'Redwood City', 'US'," "'You find Redwood City in the heart of the Bay Area " "just north of Silicon Valley. The largest nearby city is " "San Jose which is the third largest city in California " "and the 10th largest in the US.')") query.exec_("insert into offices " "values(3, 3, 'Berlin', 'Germany'," "'Berlin, the capital of Germany is dynamic, cosmopolitan " "and creative, allowing for every kind of lifestyle. " "East meets West in the metropolis at the heart of a " "changing Europe.')") query.exec_("insert into offices " "values(4, 4, 'Munich', 'Germany'," "'Several technology companies are represented in Munich, " "and the city is often called the \"Bavarian Silicon Valley\". " "The exciting city is also filled with culture, " "art and music. ')") query.exec_("insert into offices " "values(5, 5, 'Beijing', 'China'," "'Beijing as a capital city has more than 3000 years of " "history. Today the city counts 12 million citizens, and " "is the political, economic and cultural centre of China.')") query.exec_("create table images (locationid int, file varchar(20))") query.exec_("insert into images values(0, 'images/oslo.png')") query.exec_("insert into images values(1, 'images/brisbane.png')") query.exec_("insert into images values(2, 'images/redwood.png')") query.exec_("insert into images values(3, 'images/berlin.png')") query.exec_("insert into images values(4, 'images/munich.png')") query.exec_("insert into images values(5, 'images/beijing.png')") return True
from PyQt4 import QtCore, QtGui, QtSql import connection def initializeModel(model): model.setTable('person') model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit) model.select() model.setHeaderData(0, QtCore.Qt.Horizontal, "ID") model.setHeaderData(1, QtCore.Qt.Horizontal, "First name") model.setHeaderData(2, QtCore.Qt.Horizontal, "Last name") def createView(title, model): view = QtGui.QTableView() view.setModel(model) view.setWindowTitle(title) return view if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) if not connection.createConnection(): sys.exit(1) model = QtSql.QSqlTableModel() initializeModel(model) view1 = createView("Table Model (View 1)", model) view1.show() sys.exit(app.exec_())
#!/usr/bin/env python3 """Example for aiohttp.web basic server """ import asyncio import textwrap from aiohttp.web import Application, Response, StreamResponse import aiohttp_jinja2 import jinja2 def intro(request): txt = textwrap.dedent("""\ Type {url}/hello/John {url}/simple or {url}/change_body in browser url bar """).format(url='127.0.0.1:8080') binary = txt.encode('utf8') resp = StreamResponse() resp.content_length = len(binary) resp.start(request) resp.write(binary) return resp def simple(request): return Response(body=b'Simple answer') def change_body(request): resp = Response() resp.body = b"Body changed" return resp @aiohttp_jinja2.template('tmpl.jinja2') @asyncio.coroutine def hello(request): resp = StreamResponse() name = request.match_info.get('name', 'Anonymous') answer = ('Hello, ' + name).encode('utf8') resp.content_length = len(answer) resp.start(request) resp.write(answer) yield from resp.write_eof() return resp @asyncio.coroutine def init(loop): app = Application(loop=loop) app.router.add_route('GET', '/', intro) app.router.add_route('GET', '/simple', simple) app.router.add_route('GET', '/change_body', change_body) app.router.add_route('GET', '/hello/{name}', hello) app.router.add_route('GET', '/hello', hello) aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates/')) # aiohttp_jinja2.setup(app, loader=jinja2.DictLoader( # {'tmpl.jinja2': "<html><body><h1>{{name}}</h1></body></html>"})) handler = app.make_handler() srv = yield from loop.create_server(handler, '127.0.0.1', 8080) print("Server started at http://127.0.0.1:8080") return srv, handler loop = asyncio.get_event_loop() srv, handler = loop.run_until_complete(init(loop)) try: loop.run_forever() except KeyboardInterrupt: loop.run_until_complete(handler.finish_connections())
WSGIScriptAlias / "C:/Apache24/htdocs/django_test_project/django_test_project/wsgi.py"
WSGIPythonPath "C:/Apache24/htdocs/django_test_project"
<Directory "C:/Apache24/htdocs/django_test_project">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
ImportError: Could not import settings 'django_test_project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named django_test_project.settings\r
import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_test_project.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
sys.path.append("C:\\Apache24\\htdocs\\django_test_project")
End of script output before headers: wsgi.py
import os import sys import importlib os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_test_project.settings") sys.path.append("C:\\Apache24\\htdocs\\django_test_project") settings_module = os.environ.get("DJANGO_SETTINGS_MODULE") mod = importlib.import_module(settings_module) f = open("test.log", "w") f.write("%s \n" % (str(mod), )) f.close() from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
<module 'django_test_project.settings' from 'C:\Apache24\htdocs\django_test_project\django_test_project\settings.pyc'>
WSGIScriptAlias / "C:/Apache24/htdocs/django_test_project/wsgi.py"
End of script output before headers: wsgi.py
# Вставить из буфера обмена def clipboard_paste(): cur_func=sys._getframe().f_code.co_name if sys_type=='win': try: win32clipboard.OpenClipboard() if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_UNICODETEXT): line=win32clipboard.GetClipboardData() else: line=err_mes_unavail Warning(cur_func,mes.cf_text_failure) win32clipboard.CloseClipboard() line=str(line) if line==None: line='' except: line=err_mes_paste Warning(cur_func,mes.clipboard_paste_failure) else: try: line=pyperclip.paste() except: line=err_mes_paste return line