Let's say I have this :
class whatever(object):
def __init__(self):
pass
and this function:
def create_object(type_name):
# create an object of type_name
I'd like to be able to call the create_object like this:
inst = create_object(whatever)
and get back an instance of whatever. I think this should be doable without ...
Why is there no built-in tree view in the Python Django framework?
Isn't there an easy way to visualize a model when a class has an 1:n relation to itself?
I know about some fancy google code projects to achieve that but I think there must be some common sense among the Django community to handle this common case. Any ideas?
...
I'm testing my application (on Google App Engine live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes).
I keep getting db.Timeout very often though.
How do I deal with this? I was going to surround all my queries with really brutal code like this:
querySucceeded = Fa...
What are people's experiences with any of the Git modules for Python? (I know of GitPython, PyGit, and Dulwich - feel free to mention others if you know of them.) I am writing a program which will have to interact (add, delete, commit) with a Git repository, but have no experience with Git, so one of the things I'm looking for is ease ...
I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice.
Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one.
Or suggest another data structure.
EDIT: There are no multiple conversations. Lets...
I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.
import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random() * len(file))],
...
I'm investigating migrating a source code repository currently kept under SCCS on an aging Digital UNIX box to Subversion on a Windows box. My initial searching has led me to a python script, sccs2svn, which looks like it would do the job - with some restrictions. A du -sk on the SCCS directory shows it to be about 550MB in size.
From w...
I'm trying to write a very simple Python utility for personal use that counts the number of lines in a text file for which a predicate specified at the command line is true. Here's the code:
import sys
pred = sys.argv[2]
if sys.argv[1] == "stdin" :
handle = sys.stdin
else :
handle = open(sys.argv[1])
result = 0
for line in han...
I'm working on a Python script to create hashed strings from an existing system similar to that of ASP.NET's MembershipProvider. Using Python, is there a way to take a hexadecimal string and convert it back to a binary and then do a base64 encoding, somehow treating the original string as Unicode. Let's try some code. I'm looking to re...
I'm looking for implementations of set reconciliation algorithm. The problem is following: there are two sets with elements identified by some relatively compact value (e.g. UUID or MD5/SHA1/whatever hash) sitting on different machines. These sets differ in relatively few elements and I want to synchronize these sets while transferring m...
I have a text file with several lines in the following format:
gatename #outputs #inputs list_of_inputs_separated_by_spaces * gate_id
example:
nand 3 2 10 11 * G0 (The two inputs to the nand gate are 10 and 11)
or 2 1 10 * G1 (The only input to the or gate is gate 10)
What I need to do is rename the contents such that I eliminate th...
Is there any reason why Nose wouldn't be able to find tests in Ubuntu 9.04? I'm using nose 0.11.1 with python 2.5.4. I can run tests only if I explicitly specify the filename. If I don't specify the filename it just says 0 tests.
The same project runs tests fine on my Mac, so i'm quite stumped.
...
How do I find the name of the file that is the "importer", within the imported file?
If a.py and b.py both import c.py, is there anyway that c.py can know the name of the file importing it?
...
So, I am trying to make a realistic bouncing function, where the turtle hits a wall and bounces off at the corresponding angle. My code looks like this:
def bounce(num_steps, step_size, initial_heading):
turtle.reset()
top = turtle.window_height()/2
bottom = -top
right = turtle.window_width()/2
left = -right
turtle.le...
Hi, I wonder if anyone has any insights into this. I have a bash script that should put my ssh key onto a remote machine. Adopted from here, the script reads,
#!/usr/bin/sh
REMOTEHOST=user@remote
KEY="$HOME/.ssh/id_rsa.pub"
KEYCODE=`cat $KEY`
ssh -q $REMOTEHOST "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/autho...
I had a combinatorics assignment that involved getting every word with length less than or equal to 6 from a specific combination of strings. In this case, it was S = { 'a', 'ab', 'ba' }. The professor just started listing them off, but I thought it would be easier solved with a program. The only problem is that I can't get a good alg...
Hello ,
I am sending packets from one pc to other. I am using python socket socket.socket(socket.AF_INET, socket.SOCK_DGRAM ). Do we need to take care of order in which packets are received ?
In ISO-OSI model layers below transport layer handle all packets communication. Do all ISO-OSI layers present in the program ? Or some of them pr...
Hello,
I have a simple string that I want to read into a float without losing any visible information as illustrated below:
s = ' 1.0000\n'
When I do f = float(s), I get f=1.0
How to trick this to get f=1.0000 ?
Thank you
...
I'm using the multiprocessing library in Python. I can see how to define that objects returned from functions should have proxies created, but I'd like to have objects in the current process turned into proxies so I can pass them as parameters.
For example, running the following script:
from multiprocessing import current_process
from...
class gpagelet:
"""
Holds 1) the pagelet xpath, which is a string
2) the list of pagelet shingles, list
"""
def __init__(self, parent):
if not isinstance( parent, gwebpage):
raise Exception("Parent must be an instance of gwebpage")
self.parent = parent # This must be a gwebpage...