python

How to add a button (Add-in) to Outlook using Python

I'm looking the way to build an AddIn for Outlook with Python that add a button to the toolbar that has a behavior (doesn't matter). I've searched around and didn't found anything. The only things I've found are backend, no GUI. thanks! ...

How do you add a model method to an existing class within an interactive session (in iPython)?

I have a basic model: class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) state = USStateField() I start up an iPython session with: $ python manage.py shell >>> from app.models import Person How do I add this model method within the iPython session? >>> ...

How do I convert (or scale) axis values and redefine the tick frequency in matplotlib?

I am displaying a jpg image (I rotate this by 90 degrees, if this is relevant) and of course the axes display the pixel coordinates. I would like to convert the axis so that instead of displaying the pixel number, it will display my unit of choice - be it radians, degrees, or in my case an astronomical coordinate. I know the conversion f...

Looking for values in nested tuple

Hi Say I have: t = ( ('dog', 'Dog'), ('cat', 'Cat'), ('fish', 'Fish'), ) And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not matter really, I want to search for a string in only the lowercase values. if 'fish' in t: print "F...

Hacking JavaScript Array Into JSON With Python

I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this: var txns = [ { apples: '100', oranges: '20', type: 'SELL'}, { apples: '200', oranges: '10', type: 'BUY'}] I have no control over the format of this ...

Using Eval in Python to create class variables

I wrote a class that lets me pass in a list of variable types, variable names, prompts, and default values. The class creates a wxPython panel, which is displayed in a frame that lets the user set the input values before pressing the calculate button and getting the results back as a plot. I add all of the variables to the class using ...

Python value unpacking error

I'm building a per-user file browsing/uploading application using Django and when I run this function def walkdeep(request, path): path, dirs, files = walktoo('/home/damon/walktemp/%s' % path) return render_to_response('walk.html', { 'path' : path[0], 'dirs' : path[1], 'files' : path[2], }, context_i...

XML parsing expat in python handling data

I am attempting to parse an XML file using python expat. I have the following line in my XML file: <Action>&lt;fail/&gt;</Action> expat identifies the start and end tags but converts the & lt; to the less than character and the same for the greater than character and thus parses it like this: outcome: START 'Action' DATA '<' DATA 'f...

Change python file in place

Hello, I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files? Thanks! ...

Using URLS that accept slashes as part of the parameter in Django

Is there a way in Django to accept 'n' parameters which are delimited by a '/' (forward slash)? I was thinking this may work, but it does not. Django still recognizes forward slashes as delimiters. (r'^(?P<path>[-\w]+/)$', 'some.view', {}), ...

Virtualenv with Eclipse (Galileo)

Does anybody have directions for getting Eclipse (Galileo), PyDev, and Virtualenv working together? I'm specifically trying to run Pinax but any instructions are fine. I thought I had it (and even blogged everything but the final step - interactive debugging) and still there is no solution. I'm specifically on OS X but any answer shou...

What are the best books and resources for learning to develop, deploy and/or host Django?

I'm a newbie on the Django scene coming from an ASP.NET C# background. I'm looking for some good resources to help me learn the ins and outs of Django/Python. Any recommendations? ...

Difference between "inspect" and "interactive" command line flags in Python

What is the difference between "inspect" and "interactive" flags? The sys.flags function prints both of them. How can they both have "-i" flag according to the documentation of sys.flags? How can I set them separately? If I use "python -i", both of them will be set to 1. Related: tell whether python is in -i mode ...

How to make easy_install expand a package into directories rather than a single egg file?

How exactly do I configure my setup.py file so that when someone runs easy_install the package gets expanded into \site-packages\ as a directory, rather than remaining inside an egg. The issue I'm encountering is that one of the django apps I've created won't auto-detect if it resides inside an egg. EDIT: For example, if I type easy_in...

Connection refused when trying to open, write and close a socket a few times (Python)

I have a program that listens on a port waiting for a small amount of data to tell it what to do. I run 5 instances of that program, one on each port from 5000 to 5004 inclusively. I have a second program written in Python that creates a socket "s", writes the data to port 5000, then closes. It then increments the port number and create...

py2exe: Compiled Python Windows Application won't run because of DLL

I will confess I'm very new to Python and I don't really know what I'm doing yet. Recently I created a very small Windows application using Python 2.6.2 and wxPython 2.8. And it works great; I'm quite pleased with how well it works normally. By normally I mean when I invoke it directly through the Python interpreter, like this: > python...

Simulating Pointers in Python

I'm trying to cross compile an in house language(ihl) to Python. One of the ihl features is pointers and references that behave like you would expect from C or C++. For instance you can do this: a = [1,2]; // a has an array b = &a; // b points to a *b = 2; // derefernce b to store 2 in a print(a); // outputs 2 print(*b); ...

MPI signal handling

When using mpirun, is it possible to catch signals (for example, the SIGINT generated by ^C) in the code being run? For example, I'm running a parallelized python code. I can except KeyboardInterrupt to catch those errors when running python blah.py by itself, but I can't when doing mpirun -np 1 python blah.py. Does anyone have a sugge...

Trying to import a module that imports another module, getting ImportError

In ajax.py, I have this import statement: import components.db_init as db In components/db_init.py, I have this import statement: # import locals from ORM (Storm) from storm.locals import * And in components/storm/locals.py, it has this: from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode, Pickle from storm.prope...

Scanning huge tables with SQLAlchemy using the ORM

I am currently playing around with SQLAlchemy a bit, which is really quite neat. For testing I created a huge table containing my pictures archive, indexed by SHA1 hashes (to remove duplicates :-)). Which was impressingly fast... For fun I did the equivalent of a select * over the resulting SQLite database: session = Session() for p i...