python

How to override Py_GetPrefix(), Py_GetPath()?

I'm trying to embed the Python interpreter and need to customize the way the Python standard library is loaded. Our library will be loaded from the same directory as the executable, not from prefix/lib/. We have been successful in making this work by manually modifying sys.path after calling Py_Initialize(), however, this generates a wa...

how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url

Say I have the following set of urls in a db url data ^(.*)google.com/search foobar ^(.*)google.com/alerts barfoo ^(.*)blah.com/foo/(.*) foofoo ... 100's more Given any url in the wild, I would like to check to see if that url belongs to an existing set of urls and get the corresponding data field. My questi...

Python xml.dom and bad XML

I'm trying to extract some data from various HTML pages using a python program. Unfortunately, some of these pages contain user-entered data which occasionally has "slight" errors - namely tag mismatching. Is there a good way to have python's xml.dom try to correct errors or something of the sort? Alternatively, is there a better way to...

IE8 automation and https

I'm trying to use IE8 through COM to access a secured site (namely, SourceForge), in Python. Here is the script: from win32com.client import gencache from win32com.client import Dispatch import pythoncom gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}', 0, 1, 1) class SourceForge(object): def __init__(self, baseURL=...

Create instance of a python class , declared in python, with C API

Hello, I want to create an instance of a Python class defined in the __main__ scope with the C API. For example, the class is called MyClass and is defined as follows: class MyClass: def __init__(self): pass The class type lives under __main__ scope. Within the C application, I want to create an instance of this class. ...

Scrolling through a `wx.ScrolledPanel` with the mouse wheel and arrow keys

In my wxPython application I've created a wx.ScrolledPanel, in which there is a big wx.StaticBitmap that needs to be scrolled. The scroll bars do appear and I can scroll with them, but I'd also like to be able to scroll with the mouse wheel and the arrow keys on the keyboard. It would be nice if the "Home", "Page Up", and those other ke...

Python Xlib catch/send mouseclick

Hello, At the moment I'm trying to use Python to detect when the left mouse button is being held and then start to rapidly send this event instead of only once. What I basically want to do is that when the left mouse button is held it clicks and clicks again until you let it go. But I'm a bit puzzled with the whole Xlib, I think it's ver...

How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home?

Hello, I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer. Thanks! ...

What is the DRY way to configure different log file locations for different settings?

I am using python's logging module in a django project. I am performing the basic logging configuration in my settings.py file. Something like this: import logging import logging.handlers logger = logging.getLogger('project_logger') logger.setLevel(logging.INFO) LOG_FILENAME = '/path/to/log/file/in/development/environment' handler =...

Difference in SHA512 between python hashlib and sha512sum tool

I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library. Here is what I get on my Ubuntu 8.10: $ echo test | sha512sum 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123 - $ python Python 2.5.2 (r252:60911, Oct ...

Python socket accept blocks - prevents app from quitting

I've written a very simple python class which waits for connections on a socket. The intention is to stick this class into an existing app and asyncronously send data to connecting clients. The problem is that when waiting on an socket.accept(), I cannot end my application by pressing ctrl-c. Neither can I detect when my class goes out...

Possible to access gdata api when using Java App Engine?

I have a dilemma where I want to create an application that manipulates google contacts information. The problem comes down to the fact that Python only supports version 1.0 of the api whilst Java supports 3.0. I also want it to be web-based so I'm having a look at google app engine, but it seems that only the python version of app engi...

Can you suggest any extended examples on object-oriented software design?

I am looking for instructional materials on object-oriented software design that are framed as extended examples. In other words, over the course of several lessons or chapters, the author would develop a moderately large piece of software and explain the design approach step by step. Ideally, the material would address not only the desi...

cx_Oracle and the data source paradigm

There is a Java paradigm for database access implemented in the Java DataSource. This object create a useful abstraction around the creation of database connections. The DataSource object keeps database configuration, but will only create database connections on request. This is allows you to keep all database configuration and initializ...

Python threads - crashing when they access postgreSQL

Hello, here is a simple threading program which works fine: import psycopg2 import threading import time class testit(threading.Thread): def __init__(self, currency): threading.Thread.__init__(self) self.currency = currency def run(self): global SQLConnection global cursor SQLString = "...

using task queues to schedule the fetching/parsing of a number of feeds in appengine python

Say I had over 10,000 feeds that I wanted to periodically fetch/parse. If the period were say 1h that would be 24x10000 = 240,000 fetches. The current 10k limit of the labs taskqueue api would preclude one from setting up one task per fetch. How then would one do this? Update: re: fetching nurls per task: given the 30second timeout pe...

MetaPython: Adding Methods to a Class

I would like to add some methods to a class definition at runtime. However, when running the following code, I get some surprising (to me) results. test.py class klass(object): pass for i in [1,2]: def f(self): print(i) setattr(klass, 'f' + str(i), f) I get the following when testing on the command line: >>> impor...

Rendering common session information in every view

I'd like to output some information that depends on session data in Django. Let's take a "Login" / "Logged in as | Logout" fragment for example. It depends on my request.session['user']. Of course I can put a user object in the context every time I render a page and then switch on {% if user %}, but that seems to break DRY idea - I wou...

How to resume program (or exit) after opening webbrowser?

I'm making a small Python program, which calls the webbrowser module to open a URL. Opening the URL works wonderfully. My problem is that once this line of code is reached, the problem is unresponsive. How do I get the program to proceed past this line of code and continue to execute? Below the problematic line is the problematic line, ...

How to create Classes in Python with highly constrained instances

In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). Another good example are integers: if a and b are instances of the int type the...