2018年1月10日 星期三

Python: Divide a path on the extension separator

Python: Divide a path on the extension separator

Python Basic: Exercise-106 with Solution

Write a Python program to divide a path on the extension separator.
Sample Solution:-
import os.path
for path in [ 'test.txt', 'filename', 'F:\Python_APSC/test.txt', '/', '' ]:
    print('"%s" :' % path, os.path.splitext(path))

 split(path):將路徑分解為(文件夾,文件名) 
 splitext(path):將路徑分解為(其余部分,.擴展名),若文件名中沒有擴展名,擴展名部分為空字符串

=========== RESTART: F:/Python_APSC/py-ex-basic-106.py ==========
"test.txt" : ('test', '.txt')
"filename" : ('filename', '')
"F:\Python_APSC/test.txt" : ('F:\\Python_APSC/test', '.txt')
"/" : ('/', '')
"" : ('', '')
>>> 

沒有留言:

張貼留言

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...