Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what is the syntax for adding newline to this list expression

So I am trying to write a few different values of this list to a few specific lines of this text file essentially replacing them. I got a tip on my last question to seperate the lines in this output I need to do \n however I am struggling to implement this within this list expression. If I do it within the writeline command it gives me every line within the file with an extra whitespace line. If anyone has any ideas please let me know. this is the code:

def writeAPconstants(roll_pred , roll_resp, roll_error, roll_rate, roll_tunetime):





# takes line index to map function inputs as new autopilot constant values
APlist[line_index[0]]  = "P acf/_ott_phi_sec_into_future" ' ' + roll_pred
APlist[line_index[1]] = "P acf/_ott_roll_response" + ' ' + roll_resp
APlist[line_index[2]] = "P acf/_ott_phi_deg_off_for_full_def" + ' ' + roll_error
APlist[line_index[3]] = "P acf/_ott_roll_rate" + ' ' + roll_rate
APlist[line_index[4]] = "P acf/_ott_phi_sec_to_tune" + ' ' + roll_tunetime
APfile.seek(0)
APfile.writelines(APlist)
APfile.truncate()

#closes file
APfile.close()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The lines returned by readlines() have newlines appended. You need to add newlines to the end of each string you assign to a list member.

APlist[line_index[0]]  = "P acf/_ott_phi_sec_into_future" ' ' + roll_pred + '\n'
APlist[line_index[1]] = "P acf/_ott_roll_response" + ' ' + roll_resp + '\n'
APlist[line_index[2]] = "P acf/_ott_phi_deg_off_for_full_def" + ' ' + roll_error + '\n'
APlist[line_index[3]] = "P acf/_ott_roll_rate" + ' ' + roll_rate + '\n'
APlist[line_index[4]] = "P acf/_ott_phi_sec_to_tune" + ' ' + roll_tunetime + '\n'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading