标签: indentation

0
推荐指数
1
解决办法
758
查看次数

python Django模型缩进错误

from django.db import models

class Category(models.Model):
        title = models.CharField(max_length=250)
        slug = models.SlugField(unique=True)
        description = models.TextField()

        class Meta:
        verbose_name_plural = "Categories"

        def __unicode__(self):
        return self.title
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

verbose_name_plural = "Categories"
                  ^ IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)

我使用gedit使用空格作为选项卡的选项(也试图改变标签宽度)..我几乎可以肯定代码是正确的..但是间距和标签的一些问题..

python django indentation

0
推荐指数
1
解决办法
2093
查看次数

在源代码文件中为emacs定义perl缩进?

是否可以在源Perl文件的顶部放置注释,以使Emacs在同一文件中遵守4空格缩进规则,而不管在其中定义的默认缩进规则.emacs

我发现自己用不同的缩进编辑Perl文件,一些2间距,一些4间距,我希望Emacs自动遵循文件本身描述的缩进规则,而不是每次都要更改配置.

所有这些都cperl-mode用于Perl编辑(http://www.emacswiki.org/emacs/CPerlMode).

我尝试在此示例perl脚本的末尾添加以下注释:

#!/usr/bin/perl

my @a = (1,2,3,4,5,6);
for my $e (@a) {
  print "$e\n";
}

# Local variables:
# perl-indent-level: 4
# End:
Run Code Online (Sandbox Code Playgroud)

但它仍然使用缩进级别2.也许原因是因为它没有覆盖.emacs设置?

emacs perl indentation

0
推荐指数
1
解决办法
130
查看次数

为什么vim中的缩进在不同的编辑器中看起来有所不同?

我只是用vim来编辑一个javascript文件.我在vim中的缩进设置如下:

http://take.ms/XPgNb

当我编辑文件的一部分时,在vim中看起来好像缩进是正确的:

http://take.ms/hp7kh

但是,在SourceTree和Sublime Text中,缩进不正确:

SourceTree:

http://take.ms/ByRLS

崇高文字:

http://take.ms/HaiwY

任何人都可以向我解释为什么会发生这种情况以及我如何解决这个问题?我也很好奇,实际上,这是文件状态的"真实"表示.

vim indentation

0
推荐指数
1
解决办法
193
查看次数

在基本程序中使用 else 出现错误:unindent 与任何外部缩进级别不匹配

当我运行以下代码时,出现错误:“IndentationError:unident 与任何外部缩进级别不匹配”。

我究竟做错了什么?我在下面包含了我的代码以供参考:

file=open('csquetionseasy.txt','r')

print(file.read(432))

answersinputeasy=input('enter the letter responding to the correct answer for all 3 questions e.g. BBB')

if answersinputeasy==('BAA'):
    print('you got 3/3!')

else:
    if answersinputeasy==('BAB'):
        print('2/3!')
        else:
            if answersinputeasy==('BBB'):
                print('1/3!')
                else:
                    if answersinputeasy==('ABB'):
                        print('0/3!')
                        else:
                            if answersinputeasy==('AAB'):
                                print('1/3!')
                                else:
                                    if answersinputeasy==('AAA'):
                                        print('2/3!')
                                        else:
                                            if answersinputeasy==('ABA'):
                                                print('1/3!')
Run Code Online (Sandbox Code Playgroud)

python if-statement indentation syntax-error

0
推荐指数
1
解决办法
1184
查看次数

代表下一行代码的最佳Python方法是什么?

基本思想是写这样的一行:

url = 'https://{host}?key={key}&lang={lang}&text='.format(**data)  + '&text='.join(words)
Run Code Online (Sandbox Code Playgroud)

想要用PEP 8样式重写它,所以写了这样的代码:

url = 'https://{host}?key={key}&lang={lang}&text='.format(**data) \
    + '&text='.join(words)
Run Code Online (Sandbox Code Playgroud)

其中哪一项是对的?

如果两者都不行,我想听听为什么,然后看看你会怎么写。

python pep8 indentation

0
推荐指数
1
解决办法
69
查看次数

为什么 Python 会忽略注释缩进?

显然,这:

def f():
    pass
# maybe the function is over
    pass  # oh wait, it's not

f()
Run Code Online (Sandbox Code Playgroud)

是有效的语法,而这不是:

def f():
    pass
''' maybe the function is over '''
    pass  # oh wait, it's not

f()
Run Code Online (Sandbox Code Playgroud)

这对我来说是一个巨大的惊喜。所以我的问题是:

  • 为什么?为什么 Python 不认为第一个版本是语法错误?
  • PEP8 中是否有任何建议不要这样做?

python whitespace comments indentation

0
推荐指数
1
解决办法
181
查看次数

HTML 表格中的缩进

我的 HTML 代码如下所示:

<style type="text/css">
<!--
    td.indent    {text-indent:10mm; }
//-->
</style>
Run Code Online (Sandbox Code Playgroud)

[...]

<table>
    <tr>
        <td class="indent"> Long line of text </td>
        <td class="indent"> Some other text </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

表中的输出文本按预期缩进:

              Long line of text
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下命令添加换行符时<br>

<td class="indent"> Long line of<br> text </td>
Run Code Online (Sandbox Code Playgroud)

<br>仅缩进前面的部分:

              Long line of
text
Run Code Online (Sandbox Code Playgroud)

我怎样才能让输出看起来像这样?

              Long line of
              text
Run Code Online (Sandbox Code Playgroud)

html css indentation

0
推荐指数
1
解决办法
92
查看次数

需要python帮助

import os
import sys, urllib2, urllib
import re
import time
from threading import Thread

class testit(Thread):
   def __init__ (self):
      Thread.__init__(self)
   def run(self):
        url = 'http://games.espnstar.asia/the-greatest-odi/post_brackets.php'
        data = urllib.urlencode([('id',"btn_13_9_13"),  ('matchNo',"13")])
        req = urllib2.Request(url)
        fd = urllib2.urlopen(req, data)
<TAB>fd.close()
<TAB>"""while 1:
                data = fd.read(1024)
                if not len(data):
                        break
                sys.stdout.write(data)"""
        url2 = 'http://games.espnstar.asia/the-greatest-odi/post_perc.php'
        data2 = urllib.urlencode([('id',"btn_13_9_13"),  ('matchNo',"13")])
        req2 = urllib2.Request(url2)
        fd2 = urllib2.urlopen(req2, data2)
<TAB>#prints current votes
        while 1:
                data2 = fd2.read(1024)
                if not len(data2):
                        break
                sys.stdout.write(data2)
<TAB>fd2.close()
        print time.ctime()
        print " ending …
Run Code Online (Sandbox Code Playgroud)

python indentation

-1
推荐指数
1
解决办法
292
查看次数

总Python处女,这段代码有什么问题?"检测缩进错误."

这段代码有什么问题,在你问我之前用youtube视频和简短的教程做了这一切.非常感谢有人可以帮我编码,在这种情况下只需要我的Skype,我会加你,我需要这样做!:).

在第253行左右,它说需要"预期的缩进块"我真的不知道该怎么做.

    import pygame, sys, time, random, Globals
from pygame.locals import *

pygame.init()
pygame.mixer.init(frequency=22050, size=-16, channels=10, buffer=4096)

#Classes

class MenuButton(pygame.sprite.Sprite):
    def __init__(self, image, image_dem, x, y):
        self.image = pygame.image.load(image[0]).convert_alpha()
        self.image_over = pygame.image.load(image[1]).convert_alpha()
        self.image_dem = image_dem
        self.x = x
        self.y = y
        self.rect = pygame.Rect(self.x, self.y, self.image_dem[0], self.image_dem[1])
    def setXY(x, y):
        self.x = x
        self.y = y
    def setImage(image, dem):
        self.image = pygame.image.load(image[0]).convert_alpha()
        self.image_over = pygame.image.load(image[1]).convert_alpha()
        self.image_dem = dem

class Sprite(pygame.sprite.Sprite):
    def __init__(self, image, image_dem, x, y):
        self.image = pygame.image.load(image).convert_alpha()
        self.image_dem …
Run Code Online (Sandbox Code Playgroud)

python pygame compiler-errors indentation

-1
推荐指数
1
解决办法
145
查看次数