Tab Character?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tbonejo@gmail.com

    Tab Character?

    How do I make a tab character in code to split a line read with tabs in
    it?


    Thanks.

    Tom

  • John Zenger

    #2
    Re: Tab Character?

    Tab is \t . As in:

    print "coke\tpeps i"
    tsvline.split(" \t")

    tbonejo@gmail.c om wrote:[color=blue]
    > How do I make a tab character in code to split a line read with tabs in
    > it?
    >
    >
    > Thanks.
    >
    > Tom
    >[/color]

    Comment

    • Ben Finney

      #3
      Re: Tab Character?

      "tbonejo@gmail. com" <tbonejo@gmail. com> writes:[color=blue]
      > How do I make a tab character in code to split a line read with tabs in
      > it?[/color]

      For such non-printing characters it's best not to have them literally
      in your code, but to use an escape sequence to generate them at
      run-time::
      [color=blue][color=green][color=darkred]
      >>> foo = "\t"
      >>> print foo[/color][/color][/color]
      [color=blue][color=green][color=darkred]
      >>> print ord(foo)[/color][/color][/color]
      9

      This is explained in the "String literals" section of the Python
      reference.

      <URL:http://docs.python.org/dev/ref/strings.html>

      --
      \ "A celebrity is one who is known by many people he is glad he |
      `\ doesn't know." -- Henry L. Mencken |
      _o__) |
      Ben Finney

      Comment

      • Larry Bates

        #4
        Re: Tab Character?

        tbonejo@gmail.c om wrote:[color=blue]
        > How do I make a tab character in code to split a line read with tabs in
        > it?
        >
        >
        > Thanks.
        >
        > Tom
        >[/color]
        You should also take a look at csv module. If you are reading lines
        that contain tab delimeted data the csv module can make splitting very
        easy.

        -Larry Bates

        Comment

        Working...