python - 语法错误 : mismatched input 'print' expecting INDENT

标签 python linux command-line-interface jython indentation

在 Linux 上安装 Jython 后,如何导入 sys 并打印详细信息?

thufir@doge:~$ 
thufir@doge:~$ jython --version
"my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15.
Jython 2.5.3
thufir@doge:~$ 
thufir@doge:~$ jython -i
"my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15.
Jython 2.5.3 (, Dec 21 2015, 23:18:42) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_111
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import sys
>>> r=sys.registry
>>> for k in r:
... print k, r[k]
  File "<stdin>", line 2
    print k, r[k]
    ^
SyntaxError: mismatched input 'print' expecting INDENT
>>> exit()
thufir@doge:~$ 

据推测,此代码适用于 Windows,但仍应执行。它们是什么类型的缩进?我输入的完全一样 example .是否有空格或制表符对我来说不明显?

我试着缩进了一点:

thufir@doge:~$ 
thufir@doge:~$ jython -i
"my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15.
Jython 2.5.3 (, Dec 21 2015, 23:18:42) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_111
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> r=sys.registry
>>> for k in r:
...  print k, r[k]
...  ;
  File "<stdin>", line 3
    ;
    ^
SyntaxError: mismatched input ';' expecting DEDENT
>>> exit()
thufir@doge:~$ 

最佳答案

如果你们中有人想要积分,我当然会接受你的回答。这是我如何让它工作的:

thufir@doge:~$ 
thufir@doge:~$ jython -i
"my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15.
Jython 2.5.3 (, Dec 21 2015, 23:18:42) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_111
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> r=sys.registry
>>> for k in r:
...  print k, r[k]
... 
java.runtime.name Java(TM) SE Runtime Environment
python.cachedir /home/thufir/.jython-cache
sun.boot.library.path /usr/lib/jvm/java-8-oracle/jre/lib/amd64
java.vm.version 25.111-b14
java.vm.vendor Oracle Corporation
java.vendor.url http://java.oracle.com/
path.separator :
java.vm.name Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg sun.io
user.country CA
sun.java.launcher SUN_STANDARD
sun.os.patch.level unknown
python.console.readlinelib Editline
java.vm.specification.name Java Virtual Machine Specification
user.dir /home/thufir
java.runtime.version 1.8.0_111-b14
java.awt.graphicsenv sun.awt.X11GraphicsEnvironment
java.endorsed.dirs /usr/lib/jvm/java-8-oracle/jre/lib/endorsed
os.arch amd64
python.home /usr
java.io.tmpdir /tmp
line.separator 

java.vm.specification.vendor Oracle Corporation
os.name Linux
sun.jnu.encoding UTF-8
python.console org.python.util.ReadlineConsole
java.library.path /usr/lib/jni
java.specification.name Java Platform API Specification
java.class.version 52.0
sun.management.compiler HotSpot 64-Bit Tiered Compilers
os.version 4.4.0-21-generic
python.executable /usr/bin/jython
user.home /home/thufir
user.timezone 
java.awt.printerjob sun.print.PSPrinterJob
file.encoding UTF-8
java.specification.version 1.8
java.class.path /usr/share/java/jython.jar:/usr/share/java/antlr3-runtime-3.2.jar:/usr/share/java/stringtemplate.jar:/usr/share/java/antlr3-3.2.jar:/usr/share/java/asm3.jar:/usr/share/java/asm3-commons.jar:/usr/share/java/asm3-tree.jar:/usr/share/java/jnr-constants.jar:/usr/share/java/guava.jar:/usr/share/java/jsr305.jar:/usr/share/java/jnr-posix.jar:/usr/share/java/jffi.jar:/usr/share/java/jnr-ffi.jar:/usr/share/java/jnr-x86asm.jar:/usr/share/java/jnr-netdb.jar:/usr/share/java/livetribe-jsr223.jar:/usr/share/java/jline.jar:/usr/share/java/servlet-api-3.1.jar:/usr/share/java/libreadline-java.jar
user.name thufir
python.console.encoding UTF-8
java.vm.specification.version 1.8
sun.java.command org.python.util.jython -i
java.home /usr/lib/jvm/java-8-oracle/jre
sun.arch.data.model 64
user.language en
java.specification.vendor Oracle Corporation
awt.toolkit sun.awt.X11.XToolkit
java.vm.info mixed mode
java.version 1.8.0_111
java.ext.dirs /usr/lib/jvm/java-8-oracle/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path /usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/classes
java.vendor Oracle Corporation
python.path /usr/lib/site-python:/usr/share/jython/Lib
file.separator /
java.vendor.url.bug http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding UnicodeLittle
sun.cpu.endian little
sun.desktop gnome
sun.cpu.isalist 
>>> 
>>> exit()
thufir@doge:~$ 

我知道 python 使用空格,但据我所知是遵循示例教程。不是为了防御,但他们可以提到按两次输入键。总之,很好的评论,谢谢,知道了。

关于python - 语法错误 : mismatched input 'print' expecting INDENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41682706/

相关文章:

Python cmd 模块 - 从行中解析值

python - Pandas - 检查数据帧的子集是否在另一个数据帧中

python - 使用 mongodb (mongoengine) 和 redis 测试 django

python - 替换 block 大小小于阈值的重复项 - Python

linux - Ksh 脚本 : How to remain in ssh and continue the script

php - 使用转储文件在 CLI 模式下使用 PHP APC 缓存

python - Pandas 在键中与 NaN 合并

linux - CentOS 6.5 R 安装依赖项

linux - Linux bash shell 中的 ". file"和 "./file"有什么区别?

database - Codeigniter CLI Controller 事故