简体   繁体   English

如何修复 Spyder 上的缩进/制表符问题

[英]How to fix indentation / tab issue on Spyder

I'm trying to get the python shell to display this print statement without the large gap at the backslash.我试图让 python shell 显示此打印语句,而在反斜杠处没有大的间隙。 I have already tried going into Source > Fix indentation.我已经尝试进入 Source > Fix indentation。

    print('\nAverage median \
           income in {:2s}: ${:<10,.2f}'.format(state, income))
Average median        income in MI: $51,601.37

Any guidance helps, thanks!任何指导都有帮助,谢谢!

Try removing the tab before 'income' in ur code print('\nAverage median \income in {:2s}: ${:<10,.2f}'.format(state, income))尝试在你的代码print('\nAverage median \income in {:2s}: ${:<10,.2f}'.format(state, income))删除“income”之前的选项卡

This is not a Spyder problem.这不是 Spyder 的问题。 It's your code.这是你的代码。 I think your backslash was intending to separate a line of code across two lines, but the backslash must be outside of your string, otherwise you're just escaping a space inside a string.我认为您的反斜杠打算将一行代码分隔成两行,但反斜杠必须在您的字符串之外,否则您只是 escaping 字符串内的空格。 If you must keep the code separated on two lines while preserving indentation, simply close your quotes and reopen them, keeping the backslash outside the quotes:如果您必须在保留缩进的同时将代码分隔为两行,只需关闭引号并重新打开它们,将反斜杠保留在引号之外:

print('\nAverage median ' \
       'income in {:2s}: ${:<10,.2f}'.format(state, income))
Average median income in MI: $51,601.37

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM