python-3.x - 如何确定文件扩展名?
问题描述
我试图复制路径为:userDATA\user1\profile_image 的图像,但不幸的是,我不知道文件扩展名,因为用户可以删除自己的图像,因此后缀有时会有所不同。
file_path = drop_image_instance.image_path # the path looks like this: C:\user\images\download1.png
copyfile(file_path, "userDATA\\" + username + "\\profile_image")
我的问题是,我怎样才能找出文件有哪个后缀,或者我怎样才能检测到 file_path 的结尾?例如:
def find_suffix(path):
file_ending = path[1]
return file_ending
感谢您的回答!
解决方案
推荐阅读
- php - 如何在 Google 日历活动中更新与会者列表?
- javascript - 我应该将提供程序 redux 放在哪里?
- c - 我的阅读程序中不断显示“双重释放或损坏(输出)”,但我不确定这意味着什么(已修复)
- python - 了解类函数中的继承(python)
- python - 查询列表理解
- angular - Angular - ngClass 在按钮单击之前已经存在
- javascript - SwiperJS - 上一个和下一个按钮不起作用
- c# - 在什么情况下,Azure Functions 会在消费计划上触发“CancellationToken”信号?
- java - jsp中的request.getParameter返回null或空字符串
- python - Python Pandas:如何用相应的列名填充空行?