This is the python code from a file 'legend.py' that prints the contents of variable 'doc' to console:

print '\n'.join (doc)

Now through the above code, whatever is inside doc gets written to the console, if I run python legend.py description.xml

Below is a shell script :

for z in {0..1}; do python legend.py -z $z description.xml > $z.html; done

The above script takes as an input the above mentioned python file 'legend.py' and 'description.xml' as an input of 'legend.py'

and

Then it generates 0.html and 1.html files containing the contents of variable 'doc'

Problem statement:

I want to write a python code, which writes the contents of doc to an html file, inside 'legend.py'

rather than through the command prompt !!

I tried searching Google but couldn't get much help,

Please guide if you can !!

Oh I did manage to solve it as follows:

fileHandle = open ( 'test.html', 'a' )
fileHandle.write ('\n'.join(doc))
fileHandle.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.