python

Decoding html encoded strings in python

I have the following string... "Scam, hoax, or the real deal, he’s gonna work his way to the bottom of the sordid tale, and hopefully end up with an arcade game in the process." I need to turn it into this string... Scam, hoax, or the real deal, he’s gonna work his way to the bottom of the sordid tale, and hopefully en...

Python script embedded in Windows Registry

We all know that windows has the feature that you can right click on a file and numerous options are shown. Well you can add a value to this menu. I followed this guide : jfitz.com/tips/rclick_custom.html Basically I have a script that runs when I right click on a certain file type. Alright, so everything is going flawlessly, however w...

What is the underlying data structure for Python lists?

What is the typical underlying data structure used to implement Python's built-in list data type? ...

capture stderr from python subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

I have seen this posted so many times here; yet failed to capture intentional errors from command. Best partial work I have found so far.. from Tkinter import * import os import Image, ImageTk import subprocess as sub p = sub.Popen('datdsade',stdout=sub.PIPE,stderr=sub.PIPE) output, errors = p.communicate() root = Tk() text = Text(root...

How can I count unique terms in a plaintext file case-insensitively?

This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file. I only need this for quick sanity-checking, so it doesn't need to be well-engineered. ...

How to save indention format of file in Python

I am saving all the words from a file like so: sentence = " " fileName = sys.argv[1] fileIn = open(sys.argv[1],"r") for line in open(sys.argv[1]): for word in line.split(" "): sentence += word Everything works okay when outputting it except the formatting. I am moving source code, is there any way I can sa...

best practice for user preferences in $HOME in Python

For some (small) programs I'm writing in Python, I'd like to be able to set, store and retrieve user preferences in a file in a portable (multi-platform) way. I'm obviously thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg". Is os.path.expanduser() the best way for achieving this or there's som...

Python: Looping through all but the last item of a list

I would like to loop through a list checking each item against the one following it. Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can. ...

producer/consumer problem with python multiprocessing

I am writing a server program with one producer and multiple consumers, what confuses me is only the first task producer put into the queue gets consumed, after which tasks enqueued no longer get consumed, they remain in the queue forever. from multiprocessing import Process, Queue, cpu_count from http import httpserv import time def w...

Regular Expression for Stripping Strings from Source Code

Hello, I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello"""). To clarify, I will provide some examples...

Migrating from python 2.4 to python 2.6

I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring to use new 2.6 features if that leads to cleaner, more robust cod...

How to convert specific character sequences in a string to upper case using Python?

Hi All, I am looking to accomplish the following and am wondering if anyone has a suggestion as to how best go about it. I have a string, say 'this-is,-toronto.-and-this-is,-boston', and I would like to convert all occurrences of ',-[a-z]' to ',-[A-Z]'. In this case the result of the conversion would be 'this-is,-Toronto.-and-this-is...

Please point me to (good) documentation about QT layouts for plasma development

I am trying to develop a plasmoid in python. I got some good tutorials here (techbase.kde.org/Development/Tutorials/Plasma) and they are really helpful, but they don't have documentation or examples about QT layouts and their usage. I haven't programmed with QT, but I know C++ well. So, the resources shouldn't be necessarily python api...

Reporting charts and data for MS-Office users

We have lots of data and some charts repesenting one logical item. Charts and data is stored in various files. As a result, most users can easily access and re-use the information in their applications. However, this not exactly a good way of storing data. Amongst other reasons, charts belong to some data, the charts and data have some ...

django auth User truncating email field

I am having an issue with the django.contrib.auth User model where the email max_length is 75. I am receiving email addresses that are longer than 75 characters from the facebook api, and I need to (would really like to) store them in the user to continuity among users that are from facebook connect and others. I am able to solve the p...

Python plotting libraries

What alternatives are there to pylab for plotting in python? In particular, I'm looking for something that doesn't use the stateful model that pylab does. ...

How can I handle a mouseMiddleDrag event in PythonCard?

I would like to use the middle mouse button to drag an image in an application written in Python and using PythonCard/wxPython for the GUI. The latest version of PythonCard only implements a "left mouse button drag" event and I am trying to modify PythonCard to handle a "middle mouse button drag" as well. Here is the relevant code from...

Swig bindings for python/lua do not initialize member data properly

I'm trying to build a set of Lua bindings for a collection of C++ classes, but have been toying with Python to see if I get better results. In either language the bindings seem to work, however, when I initialize an instance of a class that contains members of other classes, those data members do not seem to be guaranteed to be initializ...

Would it be possible to write a 3D game as large as World of Warcraft in pure Python?

Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings. If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do things out of habit! Any informat...

How to debug PYGTK program

When python raise an exception in the middle of a pygtk signal handling callback, the exception is catched by the gtk main loop, its value printed and the main loop just continue, ignoring it. If you want to debug, with something like pdb (python -m pdb myscript.py), you want that when the exception occure PDB jump on it and you can sta...