Re: How to port bytes formatting to Python 3.x ?

Discussion in 'Python' started by Stefan Behnel, Jan 1, 2011.

  1. Baptiste Lepilleur, 01.01.2011 12:53:
    > 2011/1/1 Stefan Behnel
    >> Baptiste Lepilleur, 01.01.2011 10:01:
    >>> I'm trying to port a small library to Python 3.x, and I'm wondering what
    >>> is the best way to port statements such as the one belows that are
    >>> frequently found in network protocol implementation:
    >>> ...
    >>>

    >> See my answer in the other thread you started on this topic. You need to
    >> wrap the literal in a function call that converts it to a bytes literal when
    >> running in Python 3.

    >
    > Is there a robust implementation of the format operator % for bytes that can
    > substitute %s?


    Concatenation is portable and seems to suite your examples (which you
    stripped above). For more involved cases (as are also likely to occur in
    network protocol code), have a look at the struct module.

    http://docs.python.org/py3k/library/struct.html

    Stefan
    Stefan Behnel, Jan 1, 2011
    #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. Jason Collins
    Replies:
    3
    Views:
    5,992
    Jason Collins
    Feb 18, 2004
  2. mrby

    4-bytes or 8-bytes alignment?

    mrby, Nov 2, 2004, in forum: C Programming
    Replies:
    8
    Views:
    402
    Mark McIntyre
    Nov 2, 2004
  3. Replies:
    5
    Views:
    515
    Flash Gordon
    Apr 9, 2006
  4. Yandos
    Replies:
    12
    Views:
    5,097
    Pete Becker
    Sep 15, 2005
  5. Replies:
    8
    Views:
    482
    Bob Hairgrove
    Apr 10, 2006
Loading...

Share This Page