python

State of Python Packaging: Buildout, Distribute, Distutils, EasyInstall, etc...

The last time I had to worry about installing Python packages was two years ago working with Enthought, NumPy and MayaVi2. That experience gave me lingering nightmares related to quirky behavior installing & updating Python packages in non-standard locations (in $HOME/usr/local2.6/, for example). Anyway, my work is taking me back to in...

Play Subset of audio file using Pyglet

How can I use the pyglet API for sound to play subsets of a sound file e.g. from 1 second in to 3.5seconds of a 6 second sound clip? I can load a sound file and play it, and can seek to the start of the interval desired, but am wondering how to stop playback at the point indicated? ...

Does Paramiko support non-secure telnet and ftp instead of just SSH and SFTP?

I'm looking at existing python code that heavily uses Paramiko to do SSH and FTP. I need to allow the same code to work with some hosts that do not support a secure connection and over which I have no control. Is there a quick and easy way to do it via Paramiko, or do I need to step back, create some abstraction that supports both para...

change desktop background

how can i change desktop background with python i want to do it in both windows and linux thanks ...

how can i change '>' to '>' ,and change '>' to '>'

print u'&lt;'#how can i print '<' print '>' #how can i print '&gt;' thanks ...

Why doesn't my Django site return a 404 when checked with this URL parser?

Here's a simple python function that checks if a given url is valid: from httplib import HTTP from urlparse import urlparse def checkURL(url): p = urlparse(url) h = HTTP(p[1]) h.putrequest('HEAD', p[2]) h.endheaders() if h.getreply()[0] == 200: return 1 else: return 0 This works for most sites, but wit...

Jython Optimizations

Are their any ways to optimize Jython without resorting to profiling or significantly changing the code? Specifically are there any flags that can be passed to the compiler, or code hints in tight loops. ...

Web2Py Working Directory

Well I want to use WEb2Py because it's pretty nice.. I just need to change the working directory to the directory where all my modules/libraries/apps are so i can use them. I want to be able to import my real program when I use the web2py interface/applications. I need to do this instead of putting all my apps and stuff inside the Web2P...

pip equivalent to "easy_install ."

Simple Question ;) Is there a way to simply install the package using pip once you build it. Using easy_install I would simply build my package it (python setup.py build), then if I was happy do a easy_install . and this would dump the resulting egg into the right place. How do I do this using pip? ...

what does '__getnewargs__' do in this code .

class NavigableString(unicode, PageElement): def __new__(cls, value): if isinstance(value, unicode): return unicode.__new__(cls, value) return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) def __getnewargs__(self):#this line return (NavigableString.__str__(self),) thanks ...

Web2py Import Once per Session

I'm using Web2Py and i want to import my program simply once per session... not everytime the page is loaded. is this possible ? such as "import Client" being used on the page but only import it once per session.. ...

Parsing Python Code From Within Python?

We have an older C++ tool that generates some python code automatically. I tried to slog through the C++ source tool, today and pretty much wanted to shoot my self. The thing is what i want to do, is clean up the source created by the tool and link the classes to our internal documentation system via adding sphinx tags. Now what i am w...

How to specify psycopg2 parameter for an array for timestamps (datetimes)

I'd like to run a PostgreSQL query in Python using psycopg2, which filters by a column of type timestamp without timezone. I have a long list of allowed values for the timestamp (rather than a range) and psycopg2 convenient handles arrays, so I thought that this should work: SELECT somestuff FROM mytable WHERE thetimestamp = ANY (%(time...

Python web server ?

I want to develop a tool for my project using python. The requirements are: Embed a web server to let the user get some static files, but the traffic is not very high. User can configure the tool using http, I don't want a GUI page, I just need a RPC interface, like XML-RPC? or others? Besides the web server, the tool need some backgr...

What causes subprocess.call to output blank file when attempting db export with mysqldump?

I am having some problems using subprocess.call to export a database using mysqldump. I'm using Python 3.1 installed on Windows 7. from time import gmtime, strftime import subprocess DumpDir = "c:/apps/sqlbackup/"; DumpFile = "mysqldump-" + strftime("%Y-%m-%d-%H-%M-%S", gmtime()) + ".sql"; params = [r"mysqldump --user root --password=...

How to get Python code to work with C++ App?

I have the following python 3 file: import base64 import xxx str = xxx.GetString() str2 = base64.b64encode(str.encode()) str3 = str2.decode() print str3 xxx is a module exported by some C++ code. This script does not work because calling Py_InitModule on this script returns NULL. The weird thing is if I create a stub xxx.py in the sa...

Hooking into a wave-out on different platforms

I am going to apologize in advance for being extremely vague, but my knowledge in this area is somewhat limited so I don't know the neccessary "keywords" to make my point/question clear. Sorry. What I want to do is to find a way to obtain access to raw audio data as it is being output, say, when some external application is playing back...

Is this essential functional programming feature missing from python?

I have a class in python that allows me to save a function (in a database) for later use. Now I need to have a method in the class that allows me to call this function on some arguments. Since I don't know how many arguments the function has ahead of time, I have to pass them in as list. This is where things fall apart because I can't fi...

What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)?

a='aaaa' print isinstance(a, basestring)#true print isinstance(a, str)#true ...

how can i escape '\xff\xfe' to a readable string.

i see a string in this code: data[:2] == '\xff\xfe' i don't know what '\xff\xfe' is, so i want to escape it ,but not successful import cgi print cgi.escape('\xff\xfe')#print \xff\xfe how can i get it. thanks ...