python

What's the best way to do literate programming in Python on Windows?

I've been playing with various ways of doing literate programming in Python. I like noweb, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent each chunk of code as it will be in the final program --- which I don't necessarily kno...

How do I calculate the numeric value of a string with unicode components in python?

Along the lines of my previous question, http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python , I would like to find a more elegant solution to calculating the value of a string that contains unicode numeric values. For example, take the strings "1⅕" and "1 ⅕". I would like these to resolve...

How do you resolve traditional coding standard vs python idomatic code?

In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers. The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something that would have clearly been f...

Django ORM in a python threaded application .. Does not exit

I have a standalone threaded python application in which I use Django's ORM (Postgres). After I join all my threads and wait for the application to exit(sys.exit(0)), there is still an extra thread running, for which the sys.exit waits: All the threads I started exited. Does Django spawn threads to handle database connectivity? This ...

Does __str__() call decode() method behind scenes?

It seems to me that built-in functions __repr__ and __str__ have an important difference in their base definition. >>> t2 = u'\u0131\u015f\u0131k' >>> print t2 ışık >>> t2 Out[0]: u'\u0131\u015f\u0131k' t2.decode raises an error since t2 is a unicode string. >>> enc = 'utf-8' >>> t2.decode(enc) ---------------------------------------...

Django Formset without instance

Hi. In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author. What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in the same formset. Can you gime a light? thanks. ...

how can I force division to be floating point in Python?

I have two integer values a and b, but I need their ratio in floating point. I know that a<b and I want to calculate a/b, so if I use integer division I'll always get 0 with a remainder of a. How can I force c to be a floating point number in Python when: c = a / b ...

How to prevent Satchmo forms from displaying asterisk after required fields?

I'm customizing my Satchmo store forms and have an icon that appears before any required fields. The problem is, Satchmo seems to want to render a text asterisk after the required fields. I'm using field.label to get this label, should I be using something else? EDIT: All my form templates are hard coded. I have an inclusion tag that...

Python standard module for emulating geometric points

Is there a standard class in Python to emulate a geometric point that includes coordinates and a value, including arithmetic operations between the coordinates? ...

Standard Solution for Decoding Additive Numbers

From the Oracle docs. A number representing one or more statistics class. The following class numbers are additive: 1 - User 2 - Redo 4 - Enqueue 8 - Cache 16 - OS 32 - Real Application Clusters 64 - SQL 128 - Debug It there a standard solution for taking say 22 and decoding that into 16, 4, and 2? My first guess ...

Displaying X and y axis in pylab

Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis. ...

Django ModelForm CheckBox Widget

I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so: # Type of Media MEDIA_CHOICE...

Python: Possible to share in-memory data between 2 separate processes

I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server? So, serverA starts up and creates an object. serverB starts up and can read from the object in serverA. * EDIT * ...

Importing Model / Lib Class and calling from controller

I'm new to python and pylons although experienced in PHP. I'm trying to write a model class which will act as a my data access to my database (couchdb). My problem is simple My model looks like this and is called models/BlogModel.py from couchdb import * class BlogModel: def getTitles(self): # code to get titles here ...

Regex Matching Error

Hi Everyone, I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question. I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says raise error, v # invalid express...

Really long query

How do u do long query? Is there way to optimize it? I would do complicated and long query: all_accepted_parts = acceptedFragment.objects.filter(fragmentID = fragment.objects.filter(categories = fragmentCategory.objects.filter(id=1))) but it doesn't work, i get: Error binding parameter 0 - probably unsupported type. I will be than...

Python http proxy library based on libevent or comparable technology?

I'm looking to build an intelligent reverse http proxy capable of routing, header examination and enrichment (eg. examine and build cookies and http headers), and various other fanciness. For a general idea of what I'm looking to build see Ruby Proxies for Scale and Monitoring - except in Python. I realize that Twisted is an exceedingl...

InlineFormSet with queryset of different model

What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products. class Product(models.Model): name = models.CharField(max_length=100) pric...

Calling a base class's classmethod in Python

Consider the following code: class Base(object): @classmethod def do(cls, a): print cls, a class Derived(Base): @classmethod def do(cls, a): print 'In derived!' # Base.do(cls, a) -- can't pass `cls` Base.do(a) if __name__ == '__main__': d = Derived() d.do('hello') > $ python p...

Differences between Smalltalk and python ?

I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it. Apart from message passing, what are other notable conceptual differences between Smalltalk and python which could allow me ...