Код: Выделить всё
with open('test3.txt') as file:
my_list = file.readlines()
b = [line.strip() for line in my_list]
Код: Выделить всё
['"url": "https://services.swpc.noaa.gov/images/animations/d-rap/north-pole/d-rap/`latest`.png",', '"httpVersion": "http/2.0",', '"headers": [', '{', '"name": ":authority",', '"value": "services.swpc.noaa.gov"', '},', '{', '"name": ":method",', '"value": "HEAD"', '},', '{', '"name": ":path",', '"value": "/images/animations/d-rap/north-pole/d-rap/`latest`.png"', '"url": "https://services.swpc.noaa.gov/images/animations/d-rap/global_f05/d-rap/`latest`.png",', '"httpVersion": "http/2.0",', '"headers": [', '{', '"name": ":authority",', '"value": "services.swpc.noaa.gov"', '},', '{', '"name": ":method",', '"value": "HEAD"', '},', '{', '"name": ":path",', '"value": "/images/animations/d-rap/global_f05/d-rap/`latest`.png"', '},', '{', '"name": ":scheme",', '"value": "https"', '},', '{', '"name": "accept",', '"value": "*/*"', '},', '{', '"name": "accept-encoding",', '"value": "gzip, deflate, br"', '', '']
Код: Выделить всё
'"url": "https://services.swpc.noaa.gov/images/animations/d-rap/north-pole/d-rap/`latest1`.png",'
Код: Выделить всё
'"value": "/images/animations/d-rap/north-pole/d-rap/`latest2`.png"', '
вот мой «код», но он не работает:
Код: Выделить всё
with open('test3.txt') as file:
my_list = file.readlines()
b = [line.strip() for line in my_list]
latest_count = 1
latest_count2 = 2
for i in range(len(b)):
if b[i] == '"url": "https://services.swpc.noaa.gov/images/animations/d-rap/north-pole/d-rap/latest.png",':
b[i] = f'"url": "https://services.swpc.noaa.gov/images/animations/d-rap/north-pole/d-rap/latest{latest_count}.png",'
latest_count += 1
elif b[i] == '"value": "/images/animations/d-rap/global_f05/d-rap/latest.png"':
b[i] = f'"value": "/images/animations/d-rap/global_f05/d-rap/latest{latest_count2}.png"'
latest_count2 = 2
print(b)
Подробнее здесь: https://stackoverflow.com/questions/783 ... -change-it