python

Endless problems with a very simple python subprocess.Popen task

I'd like python to send around a half-million integers in the range 0-255 each to an executable written in C++. This executable will then respond with a few thousand integers. Each on one line. This seems like it should be very simple to do with subprocess but i've had endless troubles. Right now im testing with code: // main() u32 num;...

A lightweight protocol for Python and Erlang interaction

What protocol preferred to use for interaction between Python-code and Erlang-code over Internet? ASN.1 would be ideally for me, but its implementation in Python cannot generate encoder/decoder out from notation. ...

best way to find out type

hi, I have a dict val_dict - {'val1': 'abcd', 'val': '1234', 'val3': '1234.00', 'val4': '1abcd 2gfff'} All the values to my keys are string. So my question is how to find out type for my values in the dict. I mean if i say`int(val_dict['val1']) will give me error. Basically what I am trying to do is find out if the string is actual...

Can I get psycopg2 to work on Windows with a python built with vc9?

I have a question similar to http://stackoverflow.com/questions/1306367/python-importerror-dll-load-failed-when-trying-to-import-psycopg2-library I'm trying to run psycopg2 with Python 2.6.5, built with Visual Studio 2008 (vc9). I get this error: from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: DLL load fail...

Decorator Module Standard

I was wondering if it's frowned upon to use the decorator module that comes with python. Should I be creating decorators using the original means or is it considered okay practice to use the module? ...

Python re.IGNORECASE being dynamic

I'd like to do something like this: re.findall(r"(?:(?:\A|\W)" + 'Hello' + r"(?:\Z|\W))", 'hello world',re.I) And have re.I be dynamic, so I can do case-sensitive or insensitive comparisons on the fly. This works but is undocumented: re.findall(r"(?:(?:\A|\W)" + 'Hello' + r"(?:\Z|\W))", 'hello world',1) To set it to sensitive. Is...

Using Tcl DSL in Python

I have a bunch of Python functions. Let's call them foo, bar and baz. They accept variable number of string arguments and does other sophisticated things (like accessing the network). I want the "user" (let's assume he is only familiar with Tcl) to write scripts in Tcl using those functions. Here's an example (taken from Macports) th...

Sphinx autodoc is not automatic enough

I'm trying to use Sphinx to document a 5,000+ line project in Python. It has about 7 base modules. As far as I know, In order to use autodoc I need to write code like this for each file in my project: .. automodule:: mods.set.tests :members: :show-inheritance: This is way too tedious because I have many files. It would be much...

Fast iterating over first n items of an iterable (not a list) in python

Hello! I'm looking for a pythonic way of iterating over first n items of an iterable (upd: not a list in a common case, as for lists things are trivial), and it's quite important to do this as fast as possible. This is how I do it now: count = 0 for item in iterable: do_something(item) count += 1 if count >= n: break Doesn't seem ...

Using Ruby/Python code in an iPhone OS app?

My app needs to use a library which is only available for Python and Ruby. From my understanding, Apple allows Ruby to run on iPhone as long as users can't execute arbitrary code (Rhomobile uses Ruby). How can I bundle Ruby/Python with my app, call a function from my Obj-C code, and get the result (a string) back in C or Obj-C format? ...

Intelligent search and generation of Java code, preferrably using Python?

Basically, I do lots of one-off code generation, large-scale refactorings, etc. etc. in Java. My tool language of choice is Python, but I'll take whatever solutions you can offer. Here is a simplified illustration of what I would like, in a pseudocode Generating an implementation for an interface search within my project: for eac...

'int' object is not callable

I'm trying to define a simply Fraction class And I'm getting this error: python fraction.py Traceback (most recent call last): File "fraction.py", line 20, in <module> f.numerator(2) TypeError: 'int' object is not callable The code follows: class Fraction(object): def __init__( self, n=0, d=0 ): self.numerator = n ...

Google App Engine getting verbose_name of a property from an instance

Given a model like so: from google.appengine.ext import db class X(db.Model): p = db.StringProperty(verbose_name="Like π, but more modern.") How does one access verbose_name from x=X() (an instance of X)? One might expect that x.p.verbose_name would work, or alternatively x.properties()['p'].verbose_name, but neither seems to w...

Generating Mouse-Keyboard combination events in python

I want to be able to do a combination of keypresses and mouseclicks simultaneously, as in for example Control+LeftClick At the moment I am able to do Control and then a left click with the following code: import win32com, win32api, win32con def CopyBox( x, y): time.sleep(.2) wsh = win32com.client.Dispatch("WScript.Shell") w...

Operations on Python hashes

I've got a rather strange problem. For a Distributed Hash Table I need to be able to do some simple math operations on MD5 hashes. These include a sum (numeric sum represented by the hash) and a modulo operation. Now I'm wondering what the best way to implement these operations is. I'm using hashlib to calculate the hashes, but since the...

Check if the internet cannot be accessed in Python

I have an app that makes a HTTP GET request to a particular URL on the internet. But when the network is down (say, no public wifi - or my ISP is down, or some such thing), I get the following traceback at urllib2.urlopen: 70, in get u = urllib2.urlopen(req) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/url...

Tag Suggestion system, approaches and ideas

Hi guys! -- I am working on a (auto) tag suggestion system (NOT tag autocomplete). Lets say I want to suggest tags for a given question like here on SO (although SO's tagging system is auto-complete). My main idea is to get the intersection between the tags_set and the given question.split()_set. (In python the set_intersection is effici...

How can I make this timer run forever?

from threading import Timer def hello(): print "hello, world" t = Timer(30.0, hello) t.start() This code only fires the timer once. How can I make the timer run forever? Thanks, updated this is right : import time,sys def hello(): while True: print "Hello, Word!" sys.stdout.flush() time.sleep(2.0...

Why regular expression's "non-capturing" group is not working

In my snippet below, the non-capturing group "(?:aaa)" should be ignored in matching result, so the result should be "_bbb" only. However, I get "aaa_bbb" in matching result; only when I specify group(2) does it show "_bbb". import re string1 = "aaa_bbb" print(re.match(r"(?:aaa)(_bbb)", string1).group()) >>> aaa_bbb ...

how to set inbound mail for google-app-engine..

this is my set: ...