python

Django: Blank Choices in Many To Many Fields

When making forms in Django, the IntegerField comes with a blank choice (a bunch of dashes "------") if called with blank=True and null=True. Is there any way to get ManyToManyField to include such an explicit blank choice? I've tried subclassing ManyToManyField with no success: class ManyFieldWithBlank(ManyToManyField): """ ...

why does python's list.append evaluate to false?

Is there a reason being list.append evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play? >>> u=[] >>> not u.append(6) True ...

What are cycles ? in relation to python

im using the fantastic eric4 ide to code python, it's got a tool built in called 'cyclops', which is apparently looking for cycles. After running it, it gives me a bunch of big bold red letters declaring there to be a multitude of cycles in my code. The problem is the output is nearly indecipherable, there's no way im gonna understand wh...

Embedding Python Design

There are lots of tutorials/instructions on how to embed python in an application, but nothing (that I've seen) on overall design for how the embedded interpreter should be used and interact with the application. The only idea I could think of would be to simply give the user a method (menu option, etc) of executing scripts in the progr...

What does ** operator do in Python?

What does this mean in python: sock.recvfrom(2**16) I know what sock is and I get the jest of recvfrom function, but what the hell is 2**16? ...

Alternative to PycURL ?

Hey, Here's a bit of code that is uploading a file: file_size = os.path.getsize('Tea.rdf') f = file('Tea.rdf') c = pycurl.Curl() c.setopt(pycurl.URL, 'http://localhost:8080/openrdf-sesame/repositories/rep/statements') c.setopt(pycurl.HTTPHEADER, ["Content-Type: application/rdf+xml;charset=UTF-8"]) c.setopt(pycurl.PUT, 1) ...

Django: Streaming dynamically generated XML output through an HttpResponse

Dear fellow users, recently I wanted to return through a Django view a dynamically generated XML tree. The module I use for XML manipulation is the usual cElementTree. I think I tackled what I wanted by doing the following: def view1(request): resp = HttpResponse(g()) return resp def g(): root = Element("ist") list...

website load testing Python script

Hello, I am after a Python script to help me load test my Google App Engine website. I want to give it a set of URLs and a request rate (would need to use threads) and then measure the response times of my website. I have had a look at a few solutions but they don't let you set an upper limit for the request rate. Any ideas? Thanks ...

'getattr(): attribute name must be string' error in admin panel for a model with an ImageField

I have the following model set up: class UserProfile(models.Model): "Additional attributes for users." url = models.URLField() location = models.CharField(max_length=100) user = models.ForeignKey(User, unique=True) avatar = models.ImageField(upload_to='/home/something/www/avatars', height_field=80, width_field=80) ...

Python .pyc files removal problem in django app

Hi i have a following solution structure in python: main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc files from svn), it doesn't see the assembly (if it...

What's the easiest way of finding a child instance from a parent instance in Django?

My application uses class inheritance to minimize repetition across my models. My models.py looks kind of like this: class BaseModel(models.Model): title = models.CharField(max_length=100) pub_date = models.DateField() class Child(BaseModel): foo = models.CharField(max_length=20) class SecondChild(BaseModel): bar = models...

Sort a multidimensional list by a variable number of keys

I've read this post and is hasn't ended up working for me. Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer Here's my situation, I have a tab-delimited text document. There are about 125,000 lines and 6 columns per line (columns are separated by a tab character). I've spl...

Limitations of TEMP directory in Windows?

I have an application written in Python that's writing large amounts of data to the %TEMP% folder. Oddly, every once and awhile, it dies, returning IOError: [Errno 28] No space left on device. The drive has plenty of free space, %TEMP% is not its own partition, I'm an administrator, and the system has no quotas. Does Windows artificia...

org.apache.commons.lang.StringEscapeUtils in python

Hello, is there any python module or code that implements the org.apache.commons.lang.StringEscapeUtils.escapeHtml ? exactly the same as in http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml(java.lang.String) i googled around but could only find the cgi.escape function that doesn't do the sam...

Is it possible to delete a method from an object (not class) in python?

I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like: >>> wiz=Wizard() >>> dir(wiz) ['__doc__', '__module__', 'addmana'] >>> wiz.addmana() >>> dir(wiz...

BeautifulSoup - extracting attribute values

If Beautiful Soup gives me an anchor tag like this: <a class="blah blah" id="blah blah" href="link.html"></a> How would I retrieve the value of the href attribute? ...

Call Ruby or Python API in C# .NET

I have a lot of APIs/Classes that I have developed in Ruby and Python that I would like to use in my .NET apps. Is it possible to instantiate a Ruby or Python Object in C# and call its methods? It seems that libraries like IronPython do the opposite of this. Meaning, they allow Python to utilize .NET objects, but not the reciprocal of t...

Uploading to the cheeseshop different versions of a package for different versions of Python

I have an open-source Python project (called GarlicSim), and I maintain 4 different versions of it for Python versions 2.4, 2.5, 2.6 and 3.1. Yes, maybe it's unusual, but I like using as much features as possible. I keep them in 4 different forks of the repository. Now I want to upload my project to the cheeseshop. What's the way to do ...

Python: saving output of a for loop to file

Hi, I have opened a file with blast results and printed out the hits in fasta format to the screen. the code looks like this: result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() for alignment in blast_record.alignmen...

Problem with SPARQLWrapper (Python)

Howdy, I'm making a SPARQL query against the Sesame store in localhost, using SPARQLWrapper: sparql = SPARQLWrapper('http://localhost:8080/openrdf-sesame/repositories/rep/statements') sparql.setQuery(query) sparql.setReturnFormat(JSON) results = sparql.query().convert() However, I'm getting: File "build/bdist.linux-i686/egg/...