LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Converting a Shell script to a Python script (https://www.linuxquestions.org/questions/programming-9/converting-a-shell-script-to-a-python-script-785331/)

Aquarius_Girl 01-28-2010 06:50 AM

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

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

Code:

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 !!

ghostdog74 01-28-2010 08:04 AM

first, then you need to start getting to know Python. Go to the docs (see my sig) and read the tutorial

bgeddy 01-28-2010 12:11 PM

The requirement is really quite trivial given a knowledge of python so for when you are familiar with python or for anyone else following this - coincidentally I just came across this package Scripy which looks interesting and relevant to this thread. I've not used this myself so can't comment on its merits.

Aquarius_Girl 01-28-2010 11:54 PM

Quote:

Originally Posted by ghostdog74
first, then you need to start getting to know Python. Go to the docs (see my sig) and read the tutorial

Thanks for replying!

I did study little python 3 years back, don't have much time to go all over again right now..

I'll be great-full if some one could give me a hint or a pointer for this problem..

Aquarius_Girl 01-29-2010 12:27 AM

Oh I just did this right now and it worked (for now):

Code:

fileHandle = open ( 'test.html', 'a' )
fileHandle.write ('\n'.join(doc))
fileHandle.close()



All times are GMT -5. The time now is 12:32 AM.