gpt4 book ai didi

python - 在不同的函数中多次读取文本文件并在Python的一个主函数中访问这些函数

转载 作者:行者123 更新时间:2023-12-01 05:12:52 26 4
gpt4 key购买 nike

我正在尝试在不同的函数中多次读取文本文件,并在一个主函数中访问这些函数。

我的主要功能代码:

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)

关于python - 在不同的函数中多次读取文本文件并在Python的一个主函数中访问这些函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23810126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com