Every line of 'python remove file extension' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
21 def remove_file_extension(filename): 22 return os.path.splitext(filename)[0]
495 def stripext (filename): 496 """Return the basename without extension of given filename.""" 497 return os.path.splitext(os.path.basename(filename))[0]
23 def fix_filename(filename): 24 """ 25 Fixes the __file__ attribute to make tests work even after being byte 26 compiled. 27 """ 28 return os.path.abspath( 29 filename[:-1] if filename.endswith('.pyc') else filename 30 )
35 def replace_ext(f, e): 36 return os.path.splitext(f)[0] + e
182 def stripExt(path): 183 return os.path.splitext(path)[0]
24 def file_extension(path): # 文件扩展名 25 return os.path.splitext(path)[1]
4 def truncate_extension(filename): 5 return os.path.splitext(filename)[0]
41 def get_filename(path, with_ext=True): 42 """Returns file name from given file, with or without extension. 43 It finds last "os.sep" inside string and returns tail. 44 :param path: path with file name 45 :type path: str 46 :param with_ext: return file name with extension or not 47 :type with_ext: bool 48 :return: file name with or without extension 49 :rtype: str 50 """ 51 52 # find last separator; prefer os.sep otherwise search for normal slash 53 last_sep = path.rfind(os.sep) 54 if last_sep < 0: 55 last_sep = path.rfind("/") 56 57 new_path = path[last_sep + 1:] 58 if not with_ext and new_path.rfind(".") > 0: 59 new_path = new_path[:new_path.rfind(".")] 60 return new_path
8 def get_ext(file): 9 filename, file_extension = os.path.splitext(file) 10 if "." in file_extension: 11 param, value = file_extension.split(".",1) 12 return value, filename
10 def os_fix_filename(filename): 11 """Alter filenames containing illegal characters, depending on the OS. 12 13 Ref: https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names/31976060#31976060 14 """ 15 if system() == "Windows": 16 return re_sub(r"[\<\>\:\"\/\\\|\?\*]+", "", filename) 17 return re_sub(r"[\/]+", r"\\", filename)