Skip to content
Advertisement

Python values with units

I need to keep track of units on float and int values in Python, but I don’t want to use an external package like magnitude or others, because I don’t need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don’t want to

What is the default content-type/charset?

According to this answer: urllib2 read to Unicode I have to get the content-type in order to change to Unicode. However, some websites don’t have a “charset”. For example, the [‘content-type’] for this page is “text/html”. I can’t convert it to Unicode. Is there a default “encoding” (English, of course)…so that if nothing is found, I can just use that?

Creating thumbnails from video files with Python

I need to create thumbnails for a video file once I’ve uploaded to a webapp running python. How would I go about this… I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically. Answer A simple combination of PyMedia and PIL would do

Understanding generators in Python

I am reading the Python cookbook at the moment and am currently looking at generators. I’m finding it hard to get my head round. As I come from a Java background, is there a Java equivalent? The book was speaking about ‘Producer / Consumer’, however when I hear that I think of threading. What is a generator and why would

Read from File, or STDIN

I’ve written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities like grep, cut etc. So, I would like it to have the following usage How can I implement the following? if a filename is

How do I concatenate two lists in Python?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. How do I concatenate two lists in Python? Example: Expected outcome: Answer Use the + operator to combine the lists: Output:

Advertisement