python

How to expose std::vector<int> as a Python list using SWIG?

I'm trying to expose this function to Python using SWIG: std::vector<int> get_match_stats(); And I want SWIG to generate wrapping code for Python so I can see it as a list of integers. Adding this to the .i file: %include "typemaps.i" %include "std_vector.i" namespace std { %template(IntVector) vector<int>; } I'm running SWIG ...

Is there a good Python GUI shell?

I saw this the other day (scroll all the way down to see some of the clever stuff): http://www.mono-project.com/CsharpRepl And wondered whether something like this exists for Python. So, is there a good Python GUI shell that can do stuff like that C# shell can do? Edit: Here are links to screenshots from the article, showing wha...

Is there a more Pythonic way to merge two HTML header rows with colspans?

I am using BeautifulSoup in Python to parse some HTML. One of the problems I am dealing with is that I have situations where the colspans are different across header rows. (Header rows are the rows that need to be combined to get the column headings in my jargon) That is one column may span a number of columns above or below it and the...

How can I repeat a string in Perl?

In Python, if I do this: print "4" * 4 I get > "4444" In Perl, I'd get > 16 Is there an easy way to do the former in Perl? ...

python argument binders

how can I bind arguments to a python method to store a nullary functor for later invocation? similar to C++'s boost::bind ...

Dictionary or If statements, Jython

Hi Guys, I am writing a script at the moment that will grab certain information from HTML using dom4j. Since Python/Jython does not have a native switch statement I decided to use a whole bunch of if statements that call the appropriate method, like below: if type == 'extractTitle': extractTitle(dom) if type == 'extractMetaTags': ...

How do I script an OLE component using Python?

I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started? I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython? ...

How do I search for unpublished Plone content in an IPython debug shell?

I like to use IPython's zope profile to inspect my Plone instance, but a few annoying permissions differences come up compared to inserting a breakpoint and hitting it with the admin user. For example, I would like to iterate over the content objects in an unpublished testing folder. This query will return no results in the shell, but w...

Can anyone recommend a decent FOSS PDF generator for Python?

I need a basic pdf generator that'll let me toss some images and text into a pdf file. The ability to have some basic drawing commands (lines and so forth) would also be a plus. I did read through this question, but I really don't need a report generator and most of the responses there seemed like real overkill for what I'm trying to ...

python: import a module from a folder

How do I import a python module given its relative path? For example, if dirFoo contains Foo.py and dirBar, and dirBar contains Bar.py, how do I import Bar.py into Foo.py? Here's a visual representation: dirFoo\ Foo.py dirBar\ Bar.py Foo wishes to include Bar, but restructuring the folder heirarchy is not an option. ...

Python: How do I generate a keypress?

I am opening a process (with os.popen() ) that, for some commands, detects certain keypresses (e.g. ESC - not the character, the key). Is there a way to send keypress events to the process? ...

What is the Python equivalent of static variables inside a function?

What is the idiomatic Python equivalent of this C/C++ code? void foo() { static int counter = 0; counter++; printf("counter is %d\n", counter); } specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing the function into a class change anything? ...

making a python GUI

How do I make a GUI for my python program because now it only runs in Idle and a command line and what software packages can I use and where can I get them? Thanks. ...

PyOpenGl or pyglet?

I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet Which would you recommend and why? ...

Set permissions on a compressed file in python

I have a file test.txt that is inside a zip archive test.zip. The permissions on test.txt are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell. EDIT: Here's what I've got so far: import zipfile z = zipfile.ZipFile('test....

Atomic operations in Django?

I'm trying to implement (what I think is) a pretty simple data model for a counter: class VisitorDayTypeCounter(models.Model): visitType = models.CharField(max_length=60) visitDate = models.DateField('Visit Date') counter = models.IntegerField() When someone comes through, it will look for a row that matches the visitType ...

email body from a parsed email object in jython

I have an object. fp = open(self.currentEmailPath, "rb") p = email.Parser.Parser() self._currentEmailParsedInstance= p.parse(fp) fp.close() self.currentEmailParsedInstance, from this object I want to get the body of an email, text only no html.... How do I do it? something like this? newmsg=self._current...

Python - sort a list of nested lists

I have input consisting of a list of nested lists like this: l = [[[[[39]]]], [1, 2, 3], [4, [5, 3], 1], [[[[8, 9], 10], 11], 12]] I want to sort this list based on the sum of all the numbers in the nested lists... so, the values I want to sort by of l would look like this: [39, 6, 13, 50] Then I want to sort based on these. So the...

Python Linked List

What's the easiest way to use a linked list in python? In scheme, a linked list is defined simply by '(1 2 3 4 5). Python's lists, [1, 2, 3, 4, 5], and tuples, (1, 2, 3, 4, 5), are not, in fact, linked lists, and linked lists have some nice properties such as constant-time concatenation, and being able to reference separate parts of them...

When is "self" required?

I have been using classes for only a short while and when I write a method, I make all variables reference self, e.g. self.foo. However, I'm looking through the wxPython in Action book and notice that "self" isn't used all the time. For example: import wx class TextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(se...