wrong output when python tries to read a text file from mql5

 

hello
i have a script in mql5 that creates a text file with one string "hello"
when i try to read my text file with python , the output is wrong "ÿþhello"
my code in mql5 :
  int handle=FileOpen("file.txt",FILE_WRITE|FILE_TXT);
  FileWriteString(handle,"hello");
  FileClose(handle);

and in python:

    path="file.txt"
    text=open(path,"r")
    text_string=text.readline(44)
    print(text_string)

please tell me why the result is wrong!
i tried this script in mql4 and it worked correctly , but in mql5 gives me wrong value
help me please 
 
Amini1382: i have a script in mql5 that creates a text file with one string "hello" when i try to read my text file with python , the output is wrong "ÿþhello" my code in mql5 : and in python:

please tell me why the result is wrong! i tried this script in mql4 and it worked correctly , but in mql5 gives me wrong value help me please 

The result is not wrong. You must decide if you want an ASCII/ANSI file or a Unicode file.

You did not specify the format when you create the file, so it defaulted to a UTF format, with a Byte Order Mark (BOM) header at the beginning of the file.

If you want an ASCII or ANSI file, then specify it and the codepage when you create the file in MQL5.

EDIT: Alternatively have Python read it as Unicode or auto-detect. I don't use Python so don't know how that is done.

 
Fernando Carreiro #:

The result is not wrong. You must decide if you want an ASCII/ANSI file or a Unicode file.

You did not specify the format when you create the file, so it defaulted to a UTF format, with a Byte Order Mark (BOM) header at the beginning of the file.

If you want an ASCII or ANSI file, then specify it and the codepage when you create the file in MQL5.

EDIT: Alternatively have Python read it as Unicode or auto-detect. I don't use Python so don't know how that is done.

thank you very much !

your advice works for me

my python gives right value when i change :

int handle=FileOpen("file.txt",FILE_WRITE|FILE_TXT);

to :

int handle=FileOpen("file.txt",FILE_WRITE|FILE_TXT|FILE_ANSI);
Reason: