-2

I am trying to print to a textfile, but I keep getting this output :

array = ('0', '0', '0', '0') 

the desired output I want is

array = 0 0 0 0

here is the code snippet im having problems with.

nonCharge_reference = self.ui.nonCharge_reference_textbox.text()
    nonCharge_Engine_1 = self.ui.nonCharge_engine1_textbox.text()
    nonCharge_Engine_2 = self.ui.nonCharge_engine2_textbox.text()
    nonCharge_Engine_3 = self.ui.nonCharge_engine3_textbox.text()
print(f'#',
"\n"f'array = {nonCharge_reference, nonCharge_Engine_1, nonCharge_Engine_2,nonCharge_Engine_3,}'
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
juice
  • 23
  • 4

3 Answers3

1

Don't put them in a single {}. That's creating a tuple and then printing that. Format each variable separately.

print(f'#\narray = {nonCharge_reference} {nonCharge_Engine_1} {nonCharge_Engine_2} {nonCharge_Engine_3}')
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

Use <string>.join(<array>)

0

You can use the join method to concatenate those items in a string. This way: str_array = " ".join(array). This will concatenate elements in the array, separating them by an space " ". str_array will have that value. For more info, check out the documentation at Python docs