Help required to read and print lines based on the type of first character

Abhinayaraj.Raju at Emulex.Com Abhinayaraj.Raju at Emulex.Com
Wed Mar 4 04:36:01 EST 2009


Hi,

I am a beginner in Python. In fact, beginner to coding/ scripting.

Here is a scenario, I need to code. Need your help on this:

A script that
1.      Reads from a file (may be a local file say test.txt)
2.      And, if the line begins with a "#", should print the line one time
3.      if the line has "##", should print the line 2 times,
4.      And, if there are "###" in the beginning of the line, should print the same line 3times,
5.      And, if the line contains "####" or more "#"'s, then print as "an invalid line"
6.      if the line contains no "#" then print "looks like a code line"

For this as far the info I could understand,

-       We need to use open('TextFile.txt') function
-       Need to start a While loop/ For in loop
-       By some means individually read every single line and check for the above conditions

In this regard, I wish you could guide on what kind of syntax/ structure/ commands to use.

Thanks
Abhi



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090304/580e7f20/attachment.html>


More information about the Python-list mailing list