python

Virtualenv on Ubuntu with no site-packages

I've been using virtualenv lately while developing in python. I like the idea of a segregated development environment using the --no-site-packages option, but doing this while developing a PyGTK app can be a bit tricky. The PyGTK modules are installed on Ubuntu by default, and I would like to make a virtualenv (with --no-site-packages) a...

Translate SVN path to local file system path in Python

I'm writing a utility in Python that will attach changed files in Subversion to an email and send it when a subset of folders that are under source control in SVN have been changed. I am using the pysvn library to access the repository. I have a copy of the files on my local file system and I do an update to check if the files have cha...

Python with PIL and Libjpeg on Leopard

I'm having trouble getting pictures supported with PIL - it throws me this: "IOError: decoder jpeg not available" I installed PIL from binary, not realizing I needed libjpeg. I installed libjpeg and freetype2 through fink. I tried to reinstall PIL using instructions from http://timhatch.com/ (bottom of the page) "* Download PIL 1.1....

How to determine if a directory is on same partition

Say I have an input file, and a target directory. How do I determine if the input file is on the same hard-drive (or partition) as the target directory? What I want to do is the copy a file if it's on a different, but move it if it's the same. For example: target_directory = "/Volumes/externalDrive/something/" input_foldername, input_f...

OS X: Determine Trash location for a given path

Simply moving the file to ~/.Trash/ will not work, as if the file os on an external drive, it will move the file to the main system drive.. Also, there are other conditions, like files on external drives get moved to /Volumes/.Trash/501/ (or whatever the current user's ID is) Given a file or folder path, what is the correct way to dete...

How can I add post-install scripts to easy_install / setuptools / distutils?

I would like to be able to add a hook to my setup.py that will be run post-install (either when easy_install'ing or when doing python setup.py install). In my project, PySmell, I have some support files for Vim and Emacs. When a user installs PySmell the usual way, these files get copied in the actual egg, and the user has to fish them ...

Lua as a general-purpose scripting language?

When I see Lua, the only thing I ever read is "great for embedding", "fast", "lightweight" and more often than anything else: "World of Warcraft" or in short "WoW". Why is it limited to embedding the whole thing into another application? Why not write general-purpose scripts like you do with Python or Perl? Lua seems to be doing great ...

How can I optimize this Google App Engine code?

I'm relatively new to the python world, but this seems very straight forward. Google is yelling at me that this code needs to be optimized: class AddLinks(webapp.RequestHandler): def post(self): # Hash the textarea input to generate pseudo-unique value hash = md5.new(self.request.get('links')).hexdigest() ...

Python Regex Use - How to Get Positions of Matches

Maybe I'm overlooking something in the Python re library but how can I get the start and end positions of for all matches of my pattern matches in a string? For example for pattern r'[a-z]' on string 'a1b2c3d4' I'd want to get the positions where it finds each letter. (ideally I'd like to get the text of the match back too). Any ideas...

How to scp in python?

What's the most pythonic way to scp a file in Python? The only route I'm aware of is os.system('scp "%s" "%s:%s"' % (localfile, remotehost, remotefile) ) which is a hack, and which doesn't work outside linux-like systems, and which needs help from the Pexpect module to avoid password prompts unless you already have passwordless SSH ...

smart truncate in python?

I am looking for a way to do smart truncating in python. By this I mean that if a string is over X amount of characters then it will only show the first X characters and a suffix like '...'. By "smart" I mean that it will not cutoff words in the middle instead it will cut off on spaces. For instance, not "this is rea...", instead "this i...

What do you like about Django?

I started to learn Django a few days ago, and as i dive into it it seems that I'm starting to like it even more. Trying to migrate from other language. I won't say which one, as the purpose of this question is not to bash anything. So i would like to know your opinion about Django. What do you like about it? What made you switch/use...

How to specify relations using SQLAlchemy declarative syntax?

I can't find any proper documentation on how to specify relations using the declarative syntax of SQLAlchemy.. Is it unsupported? That is, should I use the "traditional" syntax? I am looking for a way to specify relations at a higher level, avoiding having to mess with foreign keys etc.. I'd like to just declare "addresses = OneToMany(Ad...

Is it possible to communicate with a sub subprocess with subprocess.Popen?

I'm trying to write a python script that packages our software. This script needs to build our product, and package it. Currently we have other scripts that do each piece individually which include csh, and perl scripts. One such script is run like: sudo mod args where mod is a perl script; so in python I would do proc = Popen(['sud...

How to get the function name as string in Python?

In Python, How do I get the function name as a string without calling the function? def my_function(): . . . print get_function_name_as_string(my_function) # my_function is not in quotes output => "my_function" is this available in python? if not, any idea how to write get_function_name_as_string in python? ...

script languages on windows mobile - something similar to python @ nokia s60

I try to find something similar to nokia's python for windows mobile based devices - a script interpreter [in this case also able to create standalone apps] with easy access to all phone interfaces - ability to make a phone call, send SMS, make a photo, send a file over GPRS, etc... While there is 2.5 pythonce available for windows mobi...

What is the best way to serve static web pages from within a django app?

I am building a relatively simple django app and apart from the main page where most of the dynamic parts of the application are, there are a few pages that I will need that will not be dynamic at all (About, FAQ, etc.). What is the best way to integrate these into django, idealing still utilizing the django template engine? Should I jus...

Possible Google Riddle?

My friend was given this free google website optimizer tshirt and came to me to try and figure out what the front logo meant. t-shirt So, I have a couple of guesses as to what it means, but I was just wondering if there is something more. My first guess is that each block represents a page layout, and the logo "You should test that" j...

Bizarre python ImportError

Here's my setup: a Mac, running OS X Tiger. Windows XP running in a virtual machine (Parallels). Windows XP has my Mac home directory mapped as a network drive. I have two files in a directory of my Mac home directory: foo.py pass test.py import foo If I run test.py from within my virtual machine by typing 'python test.py', I g...

How can I use a DLL from Python

What is the easiest way to use a DLL from within Python? Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python? Native Python functionality is strongly preferred over using a 3rd party library. ...