相关疑难解决方法(0)

在Notepad ++中将制表符转换为空格

如何在Notebookpad ++中将制表符转换为空格?

我发现一个网页表明它是可能的,但我找不到任何有关如何操作的信息.

我希望能够做到这一点,因为一些Web表单不尊重带有选项卡的代码.

whitespace notepad++ indentation

1042
推荐指数
9
解决办法
70万
查看次数

为什么我会收到"IndentationError:期望缩进块"?

if len(trashed_files) == 0 :
    print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir)
else :
    index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1))
    if index == "*" :
        for tfile in trashed_files :
            try:
                tfile.restore()
            except IOError, e:
                import sys
                print >> sys.stderr, str(e)
                sys.exit(1)
    elif index == "" :
        print "Exiting"
    else :
        index = int(index)
        try:
            trashed_files[index].restore()
        except IOError, e:
            import sys
            print >> sys.stderr, str(e)
            sys.exit(1)
Run Code Online (Sandbox Code Playgroud)

我正进入(状态:

        elif index == "" :
        ^
    IndentationError: expected …
Run Code Online (Sandbox Code Playgroud)

python

50
推荐指数
2
解决办法
37万
查看次数

我得到一个IndentationError.我如何解决它?

我有一个Python脚本:

if True:
    if False:
        print('foo')
   print('bar')
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行我的脚本时,Python提出了一个IndentationError:

  File "script.py", line 4
    print('bar')
               ^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

我一直在玩我的程序,我还能够产生其他三个错误:

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation

这些错误意味着什么?我究竟做错了什么?我该如何修复我的代码?

python error-handling code-formatting exception indentation

38
推荐指数
1
解决办法
2万
查看次数

Python:"缩进错误:unindent与任何外部缩进级别都不匹配"

我只是无法弄清楚这有什么问题......

#!/usr/bin/env python
#
#       Bugs.py
#       

from __future__ import division

# No Module!
if __name__ != '__main__': 
    print "Bugs.py is not meant to be a module"
    exit()

# App
import pygame, sys, random, math
pygame.init()

# Configuration Vars
conf = {
    "start_energy": 50, 
    "food_energy": 25, 
    "mate_minenergy": 50, 
    "mate_useenergy": 35, 
    "lifespan": 300000
}

class Bugs:
    def __init__(self):
        self.list  = []
        self.timers= {}
        # Names / colors for sexes
        self.sex = ["Male", "Female"]
        self.color = ["#CBCB25", "#A52A2A"]
        # Bug info tracking …
Run Code Online (Sandbox Code Playgroud)

python indentation

25
推荐指数
4
解决办法
12万
查看次数

Python IndentationError unindent与任何外部缩进级别都不匹配

我是初学者python,

我有这个错误:

Error : 
def on_data(self,data):
                      ^
IdentationError : unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

我用notepad++in 编码windows 8.1.我不明白为什么我有这个错误,我已经注意到标签和空间.

我想在self.file中保存数据

这是我的代码:

from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from tweepy import Stream
import tweepy
import time



class StdOutListener(StreamListener):

    def __init__(self,file):
        self.file = file

    def on_data(self, data):

        print data
        self.file.write(data)
        return True

    def on_error(self, status):
        print status


def main() :
    file = open('work.txt','w')
    listn = StdOutListener(file)
    consumer_key=""
    consumer_secret=""

    access_token=""
    access_token_secret=""

    auth = tweepy.OAuthHandler(consumer_key, …
Run Code Online (Sandbox Code Playgroud)

python indentation

8
推荐指数
2
解决办法
16万
查看次数

PYTHON ERROR:IndentationError:unindent与任何外部缩进级别都不匹配

运行这段代码时:

#timestamp, capture, and tweet an image
def stamp_cap_tweet():    
    timestamp = time.strftime("%d%m%Y-%H%M%S")
    os.system("fswebcam -r 960x720 -d /dev/video0 " + timestamp + ".jpg") #save image to disk
    twit.update_status_with_media(timestamp + ".jpg", status = "@shahidrogers " + timestamp) #tweet image @username
    print "Tweeted image at " + timestamp #make a record in the Python output
Run Code Online (Sandbox Code Playgroud)

我收到了错误

文件"tweetpicture.py",第17行

os.system("fswebcam -r 960x720 -d /dev/video0 " + timestamp + ".jpg")                                                  
                                                                    ^                                                   IndentationError:
Run Code Online (Sandbox Code Playgroud)

unindent与任何外部缩进级别都不匹配

这可能意味着什么?我已经四处搜索,人们已经说过有标签和空格的混合,但我完全不理解这一点,因为我还是Python的新手,这是我的前几行编码.

谢谢!

python

2
推荐指数
1
解决办法
2万
查看次数