0

Using the below Python scripts i can able to create html file by already set the variables(a,b,c,d) as global.I want to run the script dynamically, even also i don't set some variables as globally ,for eg: if we didn't set the value of "a" as global it throwing error "global 'a' is not defined".So please let me know any python scripts for dynamically taking the values and convert them in to html table.

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)
2
  • 3
    Taking the values from where? Commented May 21, 2013 at 8:25
  • It is in seperate file html2, so we give import html2. Commented May 21, 2013 at 10:19

1 Answer 1

3

table_data needs a, b, etc. to be defined. It incorporates their values into a new global.

This has otherwise nothing to do with HTML.table(); your table_data list cannot be defined as it currently stands without a and b being defined as well.

If you want a, b, c and d used as parameters from another module, you need to make this a function:

def create_table(a, b, c, d):
    table_data = [
    ['S.No',   'Testcase - ID',   'Result'],
    ['1',       a,         b],
    ['2',       c,         d],

    ]
    return HTML.table(table_data)

Now you can call create_table() with different parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Martijin for your reply, but we using this script to get the final output as HTML file, so we take regular expression and store the variables as output and again declare that variable as global then call the variable in html Scripts here we set, a-TC-01 ,b-Passed,c-TC-02,d- Passed: but if we didnt run Testcase 1 we cannot able to take the output and store the variable in 'a' and 'b'on that case it throwing error "global a is not defined" so please let me know any python scripts to take the values dynamically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.