密钥的输出I具有存储一个字符串作为关键字的词典,和整数的值。在我的输出中,我希望将键显示为不带圆括号或逗号的字符串。我将如何做到这一点?格式化从字典
for f_name,f_loc in dict_func.items():
print ('Function names:\n\n\t{0} -- {1} lines of code\n'.format(f_name, f_loc))
输出:
Enter the file name: test.txt
line = 'def count_loc(infile):'
There were 19 lines of code in "test.txt"
Function names:
('count_loc(infile)',) -- 15 lines of code
只是柜面还不清楚,我想输出的最后一行显示为:
count_loc(infile) -- 15 lines of code
编辑
name = re.search(func_pattern, line).groups()
name = str(name)
我输出之前使用类型(),我VERI田间它仍然是一个字符串,但输出时一样,名字是一个元组
啊,我看我做什么,但我仍然不确定如何解决它。当我获得函数的名称并使用正则表达式时,我使用了.groups()方法。我将在原始代码中添加该代码,因为我已将其转换为str,并且仍然产生相同的输出 – Justen 2009-05-29 22:49:15
如果使用.groups(),请尝试仅使用工作的.group() – 2009-05-29 22:51:43