The following code doesn't work in Python 3.x, but it used to work with old-style classes:
class Extender:
def extension(self):
print("Some work...")
class Base:
pass
Base.__bases__ += (Extender,)
Base().extension()
Question is simple: How can I add dynamically (at runtime) a super class to a class in Python 3.x?
B...
I'm using mapnik to draw a layer with bitmap images. It works good, but it looks like the bottom-right of the image is the x, y of my coordinates. How to align the image so that the center of the image is placed on my coordinates?
point_looks = mapnik.PointSymbolizer(output_filename_abs, 'png', 32, 32)
layout_rule = mapnik.Rule()
layou...
I am leaning towards uwsgi+nginx for my Django app, can anyone share the best method for starting up my uwsgi processes? Does anyone have experience tuning uwsgi?
...
I have a simple socket class: MySocketLib.py ..
import socket
class socklib():
def create_tcp_serversocket(self,port):
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind((socket.gethostname(), port))
serversocket.listen(5)
return serversocket
def send_msg(self, s...
Hey all,
related question: http://stackoverflow.com/questions/919056/python-case-insensitive-replace
What's the best way to do a case insensitive replace WITHOUT HURTING THE CACHE in the re module? I'm monitoring carefully the cache to make sure my favorite regexes stay there (speed, of course).
I just notice that my code:
ner_token_...
Hi guys,
Is there anyone that has some ideas on how to implement the AdaBoost (Boostexter) algorithm in python?
Cheers!
...
Textmate has a Python PEP8 bundle that will run pep8 validation on your file. How can I set it to do the equivalent of pep8 --ignore=E501 my_file.py?
...
ipython's %his command outputs recent commands entered by the user. Is it possible to search within these commands? Something like this:
[c for c in %history if c.startswith('plot')]
EDIT I am not looking for a way to rerun a command, but to locate it in the history list. Of course, sometimes I will want to rerun a command after locat...
I'm running some subprocesses from python in parallel. I want to wait until every subprocess have finished. I'm doing a non elegant solution:
runcodes = ["script1.C", "script2.C"]
ps = []
for script in runcodes:
args = ["root", "-l", "-q", script]
p = subprocess.Popen(args)
ps.append(p)
while True:
ps_status = [p.poll() for p in...
I am relatively new to Python, and I am experimenting with writing the following date calc functions
find the date that is/was Monday for a specified datetime
find the first non-weekend day of the month in a specified datetime
find the first non-weekend day of the year in a specified datetime
find the Nth [day of week] for a month in a...
I am getting the following error on my website:
Error importing openid store django_authopenid.openid_store: "No ElementTree library found. You may need to install one. Tried importing ['lxml.etree', 'xml.etree.cElementTree', 'xml.etree.ElementTree', 'cElementTree', 'elementtree.ElementTree']"
i have commented all the django openid co...
HI
I have created a simple software. Now Iam trying to give a GUI to it . Since I have coded in python Iam using pygtk . I have made main window and now I want to add a pop up window ,which will become active as I press open button(already created) in main window .
I have no previous experience with pygtk
..............
...
Is there any lib that can replace national characters to ASCII equivalents, like:
"Cześć"
to:
"Czesc"
I can of course create map:
{'ś':'s', 'ć': 'c'}
and use some replace function. But I don't want to hardcode all equivalents into my program, if there is some function that already does that.
...
I have a Django model that looks like this:
class Categories(models.Model):
"""
Model for storing the categories
"""
name = models.CharField(max_length=8)
keywords = models.TextField()
spamwords = models.TextField()
translations = models.TextField()
def save(self, force_insert=False, force_update=False):
...
I have an ordered (i.e. sorted) list that contains dates sorted (as datetime objects) in ascending order.
I want to write a function that iterates through this list and generates another list of the first available dates for each month.
For example, suppose my sorted list contains the following data:
A = [
'2001/01/01',
'2001/01/03',
...
Hiya,
I am adding UTF-8 data to a database in Django.
As the data goes into the database, everything looks fine - the characters (for example): “Hello” are UTF-8 encoded.
My MySQL database is UTF-8 encoded. When I examine the data from the DB by doing a select, my example string looks like this: ?Hello?. I assume this is showing the c...
Hi folks,
I'd like to use lxml library to validate XML Schemas in Python 3.1.2.
Since the Snow Leopard MAC OS comes with the Python 2.6.1 installed, firstly, I downloaded the Python 3.1.2 automated installer at http://www.python.org/ftp/python/3.1.2/python-3.1.2-macosx10.3-2010-03-24.dmg and installed it.
Secondly, I downloaded lxml 2...
http://code.google.com/p/django-multilingual-model/
I am trying to understand how the multilanguage feature works and i found the example in the above link
What i have done is i have created a project as test and included that in settings.py
And in the test directory i have the multilingual.py and the code for this is the above said ...
I have a script like this:
import datetime
# variable cal_start_of_week_date has type <type 'datetime.date'>
# variable period has type <type 'datetime.timedelta'>
cal_prev_monday = (cal_start_of_week_date - period).date()
When the above statement is executed, I get the error:
AttributeError: 'datetime.date' object has no attribut...
Hi!
I need an advice. What python framework I can use to develop a SOAP web service? I know about SOAPpy and ZSI but that libraries aren't under active development. Is there something better?
Thanks.
...