LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-28-2010, 06:50 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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 !!

Last edited by Aquarius_Girl; 01-28-2010 at 07:00 AM.
 
Old 01-28-2010, 08:04 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
first, then you need to start getting to know Python. Go to the docs (see my sig) and read the tutorial
 
Old 01-28-2010, 12:11 PM   #3
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 01-28-2010, 11:54 PM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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..
 
Old 01-29-2010, 12:27 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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()
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script for converting filenames to proper case? Yalla-One Programming 9 02-03-2010 02:37 AM
shell script and python? aedmlinux Linux - Laptop and Netbook 3 06-01-2009 10:38 AM
Converting a shell script with dialog boxes into a GNOME application kushalkoolwal Programming 4 10-17-2008 06:21 AM
Converting a Script from SHELL to PHP gcclinux Programming 3 02-21-2008 05:51 AM
converting shell script to php script ? ibro Linux - General 6 05-24-2004 05:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration