Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

Reading from STDIN: python script.



  1. Recently I started to study python . In this site I present many scripts. For simple tasks, I use bash and for more complex ones perl. Since my daughter starts to study python , so do I.

  2. This script reads line by line from STDIN and checks if 192 is found in the beginning of the string. If so an asterisk is printed. If not a minus is printed.

  3. I had some problems using the method rstrip . From search in the web, I found that split works better. The code is shown below:

    #!/usr/bin/python

    #handle regular expression
    import re

    import sys

    for line_i in sys.stdin:
      #same as perl chomp
      #line.rstrip()
      line_a = line_i.splitlines()

      line = line_a[0]
      ix = line.find('192')
      #!= -1 pattern found somewhere in line
      #== 0 pattern found in string start
      if(ix == 0):
        print "* ", line
      else:
        print "- ", line




Search This Site


Feedback This Site




new pages on this site