python

how to get a descendant from parent entity

I can't seem to find a quick answer on how to get Datastore descendants given a reference to the parent entity. Here's a quick example: # a person who has pets john=Person(**kwargs) # pets fluffy=Pet(parent=john, ...) rover=Pet(parent=john, ...) # lengthy details about john that are accessed infrequently facts=Details(parent=john, .....

Encrypting file with python

Is there a way to use python to encrypt/decrypt a file? Something like Axcrypt Thanks in advance ...

Auto Increment While Building list in Python

Here is what I have so far. Is there anyway, I can auto increment the list while it is being built? So instead of having all ones, I'd have 1,2,3,4.... possible = [] possible = [1] * 100 print possible Thanks, Noah ...

Invalid syntax error in simple Python-3 program

from TurtleWorld import * import math bob = Turtle() print(bob) draw_circle(turtle, r): d = r*2 c = d*math.pi degrees = 360/25 length = c // 25 for i in range(25): fd(turtle, length) rt(turtle, degrees) draw_circle(bob, 25) wait_for_user() The problem in on line 7: draw_circle(turtle, r): ...

Be my human compiler: What is wrong with this Python 2.5 code?

My framework is raising a syntax error when I try to execute this code: from django.template import Template, TemplateSyntaxError try: Template(value) except TemplateSyntaxError as error: raise forms.ValidationError(error) return value And here's the error: from template_field import TemplateTextFi...

Python project deployment design

Here is the situation: the company that I'm working in right now gave me the freedom to work with either java or python to develop my applications. The company has mainly experience in java. I have decided to go with python, so they where very happy to ask me to give maintenance to all the python projects/scripts related to the database...

Python Class in module not loading in one computer, but the other.

So I have two files: File 1 has this method in it: import MyGlobals global old_function def init(): import ModuleB global old_function MyGlobals.SomeNumber = 0 old_function = ModuleB.someClass.function ModuleB.someClass.function = someNewFunction File 2 has a class "someClass" and a class "someOtherClass". That be...

update python modules

How can I update all python modules I have installed on ubuntu? ...

raw_input and timeout

I have thise huge code that I'm going to implement . Before I start that, I want to do a raw_input('Enter something: .'). I want it to sleep for 3 secs and if there's no input, then cancel the raw-input prompt and run the rest of the code. Then the code loops and implements the raw_input again. I want it so that if somedoes put a raw_i...

memory size of Python data structure

How do I find out the memory size of a Python data structure? I'm looking for something like: sizeof({1:'hello', 2:'world'}) It is great if it counts every thing recursively. But even a basic non-recursive result helps. Basically I want to get a sense of various implementation options like tuple v.s. list v.s. class in terms of memory...

Design Golf: modeling an Address in appengine, aka an AddressProperty?

Today I was refactoring some code and revisited an old friend, an Address class (see below). It occurred to me that, in our application, we don't do anything special with addresses-- no queries, only lightweight validation and frequent serialization to JSON. The only "useful" properties from the developer point-of-view are the label an...

Sorting scheduled events python

So I have list of events that are sort of like alarms. They're defined by their start and end time (in hours and minutes), a range of days (ie 1-3 which is sunday through wed.), and a range of months (ie 1-3, january through march). The format of that data is largely unchangeable. I need to, not necessarily sort the list, but I need to f...

How do I merge two lists into a single list?

I have a = [1, 2] b = ['a', 'b'] I want c = [1, 'a', 2, 'b'] ...

Create x lists in python dynamically

(First, I chose to do this in Python because I never programmed in it and it would be good practice.) Someone asked me to implement a little "combination" program that basically outputs all possible combinations of a set of group of numbers. Example, if you have: (1,2,3) as the first set, (4,5,6) as the second, and (7,8,9) as the th...

How to combine Cmd and Matplotlib in python

Hi there, I'd like to combine interactive plotting in Matplotlib and the Command line interface Cmd in python. How can I do this? Can I use threading? I tried the following: from cmd import Cmd import matplotlib.pylab as plt from threading import Thread class MyCmd(Cmd): def __init__(self): Cmd.__init__(self) self...

Number Guesser: Please Review and Make it More Pythonic

I'm working on learning python, here is a simple program, I wrote: def guesser(var, num1,possible): if var == 'n': cutoff = len(possible)/2 possible = possible[0:cutoff] cutoff = possible[len(possible)/2] #print possible if (len(possible) == 1): print "Your Number is:", possible ...

What are the differences between the two Python 2.7 Mac OS X disk image installers?

Python 2.7 has two different disk image installers for Mac OS X. My questions are: What are the differences between the two Python 2.7 disk image installers? Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6 Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5 or later If running Mac...

Django: Proxy Meta-class ignoring verbose_name_plural

Django-admin is pluralizing a model that I have running as a proxy class. The normal case here works fine: class Triviatheme(models.Model): [ ... elided ... ] class Meta: db_table = u'TriviaTheme' verbose_name_plural='trivia themes' But for a main content table, I have a parent model called 'Content', and a p...

How can I make setuptools install a package that's not on PyPI?

I've just started working with setuptools and virtualenv. My package requires the latest python-gearman that is only available from GitHub. The python-gearman version that's on PyPI is an old one. The Github source is setuptools-compatible, i.e. has setup.py, etc. Is there a way to make setuptools download and install the new version ins...

About pyjamas maturity vs GWT maturity (with short dead lines) for a web application

I love both, python and Java and I have this first 'serious' web application project that I would like to carry out. I find it hard to choose between pyjamas + django and GWT + Hibernate. In fact, from my beginner point of view, it seems like the python world is more suitable for a quickly-developed and fun web application. And, on t...