python

Problems calling Python from C++

test.py def add(a,b): """ """ print a,b,a+b return a+b c program #include <python.h> int _tmain(int argc, _TCHAR* argv[]) { try { PyObject *pName,*pModule,*pDict,*pFunc,*pArgs1,*pArgs2,*pOutput; Py_Initialize(); if(!Py_IsInitialized()) return -1; pModule=PyImport_ImportModule("test"); pDict=PyModule_GetDict(pModu...

'Unexpected Section Title' with Sphinx -- is numpy the issue?

When running sphinx-build . html/ in my doc/ directory, I get the following output: $ sphinx-build . html/ Running Sphinx v0.6.4 No builder selected, using default: html loading pickled environment... done building [html]: targets for 0 source files that are out of date updating environment: 0 added, 1 changed, 0 removed reading sour...

Run pdb without stdin/stdout using FIFO

I am developing FUSE filesystem with python. The problem is that after mounting a filesystem I have no access to stdin/stdout/stderr from my fuse script. I don't see anything, even tracebacks. I am trying to launch pdb like this: import pdb pdb.Pdb(None, open('pdb.in', 'r'), open('pdb.out', 'w')).set_trace() All works fine but very...

How to pad all the numbers in a string.

I've got lots of address style strings and I want to sort them in a rational way. I'm looking to pad all the numbers in a string so that: "Flat 12A High Rise" becomes "Flat 00012A High Rise", there may be multiple numbers in the string. So far I've got: def pad_numbers_in_string(string, padding=5): numbers = re.findall("\d+", stri...

python ctypes.WinDLL error , _dlopen(self._name, mode) cant be found

ctypes.WinDLL("C:\Program Files\AHSDK\bin\ahscript.dll") Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\ctypes_init_.py", line 353, in init self._handle = _dlopen(self._name, mode) WindowsError: [Error 126] The specified module could not be found how can i solve it ... i found the _dlopen in C:\Py...

sound way to feed commands to twisted ssh after reactor.run()

Guys this is a question about python twisted ssh lib. All sample code even production code I saw acting as a ssh client based on twisted.conch.ssh are all interacting with server in such a mode: prepare some commands to run remotely; define call backs; kick off reactor then suspend for new feedback; After the reactor.run(), I never ...

Why does using threading.Event result in SIGTERM not being caught?

I have a threaded Python daemon. Like any good daemon, it wants to launch all of its worker threads, then wait around until it's told to terminate. The normal signal for termination is SIGTERM, and in most languages I'd hold to terminate by waiting on an event or mutex, so using threading.Event made sense to me. The problem is that Pytho...

Python : How to import a module if I have its path as a string ?

Lets say I have path to a module in a string module_to_be_imported = 'a.b.module' How can I import it ? ...

python - gtk treeview - liststore with real-time update.

hi, i am having a issue with treeview liststore trying to get a real-time update, and I created a example to simulate what I'd like to do. I want liststore1 updated each loop. http://img204.imageshack.us/i/capturadetela5.png/ it should update the treeview column 'speed' and give to it a different number every second, something like a d...

Mysql database Import Error in python

hi, i have installed python 2.6.4. i have downloaded mysql database module. but i don't know where to place that module in python package. when i execute the program it shows import error "no module named mysql db". please tell me where to place the module. ...

django: Nonelogout in admin urls

After upgrading to Django 1.2 I have strange urls in my administration panel. They look like this: http://example.com/admin/Nonelogout/ or http://example.com/admin/Nonepassword_change/ What might have gone wrong during the migration and what I need to fix? I have found in django source, that it is caused by root_path, but I have n...

Use latin characters in appengine

How can store latin characters in appengine? (e.g. "peña") when I want to store this I get this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 2: ordinal not in range(128) I can change the Ñ by N, but, there not another and better way? And if i encode the value, how can print "Peña" again? ...

Why are Google API queries through simplejson returning "responseData": null?

I'm trying to screenscrape the first result of a Google search using Python and simplejson, but I can't access the search results the way that many examples online demonstrate. Here's a snippet: url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;%s' % (query) search_results = urllib.urlopen(url) json = simplejson.load(...

SimpleDB query performance improvement using boto

Hello, I am trying to use the SimpleDB in following way. I want to keep 48 hrs worth data at anytime into simpledb and query it for different purposes. Each domain has 1 hr worth data, so at any time there are 48 domains present in the simpledb. As the new data is constantly uploaded, I delete the oldest domain and create a new domai...

How to get the system info with Python?

I need to get the info under what environment the software is running. Does python have a library for this purpose? I want to know the following info. OS name/version Name of the CPU, clock speed Number of CPU core Size of memory ...

I'm looking for a library that converts HTML to Textile in Python

What do you recommend? ...

Reading .csv in Python without looping through the whole file?

Hello, The only way I've seen Python's csv.reader used is in a for loop, which goes through the whole file without saving past values of the read in variables. I only need to work with 2 consecutive lines of the (enormous) file at a time. Using the csv.reader for loop, I only have 1 line at a time. Is there a way to use Python's csv mo...

How does this Python decorator work?

I was looking at some lazy loading property decorators in Python and happened across this example (http://code.activestate.com/recipes/363602-lazy-property-evaluation/): class Lazy(object): def __init__(self, calculate_function): self._calculate = calculate_function def __get__(self, obj, _=None): if obj is None...

Pickling Django request objects

I'm trying to pickle a request object so that I can run my view code in a debugger with valid input. However, I'm getting Can't pickle 'lock' object: <thread.lock object at 0x93ad240> I looked through the request object, but couldn't find a thread.lock object anywhere in it. Does anyone know where it is? Is there a better way to go ab...

Making lxml.objectify ignore xml namespaces?

So I gotta deal with some xml that looks like this: <ns2:foobarResponse xmlns:ns2="http://api.example.com"&gt; <duration>206</duration> <artist> <tracks>...</tracks> </artist> </ns2:foobarResponse> I found lxml and it's objectify module, that lets you traverse a xml document in a pythonic way, like a dictionary. Problem is: ...