Jump to content
Fórum Script Brasil
  • 0

Manipulando arquivos com extensão .dat em python


andersonparagao
 Share

Question

Bom dia pessoal!

Estou tentando fazer uma rotina que leia um arquivo de extensão .dat e quero converte-lo em um .txt com os dados decimais. Alguém pode me ajudar?

esse é o trecho do código que eu fiz:

from struct import *
arq = open('VAZOES.DAT', 'rb')
a = arq.readline()
arq.close()
print(a)
for line in a:
print(line, end = ' ')
a saída do print(a) é:
b'\xb2\x00\x00\x00\xb2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4\x05\x00\x00\x9a\x06\x00\x00\xc9\x06\x00\x00\xdf\x06\x00\x00\x1b\x07\x00\x00\x93\x07\x00\x00\xa2\x08\x00\x00\x00\x00\x00\x00\x98\x00\x00\x00\x03\x01\x00\x00\x07\x01\x00\x00l\r\x00\x00\xec\x0f\x00\x00\x00\x00\x00\[email protected]\x01\x00\x00\x00\x00\x00\x00\xce\x00\x00\x00\x1d\x01\x00\x00\x90\x03\x00\x00I\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n'
e a saída do print(line, end = ' ') é:
178 0 0 0 178 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 196 5 0 0 154 6 0 0 201 6 0 0 223 6 0 0 27 7 0 0 147 7 0 0 162 8 0 0 0 0 0 0 152 0 0 0 3 1 0 0 7 1 0 0 108 13 0 0 236 15 0 0 0 0 0 0 64 1 0 0 0 0 0 0 206 0 0 0 29 1 0 0 144 3 0 0 73 2 0 0 0 0 0 0 0 0 0 0 200 2 0 0 0 0 0 0 0 0 0 0 10
porém o resultado não é esse, era pra ser algo assim:
1 1931 178 371 326 479 332 226 125 89 112 192 153 215
alguém pode me ajudar?
Desde já agradeço!
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...