这段代码如何Pythonic
天蓬老师
天蓬老师 2017-04-18 09:43:43
0
2
379
str = 'title={WiMAX Power Amplifier Design based on Si-LDMOS},author={Nader, Charles and De Carvalho, Nuno Borges},journal={University of Galve, Sweden},year={2006}'
for item in str.split('},'):
    try:
        if 'author' in item:
            print(item.split('{', 1)[1])
    except Exception as e:
        print(e)
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
巴扎黑
d = dict([s.split('={') for s in str.split('},')])
print(d['author'])
左手右手慢动作

Use regular expressions:

pattern = re.compile(r'author={?P<author>[a-zA-Z,]}')
match = pattern.match(str)
if match:
    print(match.group(1))
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!