10 examples of 'python get filename from path' in Python

Every line of 'python get filename from path' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
36def get_path(filename):
37 return os.path.join(os.path.dirname(__file__), 'test_data', filename)
12def path(filename: str):
13 scriptdir = os.path.dirname(os.path.realpath(__file__))
14 return os.path.join(scriptdir, filename)
66def get_file_path(filename):
67 """
68 Find the book_title excel file path.
69 """
70 root_dir = d(d(abspath(__file__)))
71 root = Path(root_dir)
72 filepath = root / 'stateful_book' / filename
73 return r'{}'.format(filepath)
249def get_module_path(fpath):
250 """Given a module filename, return its full Python name including
251 enclosing packages. (based on existence of ``__init__.py`` files)
252 """
253 if basename(fpath).startswith('__init__.'):
254 pnames = []
255 else:
256 pnames = [splitext(basename(fpath))[0]]
257 path = dirname(abspath(fpath))
258 while isfile(join(path, '__init__.py')):
259 path, pname = split(path)
260 pnames.append(pname)
261 return '.'.join(pnames[::-1])
42def _is_py(path):
43 '''We need to make sure we are writing out Python files.'''
44 return path.split('.')[-1] == 'py'
9def get_path(dir, filename):
10 return os.path.join(
11 os.path.dirname(__file__),
12 dir, filename
13 )
344def get_filename(self, path=None):
345 return self.filename
212def get_name_from_path(path: str) -> str:
213 """
214 Get name from path to the file
215 :param path: path to the file
216 :return: name of the file
217 """
218 return os.path.splitext(os.path.basename(path))[0]
55def get_name_from_path(file_path: str) -> str:
56 return file_path.split(os.sep)[-1]
154def find_module(module_name, path=None):
155 """ Returns the filename for the specified module. """
156
157 components = module_name.split('.')
158
159 try:
160 # Look up the first component of the module name (of course it could be
161 # the *only* component).
162 f, filename, description = imp.find_module(components[0], path)
163
164 # If the module is in a package then go down each level in the package
165 # hierarchy in turn.
166 if len(components) > 0:
167 for component in components[1:]:
168 f,filename,description = imp.find_module(component, [filename])
169
170 except ImportError:
171 filename = None
172
173 return filename

Related snippets