python

How to call Wine dll from python on Linux?

I'm writing a python script in Linux, and need to call some Windows functions available in Wine. Specifically, AllocateAndInitializeSid and LookupAccountSidW, to determine who is logged in to a remote Windows computer. These functions are part of advapi32.dll in Wine (edit: using the answers, I was able to call the function, but Lookup...

Performing unbiased program/script performance comparison

I want to perform a comparison of multiple implementations of basically the same algorithm, written in Java, C++ and Python, the latter executed using Pypy, Jython and CPython on a Mac OS X 10.6.4 Macbook Pro with normal (non-SSD) HDD. It's a "decode a stream of data from a file" type of algorithm, where the relevant measurement is tota...

SQLAlchemy equivalent to Django's annotate() method

I'm doing a join like this in SQLAlchemy: items = Item.query\ .outerjoin((ItemInfo, ItemInfo.item_id==Item.id)) items.add_columns(ItemInfo.count) This causes SQLAlchemy to return tuples: >>> items.first() (<Item ...>, 2) I'd much prefer it if the "count" value would instead be returned as an attribute of the item, i.e. I wa...

Saving map data in a 2d ORPG

I'm trying to figure out how I can best save the map data for a 2d ORPG engine I am developing, the file would contain tile data (Is it blocked, what actual graphics would it use, and various other properties). I am currently using a binary format but I think this might be a bit too limited and hard to debug, what alternatives are there...

HELPppppppppppppppppppppppppp.....

heres another code......but its also not running...dont know wot the problem is...plz hepl!!! import serial ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) x = ser.read() # read one byte s = ser.read(10) # read up to ten bytes (timeout) line = ser.readline() # read a '\n' terminated line ser.close() Tracebac...

Return a range of elements of each list inside a list of lists

From a list mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] how can I get a new list of lists composed of the first two elements of each "inside" list e.i. newlist = [[1, 2], [4, 5], [7, 8]]? Is there a one-liner that can do this efficiently (for large lists of lists)? ...

Python, ArcObjects, and .AppRef: how to get from IAppROT to IMxDocument?

I am writing an external Python/comtypes script (in PythonWin) that needs to get a reference to the current ArcGIS 10.0 ArcMap session (through the ArcObjects COM). Because the script is outside the application boundary, I am getting the application reference through the AppROT (running object table). The first code snippet below is the...

Python std methods hierarchy calls documented ?

Hi, just encountered a problem at dict "type" subclassing. I did override __iter__ method and expected it will affect other methods like iterkeys, keys etc. because I believed they call __iter__ method to get values but it seems they are implemented independently and I have to override all of them. Is this a bug or intention they don't...

Python parse date format, ignore parts of string

I want' to parse dates in this format, but ignore parts of the string. 'Wed, 27 Oct 1770 22:17:00 GMT' From what I have gathered, datetime does not support time zones very well. Which is fine, I really just want to ignore the timezone part of the string, without having to do string manipulation on it. Is there something I can replace %Z ...

using float('nan') to represent missing values - safe?

Python 3.1 I am doing some calculations on a data that has missing values. Any calculation that involves a missing value should result in a missing value. I am thinking of using float('nan') to represent missing values. Is it safe? At the end I'll just check def is_missing(x): return x!=x # I hope it's safe to use to check for NaN ...

How to use Python re module to replace \n with nothing in a single file

Regards to all. I'm developing a Image compression system using Python Image Library. The basic workflow is: Read all images of a certain directory with : find /opt/images -name *.jpg > /opt/rs/images.txt Read this file and storage the result in a Python list Iterate the list, create a Image object and passing like a argument to the co...

Python XML Parse (using schema to generate dataset)

I'm looking to parse a xml file using Python and I was wondering if there was any way of automating the task over manually walking through all xml nodes/attributes using xml.dom.minidom library. Essentially what would be sweet is if I could load a xml schema for the xml file I am reading then have that automatically generate some kind o...

How to add random delays between the queries sent to Google to avoid getting blocked in python

Hi, I have written a program which sends more than 15 queries to Google in each iteration, total iterations is about 50. For testing I have to run this program several times. However, by doing that, after several times, Google blocks me. is there any ways so I can fool google maybe by adding delays between each iteration? Also I have hea...

How to get CUSIP-Description data using Bloomberg API?

I had a look at Asynchronous data through Bloomberg's new data API (COM v3) with Python? before posting which has some pretty awesome info, but what I need is a way to create a CUSIP-Description table in a database using the Bloomberg API (to save $$$ by avoiding a CUSIP subscription) Does anyone know how to populate a table with CUSIP ...

embedding python ImportError: libpyglib PyExc_ImportError linking

I am running 64 bit ubuntu 10.10 in case there are know issues with this setup, basically i am embedding python inside a c application i managed to get this to work i can call functions from the original c program and the scripts run until i import gtk in the python script this causes the error below. I am using the waf build system to ...

Python app engine: how to save a image?

This is what I got from flex 4 file reference upload: self.request = Request: POST /UPLOAD Accept: text/* Cache-Control: no-cache Connection: Keep-Alive Content-Length: 51386 Content-Type: multipart/form-data; boundary=----------ei4cH2gL6ae0ei4ae0gL6GI3KM7ei4 Host: localhost:8080 User-Agent: Shockwave F...

[edited] How to deal with utf-8 encoded String and BeautifulSoup?

How can I replace HTML-entities in unicode-Strings with proper unicode? u'&quot;HAUS Kleider&quot; - &Uuml;ber das Bekleiden und Entkleiden, das Verh&Yuml;llen und Veredeln' to u'"HAUS-Kleider" - Über das Bekleiden und Entkleiden, das Verhüllen und Veredeln' edit Actually the entities are wrong. At it seems like BeautifulSoup f...e...

How can I create a TABLE if and only if it does not exist?

I'm trying conn = MySQLdb.connect (host = "localhost", user = "username", passwd = "password", db = "my_db") cursor = conn.cursor () q = """IF NOT EXISTS CREATE TABLE %s ( course VARCHAR(15), student VARCHAR(15), teacher VARCHA...

Does anyone see why the first part of my regex isn't working in Python?

I tested this regex out in RegexBuddy ,[A-Z\s]+?,(LA|RO|MU|FE|AV|CA),(ML|FE|MN|FS|UN)?,(\d+/\d+/\d{4})? and it seems to be able to do what I need it to do - capture a piece of data that looks like one of the following: ,POWDER,RO,ML,8/19/2002 ,POWDER,RO,,, ,POWDER,RO,,8/19/2002 ,POWDER,RO,ML,, When I use it in a python string: r",...

Text in Text Widget as a variable

Hi, so I've got this little Text widget with a scroll bar and I've got a question. How do I make text in this Text widget a variable ? If I made this text a variable I would be able to open a text file and edit it's text or save the text I've written, etc or maybe it's a wrong way that I'm approaching this, is there a better way to do t...