27 มกราคม 2559

Published มกราคม 27, 2559 by with 0 comment

ทิปการเขียนโปรแกรม Python : วิธีการแยกนามสกุลไฟล์ออกจากไฟล์

ใช้โมดูล os เข้ามาช่วยแยกนามสกุลไฟล์ด้วยคำสั่ง os.path.splitext
ตัวอย่างเช่น

[python]
>>> import os
>>> filename, file_extension = os.path.splitext('/path/to/somefile.ext')
>>> filename
'/path/to/somefile'
>>> file_extension
'.ext'
[/python]

ที่มา : https://stackoverflow.com/questions/541390/extracting-extension-from-filename-in-python

0 ความคิดเห็น:

แสดงความคิดเห็น

แสดงความคิดเห็นได้ครับ :)