1
如何收集一組字符串之間的文本(數據)?例如,我在下面有這個代碼片斷,這是json的一個修改版本,我沒有能力更改。python解析字符串以獲取文本之間的內容
但是我想presets = {...}
之間
{
data = {
friends = {
max = 0 0,
min = 0 0,
},
family = {
cars = {
van = "honda",
car = "ford",
bike = "trek",
},
presets = {
location = "italy",
size = 10,
travelers = False,
},
version = 1,
},
},
}
收集數據,所以我得到的字符串是無論是兩個支架
{...}
以下單詞預設之間。在這種情況下,這將是:
location = "italy",
size = 10,
travelers = False,
我的起點,那麼遠,
filepath = "C:/Users/jmartini/Projects/assets/tool_source.cfg"
with open(filepath, 'r') as file:
data = file.read().replace('\n', '').replace('\t', '')
print data
雙「打印」 – JokerMartini
@JokerMartini sry這是一個錯字糾正 – vks