Hi,
I'm fairly new to Python and recursive functions as a whole, so pardon my ignorance.
I am trying to implement a binary search tree in Python and have the following insert method (taken out of a class):
def insert(self, key, root=None):
'''Inserts a node in the tree'''
if root == None:
root = self.root
if root.k...
hello again!
I have some code that throws causes syncdb to throw an error (because it tries to access the model before the tables are created).
Is there a way to keep the code from running on syncdb? something like:
if not syncdb:
run_some_code()
Thanks :)
edit: PS - I thought about using the post_init signal... for the code th...
I'm learning Python and can't even write the first example:
print 2 ** 100
this gives SyntaxError: invalid syntax
pointing at the 2.
Why is this? I'm using version 3.1
...
Possible Duplicate:
python - decimal place issues with floats
In [4]: 52+121.2
Out[4]: 173.19999999999999
...
In PHP, you have preg_replace($patterns, $replacements, $string), where you can make all your substitutions at once by passing in an array of patterns and replacements.
What is the equivalent in Python?
I noticed that the string and re functions replace() and sub() don't take dictionaries...
Edited to clarify based on a comment by ric...
Possible Duplicates:
Use only some parts of Django?
Using only the DB part of Django
I want to use the Django ORM as standalone. Despite an hour of searching Google, I'm still left with several questions:
Does it require me to set up my Python project with a setting.py, /myApp/ directory, and modules.py file?
Can I create a ne...
I am using Tcl from Python Tkinter Module like below
from Tkinter import *
Tcl = Tcl().eval
Tcl("info patchlevel")
'8.3.5'
You can see Tcl version 8.3 is selected by python.
But i also have tcl8.4 in my system.
Now,how do i make python select tcl8.4 in Tkinter module.
Tcl8.3 does not have Expect package,so i can not use Expect pack...
Hello all,
In a classic relational database, I have the following table:
CREATE TABLE Person(
Id int IDENTITY(1,1) NOT NULL PRIMARY KEY,
MotherId int NOT NULL REFERENCES Person(Id),
FatherId int NOT NULL REFERENCES Person(Id),
FirstName nvarchar(255))
I am trying to convert this table into a Google App Engine table. ...
For a project of mine, I'm trying to implement a small part of the BitTorrent protocol, which can be found here. Specifically, I want to use the "Bencoding" part of it, which is a way to safely encode data for transfer over a socket. The format is as follows:
8:a string => "a string"
i1234e => 1234
l1:a1:be => ['a', 'b']
d1:a1:b3:one3:t...
I have a linux based web hosting provider (fatcow.com) that doesn't give any command line access and won't run the setup script for CherryPy (python web server) for me.
Is there any way to run get around this limitation so that I have a working install of CherryPy?
This might be more or a serverfault.com question, but maybe someone her...
Hello Folks,
I'm using Routes for doing all the URL mapping job. Here's a typical route in my application:
map.routes('route', '/show/{title:[^/]+}', controller='generator', filter_=postprocess_title)
Quite often I have to strip some characters (like whitespace and underscore) from the {title} parameter. Currently there's one call pe...
Hello everyone,
my question is rather a design question.
In Python, if code in your "constructor" fails, the object ends up not being defined. Thus:
someInstance = MyClass("test123") #lets say that constructor throws an exception
someInstance.doSomething() # will fail, name someInstance not defined.
I do have a situation though, wher...
User should be redirected to the Login page after registration and after logout. In both cases there must be a message displayed indicating relevant messages.
Using the django.contrib.auth.views.login how do I send these {{ info }} messages.
A possible option would be to copy the auth.views to new registration module and include all es...
I need a callback function that is almost exactly the same for a series of gui events. The function will behave slightly differently depending on which event has called it. Seems like a simple case to me, but I cannot figure out this weird behavior of lambda functions.
So I have the following simplified code below:
def callback(msg):
...
Is there a way for a Python program to determine how much memory it's currently using? I've seen discussions about memory usage for a single object, but what I need is total memory usage for the process, so that I can determine when it's necessary to start discarding cached data.
...
Hi, how do I get the author/username from an object using:
GetYouTubeVideoEntry(video_id=youtube_video_id_to_output)
I'm using Google's gdata.youtube.service Python library
Thanks in advance! :)
...
Currently I have a simple IRC bot written in python.
Since I migrated it to python 3.0 which differentiates between bytes and unicode strings I started having encoding issues. Specifically, with others not sending UTF-8.
Now, I could just tell everyone to send UTF-8 (which they should regardless) but an even better solution would be tr...
I've searched on this, but nothing has what I'm looking for.
http://www.mail-archive.com/[email protected]/msg10529.html -- Nobody answered him. This is exactly what I'm experiencing. When I set the foreground on a graphics context, it doesn't seem to actually change.
I've been through the tutorial and FAQ, but neither say much. They e...
Hello!
I want to format a list into a string in this way:
[1,2,3] => '1 2 3'. How to do this?
Is there any customizable formatter in Python as Common Lisp format?
...
I've noticed in several examples i see things such as this:
# Comments explaining code i think
@innerclass
or:
def foo():
"""
Basic Doc String
"""
@classmethod
Googling doesn't get me very far, for just a general definition of what this is. Also i cant find anything really in the python documentation.
What do these do?
...