python

Python things which are neither True nor False

I just found this : a = (None,) print (a is True) print (a is False) print (a == True) print (a == False) print (a == None) print (a is None) if a : print "hello" if not a : print "goodbye" which produces : False False False False False False hello So a neither is, nor equals True nor False, but acts as True in an if statement. W...

Installing python on 1and1 shared hosting

Hi, I'm trying to install python to a 1and1.com shared linux hosting account. There is a nice guide at this address: http://www.jacksinner.com/wordpress/?p=3 However I get stuck at step 6 which is: "make install". The error I get is as follows: (uiserver):u58399657:~/bin/python > make install Creating directory /~/bin/python/bin /usr...

Grep multi-layered iterable for strings that match (Python)

Say that we have a multilayered iterable with some strings at the "final" level, yes strings are iterable, but I think that you get my meaning: ['something', ('Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')), ('Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas',), ('text/x-pascal',['lets',...

easy_install -f vs easy_install -i

This is related to this question I asked a while back. The end game is I want to be able to install my package "identity.model" and all dependencies. like so... $ easy_install -f http://eggs.sadphaeton.com identity.model Searching for identity.model Reading http://eggs.sadphaeton.com Reading http://pypi.python.org/simple/identity.mode...

Is the Python GIL really per interpreter?

I often see people talking that the GIL is per Python Interpreter (even here on stackoverflow). But what I see in the source code it seems to be that the GIL is a global variable and therefore there is one GIL for all Interpreters in each python process. I know they did this because there is no interpreter object passed around like lua ...

Python optional parameters

Guys, I just started python recently and get confused with the optional parameters, say I have the program like this: class B: pass class A: def __init__(self, builds = B()): self.builds = builds If I create A twice b = A() c = A() and print their builds print b.builds print c.builds I found they are using the ex...

parsing string to a dict

I have a string output which is in form of a dict ex. {'key1':'value1','key2':'value2'} how can make easily save it as a dict and not as a string? ...

looking for x-platform python console library

Hello, I'm a Python newbie. I need something like Curses library for Python 2.6 or 3.1 to run on Windows and Linux without any code changes. I need functions for colorizing text and background, for clearing screen, for reading key code without showing letter on screen and for moving text cursor to specidied position. It must be comple...

union with sort in Google-App-Engine

I have a class: class Transaction(db.Model): accountDebit = db.ReferenceProperty(reference_class=Account, collection_name="kontoDuguje") accountCredit = db.ReferenceProperty(reference_class=Account, collection_name="kontoPotrazuje") amount = db.Fl...

Is there a way to perform "if" in python's lambda

In python 2.6, I want to do: f = lambda x: if x==2 print x else raise Exception() f(2) #should print "2" f(3) #should throw an exception This clearly isn't the syntax. Is it possible to perform an if in lambda and if so how to do it? thanks ...

django Unicode GET Parameter Values

I'm trying to get a GET parameter value that looks like this: http://someurl/handler.json?&q=%E1%F8%E0%F1%F8%E9 The q parameter in this case is Hebrew. I'm trying to read the value using the following code: request.GET.get("q", None) I'm getting gybrish instead of the correct text. Any idea what's wrong here? Am I missing some ...

sending email from wave robot

Anyone know how to send an email using google wave python api? Thanks ...

Python: Do relative imports mean you can't execute a subpackage by itself?

I've recently ported my Python project to run on Python 3.1. For that I had to adopt the policy of relative imports within the submodules and subpackages of my project. I've don’t that and now the project itself works, but I noticed I can't execute any of the subpackages or submodules in it. If I try, I get "builtins.ValueError: Attempte...

Human-readable binary data using Python

My work requires that I perform a mathematical simulation whose parameters come from a binary file. The simulator can read such binary file without a problem. However, I need to peek inside the binary file to make sure the parameters are what I need them to be, and I cannot seem to be able to do it. I would like to write an script in P...

PHP, Python, Ruby application with multiple RDBMS

I start feeling old fashioned when I see all these SQL generating database abstraction layers and all those ORMs out there, although I am far from being old. I understand the need for them, but their use spreads to places they normally don't belong to. I firmly believe that using database abstraction layers for SQL generation is not the...

django and executing a separate .py to manipute a database

Hello, I want to execute a random .py file, say foo.py on the myproject/myapp folder by using crobjob by some periods I have this basic model in my model.py for the app: class Mymodel(models.Model): content = models.TextField() Say I have this in my foo.py, I want to check if there is any Mymodel object that has a content field a...

How to generate random 'greenish' colors

Anyone have any suggestions on how to make randomized colors that are all greenish? Right now I'm generating the colors by this: color = (randint(100, 200), randint(120, 255), randint(100, 200)) That mostly works, but I get brownish colors a lot. ...

gobject io monitoring + nonblocking reads

I've got a problem with using the io_add_watch monitor in python (via gobject). I want to do a nonblocking read of the whole buffer after every notification. Here's the code (shortened a bit): class SomeApp(object): def __init__(self): # some other init that does a lot of stderr debug writes fl = fcntl.fcntl(0, fcntl.F_G...

Race-condition creating folder in Python

I have a urllib2 caching module, which sporadically crashes because of the following code: if not os.path.exists(self.cache_location): os.mkdir(self.cache_location) The problem is, by the time the second line is being executed, the folder may exist, and will error: File ".../cache.py", line 103, in __init__ os.mkdir(self.ca...

Using multiprocessing pool of workers

Hello, I have the following code written to make my lazy second CPU core working. What the code does basically is first find the desired "sea" files in the directory hierarchy and later execute set of external scripts to process these binary "sea" files to produce 50 to 100 text and binary files in number. As the title of the question s...