2013-05-13 53 views
2

在下面的脚本中,'a'全局设置为TC-01,b全局设置为'Passed',但执行后我能够获得值' '但是'b'价值我无法得到,所以请给我提供有价值的想法,以获得'B'的价值。如何在内部调用python global命令另一个文件的步骤

import HTML 
import html2 
from html2 import a,b 

file = open('out.html', 'w') 
# dictionary of test results, indexed by test id: 
test_results = { 
a: 'b',-----> In this only a value is take , b is not taking the value. 
#'Testcase-005': 'success' 
#'Testcase-005': 'error', 
    } 

result_colors = { 
'passed':  'lime', 
'failed':  'red', 
'error':  'yellow', 
    } 
t = HTML.Table(header_row=['Testcase - ID', 'Result']) 
for test_id in sorted(test_results): 
#create the colored cell: 
print test_results 
color = result_colors[test_results[test_id]] 
colored_result = HTML.TableCell(test_results[test_id], bgcolor=color) 
#append the row with two cells: 
t.rows.append([test_id, colored_result]) 
htmlcode = str(t) 
c=htmlcode 
print htmlcode 
file.write(c) 

回答

1
import HTML 
import html2 
from html2 import * 
#print a 
#print b 
file = open('out.html', 'w') 
table_data = [ 
['S.No', 'Testcase - ID', 'Result'], 
['1',  a,   b], 
['2',  c,   d], 

] 
htmlcode = HTML.table(table_data) 
c=htmlcode 
print htmlcode 

file.write(C) 在此之后全球呼叫A,B,C,d ...我认为这会工作

+0

正常工作... – Anub 2013-05-21 07:04:29

0

我不能完全确定你想要做什么,但我认为你的问题是因为你设置test_results[a]'b'而不是b

也就是说,您没有使用b的值,而是使用字符串'b'代替。

+0

感谢您的答复,但在这里我已经设置两个变量和b在(html2文件)全局,但我在主文件中调用我无法获得b的值。 – Anub 2013-05-14 08:48:23

相关问题