[英]Python multi-line string losing formatting
I am making a hangman game, which gets the hangman shape from a list. 我正在制作一个子手游戏,该游戏从列表中获得了子手的形状。 For some reason though, because each image is in a multiline string, somehow it loses formatting so that one line goes on the same as another. 但是由于某种原因,由于每个图像都位于多行字符串中,因此某种程度上它会丢失格式,从而使一行与另一行相同。
Here's the code: 这是代码:
'''
___________.._______
| .__________))______|
| | / / ||
| |/ / ||
| | / ||.-''.
| |/ |/ _ \
| | || `/,| #this line!
| | (\\`_.'
| | -`--'
| | | |
| | | |
| | | |
| | | _ |
| |
| |
| |
| |
| |
""""""""""""""""""""""""|
|"|"""""""\ \ '"|"|
| | \ \ | |
: : \ \ : :
. . `' . .'''
Obviously, where it say's '#this line!', that's the one that moves up. 显然,在说“ #this line!”的地方,那是向上移动的那一行。 I can provide the rest of the list if required. 如果需要,我可以提供列表的其余部分。
Thanks! 谢谢! :) :)
Try escaping the \\ (backslash). 尝试转义\\(反斜杠)。
Clarification: the line before the line that moves up ends in a '\\', this character has special meaning, if you escape it by adding another '\\' it will work properly, so change it to '\\\\'. 说明:向上移动的行之前以“ \\”结尾,此字符具有特殊含义,如果通过添加另一个“ \\”将其转义,它将正常工作,因此请将其更改为“ \\\\”。
The other thing you can do is to define your string as a raw string: 您可以做的另一件事是将字符串定义为原始字符串:
a = r ''' a = r '''
... ...
''' '''
Note the 'r' character before the string definition 注意字符串定义之前的“ r”字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.