python

Default Python compilers on MacOS X

I'm trying to install matplotlib for Python on MacOS X. If I use the system Python 2.6.1, the default compiler commands that matplotlib uses (presumably via distutils) are:: gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes g++-4.2 -Wl,-F. -bundle -undefined dynamic_lookup However, if I simply add the python.org 2.6.6 Python t...

Multiple values for key in dictionary in Python

What I'm trying to do is get 3 values from a key into separate variables. Currently I'm doing it like this: for key in names: posX = names[key][0] posY = names[key][1] posZ = names[key][2] This doesn't seem very intuitive to me even though it works. I've also tried doing this: for key, value in names: location = value U...

python format datetime with "st", "nd", "rd", "th" (english ordinal suffix) like PHP's "S"

I would like a datetime in python to output like this: Thu the 2nd at 4:30 But I find no way in python to output st, nd, rd, or th like I can with PHP datetime format with the S string (What they call "English Ordinal Suffix") (http://uk.php.net/manual/en/function.date.php). Is there a built-in way to do this in python? strftime isn'...

Language/GUI library to make map editor

I'm designing a cross-platform map editor for an application I've developed, and I'm unsure what approach to take regarding language/gui library choice. Just for some basic info, the editor needs to parse and output xml files. I'm most comfortable with C++, Lua, and Perl, but I'd also be willing to use Python (could use the practice). I...

Editing related models in profile form using django-profiles

I'm using django-profiles in my app, as it gives me a few simple views that helps me get where I want to go, faster. However, I have one problem. Given the models below, how can I create a form for editing a profile that includes all the fields on UserProfile, the first_name, last_name and email fields from User, and one or more PhoneNu...

How do I get window attributes in Tkinter?

self.attributes("-alpha", Alpha) How do I get window attributes in Tkinter? Currently I wan't my program to get the value of Alpha. ...

Python's getattr gets called twice?

I am using this simple example to understand Python's getattr function: In [25]: class Foo: ....: def __getattr__(self, name): ....: print name ....: ....: In [26]: f = Foo() In [27]: f.bar bar bar Why is bar printed twice? Using Python 2.6.5. ...

Why are mutable strings slower than immutable strings?

Why are mutable strings slower than immutable strings? EDIT: >>> import UserString ... def test(): ... s = UserString.MutableString('Python') ... for i in range(3): ... s[0] = 'a' ... ... if __name__=='__main__': ... from timeit import Timer ... t = Timer("test()", "from __main__ import test") ... print t.t...

Python or Ruby Which one should I learn?

I am new to programming.. I was thinking to start learning with Ruby or Python. y main task would be web development. But I cannot choose between them. Which language do you think I should learn? ...

PyGTK treeview and row_activated callback

Hello, I'm trying to retrieve the row data from a treemodel when the row_activated callback is fired. When row_activated is called, the 'path' variable it passes is a tuple. How do I easily use this tuple to retrieve an iter and ultimately the data itself? The treemodel class has a function to convert a string into an iter, but it seems...

Neural Network, python

Hello everyone. I am trying to write a simple neural network that can come up with weights to for, say, the y=x function. Here's my code: http://codepad.org/rPdZ7fOz As you can see, the error level never really goes down much. I tried changing the momentum and learning rate but it did not help much. Is my number of input, hidden and ou...

Python MySQL module

I'm developing a web application that needs to interface with a MySQL database, and I can't seem to find any really good modules out there for Python. I'm specifically looking for fast module, capable of handling hundreds of thousands of connections (and queries, all within a short period of time of each other), without an significant i...

Django / Python, how to check if user is logged in (how to properly use: user.is_authenticated )?

I am looking over: http://docs.djangoproject.com/en/1.2/topics/auth/#django.contrib.auth.models.User but just can't seem to figure out how to do this as its not working. I need to check if the current site user is logged in (authenticated), and am trying: request.user.is_authenticated despite being sure that the user is logged in, it ...

Setuptools not found

I am switching from Linux to OSX and when I run our build's setup.py script, I get an error message that contains the text This script requires setuptools version 0.6c7. I have tried several times to install setuptools, and have verified that the setuptools egg exists in /Library/Python/2.6/site-packages. I have no idea why it is n...

pkg_resources.VersionConflict when I try to start paster serve

Im trying to use port 80. So when i use the command "sudo paster serve development.ini --reload" I get this error pkg_resources.VersionConflict: (Pylons 0.9.7 (/usr/lib/pymodules/python2.6), Requirement.parse('Pylons>=1.0')) I tried to do "easy_install pylons" but I get "Pylons 1.0 is already the active version in easy-install.pth...

Unknown cause for TypeError in Python 2.6

I am writing a program which reads input from a file called 'votes.txt'. It reads in some line of information, each of which is a 'vote' with parties ordered by preference. The program needs to take this data, and output the winner of the election. My Code is as follows: # Define the count_votes() function def count_votes(to_count): ...

Floats incorrect? - Python 2.6

Hi, I have a programming question, as follows, for which my solution does not produce the desired output This particle simulator operates in a universe with different laws of physics to ours. Each particle has a position (x, y), velocity (vx, vy) and an acceleration (ax, ay). Every particle exerts an attractive force on every other ...

Simple RESTFUL client/server example in Python?

Is there an online resource that shows how to write a simple (but robust) RESTFUL server/client (preferably with authentication), written in Python? The objective is to be able to write my own lightweight RESTFUL services without being encumbered by an entire web framework. Having said that, if there is a way to do this (i.e. write RESF...

In Google App Engine, how do I avoid creating duplicate entities with the same attribute?

I am trying to add a transaction to keep from creating two entities with the same attribute. In my application, I am creating a new Player each time I see a new Google user logged in. My current implementation occasionally creates duplicate players when multiple json calls are made by a new Google user within a few milliseconds. When I a...

Ways to implement Flex [Bindable] in other languages

As you may know, ActionScript allows you to mark a variable as [Bindable], causing any changes to that variable to have immediate effect all over your application. Pretty neat. How would you implement this feature in your favourite programming language? My first guess was to use events or wrapper classes, but I couldn't come up with a c...