python

How to install html5lib-0.90 library for Python on Windows?

I'm using Windows, and trying to install html5lib-0.90 library on python C:\>python C:\Users\Junior\Downloads\Python\html5lib-0.90\setup.py install Traceback (most recent call last): File "C:\Users\Junior\Downloads\Python\html5lib-0.90\setup.py", line 36, in <module> for name in os.listdir(os.path.join('src','html5lib')) WindowsError: ...

Pylons: response renaming? Is there a better way?

Hi, I've got a Pylons controller with an action called serialize returning content_type=text/csv. I'd like the response of the action to be named based on the input patameter, i.e. for the following route, produced csv file should be named {id}.csv : /app/PROD/serialize => PROD.csv (so a user can open the file in Excel with a proper nam...

Python basics: How to read N ints until '\n' is found in stdin

Hey this is a really quick question. I guess I'll give correct answer in less than 2 minutes after posting this question. I've started learning python, like 5 minutes ago, so mind the stupidity of the question. To test it I'm re-writing some algorithms i had. Could someone tell me how can I read N ints from the input, and stop readin...

Adding text to p tag in Beautiful Soup

I was wondering if anyone knew how to add text to a tag (p, b -- any tag where you might want to include character data). The documentation mentions no where how you might do this. ...

Converting \n to <br> in mako files

I'm using python with pylons I want to display the saved data from a textarea in a mako file with new lines formatted correctly for display Is this the best way of doing it? > ${c.info['about_me'].replace("\n", "<br />") | n} ...

Python MySQL query not completing

Hello. I am having problems with a Python script which is basically just analysing a CSV file line-by-line and then inserting each line into a MySQL table using a FOR loop: f = csv.reader(open(filePath, "r")) i = 1 for line in f: if (i > skipLines): vals = nullify(line) try: cursor.execute(query, vals) ...

Hudson "Source code is unavailable."

I'm using Hudson to continuously build a Python project. Unit tests and code coverage work great, but this message appears when drilling into the Cobertura Coverage Report for my files that are not unit tests: Source code is unavailable.Some possible reasons are: * This is not the most recent build (to save on disk space, this plugin ...

splitting one program into several smaller and their binding in python?

i want to make from one big program 5 smaller programs:main and program1,program2,program3 and program4.programs1,2,3,4 should use variables from main program and return some new variables,and main program should use(or call) programs1,2,3,4... can i bind these programs using functions,modules or something else and how? i'm new in Pytho...

Python dictionary that maps strings to a set of strings?

I would like to be able to make a Python dictionary with strings as keys and sets of strings as the values. E.g.: { "crackers" : ["crunchy", "salty"] } It must be a set, not a list. However, when I try the following: word_dict = dict() word_dict["foo"] = set() word_dict["foo"] = word_dict["foo"].add("baz") ...

detection of communication failure when "put" in queue

I am using the multiprocessing python module with Queue for communication between processes. Some processes only send (i.e. queue.put) and I can't seem to find a way to detect when the receiving end gets terminated abruptly. Is there a way to detect if the process at the other end of the Queue gets terminated without having to get from...

how does stackoverflow get the user-info when people login site use openid .

i want to get the userid and somethins other about user. but i don't get this i used pinax what should i do ?? thanks ex:facebook Javascript (from therunaround demo): FB.Facebook.get_sessionState().waitUntilReady(function() { var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session...

Endless Recursion in Python

Full disclosure, this is part of a homework assignment (though a small snippet, the project itself is a game playing AI). I have this function built into a tree node class: def recursive_score_calc(self): current_score = self.board for c in self.children: child_score = c.recursive_score_calc() ...

The origin of using # as a comment in Python?

So I just had like this mental explosion dude! I was looking at my Python source code and was reading some comments and then I looked a the comments again. When I came across this: #!/usr/bin/env python # A regular comment Which made me wonder, was # chosen as the symbol to start a comment because it would allow the python program to ...

Python URL Characters

I really new to Python and coding in general, but I have been making some good strides. I am able to pull some data off of the web through an API, and the result should be a string. What I am seeing though, are some instances such as "& amp;"" and " &quot". (I modified the character sets so it would print properly to the screen) I fig...

Putting a message in the same line

import pythoncom, pyHook, logging, string LOG_FILENAME = 'logfile.txt' def OnKeyboardEvent(event): print 'MessageName:',event.MessageName print 'Time:',event.Time print 'WindowName:',event.WindowName print 'Ascii:', event.Ascii, chr(event.Ascii) print 'Key:', event.Key print '---' k = event.Key logging.b...

what this python code trying to do

Hi, The following python code is to traverse a 2D grid of (c, g) in some special order, which is stored in "jobs" and "job_queue". But I am not sure which kind of order it is after trying to understand the code. Is someone able to tell about the order and give some explanation for the purpose of each function? Thanks and regards! impo...

Sending "Set-Cookie" in a Python HTTP server

How do I send the "Set-Cookie" header when working with a BaseHTTPServerRequestHandler, and Cookie? BaseCookie and children don't provide a method to output the value to be passed into send_header(), and *Cookie.output() does not provide a HTTP line delimiter. Which Cookie class should I be using? Two have survived into Python3, what ar...

How do I start GWT devmode on a particular port from the console?

So, within the directory containing my GWT application, I can type in the console ant devmode And it will start up my GWT application as per usual. So far so good. However, what if wish to specify the port as a dynamic argument when starting devmode. Something conceptually like: ant devmode port=8821 Or am I supposed to pas...

Positional Comparisons in Python

(Here's a sort of hypothetical situation for everybody. I'm more looking for directions rather than straight processes, but if you can provide them, awesome!) So let's say we have a list of athletes, I'm going to use figure skaters since I'm knee deep in the Winter Olympics right now. (I'm throwing it in a dictionary since that's my fir...

how do I filter values from XML file in python

I have a basic grasp of XML and python and have been using minidom with some success. I have run into a situation where I am unable to get the values I want from an XML file. Here is the basic structure of the pre-existing file. <localization> <b n="Stats"> <l k="SomeStat1"> <v>10</v> </l> <l k="S...