![](/img/trans.png)
[英]call functions from python list one by one and run multiple times for one function
[英]Reading a text file multiple times in different functions and accessing these functions in one main function in python
我試圖以不同的功能多次讀取文本文件,並在一個主要功能中訪問這些功能。
我的主要功能代碼:
def Get_Input_And_Create_Ndf(Opened_File):
Node_Description(Opened_File)
Number_Of_Inputs = int(raw_input("Please enter number of GUI Parameters: "))
Input_Number = 0
for Input_Number in range(Number_Of_Inputs):
Input_Number = Input_Number+1
GUI_Parameter = str(raw_input("Please enter input parameter " + str(Input_Number) + " :"))
Data_Type = str(raw_input("Please select any of the following data type \n double \n float \n unsigned char \n string \n int \n long \n bool \n long double \n long long :"))
Default_Value = str(raw_input("Please select the default value for the parameter (Press Enter to skip): "))
Render_Option = str(raw_input("Please set the rendering mode (Select either cpu or gpu) :"))
if (Input_Number == 1):
Instructions_And_Brackets(Opened_File, "messages", "(")
if (Input_Number == 1, Input_Number <= Number_Of_Inputs):
pass
Message_Description(Opened_File, GUI_Parameter, Data_Type, Default_Value)
if (Input_Number == Number_Of_Inputs):
Instructions_And_Brackets(Opened_File, "", ")")
else:
pass
Cpp_File_Path = Get_Cpp_File()
Opened_Cpp_File = Open_Cpp_File(Cpp_File_Path)
Instructions_And_Brackets(Opened_File, "members", "{{")
Found_Mem_Functions = Find_Member_Functions(Opened_File, Opened_Cpp_File)
Instructions_And_Brackets(Opened_File, " ", "}};")
Instructions_And_Brackets(Opened_File, "prepend ", "{{ \n")
Prepended_Data = Find_Prepend_Data(Opened_File, Opened_Cpp_File)
Instructions_And_Brackets(Opened_File, "", "}}; \n")
Instructions_And_Brackets(Opened_File, "append", "{{ \n")
Function_Definition_Data = Find_Function_Definitions(Opened_File, Opened_Cpp_File)
有問題的功能:
Found_Mem_Functions = Find_Member_Functions(Opened_File, Opened_Cpp_File)
Prepended_Data = Find_Prepend_Data(Opened_File, Opened_Cpp_File)
Function_Definition_Data = Find_Function_Definitions(Opened_File, Opened_Cpp_File)
當我注釋掉其他兩個功能並僅使用一個功能時,所有功能都可以正常工作。 但是,如果我在主要功能中同時擁有所有三個功能。 只有我首先聲明的功能有效。 在這里Find_Member_Functions 。 我不明白這里出了什么問題!...
重置功能的實現:
def Reset_File(Opened_File, Opened_Cpp_File):
Opened_File.seek(0)
Opened_Cpp_File.seek(0)
return
您需要在每次調用后重置文件。 由於每個函數調用都會占用文件,因此您可以將文件光標設置回文件的開頭。
Opened_File.seek(0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.