我正在尝试使用MQL4创建文本文件。没有成功。就是行不通。一个非常简单的脚本:
@app.route('/unfavorite', methods=["GET","POST"])
def unfavourite:
if request.method == "POST":
any_variable_name = request.form.get("variable_name_to_access_in_python","")
print(any_variable_name) #If you want to print
return any_variable_name #If you want to see any_variable_name on web
return None
这将引发错误5002。确定,该文件不存在。我认为该脚本将创建文件。
因此,我决定使用文件夹中的记事本创建一个临时性“ teste2.txt”。同样的错误。
有人可以帮我吗?
谢谢
答案 0 :(得分:0)
如果调用文件string filename="A"+"\\B\\"+"teste2.txt";
,它将被写入TerminalInfoString(TERMINAL_DATA_PATH)
\ MQL4 \ Files \ A \ B \文件夹中。当然,您不能在文件名中使用禁止的符号,并且禁止使用完整路径(C:\ Users \ User_NAME \ AppData ...)中的“:\”
答案 1 :(得分:0)
该文件默认情况下是在... / MQL4 / Files中编写的,因此只需编写该代码即可(它创建一个名为teste2.txt的文件,并在... / MQL4 / Files中写入了teste):>
void OnStart()
{
int filehandle = FileOpen("teste2.txt",FILE_WRITE|FILE_TXT);
FileWriteString(filehandle,"teste");
FileClose(filehandle);
}
当然,您将需要检查FileX函数(FileOpen,fileWrite,FileClose等)的返回情况
答案 2 :(得分:0)
首先,您需要检查是否有文件。
//+------------------------------------------------------------------+
//| FileIsExist.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
string filename = "teste2.txt";
int fileHandle ;
if(FileIsExist(filename,0))
{
Print("Specified File Has");
fileHandle = FileOpen(filename , FILE_WRITE|FILE_TXT);
FileWriteString(fileHandle,"teste");
FileClose(fileHandle);
Print("Write to Existing File Completed");
}else
{
Print("File Not Available, Regenerating....." );
fileHandle = FileOpen(filename , FILE_READ|FILE_WRITE|FILE_TXT);
FileWriteString(fileHandle,"Writing to Newly Created File Completed - teste \n");
FileClose(fileHandle);
Print("Writing to Newly Created File Completed");
}
}
//+------------------------------------------------------------------+