1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python put space every two characters [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to modify a file containing a hex dump. There are 33 lines which contain strings like this:

    0000000000000000b00b8000c7600795
    0001906da451000000008fac0b000000


    I would like to put two spaces after every two characters, like this:

    00 00 00 00 00 00 00 00 b0 0b 80 00 c7 60 07 95


    So far I've made this script that works, but it puts two spaces in each character. I can't see what parameter I can use with .join() to make it every two characters:

    import os

    os.rename( 'hex_dump.txt', 'hex_dump.old' )

    destination = open( 'hex_dump.txt', "w" )
    source = open( 'hex_dump.old', "r" )
    for line in source:
    if len(line) > 2:
    destination.write(" ".join(line))
    source.close()
    destination.close()

    Continue reading...

Compartilhe esta Página