python-2.6

Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start?

I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they u...

Python 2.6 multiprocessing.Queue compatible with threads?

I am experimenting with the new multiprocessing module in Python 2.6. I am creating several processes each with its own multiprocessor.JoinableQueue instance. Each process spawns one or more worker threads (subclasses of threading.Thread) which share the JoinableQueue instance (passed in through each Thread's __init__ method). It seem...

if all in list == something

Using python 2.6 is there a way to check if all the items of a sequence equals a given value, in one statement? [pseudocode] my_sequence = (2,5,7,82,35) if all the values in (type(i) for i in my_sequence) == int: do() instead of, say: my_sequence = (2,5,7,82,35) all_int = True for i in my_sequence: if type(i) is not int: ...

Cygwin and Python 2.6

New to python (and programming). What exactly do I need from Cygwin? I'm running python 2.6 on winxp. Can I safely download the complete Cygwin? It just seems like a huge bundle of stuff. ...

MySQL for Python in Windows

I am finding it difficult to use MySQL with Python in my windows system. I am currently using Python 2.6. I have tried to compile MySQL-python-1.2.3b1 (which is supposed to work for Python 2.6 ?) source code using the provided setup scripts. The setup script runs and it doesn't report any error but it doesn't generate _mysql module. I...

Why did Python 2.6 add a global next() function?

I noticed that Python2.6 added a next() to it's list of global functions. next(iterator[, default])¶ Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised. What was the motivation for adding this? What can...

Django Template if tag not working under FastCGI when checking bool True

I have a strange issue specific to my Django deployment under Python 2.6 + Ubuntu + Apache 2.2 + FastCGI. If I have a template as such: {% with True as something %} {%if something%} It Worked!!! {%endif%} {%endwith%} it should output the string "It Worked!!!". It does not on my production server with mod_fastcgi. This w...

Replace html entities with the corresponding utf-8 characters in Python 2.6

I have a html text like this: &lt;xml ... &gt; and I want to convert it to something readable: <xml ...> Any easy (and fast) way to do it in Python? ...

Random strings in Python 2.6 (Is this OK?)

I've been trying to find a more pythonic way of generating random string in python that can scale as well. Typically, I see something similar to ''.join(random.choice(string.letters) for i in xrange(len)) It sucks if you want to generate long string. I've been thinking about random.getrandombits for a while, and figuring out how to c...

Any gotchas using unicode_literals in Python 2.6?

We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding: from __future__ import unicode_literals into our .py files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious gotchas (perhaps after spending a lot of time debugg...

Simple threading in Python 2.6 using thread.start_new_thread()

I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current import thread def myfunction(mystring,*args): print mystring if __name__ == '__main__': tr...

Python multiprocessing on Python 2.6 Win32 (xp)

I tried to copy this example from this Multiprocessing lecture by jesse noller (as recommended in another SO post)[http://pycon.blip.tv/file/1947354?filename=Pycon-IntroductionToMultiprocessingInPython630.mp4] But for some reason I'm getting an error, as though it's ignoring my function definitions: I'm on Windows XP (win32) which I kno...

Most memory efficient way to save binary file from the web with Python 2.6?

I'm trying to download (and save) a binary file from the web using Python 2.6 and urllib. As I understand it, read(), readline() and readlines() are the 3 ways to read a file-like object. Since the binary files aren't really broken into newlines, read() and readlines() read teh whole file into memory. Is choosing a random read() buffer...

pywikipedia name wikiquote is not defined?

Hi guys, I'm writing a bot for Wikipedia but have a problem. When I want to get stuff from another Wikimedia site I get the error - error-name 'wikiquote' is not defined. This is when I start the code off like this- import wikipedia site = wikiquote.getSite() Yet if I was to start it with wikipedia written instead of wikiquote, it ...

Remove everything after ... in python?

Hi guys, Pretty new to Python so be nice please! I have a string of text-how do I remove all the text after some certain characters? The text after will change so I want to remove after some text which doesn't change. Hope that makes sense! Thanks ...

Why does sys.exit() not exit when called inside a thread in Python?

This could be a stupid question, but I'm testing out some of my assumptions about Python and I'm confused as to why the following code snippet would not exit when called in the thread, but would exit when called in the main thread. import sys, time from threading import Thread def testexit(): time.sleep(5) sys.exit() print "post thr...

Using poll on file-like object returned by urllib2.urlopen()?

I've run into the bug described at http://bugs.python.org/issue1327971 while trying to poll a file-like object returned by urllib2.urlopen(). Unfortunately, being relatively new to Python, I can't actually determine from the responses how to get around the issue as they seem mostly geared towards fixing the bug, rather than hacking the...

Can bin() be overloaded like oct() and hex() in Python 2.6?

In Python 2.6 (and earlier) the hex() and oct() built-in functions can be overloaded in a class by defining __hex__ and __oct__ special functions. However there is not a __bin__ special function for overloading the behaviour of Python 2.6's new bin() built-in function. I want to know if there is any way of flexibly overloading bin(), an...

How to stop Python parse_qs from parsing single values into lists?

In python 2.6, the following code: import urlparse qsdata = "test=test&test2=test2&test2=test3" qs = urlparse.parse_qs(qsdata) print qs Gives the following output: {'test': ['test'], 'test2': ['test2', 'test3']} Which means that even though there is only one value for test, it is still being parsed into a list. Is there a way to en...

sqlite version for python26

which versions of sqlite may best suite for python 2.6.2? ...