python

How remove a program installed with distutils ?

I have installed a python application with this setup.py: #!/usr/bin/env python from distutils.core import setup from libyouandme import APP_NAME, APP_DESCRIPTION, APP_VERSION, APP_AUTHORS, APP_HOMEPAGE, APP_LICENSE setup( name=APP_NAME.replace(" ","-").lower(), version=APP_VERSION, description=APP_DESCRIPTION, author=...

Algorithm for counting connected components of a graph in Python

Hi, I try to write a script that counts connected components of a graph and I can't get the right solution. I have a simple graph with 6 nodes (vertexes), nodes 1 and 2 are connected, and nodes 3 and 4 are connected (6 vertexes; 1-2,3-4,5,6). So the graph contains 4 connected components. I use following script to count connected componen...

How to implement a good __hash__ function in python

When implementing a class with multiple properties (like in the toy example below), what is the best way to handle hashing? I guess that the __eq__ and __hash__ should be consistent, but how to implement a proper hash function that is capable of handling all the properties? class AClass: def __init__(self): self.a = None ...

Django-Piston - I Can't POST on a model with a ForeignKey

I'm trying to set up piston on my Django project. I ran into a brick wall when I tried to POST (create) a new entry on a model that contains a ForeignKey: location. Here is the exact error I receive: Cannot assign "u'1'": "Fest.location" must be a "Location" instance. In the above example, I tried to send over location=1 in the POST. ...

Python Swig wrapper: how access underlying PyObject

I've got class A wrapped with method foo implemented using %extend: class A { ... %extend { void foo() { self->foo_impl(); } } Now I want to increase ref count to an A inside foo_impl, but I only got A* (as self). Question: how can I write/wrap function foo, so that I have an access both to A* and underlying PyObject*...

Simple code for FTP Server in python

Hi , I want to built a simple FTP server in python which will serve the client in just downloading a text file. Can any one kindly help me by suggesting the best study material to refer and help me finding some code snippets. Thanks Nilesh.. ...

Fast python tutorial for Django beginners?

Is there a FAST python tutorial for Django beginners? ...

How to wrap nested customized C++ class (solved)

I am wrapping a C++-based data storage library for python using boost. The library is like this: class Container ... Piece* get(int index) ... ... class Piece ... Each Container (object) is composed of several Pieces. When Container.get is called it will return a pointer to Piece inside Container instead of a full copy. The pro...

Saving model in Django causes vague socket exception.

I have a simple model that when I try to save, I can see this exception in the PyDev output while debugging my Django app. I've confirmed all fields are being set to their proper values (this is a model with 5 charfield/integer properties). I've stepped through in eclipse to the line that is calling .save(), which is where the exception...

Is Python bad at XML?

EDIT The use of the phrase "bad at XML" in this question has been a point of contention, so I'd like to start out by providing a very clear definition of what I mean by this term in this context: if support for standard XML APIs is poor, and forces one to use a language-specific API, in which namespaces seem to be an afterthought, then ...

changing order of unit tests in Python

How can I make it so unit tests in Python (using unittest) are run in the order in which they are specified in the file? thanks. ...

Ways to give a SQLite a variable name

I am tracking changes made to a levels in a game. The way I currently track changes is in a sqlite database. Each level is supposed to have its own database, as just one database for all the levels would provide complications when adding and deleting levels. So for each level, I want a database that has the same name as that level. SO th...

AttributeError: 'str' object has no attribute 'append'

>>> myList[1] 'from form' >>> myList[1].append(s) Traceback (most recent call last): File "<pyshell#144>", line 1, in <module> myList[1].append(s) AttributeError: 'str' object has no attribute 'append' >>> Why myList[1] is considered a 'str' object? mList[1] returns the first item in the list 'from form' but I cannot append to i...

Get CURRENT_FILE_ENCODING for a python file or environment

How can I tell the encoding of the source file from inside a running python process, if it is even possible? ...

Is it possible to write one-liners in Python?

I was going through the code golf question here on Stack overflow and saw many perl one liner solution. My question is: Is something like that possible in Python? ...

How do I get user email using Facebook Graph API in GAE Python?

I'm using Facebook Graph API on Google App Engine. I was able to fetch all the basic info from an user. However when I tried to fetch any user info that requires permission, email for exemple, it always appears as None. I've followed the whole tutorial available at the developers blog. Here's my code: class User(db.Model): id = db....

etree Clone Node

How to clone Element objects in Python xml.etree? I'm trying to procedurally move and copy (then modify their attributes) nodes. ...

How to choose 10 different integers from range (0, 99)

I want to choose 10 random integers from 0 to 99. I know I can use: random.randint(a, b) But how to tell the randint() that I only want different integers. Do I have to just check after each random generation to see if the integer has already been generated and call the method again? That does not seem like an optimal solution. ...

Is possible to know the path of the file of a subclass in python?

I have a plugin system. The plugins subclass from a common ancestor... ad look like this: -- SDK --- basePlugin.py -- PLUGINS --- PluginA ---- Plugin.py ---- Config.ini --- PluginB ---- Plugin.py ---- Config.ini I need to read the info of Config.ini in basePlugin.py __init__. CUrrently in each plugin I do: class PluginA(BaseSync): ...

python - 'str' object has no attribute 'execute'

First time python user here, be gentle.... ;-) Python 2.6 on OSX Got a class which just has some wrappers around sqlite... here it is from pysqlite2 import dbapi2 as sqlite class SqliteDB: connection = '' curser = '' def connect(self): try: self.connection = sqlite.connect("pagespeed.sqlite") ...