我需要读一行有const关键字和返回版本作为值。你知道吗
中的内容版本.php文件
final class Version
{
/**
* The current Piwik version.
* @var string
*/
const VERSION = '2.0.3';
}
这是我写的代码,但它没有返回任何东西。我做错了什么?你知道吗
def piwik_check(module):
dirs = ["/var/www/piwik/core"]
for dir_name in dirs:
if os.path.exists(dir_name):
readme_file = open("%s/Version.php" % dir_name)
for line in readme_file.xreadlines():
if line.startswith(str.strip("const")):
#version = str(line)
version = str(line).split()[1].strip()
return {'version': version}
break
else:
continue
readme_file.close()
在您的功能中:
with
自动关闭文件,版本号是拆分后的最后一个/第四个元素,如果您只想让版本号rstrip the;
并简单地遍历file对象f
。你知道吗相关问题 更多 >
编程相关推荐