python

Fill Django application with data using very large Python script

I wrote a program that outputs a Python program that fills my Django application with data. This program however is 23 MB large and my computer won't run it. Is there a solution for this? Another possible solution to fill the database would be using a fixture. The problem is that I don't know the new primary keys yet... or I would have ...

weakref list in python

I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually). I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing this? Here's an example: impo...

How to get the filename without the extension from a path in Python?

How to get the filename without the extension from a path in Python? I found out a method called os.path.basename to get the filename with extension. But even when I import os, I am not able to call it path.basename. Is it possible to call it as directly as basename? ...

Does any one know of an RTF report generator in Django?

I know about the PDF report generator, but I need to use RTF instead. ...

soaplib with mod_wsgi/cherrypy

Hi guys, I've followed the tutorials for setting up Apache with mod_wsgi to interface cherrypy and make a site running of it. This is my "myapp.wsgi", and opening http://localhost/ works great. Opening http://localhost/ape/ actually returns the text instead of a soap-response, and http://localhost/ape/service.wsdl returns a 500 HTTP erro...

How can I add non-sequential numbers to a range?

I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers: >>> for x in range(750, 765), 769, 770, 774: print x ... [750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 76...

What payment processing frameworks, like ActiveMerchant, are available for other languages?

Rails has frameworks such as ActiveMerchant and Freemium (which uses ActiveMerchant) to simplify dealing with payment processing. What other frameworks are there for other programming languages such as PHP or Python? ...

Select Distinct Years and Months for Django Archive Page

I want to make an archive_index page for my django site. However, the date-based generic views really aren't any help. I want the dictionary returned by the view to have all the years and months for which at least one instance of the object type exists. So if my blog started in September 2007, but there were no posts in April 2008, I cou...

Why does windows give an sqlite3.OperationalError and linux does not?

The problem I've got a programm that uses storm 0.14 and it gives me this error on windows: sqlite3.OperationError: database table is locked The thing is, under linux it works correctly. I've got the impression that it happens only after a certain amount of changes have been done, as it happens in some code, that copies a lot of ob...

What's wrong with my Python SOAPpy webservice call?

I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter: from SOAPpy import WSDL wsdl = "http://www.webservicex.net/whois.asmx?wsdl" proxy = WSDL.Proxy(wsdl) proxy.soapproxy.config.dumpSOAPOut=1 proxy.soapproxy.config.dumpSOAPIn=1 proxy.GetWhoIS(HostName="google.com") (Yep, I'm ne...

Best way to profile/optimize a website on google's appengine

I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool. Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler? ...

min heap in python

Hi - I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom comparator with this module? If not, has someone else built a custom min heap? Thanks, SetJmp ...

What are the viable database abstraction layers for Python

I'm starting to get involved in an open source project Gramps which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capacity. I'm a professional developer but I'm new to python so I'm not that familiar with the current se...

Problem with python curl while submitting file

#!/usr/bin/python import pycurl import re import StringIO #CONSTANTS URL = "http://www.imagehost.org" FILE = "/datos/poop1.jpg" POST_DATA = [("a", "upload"), ("file[]", (pycurl.FORM_FILE, FILE))] buffer = StringIO.StringIO() c = pycurl.Curl() c.setopt( c.URL, URL ) c.setopt( c.POST, 1 ) c.setopt( c.POSTFIELDS, POST_DATA ) ##c.seto...

Python: How to extract variable name of a dictionary entry?

I'm wondering how I would go about finding the variable name of a dictionary element: For example: >>>dict1={} >>>dict2={} >>>dict1['0001']='0002' >>>dict2['nth_dict_item']=dict1 >>>print dict2 {'nth_dict_item': {'0001': '0002'}} >>>print dict2['nth_dict_item'] {'001': '002'} How can I go about making...

Python 2.5.2

Hello, I am using Python 2.5.2. How can i knw whether it is cpython or ironpyhton or jpython ? Another doubt.How can i use a dll developed in VB.NET in to my project ? ...

Using MultipartPostHandler to POST form-data with Python

Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: http://code.activestate.com/recipes/146306/ To...

Python 2.5.2 continued...

Hello, This is a continuation of my question Python2.5.2 The code i developed is working fine with clr.Addreference(). Now thee problem is I have to load ny script which uses dll developed in .NET to another application.They had used QT for its implementation.There is a Script console in that application.When ii entered 'import ...

python create slice object from string

I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) thanks in advance. Edit: Sorry if the original prompt was not clear, the input in this case was ":-1". The point was t...

Python dynamic function names

I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == 'RAWCONFIG': return rawconfig(*arg...