Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:48:55+00:00 2026-05-23T00:48:55+00:00

Here is how I reproduce the problem: Create a log file called ‘temp.log’ and

  • 0

Here is how I reproduce the problem:

Create a log file called ‘temp.log’ and paste this line into it

DEBUG: packetReceived '\x61\x62\x63'

I want to have a script which will read the line from the log file and decode the binary string part (‘\x61\x62\x63’). For the decoding, I am using struct, so:

struct.unpack('BBB', '\x61\x62\x63')

Should give me

(97, 98, 99)

Here is the script which I am using

import re
import struct
import sys

f = open(sys.argv[1], 'r')
for line in f:
    print line
    packet = re.compile(r"packetReceived \'(.*)\'").search(line).group(1)

    # packet is the string r'\x61\x62\x63'
    assert(len(packet), 12)

    # this works ok (returns (97, 98, 99))
    struct.unpack('BBB', '\x61\x62\x63')

    # this fails because packet is interpreted as r'\\x61\\x62\x63'
    struct.unpack('BBB', packet)

I run the script using temp.log as the argument to the script.

Hopefully the comments highlight my problem. How can I get the variable packet to be interpreted as ‘\x61\x62\x63’ ??

ASIDE: On the first edit of this question, I assumed that reading the line from the file was the same as this:
line = “DEBUG: packetReceived ‘\x61\x62\x63′”
which made packet == ‘abc’

however it is actually the same as this (using rawstring)
line = r”DEBUG: packetReceived ‘\x61\x62\x63′”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:48:56+00:00Added an answer on May 23, 2026 at 12:48 am

    As described in your question, packet is equal to '\x61\x62\x63'. Its len is 12 bytes, neither 15 nor 3 bytes.

    What confuses you, is that ipython (which I understand you are using) and the python interpreter display values using the repr() call, which tries to format values as they would be in your code. Since backslashes are special in Python string constants, repr() displays them duplicated, as they would be in Python code.

    This might be of help:

    for char in packet:
        print("%5d %2s %2r" % (ord(char), char, char))
    

    Count your characters and see how they are printed. First column displays the ordinal value of the character, second column has the character itself, third column has the repr of the character.

    EDIT

    Change the last line:

    struct.unpack('BBB', packet)
    

    to:

    struct.unpack('BBB', packet.decode('string_escape'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am playing around with this page: http://www.problemio.com/problems/problem.php?problem_id=228 To reproduce the problem, log in
Here's the simple test to reproduce the issue, this is the single class in
Here's a problem I ran into recently. I have attributes strings of the form
Here's a coding problem for those that like this kind of thing. Let's see
Here is the code to reproduce the problem: sub hello { return (h =>
Android 2.1 - Eclipse What steps will reproduce the problem? 1. Create new Texture(managed)
This query appears in mysql slow query log: it takes 11 seconds. INSERT INTO
I'm developing an Eclipse plug-in and I have a problem which is reproduced here:
Here's a page with the issue To reproduce the error, using IE - click
I've ran into one small problem. I am dynamically generating some controls and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.