我有以下python代码,应该找到单词" ACT"在一个文件中。一旦发现" ACT"它应该写下输出文件后面的所有行。我的代码将输入文件中的所有内容写入输出文件。我做错了什么?
found_ACT = False
for line in inputFile:
line.strip()
if found_ACT:
outputFile.write(line)
else:
if "ACT" in line:
found_ACT = True
答案 0 :(得分:0)
如果found_ACT
中找不到False
,则永远不会将line
更改为found_ACT = False
。您应该将"ACT" in line
放在循环中,或者直接使用for line in inputFile:
line.strip()
if "ACT" in line:
outputFile.write(line)
。
public static dynamic GetSomeData(ParameterDTO dto)
{
dynamic result = null;
string SPName = "a_legacy_stored_procedure";
using (SqlConnection connection = new SqlConnection(DataConnection.ConnectionString))
{
SqlCommand command = new SqlCommand(SPName, connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@empid", dto.EmpID));
command.Parameters.Add(new SqlParameter("@deptid", dto.DeptID));
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
dynamic row = new ExpandoObject();
row.EmpName = reader["EmpFullName"].ToString();
row.DeptName = reader["DeptName"].ToString();
row.AnotherColumn = reader["AnotherColumn"].ToString();
result = row;
}
}
}
return result;
}