python

Getting TTFB Time for an HTTP Request

Here is a python script that loads a url and captures response time: import urllib2 import time opener = urllib2.build_opener() request = urllib2.Request('http://example.com') start = time.time() resp = opener.open(request) resp.read() ttlb = time.time() - start Since my timer is wrapped around the whole request/response (including ...

Calling unknown Python functions

This was the best name I could come up with for the topic and none of my searches yielded information relevant to the question. How do I call a function from a string, i.e. functions_to_call = ["func_1", "func_2", "func_3"] for f in functions_to_call: call f ...

Google App Engine--Dynamically created templates

Hi. I'm trying to build an a simple CRUD admin section of my application. Basically, for a given Model, I want to have a template loop through the model's attributes into a simple table (once I do this, I can actually implement the CRUD part). A possible way to accomplish this is to dynamically generate a template with all the necessary ...

Do Python regular expressions allow embedded options?

In particular, I'd like to know if I can specify an embedded option in the pattern string that will enable multiline mode. That is, typically with Python regular expressions multiline mode is enabled like this: pattern = re.compile(r'foo', re.MULTILINE) I'd like a way to get multiline matching by specifying it in the pattern string, ...

adding comments to pot files automatically

I want to pull certain comments from my py files that give context to translations, rather than manually editing the .pot file basically i want to go from this python file: # For Translators: some useful info about the sentence below _("Some string blah blah") to this pot file: # For Translators: some useful info about the sentence b...

Python/Django Modeling Question

What is the best way to have many children records pointing to one parent record in the same model/table in Django? Is this implementation correct?: class TABLE(models.Model): id = models.AutoField(primary_key=True) parent = models.ForeignKey("TABLE", unique=False) ...

Freelance work and skill specialization.

I've been messing around with different languages and frameworks to find the right fit and I think at some point it would be nice to make money doing web development. Likely I would need to start out with freelance projects to find work at first, which I think would be ideal anyway. My problem is that there really doesn't seem to be mu...

create function though mysqldb

How can I define a multi-statement function or procedure in using the MySQLdb lib in python? Example: import MySQLdb db = MySQLdb.connect(db='service') c = db.cursor() c.execute("""DELIMITER // CREATE FUNCTION trivial_func (radius float) RETURNS FLOAT BEGIN IF radius > 1 THEN RETURN 0.0; ELSE RETURN...

semantic markup for Python's difflib.HtmlDiff

It appears Python's difflib.HtmlDiff, rather than using INS and DEL, uses SPAN elements with custom classes: python -c 'import difflib; txt1 = "lorem ipsum\ndolor sit amet".splitlines(); txt2 = "lorem foo isum\ndolor amet".splitlines(); d = difflib.HtmlDiff(); print d.make_table(txt1, txt2)' Before I go about fixing this myself, has a...

Is Python interpreted (like Javascript or PHP)?

I know next to nothing about Python but have decided to jump in. I'm curious though, is Python strictly interpreted at run time, or can it be used to develop programs that run as background applications (like a Java app or C program)? ...

How to find list of possible words from a letter matrix [Boggle Solver]

Lately I have been playing a game on my iPhone called Scramble. Some of you may know this game as Boggle. Essentially, when the game starts you get a matrix of letters like so: F X I E A M L O E W B X A S T U The goal of the game is to find as many words as you can that can be formed by chaining letters together. You can start with an...

How to write ampersand in node attribude?

I need to have following attribute value in my XML node: CommandLine="copy $(TargetPath) ..\..\
echo dummy > dummy.txt" Actually this is part of a .vcproj file generated in VS2008. 
&#x0A means line break, as there should be 2 separate commands. I'm using Python 2.5 with minidom to parse XML - but unfortunately I don'...

Basic python. Quick question regarding calling a function

Hi All, I've got a basic problem in python, and I would be glad for some help :-) I have two functions. One that convert a text file to a dictionary. And one that splits a sentence into separate words: (This is the functiondoc.txt) def autoparts(): list_of_parts= open('list_of_parts.txt', 'r') for line in list_of_parts: ...

Adding a user supplied property (at runtime) to an instance of Expando class in google app engine?

By creating datastore models that inherit from the Expando class I can make my model-entities/instances have dynamic properties. That is great! But what I want is the names of these dynamic properties to be determined at runtime. Is that possible? For example, class ExpandoTest (db.Expando): prop1 = db.StringProperty() prop2 = db.Str...

wxPython: Calling an event manually

How can I call a specific event manually from my own code? ...

Python borg pattern problem

I'm having problems implementing a borg in python. I found an example in an answer to this question but it's not working for me, unless I'm missing something. Here's the code: class Config: """ Borg singleton config object """ __we_are_one = {} __myvalue = "" def __init__(self): #implement the borg pattern...

How to get output of exe in python script?

When I call a external .exe program in python, how can I get the output of printf in .exe application and print them on python IDE? ...

benchmarking django apps

I'm interested in testing the performance of my django apps as I go, what is the best way to get line by line performance data? note: Googling this returns lots of people benchmarking django itself. I'm not looking for a benchmarks of django, I'm trying to test the performance of the django apps that I'm writing :) Thanks! edit: By "l...

Python: Convert those TinyURL (bit.ly, tinyurl, ow.ly) to full URLS

I am just learning python and is interested in how this can be accomplished. During the search for the answer, I came across this service: http://www.longurlplease.com For example: http://bit.ly/rgCbf can be converted to: http://webdesignledger.com/freebies/the-best-social-media-icons-all-in-one-place I did some inspecting with Fir...

Writing text with carriage return to image in Python using PIL

Hello, I have a python script that is writing text to images using the PIL. Everything this is working fine except for when I encounter strings with carriage returns in them. I need to preserve the carriage returns in the text. Instead of writing the carriage return to the image, I get a little box character where the return should be. ...