Re: Parsing files in python

Discussion in 'Python' started by Dennis Lee Bieber, Dec 24, 2012.

  1. On Mon, 24 Dec 2012 15:05:48 +1100, Chris Angelico <>
    declaimed the following in gmane.comp.python.general:


    >
    > It would also require some smart footwork at the export end,
    > recognizing that a tuple needs to be output with angle brackets.
    >

    That's the easy part... If you don't use raw tuples but define a
    class for POV vectors...

    >>> class Vector(object):

    .... def __init__(self, tpl):
    .... self.vct = tpl
    .... def __str__(self):
    .... itms = ", ".join([str(x) for x in self.vct])
    .... return "< " + itms + " >"
    ....
    >>> x = Vector((1, 2, 3))
    >>> print x

    < 1, 2, 3 >
    >>>


    {Extending that to handle a non-tuple initialization -- Vector(1, 2, 3)
    -- and operations that return Vector objects... say "y = x * 2", is
    left, as they say, as an exercise for the student <G>}
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Dec 24, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    857
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    561
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    588
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    414
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    708
    John Levine
    Feb 2, 2012
Loading...

Share This Page