2013-05-13 23 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

相關問題