python

How to get output from subprocess.Popen()

I want output from execute Test_Pipe.py, I tried following code on Linux but not work. Test_Pipe.py import time while True : print "Someting ..." time.sleep(.1) Caller.py import subprocess as subp import time proc = subp.Popen(["python", "Test_Pipe.py"], stdout=subp.PIPE, stdin=subp.PIPE) while True : data = proc.stdo...

How can I compare two lists in python and return matches.

I want to take two lists and find the values that appear in both. a = [1, 2, 3, 4, 5] b = [9, 8, 7, 6, 5] returnMatches(a, b) would return [5], for instance. ...

how do I determine whether a python script is imported as module or run as script?

The question is rather straightforward but not answered by searching. How do I determine in a python script whether this script is imported as a module or run as a script? Is there a difference at all in python? The problem is, that I want to evaluate the command line parameters only if run as a script, but not if the module is only imp...

How can I tokenize this with a regex?

Suppose I have strings like the following : OneTwo ThreeFour AnotherString DVDPlayer CDPlayer I know how to tokenize the camel-case ones, except the "DVDPlayer" and "CDPlayer". I know I could tokenize them manually, but maybe you can show me a regex that can handle all the cases? EDIT: the expected tokens are : OneTwo -> One Two ......

how to create an excel file in google app engine (python)?

I want to create an excel sheet using Google App Engine in python. my application datastore contains the data of company details like name, business, website,..etc.,. i want to put those details in an excel sheet, is it possible to generate excel file in Google App Engine using python. can anybody help me! ...

IPv6 address validation and canonicalization

What libs have you used for that? How compatible are they with one another? Or did you write your own parsing routine? I'm particularly interested in mutually-compatible implementations for Java, C++, Python, and JavaScript, which support: zero compression ("::") IPv4-mapped addresses ("::ffff:123.45.67.89") canonicalization (includ...

how to add json library

i am new to python, on my Mac, when i issue command User:ihasfriendz user$ python main.py Traceback (most recent call last): File "main.py", line 2, in <module> import json ImportError: No module named json I get error on json. how to add this library? i'm using 2.5 (the default came with leopard) ...

Python: Automatically initialize instance variables?

Hi, I have a python class that looks like this: class process: def __init__(self, PID, PPID, cmd, FDs, reachable, user): followed by: self.PID=PID self.PPID=PPID self.cmd=cmd ... Is there any way to autoinitialize these instance variables, like C++'s initialization list? It would spare lots of r...

what's wrong with my simple HTTP proxy script? (python socket based)

hi all, i wrote a smple python script for a proxy functionality. It works. However, if the requested webpage has many other http requests, e.g. Google map, the page was rendered quite slow. Could you guys give some hints, what would be the bottleneck in my code? how to improve? Thanks in advance. #!/usr/bin/python import socket,sele...

How to process UDP data in Appengine

I have a service provider who is transmitting data thro' UDP. I want to establish a connection to them, receive & process data (will be with in the 30 sec limit/request) Is it possible to get & process UDP data in appengine. I am looking for some simple example. ...

AN error about "User.add_to_class" to extend my user?I do not know why.

In my models.py, I user these code to extent two fields: User.add_to_class('bio', models.TextField(blank=True)) User.add_to_class('about', models.TextField(blank=True)) But when I creat a User : user = User.objects.create_user(username=self.cleaned_data['username'], \ email=self.cleaned_data['email'],password=self.cleaned...

How to write a large amount of data in a tarfile in python without using temporary file

I've wrote a small cryptographic module in python whose task is to cipher a file and put the result in a tarfile. The original file to encrypt can be quit large, but that's not a problem because my program only need to work with a small block of data at a time, that can be encrypted on the fly and stored. I'm looking for a way to avoid ...

How to save data with Python?

I am working on a program in Python and want users to be able to save data they are working on. I have looked into cPickle; it seems like it would be a fast and easy way to save data, it seems insecure. Since entire functions, classes, etc can be pickled, I am worried that a rogue save file could inject harmful code into the program. ...

How to run django shell from Emacs?

I'd like to be able to run ./manage.py shell in an Emacs buffer, with all the nice stuff that you get from ipython, like magic commands and autocompletion. Ideally I would also like to be able evaluate code from a buffer to the django shell. Is this possible? ...

Mechanize and Google App Engine

Has someone managed to use mechanize with Google App Engine application? ...

OpenGL in Python with Snow Leopard?

I'm interested in playing around with OpenGL in Python. I've used OpenGL in C++ and Objective-C, but I don't have much experience in Python. I'm wondering if there's a good tutorial that works in Snow Leopard. I'd prefer to stay in 64-bit mode if possible, since I've heard 32-bit programs require loading a lot of extra 32-bit libraries. ...

How do I use StandardAnalyzer with TermQuery?

I'm trying to produce something similar to what QueryParser in lucene does, but without the parser, i.e. run a string through StandardAnalyzer, tokenize this and use TermQuery:s in a BooleanQuery to produce a query. My problem is that I only get Token:s from StandardAnalyzer, and not Term:s. I can convert a Token to a term by just extrac...

What are the different options for processing uploaded PDF files in a Django application?

Our Django application needs to do a few things with uploaded PDF files: Verify that the file is a PDF and isn't corrupted Check that the file isn't encrypted Count the number of pages We run into problems with one unfortunately popular application that's idea of an unencrypted PDF export is actually an encrypted PDF file, just with ...

Removing redundant symbols from string

Let's say I have a string like that: '12,423,343.93'. How to convert it to float in simple, effective and yet elegant way? It seems I need to remove redundant commas from the string and then call float(), but I have no good solution for that. Thanks ...

Agile Software Development in Python

I have been trying to learn a cross platform language with a fast learning curve, and so it seemed obvious Python was the logical choice. I've never programmed before but I have been reading on pragmatic programming and agile development for quite some time. The question comes, "What is the single best choice to create a desktop softwa...