0

I'm using Python to recreate a program that have been written in Fortran 95, the program opens a binary file, containing only float numbers, and read a specific value, it works just fine in Fortran, when I execute the code, I get 284.69 for example. Although, when I try to do the same in Python, reading the entire first line of the file, I get characters like these:

Y{�C�x�Cz~�C�x�C�j�C�r�C�v�Ch�Ck�CVx�C

Here is how I open the file and read the values:

f = open(args.model_files[0], "r").readlines() print str(f[0])

I can't provide a file as example, because it is too big, but I affirm that there is only float numbers.

I would like to at least understand what type of characters I'm getting, or what I'm doing wrong when opening the file, any suggestion is welcome.

3
  • If file is binary you probably should use 'rb' mode Commented May 21, 2018 at 18:44
  • Check this out stackoverflow.com/questions/6286033/… Commented May 21, 2018 at 18:45
  • @MoxieBall that helped a lot, thank you! Commented May 21, 2018 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.