You're a python ninja. Here's my favorite line:
filename = img_uri.split('/')[-1]
It intrigues me. With the perl background I'm familiar with the whole split routine...but the [-1]... -1 from what? It's a nice magic :)
In python when you string split() a list (sometimes referred to as array in other languages) is returned. From that list I'm asking for the last index.
Example:
# a string img_uri = "www.foxhop.net/attachments/pic1.jpg" # a list of strings img_uri_parts = img_uri.split('/') print img_uri_parts # >>> ['www.foxhop.net', 'attachments', 'pic1.jpg'] # I want the filename, last part of the uri # In this case img_uri[2] # This will not always be true. # I always need the last element of the list. print img_uri_parts[-1] # >>> 'pic1.jpg'
For more information take a look at this page: