I have this code within a python script that returns to following output
dir = ["/var/www", "/usr/share"]
for dir_name in dirs:
if os.path.exists(dir_name):
cmd = ["drush", "st"]
rc, out, err = module.run_command(cmd, cwd=dir_name)
if rc == 0:
info = out.splitlines()
version = info[0].strip().split(':')[-1].strip()
return {'version': version}
output:
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush version : 6.2.0
Drush configuration :
Drush alias files :
How do I get the version 6.2.0 returned by the version variable?
We can do something like this?
version.partition('version')[2].split('\n')[0].split(':')[1].strip()
I took the liberty of considering
version = '''PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush version : 6.2.0
Drush configuration :
Drush alias files : '''
This should work however it is better to use regex.
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.