python

Why won't Django 1.0 admin application work?

I've just started playing with Django and am loosely following the tutorial with my own set of basic requirements. The models I've sketched out so far are a lot more comprehensive than the tutorial, but they compile fine. Otherwise, everything should have been the same. My problem is with the admin application. I can log into it, and vi...

What is your favorite IPython feature?

I've been learning (and enjoying learning!) Python via the IPython interactive shell recently... What's your favorite feature in IPython? Are there any tips and tricks you've picked up that other people might not know about? ...

Python - append vs. extend

What is the difference between the list methods append and extend? ...

Finding invocations of a certain function in a c++ file using python

I need to find all occurrences of a function call in a c++ file using python, and extract the arguments for each call. I'm playing with the pygccxml package, and extracting the arguments given a string with the function call is extremely easy: from pygccxml.declarations import call_invocation def test_is_call_invocation(call): if c...

How to configure the import path in Visual Studio IronPython projects

I have built the IronPythonIntegration solution that comes with the Visual Studio 2005 SDK (as explained at http://www.izume.com/2007/10/13/integrating-ironpython-with-visual-studio-2005), and I can now use IronPython projects inside Visual Studio 2005. However, to let a Python file import from the standard library I need to include thes...

What Python bindings are there for CVS or SVN?

I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using popen and checking the stdout and stderr and then parsing those. It was messy and error-prone. Are there any good qualit...

Looking a generic Python script to add a field and populate the field with conditions

I am looking for a script to allow users to add a text field to a .dbf table(e.g. landuse categories) and allow them to input/update the rows basing on what values in the GRIDCODE (numeric categories) field they think should be assigned into text categories.i.e. if GRIDCODE value is 4, the corresponding field value of landuse/landclass ...

In Python, is there a concise way of comparing whether the contents of two text files are the same?

I don't care what the differences are. I just want to know whether the contents are different. ...

Tiny python executable?

I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with built-in support for UPX and uses it to compress the executable but they are still really huge (about 2,7 mb). Is there any way to create even smaller Python executables? For example using a shrinked python.dll or something similiar? ...

How to embed a tag within a url templatetag in a django template?

How do I embed a tag within a url templatetag in a django template? Django 1.0 , Python 2.5.2 In views.py def home_page_view(request): NUP={"HOMEPAGE": "named-url-pattern-string-for-my-home-page-view"} variables = RequestContext(request, {'NUP':NUP}) return render_to_response('home_page.html', variables) In home_page...

Converting datetime to POSIX time

How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don't seem to find any obvious ways to do the operation the opposite way. ...

How do I keep Python print from adding spaces ?

In python, if I say print 'h' I get the letter h and a newline. If I say print 'h', I get the letter h and no newline. If I say print 'h', print 'm', I get the letter h, a space, and the letter m. How can I prevent Python from printing the space? The print statements are different iterations of the same loop so I can't just...

How to override HTTP request verb in GAE

In the context of a Google App Engine Webapp framework application: I want to changed the request verb of a request in the case a parameter _method is provided, for example if a POST request comes in with a parameter _method=PUT, I need to change the request to call the put method of the handler. This is to cope with the way prototype.j...

Storage transactions in Redland's Python bindings?

I've currently skimming through the Python-bindings for Redland and haven't found a clean way to do transactions on the storage engine via it. I found some model-transactions within the low-level Redland module: import RDF, Redland storage = RDF.Storage(...) model = RDF.Model(storage) Redland.librdf_model_transaction_start(model._model...

Python re.findall with groupdicts

I kind of wish that there were a version of re.findall that returned groupdicts instead of just groups. Am I missing some simple way to accomplish the same result? (Does anybody know of a reason that this function doesn't exist?) ...

Determine if a named parameter was passed

I would like to know if it is possible to determine if a function parameter with a default value was passed in Python. For example, how does dict.pop work? >>> {}.pop('test') Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'pop(): dictionary is empty' >>> {}.pop('test',None) >>> {}.pop('test',3) 3 >>> ...

Browser-based application or stand-alone GUI app?

I'm sure this has been asked before, but I can't find it. What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework? I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user-entry forms and dialogs. I am consi...

How to implement Google Suggest in your own web application (e.g. using Python)

In my website, users have the possibility to store links. During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar. Example: User is typing as URL: http://www.sta Suggestions which would be displayed: http://www.staples.com http:...

Can I Use Python to Make a Delete Button in a 'web page'

I have written a script that goes through a bunch of files and snips out a portion of the files for further processing. The script creates a new directory and creates new files for each snip that is taken out. I have to now evaluate each of the files that were created to see if it is what I needed. The script also creates an html index...

Which exception should I raise on bad/illegal argument combinations in Python?

I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so: def import_to_orm(name, save=False, recurse=False): """ :param name: Name of some external entity to import. :param save: Save the ORM object before returning. ...