def parsestructure(path, userid, date):
with open(f'/backups/{userid}/{date}') as structfile:
parsed = []
for line in structfile:
item = line.split() # https://docs.python.org/3/library/stdtypes.html#str.split
fullname = item[0]
if fullname.startswith(path):
name = fullname.replace(path, '') # для этого существует
namelst = name.split('/') # модуль os.path
isdir = item[1] == 'dir'
isfile = not isdir # нафиг вообще нужно
if isdir:
name = namelst[0]
pdict = {'path': path, 'name': name, 'is_dir': isdir, 'is_file': isfile}
parsed.append(pdict)
import re
s = "aaacd aaa bbbcd cccdd"
print(re.findall(r'\b(\w+)(?:cd|dd)\b|\b(\w+)\b', s))
chars = 'abcdefgh'
for char in chars:
globals()[char] = 1
print(a, b, c)
я использую стандартную функцию
char_is_special = frozenset("[ ~`!@#$%^&*()_-+={}[]:>;',</?*-+ ]").__contains__
def str_has_special(s):
return any(map(char_is_special, s))
print(char_is_special("a"), char_is_special("?"))
print(str_has_special("abc"), str_has_special("abc?"))
s = "C0 C2 D0 20 E2 F5"
b = bytes(int(c, 16) for c in s.split())
print(b.decode(encoding='windows-1251'))