python

extracting stream from pdf in python

How can I extract the part of this stream (the one named BLABLABLA) from the pdf file which contains it?? <</Contents 583 0 R/CropBox[0 0 595.22 842]/MediaBox[0 0 595.22 842]/Parent 29 0 /Resources<</ColorSpace<</CS0 563 0 R>>/ExtGState<</GS0 568 0 R>>/Font<</TT0 559 0 R/TT1 560 0 R/TT2 561 0 R/TT3 562 0 R>>/ProcSet[/PDF/Text/ImageC]/P...

Syncing Django users with Google Apps without monkeypatching

I am writing a Django app, and I would like an account to be created on our Google Apps hosted email using the Provisioning API whenever an account is created locally. I would solely use signals, but since I would like the passwords to be synchronized across sites, I have monkeypatched User.objects.create_user and User.set_password usin...

Recommendations for a language for a non-professional beginner

Duplicate See also: http://stackoverflow.com/questions/419959/language-for-non-programmers-to-start-learning-programming http://stackoverflow.com/questions/190957/what-language-is-best-for-a-beginner-to-learn http://stackoverflow.com/questions/4769/easiest-language-to-start-with I'm for advice on learning a new programming language....

How to do pretty OSD in Python

Is there a library to do pretty on screen display with Python (mainly on Linux but preferably available on other OS too) ? I know there is python-osd but it uses libxosd which looks quite old. I would not call it pretty. Maybe a Python binding for libaosd. But I did not find any. ...

Regular expression: replace the suffix of a string ending in '.js' but not 'min.js'

Assume infile is a variable holding the name of an input file, and similarly outfile for output file. If infile ends in .js, I'd like to replace with .min.js and that's easy enough (I think). outfile = re.sub(r'\b.js$', '.min.js', infile) But my question is if infile ends in .min.js, then I do not want the substitution to take place. ...

How to split strings into text and number?

I'd like to split strings like these 'foofo21' 'bar432' 'foobar12345' into ['foofo', '21'] ['bar', '432'] ['foobar', '12345'] Does somebody know an easy and simple way to do this in python? ...

Best way to poll a web service (eg, for a twitter app)

Hi, I need to poll a web service, in this case twitter's API, and I'm wondering what the conventional wisdom is on this topic. I'm not sure whether this is important, but I've always found feedback useful in the past. A couple scenarios I've come up with: The querying process starts every X seconds, eg a cron job runs a python script...

Draw rounded corners on photo with PIL

My site is full of rounded corners on every box and picture, except for the thumbnails of user uploaded photos. How can I use the Python Imaging Library to 'draw' white or transparent rounded corners onto each thumbnail? ...

Regex for managing escaped characters for items like string literals

I would like to be able to match a string literal with the option of escaped quotations. For instance, I'd like to be able to search "this is a 'test with escaped\' values' ok" and have it properly recognize the backslash as an escape character. I've tried solutions like the following: import re regexc = re.compile(r"\'(.*?)(?<!\\)\'") ...

Regex for links in html text

Hi, I hope this question is not a RTFM one. I am trying to write a Python script that extracts links from a standard HTML webpage (the <link href... tags). I have searched the web for matching regexen and found many different patterns. Is there any agreed, standard regex to match links? Adam UPDATE: I am actually looking for two diffe...

How can I programatically change the background in Mac OS X?

How would I go about programatically changing the desktop background in Mac OS X? I'd like to use python, but I'm interested in any way possible. Could I hook up to Terminal and call a certain command? ...

Restarting a Python Interpreter Quietly

Hi, I have a python interpreter embedded inside an application. The application takes a long time to start up and I have no ability to restart the interpreter without restarting the whole application. What I would like to do is to essentially save the state of the interpreter and return to that state easily. I started by storing the na...

How do I "cd" in python

"cd" as in the shell command to change working directory ... ...

Python csv.reader: How do I return to the top of the file?

When I'm moving through a file with a csv.reader, how do I return to the top of the file. If I were doing it with a normal file I could just do something like "file.seek(0)". Is there anything like that for the csv module? Thanks ahead of time ;) ...

Ignore python multiple return value

Say I have a Python function that returns multiple values in a tuple: def func(): return 1, 2 Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this: x, temp = func() ...

Is possible send a array in Obj-c for a variable arguments function?

Hi, in python is easy build a dictionary or array and pass it unpacked to a function with variable parameters I have this: - (BOOL) executeUpdate:(NSString*)sql, ... { And the manual way is do this: [db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" , @"hi'", // look! I put in a ', and I'm not escaping i...

Python: unpack to unknown number of variables?

How could I unpack a tuple of unknown to, say, a list? I have a number of columns of data and they get split up into a tuple by some function. I want to unpack this tuple to variables but I do not know how many columns I will have. Is there any way to dynamically unpack it to as many variables as I need? Thanks for your help :) ...

Programming Design Help - How to Structure a Sudoku Solver program?

Hi, I'm trying to create a sudoku solver program in Java (maybe Python). I'm just wondering how I should go about structuring this... Do I create a class and make each box a object of that class (9x9=81 objects)? If yes, how do I control all the objects - in other words, how do I make them all call a certain method in the class? Do I j...

What commercial games have been written with pyGame?

I'm curious to know what commercial games, if any, have been written with pyGame. The scale doesn't matter much, it doesn't have to be a massive success, but it should be significant that more than 2 people have ever heard of it. I ask this because nearly everything I saw on the pyGame website seemed fairly underwhelming. I understand...

3D Polygons in Python

As far as I am aware there is no inbuilt polygon functionality for Python. I want to create a 3D map and figured that polygons would be the best way to go about it. Not wanting to reinvent the wheel I did some googling and found that there's a lot of Python stuff out there, but I couldn't find what I wanted. Thus before I reinvent the w...