python

How does mercurial work without Python installed?

I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that. How does it work? Also, is it possible to force Mercurial run on IronPython and will it be compatible? Thank you. ...

MySQL LOAD DATA LOCAL INFILE example in python?

I am looking for a syntax definition, example, sample code, wiki, etc. for executing a LOAD DATA LOCAL INFILE command from python. I believe I can use mysqlimport as well if that is available, so any feedback (and code snippet) on which is the better route, is welcome. A Google search is not turning up much in the way of current info ...

how to overwrite User model

I don't like models.User, but I like Admin view, and I will keep admin view in my application. How to overwirte models.User ? Make it just look like following: from django.contrib.auth.models import User class ShugeUser(User) username = EmailField(uniqute=True, verbose_name='EMail as your username', ...) email = CharField(...

How can I use a class instance variable as an argument for a method decorator in Python?

How can I use a class instance variable as an argument for a method decorator in Python? The following is a minimal example shows what I'm trying to do. It obviously fails as the decorator function does not have access to the reference to the instance and I have no idea how to get access to the reference from the decorator. def decorato...

setuptools / dpkg-buildpackage: Refuse to build if nosetests fail

I have a very simple python package that I build into debian packages using setuptools, cdbs and pycentral: setup.py: from setuptools import setup setup(name='PHPSerialize', version='1.0', py_modules=['PHPSerialize'], test_suite = 'nose.collector' ) debian/rules: #!/usr/bin/make -f DEB_PYTHON_SYSTEM = pycentral include /usr/...

Django - Following a foriegn key relationship (i.e JOIN in SQL)

Busy playing with django, but one thing seems to be tripping me up is following a foreign key relationship. Now, I have a ton of experience in writing SQL, so i could prob. return the result if the ORM was not there. Basically this is the SQL query i want returned Select table1.id table1.text table1.user table2.user_name tab...

How can I get the memory usage before, after and of an individual spawned process in Python?

I have spawned a process using: ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] I want to do 3 things: 1) Get the memory usage of the Python script before the call to subprocess.Popen 2) Get the memory usage of the Python script after the call to subprocess.Popen 3) Get the memory usage of the spawned ...

How to make server accepting connections from multiple ports?

Hello! How can I make a simple server(simple as in accepting a connection and print to terminal whatever is received) accept connection from multiple ports or a port range? Do I have to use multiple threads, one for each bind call. Or is there another solution? The simple server can look something like this. def server(): import sys,...

"Upload" a file from django shell

I need to import some data from a excel file and a folder with images, every row in the excel describes every entry and have a list of filenames in the folder (photos related to the entry). I've done a script which creates every entry in the database and saves it trough the django shell, but i have no idea how to instantiate a InMemoryU...

Concatenating Dictionaries

I have three lists, the first is a list of names, the second is a list of dictionaries, and the third is a list of data. Each position in a list corresponds with the same positions in the other lists. List_1[0] has corresponding data in List_2[0] and List_3[0], etc. I would like to turn these three lists into a dictionary inside a dictio...

Python multiprocessing easy way to implement a simple counter?

Hey everyone, I am using multiprocessing in python now. and I am just wondering whether there exists some sort of simple counter variable that each process when they are done processing some task could just increment ( kind of like how much work done in total). I looked up the API for Value, don't think it's mutable. ...

Hit a URL on other server from google app engine

I want to hit a URL from python in google app engine. Can any one please tell me how can i hit the URL using python in google app engine. ...

Could not import Django settings into Google App Engine

Hello all you Google App Engine experts, I have used Django a little before but am new to Google App Engine and am trying to use it's development web server with Django for the first time. I don't know if this is relevent but I previously had Django 1.1 and Python 2.6 on my Windows XP and even though I have uninstalled Python 2.6 ...

No Multiline Lambda in Python: Why not?

I've heard it said that multiline lambdas can't be added in Python because they would clash syntactically with the other syntax constructs in Python. I was thinking about this on the bus today and realized I couldn't think of a single Python construct that multiline lambdas clash with. Given that I know the language pretty well, this s...

Python Dictionary to URL Parameters

I am trying to convert a Python dictionary to a string for use as URL parameters. I am sure that there is a better, more Pythonic way of doing this. What is it? x = "" for key, val in {'a':'A', 'b':'B'}.items(): x += "%s=%s&" %(key,val) x = x[:-1] ...

python and set_wrap_mode in treeview

Hi, i'Ve got a sring that i wann paste into a column: textrenderer = gtk.CellRendererText() column = gtk.TreeViewColumn('Text', textrenderer, text=COLUMN_TEXT) treeview.append_column(column) but the text is too long for the column and so the window gets automaticly resized, but i want to get the text wrapped automaticly like with this...

PYTHON: Converting list of tuples into a dictionary

Hi, I'm looking for a way to convert list of tuples which looks like this: [(1,4),(2,4),(3,4),(4,15),(5,15),(6,23),(7,23),(8,23),(9,15),(10,23),(11,15),(12,15)] into a dictionary, where key:value pair looks like this: {4:[1,2,3] ,15:[4,5,9,11,12], 23:[6,7,8,10]} Second element from a tuple becomes a dictionary key. First tuple ele...

k-means clustering implementation in python, running out of memory

 Note: updates/solutions at the bottom of this question As part of a product recommendation engine, I'm trying to segment my users based on their product preferences starting with using the k-means clustering algorithm. My data is a dictionary of the form: prefs = { 'user_id_1': { 1L: 3.0f, 2L: 1.0f, }, 'user_id_2': { 4L: 1.0f...

What is the simplest way to SSH using Python?

What is the absolute simplest way to SSH to a remote server from a local Python (3.0) script, supply a login/password, execute a command and print the output to the the Python console? I would rather not use any large external library and not install anything on the remote server. ...

Installing Pinax on Windows

Can I install Pinax on Windows Environment? Is there a easy way? Which environment do you recommend? ...