浠ヤ笅鏄娇鐢≒ython鑾峰彇璺緞涓枃浠跺悕鐨勫嚑绉嶅疄鐜版柟娉曪細
鏂规硶1锛
import os
path = '/path/to/filename.txt'
filename = os.path.basename(path)
print(filename)
杈撳嚭缁撴灉锛歠ilename.txt
鏂规硶2锛
path = '/path/to/filename.txt'
filename = path.split('/')[-1]
print(filename)
杈撳嚭缁撴灉锛歠ilename.txt
鏂规硶3锛
import pathlib
path = '/path/to/filename.txt'
filename = pathlib.Path(path).name
print(filename)
杈撳嚭缁撴灉锛歠ilename.txt
杩欎簺鏂规硶鍙互鏍规嵁鍏蜂綋鐨勯渶姹傞夋嫨鍚堥傜殑瀹炵幇鏂瑰紡銆
浠ヤ笂灏辨槸python 濡備綍鑾峰彇璺緞涓殑鏂囦欢鍚嶇殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒