python

comparing two strings with 'is' -- not performing as expected

I'm attempting to compare two strings with is. One string is returned by a function, and the other is just declared in the comparison. is tests for object identity, but according to this page, it also works with two identical strings because of Python's memory optimization. But, the following doesn't work: def uSplit(ustring): #...

Is there anything that can't be programmed with Python?

Hi guys, I hope I'm not repeating questions here. Beforehand, please no flamewar. My intention is to consult to someone that has been using python longer than me. I'm currently in the process of switching career into Python programmer. After been doing research and Googling about Python from the internet, I can see that Python can do a...

Django newbie deployment question - ImportError: Could not import settings 'settings'

Hello folks, The app runs fine using django internal server however when I use apache + mod_python I get the below error File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 75, in __init__ raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SE...

Is it safe to replace a self object by another object of the same type in a method ?

I would like to replace an object instance by another instance inside a method like this: class A: def method1(self): self = func(self) The object is retrieved from a database. ...

Newbie to python conventions, is my code on the right track?

I've been reading about python for a week now and just thought I'd try my hand at it by creating a tax bracket calculator. I'm not finished but I wanted to know if I'm on the right track or not as far as python programming goes. I've only done a little C++ programming before, and it feels like it shows (good/bad?) #There are six brack...

Web programming tutorial

Hi, I'm a programmer with some experience working on various languages and platforms, but I lack any web development experience (apart of some very basic HTML produced by PHP). I'm looking for a tutorial about the basics of web programming under Linux. I am less interested with apache configuration and server maintenance which I know q...

Make python __doc__ property display correctly in a Windows CMD window?

In Windows, if I open a command prompt, start python, and inspect something using its __doc__ property, it doesn't display correctly. Instead of the lines being separated, I see one continuous string with the newline character every once and a while. Is there a way to make it appear correctly? Here's an example of what I see: >>> has...

Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time

Note: This question has been re-asked with a summary of all debugging attempts here. I have a Python script that is running as a background process executing every 60 seconds. Part of that is a call to subprocess.Popen to get the output of ps. ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] After runn...

google appengine/python: Can I depend on Task queue retry on failure to keep insertions to a minimum?

Say my app has a page on which people can add comments. Say after each comment is added a taskqueue worker is added. So if a 100 comments are added a 100 taskqueue insertions are made. (note: the above is a hypothetical example to illustrate my question) Say I wanted to ensure that the number of insertions are kept to a minimum (so...

Python: sorting a dictionary of lists

Still learning python (finally!) and can't quite wrap my head around this one yet. What I want to do is sort a dictionary of lists by value using the third item in the list. It's easy enough sorting a dictionary by value when the value is just a single number or string, but this list thing has me baffled. Example: myDict = { 'item1' ...

Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational?

After reading "What is the Java equivalent of LINQ?", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or external stores - going to be the path of the future for most general purpose languages? Or is LINQ an interesting piece o...

is it possible to add an element to a list and preserve the order

I would like to add an element to a list that preserve the order of the list. Let's assume the list of object is [a, b, c, d] I have a function cmp that compares two elements of the list. if I add f object which is the bigger I would like it to be at the last position. maybe it's better to sort the complete list... ...

Reverting a Python/Cocoa project to use the default OSX 10.5 Python (2.5)

Hi, I have installed the latest MacPython (2.6.2) on my Leopard OS X and started an XCode PyObjC project. When I finalized the app, I built the release version and sent it to a friend of mine to try if it runs with out of the box. It did not, because it expects the latest Python, as on my computer. No matter what I tried, I could not...

Remove the "Add" functionality in Django admin

Is there a way to remove the "Add" functionality on the Django admin site? For certain entities, I only want the Django admin to be able to view them or change existing ones, but not add new ones. ...

PyOpenGL + Pygame capped to 60 FPS in Fullscreen

I'm currently working on a game engine written in pygame and I wanted to add OpenGL support. I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set up the window), it drops down...

How do I forbid easy_install from zipping eggs?

What must I put into distutils.cfg to prevent easy_install from ever installing a zipped egg? The compression is a nice thought, but I like to be able to grep through and debug that code. I pulled in some dependencies with python setup.py develop . A closer look reveals that also accepts the --always-unzip flag. It would just be nice to...

How to make the wxNotebook to expand?

(I have tagged this question as Python as well since I understand Python code so examples in Python are also welcome!). I want to create a simple window in wxWidgets: I create a main panel which I add to a form I associate a boxsizer to the main panel (splitting it in two, horizontally). I add LeftPanel to the boxsizer, I add RightPanel...

Python string templater

I'm using this REST web service, which returns various templated strings as urls, for example: "http://api.app.com/{foo}" In Ruby, I can then use url = Addressable::Template.new("http://api.app.com/{foo}").expand('foo' => 'bar') to get "http://api.app.com/bar" Is there any way to do this in Python? I know about %() templates, b...

python's sum() and non-integer values

Is there a simple and quick way to use sum() with non-integer values? So I can use it like this: class Foo(object): def __init__(self,bar) self.bar=bar mylist=[Foo(3),Foo(34),Foo(63),200] result=sum(mylist) # result should be 300 I tried overriding __add__ and __int__ etc, but I don't have found a solution yet EDIT: Th...

Multiprocessing Debugging error

Hey everyone, I am having a little trouble debugging my code. Please look below: import globalFunc from globalFunc import systemPrint from globalFunc import out from globalFunc import debug import math import time import multiprocessing """ Somehow this is not working well """ class urlServerM( multiprocessing.Process): """ ...