python

How can I define a string in a python function?

Hi, I'm playing with Python and Google App Engine for the first time but am unable to define a string within my function (mytest2), I get an indentation error on the line after the declaration. I can define one in the parameters that works (test) but can't see why I wouldn't be able to do it in the function aswell. I've read a few tuto...

Error in executing python code- dictionary problem

while stack.isEmpty() != 1: fin = stack.pop() print fin - output is (1,1) k = final.get(fin) return k def directionToVector(direction, speed = 1.0): dx, dy = Actions._directions[direction] return (dx * speed, dy * speed) directionToVector = staticmethod(directionToVector) b...

How to write a twisted server that is also a client?

Hello, How do I create a twisted server that's also a client? I want the reactor to listen while at the same time it can also be use to connect to the same server instance which can also connect and listen. ...

Reason for "all" and "any" result on empty lists

In Python, the built-in functions all and any return True and False respectively for empty iterables. I realise that if it were the other way around, this question could still be asked. But I'd like to know why that specific behaviour was chosen. Was it arbitrary, ie. could it just as easily have been the other way, or is there an underl...

Am I parsing this HTTP POST request properly?

Let me start off by saying, I'm using the twisted.web framework. Twisted.web's file uploading didn't work like I wanted it to (it only included the file data, and not any other information), cgi.parse_multipart doesn't work like I want it to (same thing, twisted.web uses this function), cgi.FieldStorage didn't work ('cause I'm getting th...

Is there an equivalent to python's urllib in c/c++ ?

any c/c++ library out there that provides functions like getUrl, urlopen, post etc. ? ...

Compiling .go ( google go language ) in Windows ... & Can python connect to Go?

Hi all, i know that go language does not support windows yet, now, how can i compile .go file is windows ? and can python connect to go ? like connecting c++ or java to python ... lol ...

Hiding console window of Python GUI app with py2exe

I have a Python program uses Qt (PyQt4 in fact) and when I launch it from its main.py, I get a console window and the GUI window (on Windows, of course). Then I compile my program with py2exe and main.exe is successfully created. However, if I run main.exe (this is what users of program will do) console window of Python still appears an...

string mask and offset with regex

I have a string on which I try to create a regex mask that will show N number of words, given an offset. Let's say I have the following string: "The quick, brown fox jumps over the lazy dog." I want to show 3 words at the time: offset 0: "The quick, brown" offset 1: "quick, brown fox" offset 2: "brown fox jumps" offset 3: "fox jumps o...

On the google app engine, how do I change the default logging level of the dev_appserver.py?

Dev_appserver.py (the local development server for Python google app engine) spews tons of useless INFO messages. I would like to up this to WARN or ERROR. How can I do that? I've tried the following, but it has no effect... logger = logging.getLogger() logger.setLevel(logging.WARN) Any ideas? ...

python 3.x speech module

Hi, Is there pyTTS or some kind of speech module for python 3.0? I can't seem to find it anywhere and I'd really like to try it out. ...

python/xpath guru issue?

hi. using python 2.4/2.5, with libxm2dom. trying to get my haed around a question/issue that I'm considering. I have a doc I import the doc, and can build the DOM (libxml2dom) I'm trying to figure out if there's a way to programatically "search" for a given term, and be able to craft the XPath function to extract the href for the te...

How can I use the python HTMLParser library to extract data from a specific div tag?

I am trying to get a value out of a HTML page using the python HTMLParser library. The value I want to get hold of is within this html element: ... <div id="remository">20</div> ... This is my HTMLParser class so far: class LinksParser(HTMLParser.HTMLParser): def __init__(self): HTMLParser.HTMLParser.__init__(self) self.see...

Adding options which both change behaviour and store an argument

Using the argparse module, is it possible to perform multiple actions for a given argument? Specifically, I'd like to provide a -l/--list option with nargs='?' that will change the behaviour of the program from its main function to one of giving information about all possibilities in a set or about one particular possibility. Normally ...

Extracting date from a string in Python

How can I extract the date from a string like "monkey 2010-07-10 love banana"? Thanks! ...

Using Web2Py in Making a blog in Python (Google App Engine)? Is it a good Idea?

I know there are tons of blogging platforms out there (Wordpress,Drupal,etc) but I want to make my own blog engine or blog platform from scratch using python as a learning tool. The idea of using Google App Engine solves the issues in hosting. Blogs relatively consumes less amount of disk space and If it scales then there's no problem of...

Basic data storage with Python

I need to store basic data of customer's and cars that they bought and payment schedule of these cars. These data come from GUI, written in Python. I don't have enough experience to use a database system like sql, so I want to store my data in a file as plain text. And it doesn't have to be online. To be able to search and filter them,...

Python Popen: are the pipes in blocking mode? how can I put them in non-blocking mode?

Hi, In the subprocess documentation, I haven't found any hint if the pipes created by PIPE are blocking or non-blocking. I.e., if I call p.stdout.read(), will it block in certain circumstances? The documentation warns about that. How can I avoid that? Using p.communicate() is not an option for me because I don't want to block/wait unt...

Twisted and enabling command line history

In a previous question of mine i get this answer: Subclass twisted.conch.recvline.HistoricRecvLine instead of twisted.protocols.basic.LineReceiver. keystrokeReceived is one of the several additional protocol callbacks available when you are using a terminal instead of a TCP connection. – Jean-Paul Calderone Which is fine. But what if w...

Execute Python program using PHP

Hi, Can I simply execute Python program using PHP like this? (in a browser) exec("python myProgram /Applications/MAMP/htdocs/somefile.xml"); or like this: exec("/path/to/python path/to/myProgram /Applications/MAMP/htdocs/somefile.xml"); Is any of this method correct? If not, what should be the right way to do it? Thanks ...