python

How would I make a simple URL extracter in Python?

How would I start on a single web page, let's say at the root of DMOZ.org and index every single url attached to it. Then store those links inside a text file. I don't want the content, just the links themselves. An example would be awesome. ...

How do you read a file into a list in Python?

I'm a first year compsci student who's extremely lost on this assignment. We are supposed to prompt a user for a number of random numbers to be generated and saved to a file. He gave us that part. The part we have to do is to open that file, convert the numbers into a list, then find the mean, standard deviation, etc without using the...

python: compare strings with newline

I'm trying to develop a script which compares a runtime generated string against one which is input by the user. Unfortunately, since user inputs his code using a textbox, I get ^M in the string input by user. Example, If I print these strings to file I get this: User Input: 1^M 2^M 3 Output of script: 1 2 3 Obviously, when I try to...

Markdown with custom syntax?

I'm using python and using markdown. Is there a simple way to add a custom syntax? I want something like [ABC] expands to a certain tag or something. or do I use regex? ...

Django admin site: implement a singleton for global variables?

Does anyone have experience (Django 1.x pref 1.3) with implementing a sort of singleton accessible from the admin page to expose some global variables for editing (site name, keywords, ...). I cant find anything like this and it sounds quite unbelievable! thanks (django-preferences is broken with 1.x) ...

Is there an easily hackable open-source Tivo media server?

Series 2 and later Tivos have a "Music on [computername]" option under "Music, Photos & Showcases" which lets you play music that's hosted on some other machine. This option seems to appear for each computer on the local network with a compatible server running. For example, a Windows PC running Tivo Desktop can show up if configured cor...

How can I generate an absolute url for a Pylons controller?

I need to generate a URL for use as a callback in an external system in my pylons application. This requires me to provide both the pylons-app-relative controller path (as generated by the url method: >>> relative_url = url(controller='my_cont', action='callback', id=generated_id) >>> print relative_url /my_cont/callback/1234 However,...

Calling a Selenium Testcase in python

I'm trying to run a selenium testcase in python. I have testcases that I can run directly from the command line no problem with python seleniumtest.py However when I try to run it from within python it is failing. __import__('seleniumtest') seleniumtest.py ends with a command unittest.main() this command seems to fail when it...

Can You Embed an TCL Script in Bash Script or Python Script That's Callable by External Programs?

I'm writing a script to extract some useful data about a series of chemical simulations I've been running. To get this data I need (1) a C-program that calculates the density from a file type called *.pdb. I already have (1). And (2) I need to use a program called vmd to get that pdb. In order to accomplish (2) from the command line,...

Examining then updating rows in sqlite with Python

I've decided that I'm not fond of the automatic filing and renaming provided by Mendeley, but have found that it keeps track of everything in an sqlite database that I can easily read and modify from Python. My question is, if I'm going to iterate over the rows of a table containing file paths and hashes that are serving as identifiers ...

How to keep a python window on top of all others (python 3.1)

I'm writing a little program that basically has a bunch of buttons that when you click one, it inputs a certain line of text into an online game I play. It would be a lot easier to use if the GUI would stay on top of the active game window so the user could be playing and then press a button on the panel without having to bring it to the...

Read static content from within the code of an application

Is there a way to read the contents of a static data directory or interact with that data in any way from within the code of an application? Edit: Please excuse me if it wasn't clear at first, I mean getting a list of the files in that directory, not reading the data in them. ...

How to list an image sequence in an efficient way? Numercial sequence comparison in Python

I have a directory of 9 images: image_0001, image_0002, image_0003 image_0010, image_0011 image_0011-1, image_0011-2, image_0011-3 image_9999 I would like to be able to list them in an efficient way, like this (4 entries for 9 images): (image_000[1-3], image_00[10-11], image_0011-[1-3], image_9999) Is there a way in python, to re...

Capturing Console output that is not written to stdout,stderr?

Hi, I have an windows application called pregeocode (we lack source), this program basically writes geocoding to an input file. This program doesn't actually write anything to console unless there is an error. This program is generally called from a small Python program (it handles the arguments etc, and does all the fun preprocessing)....

How to make Popen() understand UTF-8 properly?

This is my code in Python: [...] proc = Popen(path, stdin=stdin, stdout=PIPE, stderr=PIPE) result = [x for x in proc.stdout.readlines()] result = ''.join(result); Everything works fine, when it's ASCII. When I'm receiving UTF-8 text in stdout the result is unpredictable. In most cases the output is damaged. What is wrong here? Btw, m...

Automatically expiring variable

How to implement an automatically expiring variable in python? For example, Let the program running For one hour. I want implement an array of 6 variables, each variable in array will be automatically deleted themselves after 10 mins. And after 1 hour, there will be no variable in the array. ...

How can I use PIL to crop a select area based on face detection?

Hi I am wanting to use the python imaging library to crop images to a specific size for a website. I have a problem, these images are meant to show people's faces so I need to automatically crop based on them. I know face detection is a difficult concept so I'm thinking of using the face.com API http://developers.face.com/tools/#faces/d...

How do you get the exact path to "My Documents"?

In C++ it's not too hard to get the full pathname to the folder that the shell calls "My Documents" in Windows XP and Windows 7 and "Documents" in Vista; see http://stackoverflow.com/questions/2414828/get-path-to-my-documents Is there a simple way to do this in Python? ...

print a string in an external application (python 3.1)

Suppose I have a game and a python script running. In this game, to speak you just type whatever you want and hit enter. This python script has a button on it that I want to output a predefined string into the game, and hit enter automatically (essentially, the button causes the character to speak the string). What would be the easiest w...

Add unit to yaxis labels in MatPlotLib

I am trying to add mi or km (miles, kilometers) after the value on the yaxis of a matplotlib bar chart. Right now I am just supplying matplotlib the values and it is making the yaxis labels automatically. I can't figure out how to append mi to the end of a value. 24 > 24 mi There is an option for ax.set_7ticklabels(), but then I ...