Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试后出现Python缩进错误:_Python_Runtime Error_Indentation - Fatal编程技术网

尝试后出现Python缩进错误:

尝试后出现Python缩进错误:,python,runtime-error,indentation,Python,Runtime Error,Indentation,每当我尝试在Raspberry PI上运行此python脚本时,我都会遇到一个问题: import socket import sys # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to the port server_address = ('localhost', 10000) print >>sys.stderr, 'sta

每当我尝试在Raspberry PI上运行此python脚本时,我都会遇到一个问题:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the port
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)

# Listen for incoming connections
sock.listen(1)

while True:
    # Wait for a connection
    print >>sys.stderr, 'waiting for a connection'
    connection, client_address = sock.accept()

    try:
        print >>sys.stderr, 'connection from', client_address

        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(16)
            print >>sys.stderr, 'received "%s"' % data
            if data:
                print >>sys.stderr, 'sending data back to the client'
                connection.sendall(data)
            else:
                print >>sys.stderr, 'no more data from', client_address
                break

    finally:
        # Clean up the connection
        connection.close()
我得到这个错误:

 File "server.py", line 20
    try:
    ^
IndentationError: unexpected indent

你能告诉我这里怎么了吗?这个脚本应该创建一个简单的TCP/IP服务器,我对客户端没有这样的问题,所以我真的不明白我的错误在哪里。

Python使用空格来表示块的一个不幸的副作用是,有时在源代码中,脚本的制表符和空格混淆了


由于这个脚本非常小,您可以尝试删除每行代码前面的空白,然后正确地重新插入它。

Python使用空白来表示块的一个不幸的副作用是,有时您得到的脚本在整个源代码中混合了制表符和空格


因为这个脚本很小,您可以尝试删除每个行代码之前的空白,然后正确地重新分配它。

您尝试在尝试之前删除空白行吗?BTW缩进问题不是运行时错误。在尝试之前,您是否尝试删除空白行?BTW缩进问题不是运行时错误添加到这个,您可以在Python的空闲状态下加载代码,选择所有代码,然后点击Format->Unabify区域。完成此操作后,请尝试保存代码,然后再次尝试运行。若要添加此操作,您可以在Python的空闲状态下加载代码,选择所有代码,然后单击“格式”->“卸载区域”。完成此操作后,请尝试保存代码,然后再次尝试运行。