Below this is my code, I have a tuple of different possible extensions that the user can use to open a file. But the files that the user will open will have a name (like cat.zip or daughter.jpg). I want to remove this name (cat in the first one, daughter in the second) and replace it with "image/" followed by whatever extension they used.
I would greatly appreciate it if you could help by explaining me how to figure this out.
P.S: The code may look unfinished, that's because it is. I'm trying to figure this out before continuing.
def main():
ext = (".gif", ".jpeg", ".jpg", ".png", ".pdf", ".txt", ".zip")
file = input("What file would you like to run? \n>> ")
if file.endswith(ext):
print(file.lstrip(ext))
main()
I tried using the .replace() function or .lstrip, but I couldn't figure out how to only limit the .replace function to only the text before the extension, if I use specific characters, it could mess up the extensions being printed. I am unable to use the .lstrip function with a tuple from my experience.