python

Dynamically creating classes - Python

Hi folks, I need to dynamically create a class. To go in futher detail I need to dynamically create a subclass of Django's Form class. By dynamically I intend to create a class based on configuration provided by a user. e.g. I want a class named CommentForm which should subclass the Form class The class should have a list o...

Parsing PDF file using Regular expresions in Python

Hello, I am trying to parse some object elements from a PDF file using re module of Python. My goal is to parse each PDF object using a regular expression. A PDF object example is the following: 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj << /Type /Pages /Kids [ 3 0 R ] /Count 1 >> endobj ... When I u...

SMTP ERROR: (552, '5.6.0 Submission denied Sender does not match originator <myEmailAddress>)

I've writted a Python script to send emails via a relay server. I've tested that the appropriate email address's etc are permissioned etc by sending an email using Telnet. My Python script also work when set up to send via my old relay server. Therefore i am confused as to why i am getting the following error message: (552, '5.6.0 Sub...

How to copy a variable number of elements in a list to a uniform list and store in MySQL using Python the most efficient way?

This is a sample list (each line has variable elements) : ['1', 'Tech', 'Code'] ['2', 'Edu'] ['3', 'Money', 'Sum', '176'] I have to insert this into a MySQL table which has 4 columns (max num. of elements in a value in a list). How to do this efficiently? I have a feeling my solution is the least efficient! Here is my solution : f...

Python Unittest

I am using python unittest module to do a number of tests; however, it is very repetitive. I have a lot of data that I want to run through the same test over and over, checking if correct. However, I have to define a test for every one. For instance I want to do something similar to this. I know I could do it using a generator (found ...

Generic Python metaclass to keep track of subclasses

I'm trying to writing a generic metaclass for tracking subclasses Since I want this to be generic, I didn't want to hardcode any class name within this metaclass, therefore I came up with a function that generates the proper metaclass, something like: def make_subtracker(root): class SubclassTracker(type): def __init__(cls,...

Scipy optimize.curve_fit sometimes won't converge

Hi, I'm trying to use numpy.optimize.curve_fit to estimate the frequency and phase of an on/off sequence. This is the code I'm using: from numpy import * from scipy import optimize row = array([0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0...

Help "Install" Module for Python using WGET

I am trying to setup this python library and am having a very hard time. I suspect it is because I am a hobby programmer, but I have successfully installed programs in the past using the command line. I am using Windows and Python 2.6. The help that is shown below is taken from the website. wget http://pypi.python.org/packages/source...

TKinter: I cannot see my left frame with a button inside

I cannot see my left frame with a button inside (I'm using TKinter).. This is my code: #create window & frames root = Tk() root.title( "Medical Visualization" ) rootFrame = Frame(root) rootFrame.pack( fill=BOTH, expand=1, side=TOP ) leftframe = Frame(root, width=100, bg="blue") leftframe.pack(fill=X, expand=True) button = Button(left...

why python nose unittest teardown fixture failed

Hi, I'm using nose test framework. When running a test module, the teardown function defined in it failed. the error raised says the fixture is locked by another process. here is my test module, test_my_module.py: ... ... def teardown(): if os.path.exists(test_output_dir): shutil.rmtree(test_output_dir) ... ... @with_s...

How do I properly format a StringIO object(python and django) to be inserted into an database?

I have a requeriment to store images in the database using django, and for that I created a custom field : from django.db import models class BlobField(models.Field): __metaclass__ = models.SubfieldBase def db_type(self, connection): #TODO handle other db engines backend = connection.settings_dict['ENGINE'] ...

Django / MySql not honouring unique_together

I am using django with mysql (InnoDB) and have the following in my django model: class RowLock(models.Model): table_name = models.CharField(blank = False, max_length = 30) locked_row_id = models.IntegerField(null = False) process_id = models.IntegerField(null = True) thread_id = models.IntegerField(null = True) class...

What is location of django Built-in tags and filters?

What is location of django Built-in tags and filters? I cant find anywhere... I need it to format datetime so then i can send right formt in JSON by AJAX response.. Or maybe you can suggest me another way to do that... What i want to do it's import function which determinate filter... and use it to format my datetime in JSON. Look.. i ...

Python garbage collection can be that slow?

Hi, I have a problem with my python application, and I think it's related to the python garbage collection, even if I'm not sure... The problem is that my application takes a lot of time to exit and to switch to one function to the next one. In my application I handle very large dictionaries, containing thousands of large objects whic...

[Django] Get parameters of object in metaclass of this object

My problem is a python/django mix. I have a form model that will display some fields. Basing on some parameter of this model, the data sent to metaclass creating this object should differ. But how can I reach this parameter when inside the body of Meta ? Should I use some global var instead of object parameter (as it is introduced only t...

will yum break if I use rpms from the ius community project?

I followed this tutorial: http://blog.boxedice.com/2010/01/19/updating-python-on-rhelcentos/ because I wanted to install python2.6 on a CentOS 5.5 machine without breaking yum. And i was successfully able install python2.6. My question is that after completing the above commands the next time I try installing packages will it automatica...

gtk minimum size

Is there an easy way to request that a GTK widget have a minimum width/height? I know you can do it on the column of a TreeView, but is it available for general widgets? ...

lxml, missing doctype when serialized

In [1]: from lxml import etree I've got an HTML document: In [2]: root = etree.fromstring(u'''<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">\n<HTML></HTML>''', etree.HTMLParser()) Its doctype is parsed correctly: In [3]: root.getroottree().docinfo.doctype Out[3]: u'<!DOCTYPE html PUBLIC "-//IETF//DTD HTML//EN">' But when serializ...

Iron Python vs Razor

Hello folks, I have a little bit of experience with the new Razor syntax, but none with Iron Python. I was wondering do both meet the same needs? Is one favored by Microsoft over the other (or will be)? Appreciate your thoughts, as I'm toying with the idea of learning Iron Python, but if Razor can meet the same need, I probably won't....

Post Binary Sting to Django app using HTML 5

Hi all - I read in a file via HTML5 FileReader and jQuery like so: holder.ondrop = function(e) { this.className = ''; e.preventDefault(); var file = e.dataTransfer.files[0], reader = new FileReader(); reader.onloadend = function(event) { $.ajax({ url:"/path/to/upload", type: "POST", ...