2,209,292 questions
31
votes
4
answers
18k
views
Regex and unicode
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example), grabs the episode name (from the www.thetvdb.com API) and automatically renames them into something nicer (...
78
votes
7
answers
90k
views
Python Sound ("Bell")
I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use import os and then use a command line speech program to say "Process complete&...
17
votes
5
answers
2k
views
Python Regular Expressions to implement string unescaping
I am trying to implement string unescaping with Python regex and backreferences, and it doesn't seem to want to work very well. I'm sure it's something I'm doing wrong but I can't figure out what...
&...
12
votes
6
answers
683
views
Replacement for for... if array iteration
I love list comprehensions in Python, because they concisely represent a transformation of a list.
However, in other languages, I frequently find myself writing something along the lines of:
foreach ...
10
votes
3
answers
3k
views
Using an XML catalog with Python's lxml?
Is there a way, when I parse an XML document using lxml, to validate that document against its DTD using an external catalog file? I need to be able to work the fixed attributes defined in a ...
15
votes
7
answers
5k
views
How do I treat an integer as an array of bytes in Python?
I'm trying to decode the result of the Python os.wait() function. This returns, according to the Python docs:
a tuple containing its pid and exit status indication: a 16-bit number, whose low byte ...
266
votes
11
answers
401k
views
How to use XPath in Python?
What are the libraries that support XPath? Is there a full implementation? How is the library used? Where is its website?
17
votes
5
answers
2k
views
Best way to abstract season/show/episode data
Basically, I've written an API to www.thetvdb.com in Python. The current code can be found here.
It grabs data from the API as requested, and has to store the data somehow, and make it available by ...
182
votes
16
answers
142k
views
Python, Unicode, and the Windows console
When I try to print a string in a Windows console, sometimes I get an error that says UnicodeEncodeError: 'charmap' codec can't encode character ..... I assume this is because the Windows console ...
15
votes
4
answers
3k
views
Creating a shared library in MATLAB
A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I ...
14
votes
8
answers
2k
views
How to sell Python to a client/boss/person [closed]
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it?
324
votes
86
answers
151k
views
Best ways to teach a beginner to program? [closed]
Original Question
I am currently engaged in teaching my brother to program. He is a total beginner, but very smart. (And he actually wants to learn). I've noticed that some of our sessions have ...
315
votes
14
answers
245k
views
Create a directly-executable cross-platform GUI app using Python
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.
The problem ...
60
votes
18
answers
20k
views
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why?
27
votes
4
answers
15k
views
How do I make a menu that does not require the user to press [enter] to make a selection?
I've got a menu in Python. That part was easy. I'm using raw_input() to get the selection from the user.
The problem is that raw_input (and input) require the user to press Enter after they make a ...
415
votes
8
answers
362k
views
How do you express binary literals in Python?
How do you express an integer as a binary number with Python literals?
I was easily able to find the answer for hex:
>>> 0x12AF
4783
>>> 0x100
256
and octal:
>>> 01267
...
867
votes
19
answers
412k
views
Adding a method to an existing object instance in Python
How do I add a method to an existing object (i.e., not in the class definition) in Python?
I understand that it's not generally considered good practice to do so, except in some cases.
45
votes
6
answers
5k
views
Python and MySQL
I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as ...
58
votes
8
answers
16k
views
Using 'in' to match an attribute of Python objects in an array
I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like,
foo in iter_attr(array of python objects, attribute name)
I've looked over ...
68
votes
7
answers
10k
views
Continuous Integration System for a Python Codebase [closed]
I am starting to work on a hobby project with a Python codebase and I would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and ...
48
votes
6
answers
6k
views
How can I find the full path to a font from its display name on a Mac?
I am using the Photoshop's javascript API to find the fonts in a given PSD.
Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the ...