string - In Python 2.4, how can I strip out characters after ';'? -


Assume that I am parsing a file, which uses ; As a comment character, I do not want to parse the comments. So if I see a line like this:

  example.com. 600 in MX 8 s1b9.example.net; Hello!  

Is there a simple / more beautiful way to strip characters other than this:

  rtr = '' for the line in the file : Trig = false for line four: if not trig and char! = ';': Rtr + = char else: trig = true if rtr [max (rtr)]! = '\ N': rtr + = '\ n'   

I say that < / P>

  line.split (";") [0]  

which will give you a string of all the characters, but the first ";" character. If not ";" If the character is present, then it will give you the whole line.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -