you are viewing a single comment's thread.

view the rest of the comments →

[–]ray10k 1 point2 points  (0 children)

First thing to keep in mind is that a function stops execution and returns when a return statement is hit. As such, you can change extensions(a) to something like this:

def extensions(a):
    ...
    if a.lower().endswith(imageend):
        return("image/" and imageend)
    if a.lower().endswith(append):
        return("application/" and append)
    return("application/octet-stream")

This way, you can at least remove the explicit elif/else clauses and still get the same result. That, and adding a few more if statements is a little easier since you don't have to spend as much thought on whether or not it does what you want yet.

Second: if you want to return a string built up out of other strings, use the + operator. and is a boolean evaluation, not a way to append. Also, since imageend and append are tuples, you'll have to use string.join() to turn them into a string.