IndentationError: unexpected indent python
来源:互联网 发布:ubuntu 修改apt get源 编辑:程序博客网 时间:2024/05/16 05:58
转自: http://dikar.iteye.com/blog/308934
都知道python是对格式要求很严格的,写了一些python但是也没发现他严格在哪里,今天遇到了IndentationError: unexpected indent错误我才知道他是多么的严格。
以后遇到了IndentationError: unexpected indent你就要知道python编译器是在告诉你“Hi,老兄,你的文件里格式不对了,可能是tab和空格没对齐的问题,你需要检查下tab和空格了”。
在windows上你可以用editplus看的,虽然我不知道怎么显示出tab,但是他能显示你的文件是没对齐的,我是在ubuntu上编写python的。我用的是vim,你可以设置下vim中tab用空格替换,我在前一篇文章里写过关于这个设置的问题,我现在在补充一下,之前是在系统目录下设置的,现在我要在home目录下设置;
首先 cd ~(到你的home目录)
然后 ls -a(显示隐藏的文件)
找到.vimrc(记得是带个点前缀的)
然后编辑这个文件
找到如下的命令:
16 set autoindent
17 set smartindent
19 set tabstop=4
20 set shiftwidth=4
21 set softtabstop=4
22 set noexpandtab
然后在set tabstop=4前面加上set expandtab同时你需要把set noexpandtab这个注释掉,怎么注释呢,就是加个双引号。我没试过直接注释不加set expandtab,我想也可以(难道默认是expandtab)。这样你可以放心使用VIM了。
当然我并不是想就这样完事,我其实想看下我的代码到底哪里会有问题呢,就需要看下他的格式了,主要是看tab,这个可以同样在刚才那个文件里设置,在刚才设置的下面比如说
在set softtabstop=4下面加上一句set list。这句就可以让你的vim打开的文件显示出tab了,当然也许你觉得显示的不好看,他显示的样子是“^I”一个数字键6上那个符号和一个大写的I表示一个tab,这个不会显示出空格。他还会显示出段落的起始符^和终止符$,如果不知道这2个符号可以看下正则表达式。
以上2点设置以后,我想以后你就不会遇到IndentationError: unexpected indent这个很烦人的错误了。
以上的set命令都可以单独使用,但是只对当前打开的vim有效,你可以按下shift加冒号,然后输入set XXX,回车然后就有效果了,但是你要再次进入编辑模式才能看到。
希望分享给每个写python的人。
- IndentationError: unexpected indent python
- IndentationError: unexpected indent python
- IndentationError: unexpected indent python
- IndentationError: unexpected indent python
- python:IndentationError: unexpected indent
- IndentationError: unexpected indent python
- IndentationError: unexpected indent python
- Python的IndentationError: unexpected indent
- python错误:IndentationError: unexpected indent
- python报"IndentationError: unexpected indent"
- Python错误IndentationError: unexpected indent
- python的IndentationError: unexpected indent python
- python报"IndentationError: unexpected indent"的解决方法.
- python报错:IndentationError: unexpected indent
- Python编程错误之IndentationError: unexpected indent
- Python 报错:IndentationError: unexpected indent
- IndentationError: unexpected indent python格式问题
- python报"IndentationError: unexpected indent"的解决方法.
- YII2中常用的页面跳转,以及获取用户信息和登录信息等信息总结
- MongoDB简介和基本概念(一)
- C++静态初始化的顺序
- Poj 2689 Prime Distance(素数筛+二次素数筛)
- oracle注册表删除--彻底卸载Oracle
- IndentationError: unexpected indent python
- easyui中datagrid显示数据的时候报Cannot read property 'length' of undefined
- Android中Bitmap的加载和Cache(三级缓存 :LruCache,DiskLruCache)学习笔记
- mysql57 windows zip install
- ssh-keygen的详解----本人亲自验证过
- Fiddler实现手机抓包——风云无忌
- pthread_cond_broadcast()
- CAS4.2.7 的 php 客户端1.3.5 的简单实践
- IC设计基础系列之低功耗篇5:(数字IC)低功耗设计入门(五)——RTL级低功耗设计(续)