python

Allow user to select a file or a folder in QFileDialog

In PyQt you can do something like the following to allow the user to select a file filename = QtGui.QFileDialog.getOpenFileName(self, "Choose file..") However I would like a QFileDialog to open in which the user would be able to select either a file or a directory. I'm sure I've seen this feature in PyQt applications before, but I can...

Stream a file to the HTTP response in Pylons

I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this: with open(filepath, 'rb') as f: response.write(f.read()) That works, but it's obviously inefficient for large files. What's the best way...

email MIME Content-Disposition hyperlink

Hi i an building an mbox file from a db blob and would like to add an hyperlink to the Attachement header I am building the header like this msg=email.message_from_string(blob) msg["Content-Disposition"]="attachment; filename=filename.txt;" What do i need to add to add a http or ftp hyperlink for the filename? Thnks ...

Would it be possible to integrate Python or Perl with Ruby?

Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/ and http://code.google.com/p/ruby-perl/ , but they both seem rather outdated. Has someone generated a Ruby interface for Python's C API? Edit: Python can be integrated with many other languages ac...

Python package with compiled code

I'm looking into releasing a python package which includes an existing fortran or C program. The fortran/C program is compiled by running ./configure make The python code calls the resulting binary through subprocess calls (i.e. the code is not really wrapped as such). What I would like is that when the user types python setup.py ins...

How do I make this sorting case insensitive?

def sortProfiles(p): return sorted(p, key=itemgetter('first_name')) I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. ...

How do I do this "order by" in Django, if I have foriegn keys?

Suppose my model is this: class Ego(models.Model): event = models.ForeignKey(Event) user = models.ForeignKey(User) As you can see, this table has 2 columns, and they're both foreign keys. How do I "order by" User.first_name? Is this it? But it doesn't look like it. Ego.objects.all().order_by("User.first_name") ...

Creating subtree from tree which is represented in xml - python

Hi I have an XML (in the form of tree), I require to create sub-tree out of it. For ex: <a> <b> <c>Hello</c> <d> <e>Hi</e> </a> Subtree would be <root> <a> <b> <c>Hello</c> </b> </a> <a> <d> <e>Hi</e> </d> </a> </root> What is the best XML library in python to do it? Any algorithm that already does...

How regex a empty string in python?

I want that find empty tags, here is a example txt ="<lol1><><lol2>" rgx = "<([a-zA-Z_0-9]+)>" print re.findall(rgex, txt) I get this ['lol1', 'lol2'] I want ['lol1', '', 'lol2'] How I can do this with regex? ...

How to make script/program to make it so an application is always running?

I have a simple .exe that needs to be running continuously. Unfortunately, sometimes it crashes unexpectedly, and there's nothing that can be done for this. I'm thinking of like a C# program that scans the running application tree on a timer and if the process stops running it re-launches it... ? Not sure how to do that though.... An...

Error installing MySQL-python on MAC Snow Leopard, OS 10.6

Hello members, I am trying to install the MySQL-python on MAC OS 10.6 (Snow leopard, 64 bit). I followed the steps: 1. Installed MySQL for Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive. 2. Downloaded MySQL-python-1.2.3c1.tar.gz and unzipped it 3. CD to MySQL-python-1.2.3c1 and built it as: ARCHFLAGS="-arch x86_64" python setup.py bui...

python string class like stringbuilder in c#

Is there something string class like stringbuilder in c#? Thanks ...

Sort by key of dictionary inside a dictionary in Python

How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"? promotion_items = { 'one': {'remaining_pcs': 100, 'discount_ratio': 10}, 'two': {'remaining_pcs': 200, 'discount_ratio': 20}, } EDIT What I mean is getting a sorted list of above dictionary, not to sort the dictionary itself. ...

Concepts and tools required to scale up algorithms

Hi, I'd like to begin thinking about how I can scale up my algorithms that I write for data analysis so that they can be applied to arbitrarily large sets of data. I wonder what are the relevant concepts (threads, concurrency, immutable data structures, recursion) and tools (Hadoop/MapReduce, Terracota, and Eucalyptus) to make this happe...

What is the fastest way to check whether a folder size is greater than a specific size?

What will be the fastest way to check whether a folder size is beyond a specific size say 10 MB, 1 Gb , 10 GB etc, without actually calculating the folder size. Something like quota. A Pythonic solution will be great, but standard UNIX utilities also welcome ...

Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize)

Hello Everyone, I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searching for Python modules that could do this but they all seem to be dependent on other libraries which does not work well on AppE...

Add directory to PYTHONPATH ( multiple drives ), for auto-complete.

I have 2 hard-drives, C:\ and D:\ Django imports correctly (which is in my C drive), but my application is on my D drive. I can't move it to the C drive because of some back-up software I'm running/ I'm trying to get auto-complete to work in Komodo Edit 5 which works fine for Django, but not for my application. There are a few other re...

Find element with attribute with minidom

Given <field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/> <field name="frame.time_relative" showname="Time since reference or first frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/> <field name="frame.number" showname="Fr...

How to install python modules and dependents easily?

Are there any easy installation tools like "perl -MCPAN -e shell;" to install python modules and its dependents??? ...

python ConfigParser module

I have the following ini file [Section] value=test When i use the ConfigParser Module : import ConfigParser config = ConfigParser.ConfigParser() config.read('config.ini') str=config.get('Section', 'value') if str == 'test': print 1 else : print 0 it always print 0 could someone help ...