os.path.isfile("bob.txt") # Does bob.txt exist? Is it a file, or a directory?
os.path.isdir("bob")
4 записи с тегом "os"
Посмотреть все тегиPython: print() в файл
with open('out.txt', 'w') as f:
print('Filename:', filename, file=f) # Python 3.x
print >> f, 'Filename:', filename # Python 2.x
Python: Установить рабочую директорию (working dir)
import os
import sys
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
Python: glob() по списку путей
def cool_glob(dir_list, patterns_list, recursive=False):
output = []
template = '**/{pattern}' if recursive else '{pattern}'
for dir_name in list(set(dir_list)):
for pattern in list(set(patterns_list)):
output.extend(list(pathlib.Path(dir_name).glob(template.format(pattern=pattern))))
return output
res = cool_glob(
[r'K:\_SYNTHWAVE\music\cover', r'K:\_CLIPARTS\Космос'],
['*.png', '*.jpg', '*.gif', '*.jpeg'],
True
)
print(res)