I am working on a code where in I need to define a fuction which checks for the allowed file extensions. The fuction takes filename and extension as arguments as shown below:
def allowed_file(filename, extensions=None):
Steps to write the function:
Kindly guide how to proceed on this.
Since we don't do homework in stackoverflow I'm not going to give you the full code.
But I can give you the pseudo code:
First of all filenames in python are provided in their full form: file1.txt
, image.png
and so on.
For checking if a list contains an object we use in
operator: "txt" in extensions => True
def allowed_extensions(filename,extensions=None):
# TODO : Extract the file extension from filename
# TODO : Check if the extension exists in extensions list or not
# TODO : Return True if it exists and False if not
btw, these links can help you:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.