python

Python logging over multiple files

Hello Gentlemen, I've read through the logging module documentation and whilst I may have missed something obvious, the code I've got doesn't appear to be working as intended. I'm using Python 2.6.4. My program consists of several different python files, from which I want to send logging messages to a text file and, potentially, the sc...

Python - automating MySQL index: passing parameter

Hi Everybody, I have a function with a new improved version of the code for automatic table indexing: def update_tableIndex(self,tableName): getIndexMySQLQuery = """SELECT numberID FROM %s;""" % (tableName,) updateIndexMySQLQuery = """UPDATE %s SET numberID=%s WHERE numberID=%s;""" % (tableName,) updateIndex=1 ...

Python: Very confused about decorators...

I thought I understood decorators but not anymore. Do decorators only work when the function is created? I wanted to create a series of functions that all have a required argument called 'ticket_params' that is a dictionary. and then decorate them with something like @param_checker(['req_param_1', 'req_param_2']) and then if 'req_param_...

setting script path in a buildout using one of the distutils recipes

I am using buildout. I am using it to install openerp. I would like the scripts that openerp creates to run itself available in ${buildout:location}/bin I tried zerokspot.recipe.distutils and collective.recipe.distutils How would I get the scripts built in bin? ...

Any way to set request headers when doing a request using urllib in Python 2.x?

I am trying to make an HTTP request in Python 2.6.4, using the urllib module. Is there any way to set the request headers? I am sure that this is possible using urllib2, but I would prefer to use urllib since it seems simpler. ...

how can i use django.utils.safestring.py

from django.utils.safestring import * print SafeString('\u3042') print '\u3042' \u3042 \u3042 who can give me a better example. thanks ...

Python find list lengths in a sublist

I am trying to find out how to get the length of every list that is held within a particular list. For example: a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) I'd like to run a command like: len(a[0][:]) which would output the answer I want which is a list of the lengths [5,4,3]. That com...

how can i grab CData out of BeatuifulSoup

I have a website that I'm scraping that has a similar structure the following. I'd like to be able to grab the info out of the CData block. I'm using BeautifulSoup to pull other info off the page, so if the solution can work with that, it would help keep my learning curve down as I'm a python novice. Specifically, I want to get at the ...

Scripting Python for Linux commands

Hello, I have a question. I have been really trying to learn Python. For a project, I want to make an ncurses GUI for my backup server. My backup server runs rdiff-backup, and I want to have the ncurses take in variable names and plug them into my script. I have been trying to do a lot of reading so I don't ask dumb questions. Here...

ValueError in Django

I'm getting a strange error and can't figure out why. I'd appreciate any input. I've been stuck on this for a few days. Here is my code: models.py class Employee(models.Model): lastname = models.CharField(max_length=75) firstname = models.CharField(max_length=75) position = models.ForeignKey(Position) jurisdiction =...

How to create full compressed tar file using Python?

how can I create a .tar.gz file which compress the data as much tar can... ...

Python Code Snippets

Is there any online resource or a book that provides common code snippets? I really like the "Python Phrasebook", but it doesn't cover Python 3.1. I'd appreciate your comments and advices. Thanks! ...

Python ctypes callback function to SWIG

I have a SWIG C++ function that expects a function pointer (WNDPROC), and want to give it a Python function that has been wrapped by ctypes.WINFUNCTYPE. It seems to me that this should be compatible, but SWIG's type checking throws an exception because it doesn't know that the ctypes.WINFUNCTYPE type is acctually a WNDPROC. What can I ...

emacs windows run python program in current buffer and display the output on output window

I use the Python-mode (not the default one comes with emacs 23). I could not execute the python program currently loaded in emacs. I am getting "Symbol's function definition is void: smart-operator-mode-on" error. Any clue or any tips makes a python program and it can be run on emacs and show the result output window? Here the emacs...

Interactive Python GUI

Python have been really bumpy for me, because the last time I created a GUI client, the client seems to hang when spawning a process, calling a shell script, and calling outside application. This have been my major problem with Python since then, and now I'm in a new project, can someone give me pointers, and a word of advice in order f...

In what circumstances should you serialize data? When should you not?

I'm aware that serializing is used to convert data types into a storable format, for purposes such as caching. What I'm more specifically asking is, what are the circumstances in which you should actually decide to store data ( using serialize() in PHP, pickle module in Python, et cetera )? Let's say we had a high traffic websi...

_functools module

How does this import work, what file does it use? import _functools in python 2.5 : import _functools print _functools.__file__ Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in <module> print _functools.__file__ AttributeError: 'module' object has no attribute '__file__' and how can i g...

pyqt custom item delegate for qtablewidget

I have a QTableWidget with 5 columns in it, how do I set all items on column 2 to be a QProgressBar? I tried something like: self.downloads_table = QtGui.QTableWidget(0, 5) self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self)) Where DownloadDelegate is: class DownloadDelegate(QItemDelegate): def __init__(self, ...

Porting python app to silverlight or flash

I guess that title is self-explanatory. Is there any such effort been made? Some more info: it's client application (gui intensive) By porting I was thinking of cross-compiling. ...

Searching for individual bipartite networks

I have data in the below form, which makes up a bipartite network. A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communities within the data. For instance A1,A2,A3,A4 are all ...