python

What is the best approach to change primary keys in an existing Django app?

Hello, I have an application which is in BETA mode. The model of this app has some classes with an explicit primary_key. As a consequence Django use the fields and doesn't create an id automatically. class Something(models.Model): name = models.CharField(max_length=64, primary_key=True) I think that it was a bad idea (see http://...

All members package/module defines?

How can I know which members module/package defines? By defining I mean: somemodule.py import os # <-- Not defined in this module from os.path import sep # <-- Not defined in this module I_AM_ATTRIBUTE = None # <-- Is defined in this module class SomeClass(object): # <-- Is defined also... pass So I need a some sort of function...

What are the major differences in object models of dynamic languages like Smalltalk, Ruby and Python

I dived into understanding the Ruby object model in the last weeks, and although so far was only a user of the fruits of ruby's and python's object in the past, I became curious how these things might differ in other languages. Years ago I touched smalltalk's squeak. Smalltalk is often figuring as a referential object oriented language,...

how to perform ssh and scp equivalent function in python code

I want to login in different machine in the network and copy a file from that machine to my machine.I want to do this using python.Any idea how can i do this .I have python 2.5 a nd ubuntu 8.10 ...

How to delete element from list in Python?

I am new to python. I have created a list a = [[3,4],[5],[6,7,8]] I want to delete 3 from this list. What is the command for this? ...

Django custom auth backend not recognized on Apache

I'm trying to deploy my Django application to an Apache2 based server with mod_python. I've set the handlers right and made the configuration to make mod_python work with my project. My project implements a custom auth backend to connect my users to twitter, and my backend implementation is on: myproject |- backends/ directory.Everyth...

Recover process with subprocess.Popen?

Hi everyone! I have a python program that uses subprocess.Popen to launch another process (python process or whatever), and after launching it I save the child's PID to a file. Let's suppose that suddenly the parent process dies (because of an exception or whatever). Is there any way to access again to the object returned by Popen? I m...

What is the Java Equivalent of Python's property()?

I'm new to Java, and I'd like to create some class variables that are dynamically calculated when accessed, as you can do in Python by using the property() method. However, I'm not really sure how to describe this, so Googling shows me lots about the Java "Property" class, but this doesn't appear to be the same thing. What is the Java eq...

python - os.makedirs don't understand ~ in my path?

Hi I have a little problem with ~ in my paths. This code example creates some dirs called "~/some_dir", and do not understand that I wanted to create some_dir in my home dir. my_dir = "~/some_dir" if not os.path.exists(my_dir): os.makedirs(my_dir) Note this is on a linux based system. Thanks Johan Solution: Thanks all, if...

Installing SUDS in python 2.6.4

Hello, I am having real trouble installing SUDS in python 2.6.4. I have tried to install the setup file but it says the location of python cannot be found. This is because I have changed the location of python. I have tried to use easy_install but am having no luck. Does anyone know a simple way to do this or have a link to clear instal...

Python: delete item in a list using a for-loop

Hello. I have an array with subjects and every subject has connected time. I want to compare every subjects in the list. If there are two of the same subjects, I want to add the times of both subjects, and also want to delete the second subject information (subject-name and time). But If I delete the item, the list become shorter, and I ...

Build, syntax-check, parse and evaluate a query.

Hi, I am building a query in a textarea with different conditions selected from the html controls. Also users are open to do modification to it. Client side: For the below list of condition: a(1, 3) > 20 b(4, 5) < 90 c(3, 0) = 80 I form a query: a(1, 3) > 20 and b(4, 5) < 90 or c(3, 0) = 80 On the server side this has to be parse...

Python GTK+: create custom signals?

Is it possible to create new signals in Python GTK+ ? I'd like a skeleton code example, please. ...

How to find out if I have installed a Python module in Linux?

I tried to install a Python module by typing: sudo python setup.py install After I typed this command I got a lot of output to the screen. The lest few lines are bellow: writing manifest file 'scikits.audiolab.egg-info/SOURCES.txt' removing '/usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info' (and everything under i...

Some tables mixed together

Hello. I have 2 different tables in my database. They have some variables common and some different. For example: Table1: ID Date Name Address Fax Table2: ID Date Name e-mail Telephone number I want to display data together sorted by date & ID but from both tables. For example, first displayed will be the newest record ...

Dynamic direct_to_template

In my webapp, there are a lot of errors or other messages that just show a template that is very close to the URL. At the moment, I have half a dozen static mappers like this: (r'^/message/foo/$', 'direct_to_template', {'template': 'message/foo.html'}), (r'^/message/bar/$', 'direct_to_template', {'template': 'message/bar.html'}), Is t...

Awk, bash or python for converting a regular file?

Hi, I have a text file with lots of lines and with this structure: [('name_1a', 'name_1b', value_1), ('name_2a', 'name_2b', value_2), ..... ..... ('name_XXXa', 'name_XXXb', value_XXX)] I would like to convert it to: name_1a, name_1b, value_1 name_2a, name_2b, value_2 ...... name_XXXa, name_XXXb, value_XXX I wonder what would be the...

PyQt vs PySide comparison

I currently develop many applications in a Qt heavy C++/Python environment on Linux, porting to PC/Mac as needed. I use Python embedded in C++ as well as in a stand alone GUI. Qt is used fro xml parsing/event handling/GUI/threading and much more. Right now all my Python work is in PyQt and I wanted to see how everyone views PySide. I'm i...

Worst practices in Django you have ever seen

What are the worst mistakes made using Django framework, that you have noticed? Have you seen some real misuses, that maybe should go as warnings to the Django docs? ...

Assigning one of multiple values based on what exists

In Perl, if I want to assign $myVar a value of $var1, $var2, or $var3, based on which one evaluates to true, I would code the following: $myVar = $var1 || $var2 || $var3; I am working on separate projects in both Python and PHP, and I have not figured out how to code this situation as concisely in either language. What is the best wa...