I have a very simple Python file:
f = open('C:\\Temp\\test.txt', 'w')
f.write('Succeeded')
f.close()
which I wish to execute from a JavaScript file, like so:
jQuery.ajax({
type: "POST",
url: "/cgi-bin/python1.py",
success: function (msg) {
alert("Data Saved: " + msg);
}
});
However, all that happens is that I get...
I'm building an app on GAE that needs to report on events occurring. An event has a type and I also need to report by event type.
For example, say there is an event A, B and C. They occur periodically at random. User logs in and creates a set of entities to which those events can be attributed. When the user comes back to check the stat...
I am trying to replace newline characters in a unicode string and seem to be missing some magic codes.
My particular example is that I am working on AppEngine and trying to put titles from HTML pages into a db.StringProperty() in my model.
So I do something like:
link.title = unicode(page_title,"utf-8").replace('\n','').replace('\r','...
I'm trying to deploy OpenERP with a buildout and my own piece of code. In fact I would like to build a complete deployement structure allowing me to use OpenERP with custom modules and patch.
First of all, before adding any personnal configuration, I was trying to create a buildout which will have the responsability to configure everyth...
I frequently find myself using the following pattern for string formatting.
a = 3
b = 'foo'
c = dict(mykey='myval')
#prints a is 3, b is foo, mykey is myval
print('a is {a}, b is {b}, mykey is {c[mykey]}'.format(**vars()))
That is, I often have the values I need to print in the local namespace, represented by a call to vars(). As I l...
Here is my scenario: I am trying to automate some tasks using Paramiko. The tasks need to be started in this order (using the notation (host, task)): (A, 1), (B, 2), (C, 2), (A,3), (B,3) -- essentially starting servers and clients for some testing in the correct order. Further, because in the tests networking may get mucked up, and becau...
This question is related to others I have asked on here, mainly regarding sorting huge sets of data in memory.
Basically this is what I want / have:
Twisted XMLRPC server running. This server keeps several (32) instances of Foo class in memory. Each Foo class contains a list bar (which will contain several million records). There is...
Basically I have a Base class called "Program". I then have more specific program model types that use Program as a base class. For 99% of my needs, I don't care whether or not a Program is one of the specific child types. Of course there's that 1% of the time that I do want to know if it's one of the children.
The problem is that if I ...
I basically want the same functionality of preg_match_all()from PHP in a Python way.
If I have a regex pattern and a string, is there a way to search the string and get back a dictionary of each occurrence of a vowel, along with its position in the string?
Example:
s = "supercalifragilisticexpialidocious"
Would return:
{
'u' : 1,...
How can I yield multiple items at a time from an iterable object?
For example, with a sequence of arbitrary length, how can I iterate through the items in the sequence, in groups of X consecutive items per iteration?
(Question inspired by an answer which used this technique.)
...
Here is my current code:
def init_model(engine):
global t_user
t_user = sa.Table("User", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("name", sa.types.String(100), nullable=False),
sa.Column("first_name", sa.types.String(100), nullable=False),
sa.Column("last_name", sa.types.Stri...
Hi guys. In my project I have to use mobile camera from my own program.
I use python with S60 platform under NOKIA 6220 Classic. It has 5mp-camera.
The problem is that photos quality are very-very low. Seems that auto-focusing doesn't work.
I'd like to know maybe anyone from you made something before. I can buy new telephone if I'll nee...
How do you create custom field lookups in Django?
When filtering querysets, django provides a set of lookups that you can use: __contains, __iexact, __in, and so forth. I want to be able to provide a new lookup for my manager, so for instance, someone could say:
twentysomethings = Person.objects.filter(age__within5=25)
and get back...
Hi, I would like to be able to convert SVG documents to black and white. My try is the following Makefile script using 'sed' :
%.bw.svg: %.svg
sed '/stroke:none/!s/stroke:[^;\"]*/stroke:black/g' $< > $@
This works for lines etc but not for fillings. Basically if the stroke is not invisible (none), then I convert it to black. I wou...
I have a small web app running on AppEngine and have all my URL processing in one file and the other processing done in another file that is imported at the top of the main python.
e.g.
import wsgiref.handlers
from wsgiref.handlers import format_date_time
import logging
import os
import cgi
import datetime
from time import mktime
#Go...
Is it possible to retrieve any class information from a frame object? I know how to get the file (frame.f_code.co_filename), function (frame.f_code.co_name) and line number (frame.f_lineno), but would like to be able to also get the name of the class of the active object instance of the frame (or None if not in an instance).
...
This is for use in a JSON API.
I don't want to have:
if method_str == 'method_1':
method_1()
if method_str == 'method_2':
method_2()
For obvious reasons this is not optimal. How would I use map strings to methods like this in a reusable way (also note that I need to pass in arguments to the called functions).
Here is an exam...
I have an application that starts by loading a large pickled trie (173M) from disk and then uses it to do some processing. I'm making frequent changes to the processing part, which is inconvenient because loading the trie takes 15 minutes or so. I'm looking for a way to eliminate the repeated loading during testing, since the trie neve...
I'm not sure what I'm doing wrong here to warrant this message. Any help with my configuration would be appreciated.
"""The application's model objects"""
import sqlalchemy as sa
from sqlalchemy import orm
from project.model import meta
def now():
return datetime.datetime.now()
def init_model(engine):
"""Call me before using...
I'm just getting started with Python, and I'm stuck on the syntax that I need to convert a set of request.POST parameters to Solr's query syntax.
The use case is a form defined like this:
class SearchForm(forms.Form):
text = forms.CharField()
metadata = forms.CharField()
figures = forms.CharField()
Upon submission, the f...