我正在按照本书学习使用notepad ++的django,当我使用notepad ++为以下脚本键入函数时,会发生一些有趣的事情:
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
Run Code Online (Sandbox Code Playgroud)
它给我一个这样的错误:
IndentationError at /time/
('unexpected indent', ('M:\\DjangoStack\\projects\\beta_01\\..\\beta_01\\hello_world\\views.py', 12, 1, '\thtml = "<html>"\n'))
Run Code Online (Sandbox Code Playgroud)
但是当我直接从书中粘贴它时,没关系.我想知道为什么,我应该在notepad ++中做一些设置吗?谢谢.
我用来4 space bars在记事本++中创建缩进,我试过1 tab,似乎问题是固定的
def getText(nodelist):
"""Extracts the text between XML tags
I took this directly from http://docs.python.org/library/xml.dom.minidom.html.
For example, if I have a tag <Tag>525</Tag> this method returns me '525'
"""
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
Run Code Online (Sandbox Code Playgroud)
给我 IndentationError: unindent does not match any outer indentation level
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
Run Code Online (Sandbox Code Playgroud)
才不是.我所做的只是删除文档字符串注释.到底是怎么回事?
def contains_sequence(dna1, dna2):
''' (str, str) -> bool
Return True if and only if DNA sequence dna2 occurs in the DNA sequence
dna1.
>>> contains_sequence('ATCGGC', 'GG')
True
>>> contains_sequence('ATCGGC', 'GT')
False
'''
b=False
len2=len(dna2)
i=0
for j in dna1:
temp=dna1[i:i+len2]
if temp == dna2:
b=True
i=i+1
return b
Run Code Online (Sandbox Code Playgroud)
我是Python的新手.上面粘贴的程序在"if temp == dna2:"行中给出了一个错误"在缩进中使用制表符和空格的不一致".有人可以帮我找出缩进是如何不正确的吗?
我正在尝试编写我的第一个python脚本.这是有效的,但经过一些轻微的重构,我显然已经打破了缩进.我无法确定是什么问题.口译员抱怨以下方法.有人能说出来吗?
def dataReceived(self, data):
a = data.split(':')
print a
if len(a) > 1:
command = a[0]
content = a[1]
msg = ""
if command == "iam":
self.name = content
msg = self.name + " has joined"
elif command == "msg":
msg = self.name + ": " + content
print msg
Run Code Online (Sandbox Code Playgroud)
错误读取:文件"python_server.py",第17行a = data.split(':')^ IndentationError:预期缩进块
我经常从我的 Python 代码中得到未捕获的异常(错误),这些异常被描述为TypeErrors. 经过大量的实验和研究,我收集了以下示例(以及细微的变化):
TypeError: func() takes 0 positional arguments but 1 was given
TypeError: func() takes from 1 to 2 positional arguments but 3 were given
TypeError: func() got an unexpected keyword argument 'arg'
TypeError: func() missing 1 required positional argument: 'arg'
TypeError: func() missing 1 required keyword-only argument: 'arg'
TypeError: func() got multiple values for argument 'arg'
TypeError: MyClass() takes no arguments
TypeError: unsupported operand type(s) for +: 'int' and 'str'
TypeError: can only concatenate str …Run Code Online (Sandbox Code Playgroud) 因为我的代码中的这一部分,我无法编译:
if command == 'HOWMANY':
opcodegroupr = "A0"
opcoder = "85"
elif command == 'IDENTIFY':
opcodegroupr = "A0"
opcoder = "81"
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
抱歉:IndentationError:('unindent与任何外部缩进级别都不匹配',('wsn.py',1016,30,"\ t\telif命令=='IDENTIFY':\n"))
但我没有看到任何缩进错误.可能是什么问题?
我是初学者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) while x < len(Hand):
while y < len(Hand):
if Hand[x][0] == Hand[y][0] and y != x:
sameRank += 1
y += 1
x += 1
Run Code Online (Sandbox Code Playgroud)
它突出显示"if"之前的空格并说出语法错误......没有任何意义.
我有一段简单的代码,我不知道我的错误来自哪里.在第5行(if语句)中,解析器正在向我发出意外缩进.有人在这看到问题吗?我不.
def gen_fibs():
a, b = 0, 1
while True:
a, b = b, a + b
if len(str(a)) == 1000:
return a
Run Code Online (Sandbox Code Playgroud) 我有这个代码来自django示例教程
from django.db import models
from datetime import datetime
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
Run Code Online (Sandbox Code Playgroud)
我收到此错误:IndentationError:意外缩进
在这条线上:
def __unicode__(self):
Run Code Online (Sandbox Code Playgroud)
任何想法有什么不对?