python

Deep copy of a derived python object

I have an object in python that is derived from QtGui.QGraphicsPixmapItem with a few basic attributes and methods. After calling deepcopy on a reference to this object, I get an error saying that underlying C/C++ object has been deleted when I try to use the copy. I had received this error before, and it occured when I didn't call the ba...

Pylons - Redirects will drop from HTTPS to HTTP unless I specify the protocol... Is there a way to fix this?

On my Pylons website, I have my login form sending it's data to 'https://mysite.com'. Upon a successful login, a redirect takes place to send them to their profile page. redirect(url(controller='profile')) This sends the user to http://mysite.com/profile instead of https://mysite.com/profile. The only way I've found to fix this is to ...

Python stdout doesn't flush correctly after calling curses.

I have a program that uses curses, and then returns to the main script for further processing. After it returns, my subsequent output to stdout does not appear until there's a large amount of it (e.g. thousands of bytes). I've reduced the problem to a very simple program that fails reliably: import curses import time curses.initscr() ...

What is happening to my process?

Hello, I'm executing a SSH process like so: checkIn() sshproc = subprocess.Popen([command], shell=True) exit = os.waitpid(sshproc.pid, 0)[1] checkOut() Its important that the process form checkIn() and checkOut() actions before and after these lines of code. I have a test case that involves that I exit the SSH session by closing the...

how can I get the window name? [Python]

How can I get the window name? I want to make a script where I have some keyboard event, and I want it to happens only if the window name has something in the name, like, Firefox. how can I do it? the simplest way ...

Draw text image without crop need by PIL

I would like to draw a text by using PIL. But my problem is I need to crop the text image again after run the program. The thing i need is only text, no border. Any one can suggest? Thank you. This is my code: import Image, ImageDraw, ImageFont def draw (text, size, color) : fontPath = '/home/FreeSansBold.ttf' font = ImageFont...

Python Packager

What is the easiest way to package Python programs into stand-alone executables? ...

Creating a list with >255 elements

Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C). Anyway, so I have collection of integer literals I need to store. (Ideally >10,000 of them, currently I've only got 1000 of them) I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallow...

How to inspect mystery deserialized object in Python

I'm trying to load JSON back into an object. The "loads" method seems to work without error, but the object doesn't seem to have the properties I expect. How can I go about examining/inspecting the object that I have (this is web-based code). results = {"Subscriber": {"firstname": "Neal", "lastname": "Walters"}} subscriber = jso...

py2exe problems

c:\python26\setup.py py2exe Trying to run py2exe and when I get to command prompt I run the line above. However as opposed to converting my file it try's to open it. What am I doing wrong? ...

Why do no Python DLLs built with MSVC load with mod_wsgi?

I recently updated from Python 2.5 to 2.7 (I tried 2.6 during my hassles) and while everything works fine from the command line or in the Django runserver, mod_wsgi cannot load any module that contains DLLs (pyd) built with MSVC. For example, if I build my own versions of pycrypto or lxml then I will get the following error only from mo...

spliting an exml file into smaller files

the xml file contains information about movies. how do i split the xml file into smaller files? ( so each small file is a separate movie) ...

Elegant Solution for looping over a json hash with a fickle structure

I have a json hash which has a lot of keys. I retrieve this hash from a web service at regular intervals and for different parameters etc. This has more or less fixed structure, in the sense that keys are sometimes missing. So I end up with a lot of code of the following nature Edit: Sample data data = { id1 : {dict...}, id2 : {dict..}...

Mixing regex and shell wildcards

I have a python script that reads from a config file. The config file is going to contain some user defined regex patterns. However, I was thinking I'd like to let the user use either full regex patterns, OR shell wildcards. So I should be able to interpret both *.txt as well as .*\.txt$ correctly. So those 2 should be equivalent. How...

How to use an SVG file as input for drawing with Cairo in a pyGTK application (python)?

I am writing a small python GTK application in which I have a drawing area that I am trying to "populate" using Cairo, which is a library I never used before (so bare with me if the answer is obvious and I did not see due to inexperience). What I am trying to achieve is using an SVG image as part of my drawing (if I got Cairo naming rig...

Parsing indeterminate amount of data into a python tuple

I have a config file that contains a list of strings. I need to read these strings in order and store them in memory and I'm going to be iterating over them many times when certain events take place. Since once they're read from the file I don't need to add or modify the list, a tuple seems like the most appropriate data structure. Howe...

removing duplication in google search api?

I am performing a google search in my application through google search api. It gives me the duplicate results. How to avoid it. I refer http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje ...

how to write a regex for this expression?

url1 = http://xyz.com/abc url2 = http://xyz.com//abc I want to write a regex that validate both url1 and url2 ...

How to make single from multiple element?

l = [{'name': 'abc', 'marks': 50}, {'name': 'abc', 'marks': 50}] I want to uniqify the dictionary result. result = [{'name': 'abc', 'marks': 50}] ...

WxPython Wizard: from last to first page

I have created a simple Wizard and now I need to give the user the possibility to start again from the first page without restarting the program. I tried overwrite the GetNext() method and used SetNext() to set a new page after the last. It works but the button "Next >" changes on the last page to "Finish" and doesn't change back by itse...