Skip to main content

from a filename(str) extension or name

Project description

get_filename

我絕對不要再為了這個坑花了整整2小時 Orz......
如題,只是一個獲取檔案名稱或副檔名的東東。

From a filename(str) get extension or name.


用法 how to use

get_filename( filename=str, mode='filename', index=0):

@param  {str} filename (不能為空)
@param  {str} mode ('filename' or 'extension') or ( 1 or 2)
@param  {int} index (當 mode = 'extension' 或 2 才會作用)
@return {str}

ex1 :

  t = get_filename('explosion.hard.txt')
  t -> 'explosion.hard'

ex2 :

t = get_filename('/path/to/somefile.ext')
t = 'somefile'

ex3 :

t = get_filename('explosion.hard.txt','extension',-3)
t = get_filename('explosion.hard.txt',2,0)
t -> 'explosion'

ex4 :

t = get_filename('/path/to/somefile.txt','extension',-1)
t = get_filename('/path/to/somefile.txt',2,-1)
t -> 'txt'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_filename-1.0.0.tar.gz (2.2 kB view hashes)

Uploaded Source

Built Distributions

get_filename-1.0.0-py3.8.egg (3.6 kB view hashes)

Uploaded Source

get_filename-1.0.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page