FAQ
Hello there.

Since this is one of those problems that may have some painfully
simple solution that will make me feel like a fool, I'll start of with
this: it's _very_ late (.. yeah, it's not).

To the point.

Data returned by socket.recvfrom is a string. Obviously one that most
of the time will contain non-printable characters. Let's say
data[10:14] is a four byte integer. How can I convert the string
data[10:14] to a python integer object?

Or perhaps there's a totally different, *Pythonic*, approach to this
(extracting data from these packet-representing strings). C may have
poisoned my mind.

Thanks for reading, hoping for some ideas.

Search Discussions

  • MRAB at Apr 28, 2010 at 9:03 pm

    Maligree wrote:
    Hello there.

    Since this is one of those problems that may have some painfully
    simple solution that will make me feel like a fool, I'll start of with
    this: it's _very_ late (.. yeah, it's not).

    To the point.

    Data returned by socket.recvfrom is a string. Obviously one that most
    of the time will contain non-printable characters. Let's say
    data[10:14] is a four byte integer. How can I convert the string
    data[10:14] to a python integer object?

    Or perhaps there's a totally different, *Pythonic*, approach to this
    (extracting data from these packet-representing strings). C may have
    poisoned my mind.

    Thanks for reading, hoping for some ideas.
    Use the 'unpack' function from the 'struct' module.
  • Maligree at Apr 28, 2010 at 9:14 pm

    On Apr 28, 11:03?pm, MRAB wrote:
    Maligree wrote:
    Hello there.
    Since this is one of those problems that may have some painfully
    simple solution that will make me feel like a fool, I'll start of with
    this: it's _very_ late (.. yeah, it's not).
    To the point.
    Data returned by socket.recvfrom is a string. Obviously one that most
    of the time will contain non-printable characters. Let's say
    data[10:14] is a four byte integer. How can I convert the string
    data[10:14] to a python integer object?
    Or perhaps there's a totally different, *Pythonic*, approach to this
    (extracting data from these packet-representing strings). C may have
    poisoned my mind.
    Thanks for reading, hoping for some ideas.
    Use the 'unpack' function from the 'struct' module.
    Ah, thanks a lot.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 28, '10 at 8:48p
activeApr 28, '10 at 9:14p
posts3
users2
websitepython.org

2 users in discussion

Maligree: 2 posts MRAB: 1 post

People

Translate

site design / logo © 2022 Grokbase