python

Python : Text to ASCII & ASCII to text converter program

Hi, i am a newbie to python 2.7 , trying to create a simple program, which takes an input string from the user, converts all the characters into their ascii values, adds 2 to all the ascii values and then converts the new values into text. So for example, if the user input is "test" , the output should be "vguv". This is the code i have...

Web2py ticket invalid links

Hi, I started playing around with web2py the other day for a new project. I really like the structure and the whole concept which feels like a breath of fresh air after spending a few years with PHP frameworks. The only thing (currently) that is bothering me is the ticketing system. Each time I make a misstake a page with a link to a t...

(How) can you add methods to a collection of entities in Google App Engine python?

In GAE-python, you can model a one-to-many relationship by assigning a reference property to the child model. class Book(db.Model): title = db.StringProperty() class Author(db.Model): book = db.ReferenceProperty(Book, collection_name = 'authors') is_primary = db.BooleanProperty() name = db.StringProperty() This way, I can ...

in python how do I convert a single digit number into a double digits string?

So say i have a = 5 i want to print it as a string '05' ...

PyQt4 Threading: Sending data back to a thread

I'm writing a program, with a PyQt frontend. To ensure that the UI doesn't freeze up, I use QThreads to emit signals back to the parent. Now, I have reached a point where I need my thread to stop running, emit a signal back to the parent, then wait on the parent to return an approval for the thread to continue (after the user interacts...

Quickhelp for Python in Emacs autocomplete.el?

Hi, I am using Emacs 23.1.1 on GNU/Linux with autocomplete.el 1.3 and Ropemacs 0.6. In Lisp programming, autocomplete.el shows the documentation (known as 'QuickHelp' in autocomplete.el) of the suggested completions. Python completion with ropemacs works, but does not show quick help for the Python completion. Is it possible to enable ...

Django: Managing Session Variables to manage the browser back button

I am creating a web based Mock test paper, which needs to be fairly secure. The needs are Each question can be attempted and answered just once. All are multiple Choice questions Once a question is answered and the submit pressed, then that session must expire, and the same question must not appear either through back button or some o...

Static class members python

So I'm using static class members so I can share data between class methods and static methods of the same class (there will only be 1 instantiation of the class). I understand this fine, but I'm just wondering when the static members get initialized? Is it on import? On the first use of the class? Because I'm going to be calling the sta...

Special type of combination using itertools

I am almost finished with a task someone gave me that at first involved easy use of the product() function from itertools. However, the person asked that it should also do something a bit different like: li = [[1, 2, 3], [4, 5, 6]] A regular product() would give something like: [1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4] ...

Java Replacement

I may be posting a premature question, and maybe I'm just freaking out for no reason, but the way Oracle is handling Java is not very promising. I am a nerd who fell in love with Java from the first sight... and use it all the time in my personal/freelance projects but now I am thinking of a replacement. I am fluent in C#/VB.NET too but ...

Problems installing libxml2 on Mac OS X

I'm trying to install libxml2 on my Mac (OS 10.6.4). I'm actually trying to just run a Scrapy script in Python, which has required me to install Twisted, Zope, and now libxml2. I've downloaded the latest version (2.7.7, from xmlsoft.org) and tried following these instructions here. To summarize, I tried this command (in the python sub...

Refactoring Index/Search View

I've written an index and search view all in one if a GET request is detected it returns just the search results otherwise it returns all records. I've written this view below but I feel like I'm repeating myself a bit too much. Any ideas as to how I can slim this code down a bit would be much appreciated. def index(request): if 'q'...

Controlling the instantiation of python object

My question does not really have much to do with sqlalchemy but rather with pure python. I'd like to control the instantiation of sqlalchemy Model instances. This is a snippet from my code: class Tag(db.Model): __tablename__ = 'tags' query_class = TagQuery id = db.Column(db.Integer, primary_key=True) name = db.Column(d...

How is memcache.incr() affected by App Engine maintenance periods?

I'm working on an application that will run on Google App Engine. I would like it to respond gracefully to App Engine maintenance periods. According to the documentation, memcache will simply not store or retrieve data during maintenance periods: During a read-only maintenance period, calls to the memcache API will not throw exc...

Log every window activated in MS Windows using Python based on AHK example

I'm trying to rewrite the following autohotkey script in Python: Gui +LastFound DllCall( "RegisterShellHookWindow", UInt,WinExist() ) MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" ) OnMessage( MsgNum, "ShellMessage" ) LastActiveWindowID := WinActive("A") Return ; // End...

In Django, how do I select 100 random records from the database?

myqueryset = Content.objects.filter(random 100) ...

Bottle and Json

How do I go about returning json data from a bottle request handler. I see a dict2json method in the bottle src but I am not sure how to use it. What is in the documentation: @route('/spam') def spam(): return {'status':'online', 'servertime':time.time()} Gives me this when I bring up the page: <html> <head></head> <bod...

help deploying appengine app to custom domain

I'm having problems deploying a test app to my google apps domain. I know I'm missing something -- any kind souls out there see it? sign into appengine.google.com/a/mydomain.com create application, my-app-id verify that app.yaml has the same app id, my-app-id visit dashboard and add my domain from shell on local pc, set AUTH_DOMAIN=...

Django admin and MongoDB, possible at all?

I'm building a simple short URL service, ala bitly, for our company use. And I would like to use mongodb to store the data, but I will need some kind of simple interface to add/edit short url to long url mappings. The mongo documents will be very simple, something like this: { shortUrlSlug: 'pbbs', fullUrl: 'http://example.com/pean...

Python and C++ integration. Python prints string as multiple lines.

I'm trying to write a program in python to run a program in C++. It wasn't working right, so I made the most basic version of each I could. The C++ program merely takes in a string from stdin, and then prints it out. The Python code is written as follows: import popen2, string, StringIO fin, fout = popen2.popen2("PyTest") msg = ur"Hel...