1

I am trying to get the output of my code formatted in the following way:

Expected:

 1 aggc tgtc aatg
13 ctag gcat agaa
25 gtcg tgct gtag
37 agat agtc tgat
49 agtc gc

However, I always get the following output:

1 aggc tgtc aatg13 ctag gcat agaa25 gtcg tgct gtag37 agat agtc tgat49 agtc gc

I'm not sure how to get a new line where it is supposed to be. Can someone help me with this? Thanks a lot!

Here is my code so far that created this output (it is part of a certain function):

to_return += f'{str(index_row): >} {block_row}'
return to_return

EDIT: I came across another problem: Does anyone know how I can align the 1 in the first row to the right? I thought that the ">" sign in my code would do the trick, but my 1 stays aligned to the left side.

2
  • 4
    Your code doesn't have any newline characters. You'd want to have a \n appended to the string when your row ends Commented Jan 4, 2022 at 15:14
  • Thanks for the help! Does anyone know how I can align the 1 in the first row to the right? I thought that the ">" sign in my code would do the trick, but my 1 stays aligned to the left side Commented Jan 4, 2022 at 16:43

2 Answers 2

3

Just add the newline character (\n) to the end of your string:

to_return += f'{str(index_row): >} {block_row}\n'
return to_return
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help! My code does exactly what it needs to do now.
2

Add a new-line character (\n) at the end of the line. Like this:

to_return += f'{str(index_row): >} {block_row}'+"\n"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.