python

urllib2 read to Unicode

I need to store the content of a site that can be in any language. And I need to be able to search the content for a Unicode string. I have tried something like: import urllib2 req = urllib2.urlopen('http://lenta.ru') content = req.read() The content is a byte stream, so I can search it for a Unicode string. I need some way that wh...

Interacting with another command line program in Python.

I need to write a Python script that can run another command line program and interact with it's stdin and stdout streams. Essentially, the Python script will read from the target command line program, intelligently respond by writing to its stdin, and then read the results from the program again. (It would do this repeatedly.) I've loo...

Package for creating and validating HTML forms in Python? - to be used in Google Appengine

Is there a well maintained package available in Python for creating and validating HTML forms? I will deploying it finally on Google Appengine. ...

Python: how to call a property of the base class if this property is being overwritten in the derived class?

I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties. But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with properties? How to call the pr...

Problem with exiting a daemonized process

I am writing a daemon program that spawns several other children processes. After I run the stop script, the main process keeps running when it's intended to quit, this really confused me. import daemon, signal from multiprocessing import Process, cpu_count, JoinableQueue from http import httpserv from worker import work class Manager:...

Probability time series, observed data probabilities (deja vu)

okay folks...thanks for looking at this question. I remember doing the following below in college however I forgotten the exact solution. Any takers to steer in the right direction. I have a time series of data (we'll use three) of N. The data series is sequential in order of time (e.g. obsOne[1] occurred along with obsTwo[1] and obs...

Generating a 3d captcha [pic]

I would like to write a python script that would generate a 3d captcha like this one: Can you please tell me which graphics librarys I can use? Thanks! Source: ocr-research.org.ua ...

pywikipedia question?

Is it possible, using pywikipedia, to get just the text of the page, without any of the internal links or templates & without the pictures etc.? Cheers! ...

Checking compatibility of two python functions (or methods)

Is there a possibility to check if two python functions are interchangeable? For instance, if I have def foo(a, b): pass def bar(x, y): pass def baz(x,y,z): pass I would like a function is_compatible(a,b) that returns True when passed foo and bar, but False when passed bar and baz, so I can check if they're interchangeable...

Best way to randomize a list of strings in Python

I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output. I see several "brute force" ways of doing that (using loops, god forbid), one of which I'm ...

Commenting code in Notepad++

Hi I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code. Since so many language settings are supported in Notepad++, I'm curious to find a way to block comment cod...

Python behavior of string in loop

In trying to capitalize a string at separators I encountered behavior I do not understand. Can someone please explain why the string s in reverted during the loop? Thanks. s = 'these-three_words' seperators = ('-','_') for sep in seperators: s = sep.join([i.capitalize() for i in s.split(sep)]) print s print s stdo...

StringListProperty in GAE

Hi! Is there any way to edit StringListProperty fields via Google's Data Viewer, or some other clever approach? The last I want to do is to modify my application in such way that it provides special throwaway page for just that reason - I don't feel like it's the optimal solution. Cheers, MH ...

Writing XML from Python : Python equivalent of .NET XmlTextWriter?

I have some IronPython code which makes use of XmlTextWriter which allows me to write code like self.writer = System.Xml.XmlTextWriter(filename, None) self.writer.Formatting = Formatting.Indented self.writer.WriteStartElement(name) self.writer.WriteString(str(text)) self.writer.WriteEndElement() ... self.writer.Close() I would like ...

Emulating membership-test in Python: delegating __contains__ to contained-object correctly

Hi, I am used to that Python allows some neat tricks to delegate functionality to other objects. One example is delegation to contained objects. But it seams, that I don't have luck, when I want to delegate __contains __: class A(object): def __init__(self): self.mydict = {} self.__contains__ = self.mydict.__contains_...

Problem getting date with Universal Feed Parser

It looks like http://portland.beerandblog.com/feed/atom/ is messed up (as are the 0.92 and 2.0 RSS feeds). Universal Feed Parser (latest version from http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparser.py?spec=svn295&amp;r=295 ) doesn't see any dates. <title>Beer and Blog Portland</title> <atom:link ...

Weighted slope one algorithm? (porting from Python to R)

I was reading about the Weighted slope one algorithm ( and more formally here (PDF)) which is supposed to take item ratings from different users and, given a user vector containing at least 1 rating and 1 missing value, predict the missing ratings. I found a Python implementation of the algorithm, but I'm having a hard time porting it t...

How can I pass the environment from my Python web application to a Perl program?

How do I set Perl's %ENV to introduce a Perl script into the context of my web application? I have a website, written in a language different from Perl (Python). However I need to use a Perl application, which consists of a .pl file: #!/usr/bin/env perl "$ENV{DOCUMENT_ROOT}/foo/bar.pm" =~ /^(.+)$/; require $1; my $BAR =...

Deploying Django

When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python? This might seem like an obvious question, but I'm new to web development frameworks so I must ask :) ...

What classes of applications or problems do you prefer Python to strictly OO Languages?

I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading Programming Collective Intelligence. I understand that Python can solve any problem that C# can, and vice-versa. But I am curious to know from those who us...