python 鑾峰彇璺緞涓殑鏂囦欢鍚
浠ヤ笅鏄娇鐢≒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浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=272