This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pathlib | |
# 1 | |
# ------------------------------------------------- | |
os.environ["ALLUSERSPROFILE"] | |
# The environment variable "ALLUSERSPROFILE" is available on Windows only. | |
# On Windows returns | |
# 'C:\\ProgramData' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import pytest as pt | |
# See Python Testing with pytest. > Chapter 4 > Using tmpdir and tmpdir_factory | |
class TestStuff(object): | |
@pt.fixture(scope='class') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See | |
# https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format | |
import ntpath | |
path_to_file = r"C:\a\b\s\d\f_a\aasdas_o_g.json" | |
print(ntpath.basename(path_to_file) | |
# Output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See | |
# https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | |
from os import listdir | |
from os.path import isfile, join | |
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pendulum | |
now = pendulum.now() | |
now.format('YYYYMMDD_HHmm') |
NewerOlder