python

bulk insert in db table

Hello, I'm having an array I want to insert in a single query in a table. Any idea? ...

Replace AppEngine Devserver With Spawning (BaseHTTPRequestHandler as WSGI)

I'm looking to replace AppEngine's devserver with spawning. Spawning handles standard wsgi handlers, just like appengine, so running your app on it is easy. But the devserver takes into account your app.yaml file that has url redirects etc. I've been going through the devserver code and it is pretty easy to get the BaseHTTPRequestHandle...

How to convince my boss to use Django?

I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. I know all the technical pros and cons but when it comes...

How to find the sum of a ASCII value in a file to find the max number of ASCII and to print out the name of the highest sum of ASCII value

Here is the code I'm working with def ascii_sum(): x = 0 infile = open("30075165.txt","r") for line in infile: return sum([ord(x) for x in line]) infile.close() This code only prints out the first ASCII value in the file not the max ASCII value ...

proxies in python ftp application

I'm developing ftp client in python ftplib. How do i add proxies support to it (most ftp apps i seen seem to have it)? I'm especially thinking about socks proxies, but also other types... ftp, http (is it even possible to use http proxies with ftp program?) Any ideas how to do it? ...

Human readable cookie information using cookielib?

Is there a way to print the cookies stored in a cookielib.CookieJar in a human-readable way? I'm scraping a site and I'd like to know if the same cookies are set when I use my script as when I use the browser. ...

Sandboxing / copying a module in two separate places to prevent overwriting or monkey patching

Using these four files, all in the same directory: splitter.py #imagine this is a third-party library SPLIT_CHAR = ',' class Splitter(object): def __init__(self, s, split_char=None): self.orig = s if not split_char: self.splitted = s.split(SPLIT_CHAR) a.py #this person makes the mistake of re-setting...

Best way to obtain indexed access to a Python queue, thread-safe

I have a queue (from the Queue module), and I want to get indexed access into it. (i.e., being able to ask for item number four in the queue, without removing it from the queue.) I saw that a queue uses a deque internally, and deque has indexed access. The question is, how can I use the deque without (1) messing up the queue, (2) breaki...

How do I install PyGTK / PyGobject on Windows with Python 2.6?

Hi, I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute import gobject I get this: Traceback (most recent call last): import gobject File "C:\Python26\lib\site-packages\gtk-2.0\gobject\__init__.py", line 30, in <module> from ...

What is a global interpreter lock (GIL)?

What is a global interpreter lock and why is that an issue? A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I never wrote a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand. ...

How to insert / retrieve a file stored as a BLOB in a MySQL db using python

I want to write a python script that populates a database with some information. One of the columns in my table is a BLOB that I would like to save a file to for each entry. How can I read the file (binary) and insert it into the DB using python? Likewise, how can I retrieve it and write that file back to some arbitrary location on th...

how to register more than 10 apps in Google App Engine

Anyone knows any "legal" way to surpass the 10-app-limit Google imposes? I wouldn't mind to pay, or anything, but I wasn't able to find a way to have more than 10 apps and can't either remove one. ...

Getting DOM tree of XML document

Does anyone know how I would get a DOM instance (tree) of an XML file in Python. I am trying to compare two XML documents to eachother that may have elements and attributes in different order. How would I do this? ...

Python WWW macro

Hi, i need something like iMacros for Python. It would be great to have something like that: browse_to('www.google.com') type_in_input('search', 'query') click_button('search') list = get_all('<p>') Do you know something like that? Thanks in advance, Etam. ...

GIS: line_locate_point() in Python

I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me. Here's what I would like to do...

How to replace Python function while supporting all passed in parameters

I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict. More precisely, something like this (where f is any function, and replacement_f takes a list and a dict): def replace_func(f, replacement_f): def new_f(*args,...

HTML snippet from Python

I'm new to Python and CGI, so this may be trivial. But I'd like Python to produce a block of HTML whenever a visitor loads a page. <html> <body> <!-- Beautiful website with great content --> <!-- Suddenly... --> <h1> Here's Some Python Output </h1> <!-- RUN PYTHON SCRIPT, display output --> </body> </html> Using a Python script that...

Running a plain python interpreter in presense of ipython with manage.py shell

I have ipython installed, I want to run a plain python interpreter instead with manage.py shell. So I try, python2.5 manage.py shell --plain Which gave me an error, and text which suggest that --plain was passed to ipython So I read, http://docs.djangoproject.com/en/dev/ref/django-admin/ which suggets django-admin.py shell --plai...

How to save the username who has changed one Django model using a custom track field of AuditTrail

From AuditTrail, I have this model definition: from django.db import models import audit import random def some_callback(instance): return `random.randrange(1, 99)` + 'trackable_val' class Person(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) salary = models....

Evaluate a script (e.g. Python) in Java for Android platform

Is it possible to evaluate a string of python code (or Perl) from Java when developing Android applications? I am try to do something like evaluating a text-input script: e.g. String script = text1.getText().toString(); String result = PythonRuntime.evaluate(script); text2.setText(result); ...