python

[ask] override multiprocessing in python

how can i get variable in class which is override multiprocessing in python: #!/usr/bin/env python import multiprocessing import os class TestMultiprocess(multiprocessing.Process): def __init__(self): multiprocessing.Process.__init__(self) self.myvar = '' def myfunc(self): return os.getpid() def ...

Maximum match length of a regular expression

What is the easiest way to determine the maximum match length of a regular expression? Specifically, I am using Python's re module. E.g. for foo((bar){2,3}|potato) it would be 12. Obviously, regexes using operators like * and + have theoretically unbounded match lengths; in those cases returning an error or something is fine. Giving a...

What is proper Tokenization algorithm? & Error: TypeError: coercing to Unicode: need string or buffer, list found

Hello, I'm doing an Information Retrieval Task. As part of pre-processing I want to doing. Stopword removal Tokenization Stemming (Porter Stemmer) Initially, I skipped tokenization. As a result I got terms like this: broker broker' broker, broker. broker/deal broker/dealer' broker/dealer, broker/dealer. broker/dealer; broker/deale...

Remote debugging with WingIDE

Hi there, Using WingIDE to debug a web application, I have set a breakpoint in some Python code which runs when a web-form is submitted. Just before the breakpoint I have inserted 'import wingdbstub' to activate remote deubgging. However, execution does not stop at the breakpoint. I know the code is running because if I insert 'raise...

django template question (accessing a list)

I am writing a template for my first django website. I am passing a list of dictionaries to the template in a variable. I also need to pass a few other lists which hold boolean flags. (Note: all lists have the same length) The template looks something like this: <html> <head><title>First page</title></head><body> {% for it...

How to use Ruby CLI client to launch a JobFlow based on a JSON JobFlow description on Amazon Elastic MapReduce.

I have written a mapreduce application for hadoop and tested it at the command line on a single machine. My application uses two steps Map1 -> Reduce1 -> Map2 -> Reduce2 To run this job on aws mapreduce, I am following this link http://aws.amazon.com/articles/2294. But I am not clear how to use Ruby CLI client provide by amazon to do al...

How to perform Job scheduling algorithms using python ?

Well , i want to test out which scheduling algorithm is suitable for my application , but unable to figure out on how to go about testing. i have a set of jobs to be executed , for SMP (Symmetric Multi Process ) execution i used Parallel Python , but not able to apply Job Scheduling algorithm . For ex: if i want to implement SJF (Shor...

OpenCL for Python

I'm looking for good OpenCL wrapper\library for Python with good documantation. I tried to search some... but didn't find good enouth. Can anybody help? ...

What does fetch() fetch in GAE?

This is a follow up to my other question. I thought that mylist = list(Rep().all().fetch(50)) makes mylist a list. But when I try to get its length I get the message self.response.out.write(len(P)) TypeError: object of type 'Rep' has no len() Can anyone explain what I am doing wrong? Rep().replist = L ...

how to reliably decode various encodings to system default encoding

I am trying to work with several documents that all have various encodings - some utf-8, some ISO-8859-2, some ascii etc. Is there a reliable way of decoding to a standard encoding for processing? I have tried the following: import chardet encoding = chardet.detect(text) text = unicode(text,encoding['encoding']).decode(sys.getdefaulten...

Is there such a thing for Django as there is Heroku for Ruby on Rails

Is there a cloud based development for Django, such as there is cloud based development and hosting environment for Ruby / heroku ...

2d array of lists in python

Hello, everyone! I am trying to create a 2d matrix so that each cell contains a list of strings. Matrix dimensions are known before the creation and I need to have access to any element from the beginning (not populating a matrix dynamically). => I think some kind of preallocation of space is needed. For example, I would like to have a...

Jinja2 - Given 2 templates (as strings) how to render one that extends the other?

I'm making a simple script that works on Jinja2 templates. Right now it's just reading files in from disk manually, i.e. no Jinja Loaders. I have 2 strings (A and B), representing 2 templates. I want to make one template (B) inherit from the other (A), i.e. I have {% block body %}{% endblock %} in A, and I want to make the body block be ...

Returning a function from a function in Python

I'm writing a function in Python that takes another function as an argument. Something like this: DoStuffToFunction(myFunction, arg1, arg2, arg3) However, I want to construct myFunction based on the return of another function MakeFunction(arg1, arg2, arg3). So I do something like: def MakeFunction(arg1, arg2, arg3): def ret...

Python Read and Output from Stdin Unbuffered

In C++ or any other languages, you can write programs that continuously take input lines from stdin and output the result after each line. Something like: while (true) { readline break if eof print process(line) } I can't seem to get this kind of behavior in Python because it buffers the output (i.e. no printing will happen ...

Python: Cannot pop from empty list? When list is clearly not empty?

I'm obviously missing something here. Same project I've been working on for a number of days. Stepping through it bit by bit, seemed to be working fine. I added in a portion of the main() function to actually create the comparison lists, and suddenly starts throwing out cannot pop from empty list error at me, even through a print functio...

Extraction from a string in R or Python

I have a csv file with addresses that include ',', empty space, numbers. I have two other files with city and zip codes. I want to read the address file and extract the city name and zip codes. As you will see below the addresses have no easy pattern and is randomly sprinkled with ',' spaces etc.Here is an example. Address file 123 Ri...

Python Firewall for Windows?

I am wanting to write a custom firewall for my win XP Pro SP2 computer. I would like to do it in Python, but I'm not exactly sure how. I would like it to block everything in and out of the computer until I approve it. How would this be done? ...

What's the advantage of stack-less Python's microthread than Lua's coroutine in state machine implementation for game?

Any advantage on stack-less python implentation than Lua's coroutine? What's the difference of them? ...

Mac OS X 10.6 Python 2.7 pytidylib utidylib could not find libtidy

I am answering my own question, but because I stayed up all night figuring it out, I will hopefully save others some pain. If you are getting either of the following messages after properly installing pytidylib or utidylib, this answer may help. Learning Python on Snow Leopard, I had installed the 32-bit version of Python 2.7 so that I ...