python

Use URL Fetch of Google App Engine just to call a php script.

Hello, I wanto call a PHP script using Google App Engine. I just want to execute the script. The script updates a couple of databases on my webhost. But I guess Google App waits for the response. Is there a way by which I can start the script. The script takes some time and Google App might die during that time. ...

Enforce "spaces" or "tabs" only in python files ?

In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? Well, perhaps "enforce" is too strong, more like a "recommendation". I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is a problem, but I am searching somet...

Unit testing in python?

Hey - I'm new to python , and I'm having a hard time grasping the concept of Unit testing in python. I'm coming from Java - so unit testing makes sense because - well , there you actually have a unit - A Class. But a Python class is not necessarily the same as a Java class , and the way I use Python - as a scripting language - is more f...

Python/Django application with dynamic model name (application reuse)

Hi, excuse me in advance if this is not the right title for the problem but here it is: You have application that works with pre defined model. What happens if you want to use this application one more time in your project but pointing to different model (same structure but differen name). For example - you have a "News" application ...

mysqldb python escaping ? or %s?

Dear Everyone, I am currently using mysqldb. What is the correct way to escape strings in mysqldb arguments? Note that E = lambda x: x.encode('utf-8') 1) so my connection is set with charset='utf8'. These are the errors I am getting for these arguments: w1, w2 = u'你好', u'我好' self.cur.execute("SELECT dist FROM distance WHERE w1=? AND ...

How to read and write a file using python?

I want to write the text (which I get from AJAX) to a file, and then read it. ...

Use string as input to re.compile

I want to use a variable in a regex, like this: variables = ['variableA','variableB'] for i in range(len(variables)): regex = r"'('+variables[i]+')[:|=|\(](-?\d+(?:\.\d+)?)(?:\))?'" pattern_variable = re.compile(regex) match = re.search(pattern_variable, line) The problem is that python adds an extra backslash character f...

how to rename a file using python..

i want change 'a.txt' to 'b.kml' thanks ...

GAE, Python 2.5, Python 2.6 Side-by-side on windows

Hi On my development system, I have python 2.6, python 1.1 and GAE. I have three projects running on python 2.6 and django 1.1. And 1 project using GAE, Python 2.6 and django 1.1. I have heard that, my set-up for running GAE using python 2.6 may create some head scratching problems while deploying it on the production server, beca...

why my code print this when i read and write..

def sss(request): handle=open('b.txt','r+') handle.write("I AM NEW FILE") var=handle.read(); return HttpResponse(var) urlpatterns = patterns('', ('^$',sss), ) 1.my b.txt has nothing 2.when i run my code ,it print this : I AM NEW FILE7 ...

Find multiple regex in each line and skip result if one of the regex doesn't match

I have a list of variables: variables = ['VariableA', 'VariableB','VariableC'] which I'm going to search for, line by line ifile = open("temp.txt",'r') d = {} match = zeros(len(variables)) for line in ifile: emptyCells=0 for i in range(len(variables)): regex = r'('+variables[i]+r')[:|=|\(](-?\d+(?:\.\d+)?)(?:\))?' ...

python __init__ how to return a value

I have a class with an __init__ function. How can I return an integer value from this function when an object is created? I wrote a program,where init does command line parsing and I need to have some value set. IS it OK set it in global variable and use it in other member functions ? If so how to do that? So far , i declared a variabl...

How to get the nth element of a python list or a default if not available

Hi guys I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available? For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list Thanks! ...

meaning of the returned list of python json

Hey, I'm new to python so I really don't know the language very well. the following example was taken from here http://docs.python.org/library/json.html >>> import json >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') [u'foo', {u'bar': [u'baz', None, 1.0, 2]}] what does the u mean? and how do i know which elements are availa...

Access Delicious API via Yahoo ID without redirect to Yahoo authorizing page

To be more specific: My delicious account is a Yahoo ID so access via OAuth is required. It's for my use only to add/remove bookmarks. I have the password. It's a command line python program, not web-based. My question is: Is it possible to access my delicious account without being redirected to a Yahoo OAuth authorization page? Any...

Python: Split by 1 or more occurrences of a delimiter

Hi, I have a formatted string from a log file, which looks like: >>> a="test result" That is, the test and the result are split by some spaces - it was probably created using formatted string which gave test some constant spacing. Simple splitting won't do the trick: >>> a.split(" ") ['test', '', '', '', ...

Python XML + Java XML interoperability.

Hello. I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works would be great. ...

OpenType with Python

is there a python library for supporting OpenType features? where can i get it? please do not guide to fontforge, i live in Iran , so i can not download anything from them. ...

Renaming a pylons controller

Is there an automatic way I can use to rename a pylons controller? If I have to rename the controller manually which all files and filenames do I have to change. Thank you much! ...

django / python get image from url and display on site

Hi, Given a url to an image is there a way in Django/Python to pull this image in and then display it on my site (resized if possible) Thanks ...