I have the following string in python:
Data sent by: zabbix
The production server prod1 is unavailable
https://zabbix.com/link/to/zabbix/dashboard
Environment: prod1
Dep: dev
How can i get Environment and Dep from that string to generate url from them? I tried to go line by line but it seems not a good solution. Please help i'm novice in python. Thanks
I mean, going through line by line isn't wrong. Another option is to use regex
import re
text = '''Data sent by: zabbix
The production server prod1 is unavailable
https://zabbix.com/link/to/zabbix/dashboard
Environment: prod1
Dep: dev'''
env = re.search(r'Environment: (.+)', text).group(1)
dep = re.search(r'Dep: (.+)', text).group(1)
url = 'zabbix.com/link/to/zabbix/dashboard/{}/{}'.format(dep, env)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.