python

Does Google use Python for anything but internal utilities and administration?

I'm curious...I've read much of Python being on the approved list of languages used by Google employees, and I know they employ Guido. That said, is their use of Python focused mainly on managing servers and applications, and not for developing the applications themselves? If so, why? It seems most I read indicates they use Java for the ...

Keeping a session in python while making HTTP requests

I need to write a python script that makes multiple HTTP requests to the same site. Unless I'm wrong (and I may very well be) urllib reauthenticates for every request. For reasons I won't go into I need to be able to authenticate once and then use that session for the rest of my requests. I'm using python 2.3.4 ...

Scraping Multiple html files to CSV

I am trying to scrape rows off of over 1200 .htm files that are on my hard drive. On my computer they are here 'file:///home/phi/Data/NHL/pl07-08/PL020001.HTM'. These .htm files are sequential from *20001.htm until *21230.htm. My plan is to eventually toss my data in MySQL or SQLite via a spreadsheet app or just straight in if I can get ...

Matching text within P tags in HTML

I'd like to match the contents within each paragraph in html using a python regular expression. These paragraphs always have BR tags inside them like so: <p class="thisClass">this is nice <br /><br /> isn't it?</p> I'm currently using this pattern: pattern = re.compile('<p class=\"thisClass\">(.*?)<\/p>') Then I'm using: pattern.f...

python - match on array return value

I want to do a functional like pattern match to get the first two elements, and then the rest of an array return value. For example, assume that perms(x) returns a list of values, and I want to do this: seq=perms(x) a = seq[0] b = seq[1] rest = seq[2:] Of course I can shorten to: [a,b] = seq[0:2] rest = seq[2:] Can I use some not...

Python Environment Variables in Windows?

I'm developing a script that runs a program with other scripts over and over for testing purposes. How it currently works is I have one Python script which I launch. That script calls the program and loads the other scripts. It kills the program after 60 seconds to launch the program again with the next script. For some scripts, 60 sec...

When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation.

Scenario: I have a php page in which I call a python script. Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file. Python script when run through php, doesn't do either. Elaboration: I use a simple system command in PHP to run the python script as: /var/www/htm...

How to start a process on a remote server, disconnect, then later collect output?

I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My network is a mix of w...

Python taskbar applet

I want to code up a panel that will be used both in Linux and Windows. Ideally it will be written in Python using PyQT. What I've found so far is the QSystemTrayIcon widget, and while that is quite useful, that's not quite what I'm looking for. That widget lets you attach a menu to the left and right clicks of an icon on the system tray...

How do I call template defs with names only known at runtime in the Python template language Mako?

I am trying to find a way of calling def templates determined by the data available in the context. Edit: A simpler instance of the same question. It is possible to emit the value of an object in the context: # in python ctx = Context(buffer, website='stackoverflow.com') # in mako <%def name="body()"> I visit ${website} all the time...

How do we setup Cheetah so it runs with all templates in the templates directory and all code in the .. directory

How do we setup Cheetah so it runs with all templates in the templates directory and all code in the .. directory in code.py production=True if not production: try:web.render('mafbase.tmpl', None, True, 'mafbase') except:pass else: from templates import mafbase in templates/mafbase.tmpl and templates/mafbase.py try:web.r...

Python RegEx - Finding multiple matches in a string

Hi. I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file and the code I've go...

Capturing Implicit Signals of Interest in Django

To set the background: I'm interested in: Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache Let's say, for instance, my site sells books. As a user browses around my site I'd like to keep track of which books they've viewed, ...

Best way to retrieve variable values from a text file - Python - Json

Referring on this question, i have a similar -but not the same- problem.. On my way, i'll have some text file, structured like: var_a: 'home' var_b: 'car' var_c: 15.5 And i need that python read the file and then create a variable named var_a with value 'home', and so on. Example: #python stuff over here getVarFromFile(filename) #t...

How can I remove the top and right axis in matplotlib?

Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.: +------+ | | | | | | ---> | | | | +------+ +------- This should be easy, but I can't find the necessary options in the docs. ...

A Python walker that can ignore directories

I need a file system walker that I could instruct to ignore traversing directories that I want to leave untouched, including all subdirectories below that branch. The os.walk and os.path.walk just don't do it. ...

Scope, using functions in current module

Hi, I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module? For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to assign to a category. T...

python queue & multiprocessing queue: how they behave?

This sample code works (I can write something in the file): from multiprocessing import Process, Queue queue = Queue() def _printer(self, queue): queue.put("hello world!!") def _cmdDisp(self, queue): f = file("Cmd.log", "w") print >> f, queue.get() f.close() instead this other sample not: (errormsg: 'module' object i...

Best method for dividing list into equal parts

Possible Duplicate: How do you split a list into evenly sized chunks in Python? I have a list more than 500 elements long. I want to divide it into 5 lists, each of 100 elements. mylist = [1......................700] if len(mylist) > 100: newlist1 = mylist[0:100] someothelist = mylist[100:] if len(someothe...

Uploading multiple images in Django admin

I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it. The most user-friendly way I can see would be a file upload form with a JavaScript control that allows the...