'F String Returns on new line [closed]
I am building a song metadata library and the f string keeps returning a new line on the BPM String I added:
def all(self):
return '{} {} {} {} {} {} {} {} {} {} {}'.format(self.title,
self.length,
self.scale,
(f"{self.bpm} BPM"),
self.timesignature,
self.lyrics,
self.start,
self.end,
self.release,
self.album,
self.notes)
How do I keep the BPM string on the same line?
This is the output:
Incunabula
3:21
C Aeolian
69
BPM 4/4
BPM should be right after the 69.
Solution 1:[1]
As identified by @Selcuk, some of your strings contains whitespaces.
You can strip whitespaces (that includes newline) by using str.strip(). It removes surrounding whitespaces (before or after the string)
In your case, you can replace your BPM line (or any line that has whitespaces around it) with this.
...
(f"{self.bpm.strip()} BPM"),
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
