Форум сайта python.su
Понемногу заканчиваются последние билеты.
Знаю, что, как и год назад, найдутся особо несознательные граждане, которые будут просить билетик за день до события, соглашаясь на тройную цену стоя и без обеда.
Тем не менее настоятельно рекомендую тем, кто имеет желание посетить конференцию и все еще не приобрел билет — сделать это поскорее.
from zipfile import ZipFile, ZIP_DEFLATED zipfile = ZipFile('./zipfile.zip', mode='w', compression=ZIP_DEFLATED) for file in listOfStaticFiles: zipfile.write(file) zipfile.close()
zipfile = ZipFile('./zipfile.zip', mode='r') for info in zipfile.infolist(): print info.filename print '\tModified:\t', datetime.datetime(*info.date_time) zipfile.extractall()
class QuitButton(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) # Window какой-то код .... # buttons button1 = QtGui.QPushButton('add') button1.clicked.connect(self.add_Text) #hbox hbox = QtGui.QHBoxLayout() hbox.addWidget(button1) self.setLayout(hbox) def add_Text(self): text1 = QtGui.QLineEdit('text') hbox.addWidget(text1, 10)
def set_Text(self): hbox.text1.setText('new text')
""" A simple example to show how to access a 3D numpy array. One example shows how to access the numpy array using blitz type converters and the other shows how it can be done without using blitz by accessing the numpy array data directly. """ import scipy.weave as weave from scipy.weave import converters import numpy def create_array(): """Creates a simple 3D numpy array with unique values at each location in the matrix. """ rows, cols, depth = 2, 3, 4 arr = numpy.zeros((rows, cols, depth), 'i') count = 0 for i in range(rows): for j in range(cols): for k in range(depth): arr[i,j,k] = count count += 1 return arr def pure_inline(arr): """Prints the given 3D array by accessing the raw numpy data and without using blitz converters. Notice the following: 1. '\\n' to escape generating a newline in the C++ code. 2. rows, cols = Narr[0], Narr[1]. 3. Array access using arr[(i*cols + j)*depth + k]. """ code = """ int rows = Narr[0]; int cols = Narr[1]; int depth = Narr[2]; for (int i=0; i < rows; i++) { for (int j=0; j < cols; j++) { printf("img[%3d][%3d]=", i, j); for (int k=0; k< depth; ++k) { printf(" %3d", arr[(i*cols + j)*depth + k]); } printf("\\n"); } } """ weave.inline(code, ['arr']) def blitz_inline(arr): """Prints the given 3D array by using blitz converters which provides a numpy-like syntax for accessing the numpy data. Notice the following: 1. '\\n' to escape generating a newline in the C++ code. 2. rows, cols = Narr[0], Narr[1]. 3. Array access using arr(i, j, k). """ code = """ int rows = Narr[0]; int cols = Narr[1]; int depth = Narr[2]; for (int i=0; i < rows; i++) { for (int j=0; j < cols; j++) { printf("img[%3d][%3d]=", i, j); for (int k=0; k< depth; ++k) { printf(" %3d", arr(i, j, k)); } printf("\\n"); } } """ weave.inline(code, ['arr'], type_converters=converters.blitz) def main(): arr = create_array() print("numpy:") print(arr) print("Pure Inline:") pure_inline(arr) print("Blitz Inline:") blitz_inline(arr) if __name__ == '__main__': main()
numpy: [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] Pure Inline: No module named msvccompiler in numpy.distutils; trying from distutils creating c:\docume~1\m@d_ph~1\locals~1\temp\M@D_PHISICER\python27_intermediate\compiler_d41d8cd98f00b204e9800998ecf8427e Missing compiler_cxx fix for MSVCCompiler Found executable C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe Traceback (most recent call last): File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 105, in <module> main() File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 98, in main pure_inline(arr) File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 57, in pure_inline weave.inline(code, ['arr']) File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 355, in inline **kw) File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 482, in compile_function verbose=verbose, **kw) File "C:\Python27\lib\site-packages\scipy\weave\ext_tools.py", line 367, in compile verbose = verbose, **kw) File "C:\Python27\lib\site-packages\scipy\weave\build_tools.py", line 272, in build_extension setup(name = module_name, ext_modules = [ext],verbose=verb) File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 186, in setup return old_setup(**new_attr) File "C:\Python27\lib\distutils\core.py", line 162, in setup raise SystemExit, error CompileError: error: Bad file descriptor
weave.inline(code, ['arr'])
weave.inline(code, ['arr'], type_converters=converters.blitz)
weave.inline(code, ['arr'], compiler='gcc')
weave.inline(code, ['arr'], type_converters=converters.blitz,compiler='gcc')
numpy: [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] Pure Inline: creating c:\docume~1\m@d_ph~1\locals~1\temp\M@D_PHISICER\python27_intermediate\compiler_ceffdcf12be28532cafcaa87f8ac2f76 Found executable C:\MinGW\bin\g++.exe Traceback (most recent call last): File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 105, in <module> main() File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 98, in main pure_inline(arr) File "C:\Python32\Lib\site-packages\scipy\weave\examples\array3d.py", line 57, in pure_inline weave.inline(code, ['arr'], compiler='gcc') File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 355, in inline **kw) File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 482, in compile_function verbose=verbose, **kw) File "C:\Python27\lib\site-packages\scipy\weave\ext_tools.py", line 367, in compile verbose = verbose, **kw) File "C:\Python27\lib\site-packages\scipy\weave\build_tools.py", line 272, in build_extension setup(name = module_name, ext_modules = [ext],verbose=verb) File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 186, in setup return old_setup(**new_attr) File "C:\Python27\lib\distutils\core.py", line 162, in setup raise SystemExit, error CompileError: error: Bad file descriptor
cherrypy.HTTPRedirect("http://10.0.0.2/page/")
a = {600: {'sex':'male','name':'Joe'}, 320: {'sex':'female','name':'Sara'}, 400: {'sex':'female','name':'Kristina'}, 120: {'sex':'male','name':'Bob'}, 250: {'sex':'male','name':'Fredd'}} print a # Подсчитываем разницу во времени прибытия и сортируем ее в обратном порядке wait = list(a) wait.sort(reverse=True) print wait wait = map(lambda x: x[0]-x[1], zip(wait, wait[1:]))+[0] print wait # Заносим в словарь разницу времени прибытия for i, z in zip(sorted(a, reverse=True), wait): a[i]['wait']=z #print a #{600: {'wait': 200, 'name': 'Joe', 'sex': 'male'}, 320: {'wait': 70, 'name': 'Sara', 'sex': 'female'}, 400: {'wait': 80, 'name': 'Kristina', 'sex': 'female'}, 250: {'wait': 130, 'name': 'Fredd', 'sex': 'male'}, 120: {'wait': 0, 'name': 'Bob', 'sex': 'male'}}) for i in sorted(a, reverse=True): print '%s ушел(ла)' %(a[i]['name']) time.sleep(a[i]['wait'])
# -*- coding: utf-8 -*- import pyodbc import glob def getSelect(cl): select='select ' for sl in cl: select+=sl+',' select=select[:-1]+' from ' return select #подключаюсь и получаю курсор conn=pyodbc.connect(r"DRIVER={Microsoft dBASE Driver (*.dbf)};Dbq=E:\Code\DBF",autocommit=True).cursor() #получаю список столпцов\колонок columns=[column.column_name.decode('cp1251') for column in conn.columns(table='A_OBJEKT')] #собераю селект и вывожу его select=getSelect(columns)+'A_OBJEKT' print(select) #выполняю селект conn.execute(select)
[HY000] [Microsoft][Драйвер ODBC dBase] Ключ поиска не найден ни в одной записи. (-1601) (SQLGetData)
Traceback (most recent call last): File "C:\Program Files (x86)\JetBrains\PyCharm 2.5\helpers\pycharm\django_manage.py", line 17, in <module> run_module(manage_file, None, '__main__') File "C:\Program Files (x86)\Python27\Lib\runpy.py", line 180, in run_module fname, loader, pkg_name) File "C:\Program Files (x86)\Python27\Lib\runpy.py", line 72, in _run_code exec code in run_globals File "D:\pyCharm\pybbm\test\example_bootstrap\manage.py", line 14, in <module> execute_from_command_line(sys.argv) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line utility.execute() File "D:\pyCharm\envPyBBM\Lib\site-packages\django\core\management\__init__.py", line 382, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\core\management\base.py", line 196, in run_from_argv self.execute(*args, **options.__dict__) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\core\management\base.py", line 232, in execute output = self.handle(*args, **options) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 124, in handle User.objects.db_manager(database).create_superuser(username, email, password) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\contrib\auth\models.py", line 164, in create_superuser u = self.create_user(username, email, password) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\contrib\auth\models.py", line 160, in create_user user.save(using=self._db) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\base.py", line 463, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\base.py", line 565, in save_base created=(not record_exists), raw=raw, using=using) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\dispatch\dispatcher.py", line 172, in send response = receiver(signal=self, sender=sender, **named) File "D:\pyCharm\envPyBBM\Lib\site-packages\pybb\signals.py", line 41, in user_saved ReadTracking.objects.create(user=instance) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\manager.py", line 137, in create return self.get_query_set().create(**kwargs) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\query.py", line 377, in create obj.save(force_insert=True, using=self.db) File "D:\pyCharm\envPyBBM\Lib\site-packages\pybb\models.py", line 342, in save super(ReadTracking, self).save(*args, **kwargs) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\base.py", line 463, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\base.py", line 551, in save_base result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\manager.py", line 203, in _insert return insert_query(self.model, objs, fields, **kwargs) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\query.py", line 1576, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\sql\compiler.py", line 909, in execute_sql for sql, params in self.as_sql(): File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\sql\compiler.py", line 872, in as_sql for obj in self.query.objs File "D:\pyCharm\envPyBBM\Lib\site-packages\django\db\models\fields\__init__.py", line 292, in get_db_prep_save prepared=False) TypeError: get_db_prep_value() got an unexpected keyword argument 'connection'