working on a program that takes a file and determines what type it is. It must be a .wav or .jpg file to be correct, and if it is not one of those, it will display a message that says to choose a correct file type. However, I am stuck on how to get it to determine what type of file is being chosen, since for this program I am not allowed to use f.endswith(), so I was thinking range may work but I am unsure what the paramaters should be, or if range is even the correct choice for how to determine the file type. help please :)
def fileType():
f = pickAFile
print f
for f in range ():
start = f.rfind(".")
if start!=-1:
print A .wav file type was selected
print A .jpg file type was selected
else:
print No file type was chosen
print Please choose a different file type
ok I have tried something like this but it is giving me a syntax error, could you help me with what the issue may be?
def fileType():
f = pickAFile
print f f[f.rfind('.'):]
if f[f.rfind('.'):] == '.wav':
print "A sound file was selected."
if f[f.rfind('.'):] == '.jpg' :
print "An image file was selected
else:
print " This was an incorrect file type."
print " Please chose a .wav or .jpg file."