python

Iterate over subclasses of a given class in a given module

In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X? ...

How would you make a comma-separated string from a list?

What would be your preferred way to concatenate strings from a sequence such that between each two consecutive pair a comma is added. That is, how do you map, for instance, [ 'a', 'b', 'c' ] to 'a,b,c'? (The cases [ s ] and [] should be mapped to s and '', respectively.) I usually end up using something like ''.join(map(lambda x: x+',',...

Can someone explain __all__ in Python?

I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files. Can someone explain what this does? ...

Can the HTTP version or headers affect the visual appearance of a web page?

I know, I would have thought the answer was obviously "no" as well, but I am experiencing a strange situation where when I view my site from our staging server it appears slightly larger than when I view it from my local dev server. I have used Charles to confirm that all of the content -- the HTML, the images, the CSS, the javascript, ...

Python packages - import by class, not file

Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If app/controllers/project.py defines a class Project, app.py would import it like this: from app.controllers.project import Project I'd like to just be able to do: from app.controllers import Project How would this...

Where can I find the time and space complexity of the built-in sequence types in Python

I've been unable to find a source for this information, short of looking through the Python source code myself to determine how the objects work. Does anyone know where I could find this online? ...

Good python library for generating audio files?

Can anyone recommend a good library for generating an audio file, such as mp3, wav, or even midi, from python? I've seen recommendations for working with the id tags (song name, artist, etc) in mp3 files, but this is not my goal. Thank you very much! ...

Wacom tablet Python interface

Hello, If possible I want to catch pressure sensitive input from a Wacom tablet in Python. Are there any Python libraries available that can do this? Regards, Menno ...

Is there a Python library for generating .ico files?

I'm looking to create favicon.ico files programatically from Python, but PIL only has support for reading ico files. ...

How to know whether a window with a given title is already open in Tk?

Hi, I’ve writen a little python script that just pops up a message box containing the text passed on the command line. I want to pop it up only when the window —resulting from a previous call— is not open. from Tkinter import * import tkMessageBox root = Tk() root.withdraw() # TODO not if a window with this title exists tkMessageBox...

Python libdwarf module

I'm working on a utility which needs to resolve hex addresses to a symbolic function name and source code line number within a binary. The utility will run on Linux on x86, though the binaries it analyzes will be for a MIPS-based embedded system. The MIPS binaries are in ELF format, using DWARF for the symbolic debugging information. I'...

Which Version of Python to Use for Maximum Compatibility

If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system? I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be wor...

Django: Print url of view without hardcoding the url

Can i print out a url (/admin/manage/products/add) of a certain view in a template? Here is the rule i want to create a link for (r'^manage/products/add/$', create_object, {'model': Product, 'post_save_redirect': ''}), I would like to have /manage/products/add in a template without hardcoding it. How can i do this? Edit: I am not us...

How do you set up a python wsgi server under IIS?

I work in a windows environment and would prefer to deploy code to IIS. At the same time I would like to code in python. Having read that IIS can run fastCGI application, I went to the IIS site where it describes in detail how to get PHP up and running but not much about anything else. Does anyone have experience getting a python framew...

Is there a way to attach a debugger to a multi-threaded Python process?

I'm trying to debug a deadlock in a multi-threaded Python application after it has locked up. Is there a way to attach a debugger to inspect the state of the process? Edit: I'm attempting this on Linux, but it would be great if there were a cross-platform solution. It's Python after all :) ...

Generator Expressions vs. List Comprehension

When should you use generator expressions vs. list comprehensions in Python and vice-versa? # Generator expression (x*2 for x in range(256)) # List comprehension [x*2 for x in range(256)] ...

User Authentication in Pylons + AuthKit

I am trying to create a web application using Pylons and the resources on the web point to the PylonsBook page which isn't of much help. I want authentication and authorisation and is there anyway to setup Authkit to work easily with Pylons? I tried downloading the SimpleSiteTemplate from the cheeseshop but wasn't able to run the setup-...

What are the advantages of packaging your python library/application as an .egg file?

I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer? ...

Glade or no glade: What is the best way to use PyGtk?

Hello there. I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a b...

Embedding a remote Python shell in an application

You can embed the IPython shell inside of your application so that it launches the shell in the foreground. Is there a way to embed a telnet server in a python app so that you can telnet to a certain port and launch a remote IPython shell? Any tips for redirecting the input/output streams for IPython or how to hook it up to a telnet ...