python

How do you add a custom section to the Django admin home page?

In the Django admin each app you have registered with the admin gets its own section. I want to add a custom section for reporting that isn't associated with any app. How do I do that? ...

Is there any way to add a class attribute to an input tag generated by django.models?

I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone? ...

Show/hide a plot's legend.

I'm relatively new to python and am developing a pyqt GUI. I want to provide a checkbox option to show/hide a plot's legend. Is there a way to hide a legend? I've tried using pyplot's '_nolegend_' and it appears to work on select legend entries but it creates a ValueError if applied to all entries. I can brute force the legend to hid...

Matplotlib coord. sys origin to top left

How can I flip the origin of a matplotlib plot to be in the upper-left corner - as opposed to the default lower-left? I'm using matplotlib.pylab.plot to produce the plot (though if there is another plotting routine that is more flexible, please let me know). I'm looking for the equivalent of the matlab command: axis ij; Also, I've sp...

Python string 'join' is faster(?) than '+', but what's wrong here?

I asked the most efficient method for mass dynamic string concatenation in an earlier post and I was suggested to use the join method, the best, simplest and fastest method to do so (as everyone said that). But while I was playing with string concatenations, I found some weird(?) results. I'm sure something is going on but I can't not ge...

Python SOAP clients will not work with this WSDL

Thus far I've tried to access this WSDL: https://login.azoogleads.com/affiliate/tool/soap%5Fapi from the two common Python SOAP clients that I'm aware of: SOAPpy and ZSI.client.Binding. SOAPpy raises an exception in PyXML (xml.parsers.expat.ExpatError: not well-formed (invalid token)) and ZSI raises an exception in the urlparse librar...

Python - Passing a function into another function

I am solving a puzzle using python and depending on which puzzle I am solving I will have to use a special set of rules. How can I pass a function into another function in Python? Example def Game(listA, listB, rules): if rules == True: do... else: do... def Rule1(v): if "variable_name1" in v: return False ...

Parse an HTTP request Authorization header with Python

I need to take a header like this: Authorization: Digest qop="chap", realm="[email protected]", username="Foobear", response="6629fae49393a05397450978507c4ef1", cnonce="5ccc069c403ebaf9f0171e9517f40e41" And parse it into this using Python: {'protocol':'Digest', 'qop':'chap', 'realm':'[email protected]', '...

Python change screen resolution virtual machine

In virtualbox, the screen resolution can be anything - even something strange like 993x451, etc. I tried changing it using pywin32 but I failed:: >>> dm = win32api.EnumDisplaySettings(None, 0) >>> dm.PelsHeight = 451 >>> dm.PelsWidth = 950 >>> win32api.ChangeDisplaySettings(dm, 0) -2L which ends up being: DISP_CHANGE_BADMODE any he...

Strategy for maintaining complex filter states?

I need to maintain a list of filtered and sorted objects, preferably in a generic manner, that can be used in multiple views. This is necessary so I can generate next, prev links, along with some other very useful things for the user. Examples of filters: field__isnull=True field__exact="so" field__field__isnull=False Additionally, a...

Novice needs advice for script that gets data and returns it in a usable format.

I have a large number of images that I am putting into web pages. Rather than painstakingly enter all of the image attributes, I thought I could write a script that would do the work for me. I just need a little push in the right direction. I want the script to get the width and height of each image, then format this into an img tag th...

Can Selenium RC tests written in Python be integrated into PHPUnit?

I'm working on large project in PHP and I'm running phpundercontrol with PHPUnit for my unit tests. I would like to use Selenium RC for running acceptance tests. Unfortunately the only person I have left to write tests only knows Python. Can Selenium tests written in Python be integrated into PHPUnit? Thanks! ...

sqlalchemy create a foreign key?

I have a composite PK in table Strings (integer id, varchar(2) lang) I want to create a FK to ONLY the id half of the PK from other tables. This means I'd have potentially many rows in Strings table (translations) matching the FK. I just need to store the id, and have referential integrity maintained by the DB. Is this possible? If so,...

What does matrix**2 mean in python/numpy?

Hi, I have a python ndarray temp in some code I'm reading that suffers this: x = temp**2 Is this the dot square (ie, equivalent to m.*m) or the matrix square (ie m must be a square matrix)? In particular, I'd like to know whether I can get rid of the transpose in this code: temp = num.transpose(whatever) num.sum(temp**2,axis=1)) ...

Check whether debug is enabled in a Pylons application

I'm working on a fairly simple Pylons 0.9.7 application. How do I tell, in code, whether or not debugging is enabled? That is, I'm interested in the value of the debug setting under [app:main] in my INI file. More generally, how do I access the other values from there in my code? ...

Java equivalent of Python repr()?

Is there a Java method that works like Python's repr? For example, assuming the function were named repr, "foo\n\tbar".repr() would return "foo\n\tbar" not foo bar as toString does. ...

Preventing Python code from importing certain modules?

I'm writing an application where users can enter a python script and execute it in a sandbox. I need a way to prevent the exec'ed code from importing certain modules, so malicious code won't be as much of a problem. Is there a way to do this in Python? ...

"Inner exception" (with traceback) in Python?

My background is in C# and I've just recently started programming in Python. When an exception is thrown I typically want to wrap it in another exception that adds more information, while still showing the full stack trace. It's quite easy in C#, but how do I do it in Python? Eg. in C# I would do something like this: try { ProcessFil...

Tool for analysing and stepping through code?

Recently I came across a tool which could analyse running python code and produced a visual representation similar to a code editor to allow one to step through the different parts of the code, seeing how many times each part was called, execution time, etc. I can't find the reference to it again. Would anyone know what it might be?  ...

Python: Is there a place when I can put default imports for all my modules?

Is there a place when I can put default imports for all my modules? ...