Python字符串解析
大家讲道理
大家讲道理 2017-04-17 17:42:56
0
2
333

Python里面,比如这样几句代码:

data = {'name':'Tom','age':'18'}
fmt = 'My name is {name}, I am {age} years old.'
res = fmt.format(**data)

之后res的值就是'My name is Tom, I am 18 years old.'。
现在假设我们有res和fmt了,怎样得到data呢?
正则我想应该是没问题的,但是想问问Python里面有没有类似C里面的sscanf一样的东西可以直接拿来解析呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
Peter_Zhu

I tell you clearly that there is no function equivalent to scanf in Python, because Python recommends you to use regular expressions. Reference: Python Docs: 6.2.5.2. Simulating scanf()

刘奇

Can only be parsed manually

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!