2017-01-16 3 views
0

Nachdem ich Jython unter Linux installiert habe, wie importiere ich sys und drucke die Details?SyntaxError: nicht übereinstimmende Eingabe 'print' erwartet INDENT

[email protected]:~$ 
[email protected]:~$ jython --version 
"my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15. 
Jython 2.5.3 
[email protected]:~$ 
[email protected]:~$ 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() 
[email protected]:~$ 

Vermutlich ist dieser Code für Windows, sollte aber trotzdem ausgeführt werden. Welche Art von Einzug meinen sie? Ich tippte genau wie die example. Ist mir ein Leerzeichen oder Tab nicht ersichtlich?

ich versucht, ein bisschen Einrücken:

[email protected]:~$ 
[email protected]:~$ 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() 
[email protected]:~$ 
+0

ok wird es tun. Danke. – Thufir

+4

Sie müssen mindestens ein Leerzeichen hinzufügen, bevor Sie 'print k, r [k]' eingeben. Python verwendet keine Schlüsselwörter, um das Ende von Schleifen/Funktionen zu markieren ... Es benutzt Einrückung, um zu wissen, wo diese enden. –

+1

Es bedeutet, dass in der Schleife 'print' vorgesehen sein muss – ppasler

Antwort

1

Wenn einer von euch Punkte will, werde ich Ihre Antwort natürlich akzeptieren. Hier ist, wie ich habe es funktioniert:

[email protected]:~$ 
[email protected]:~$ 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() 
[email protected]:~$ 

Ich wusste, dass Python weißen Raum verwendet, aber, soweit ich wurde nach dem Vorbild Tutorial erzählen konnte. Nicht, um defensiv zu werden, aber sie könnten erwähnen, zweimal Enter zu drücken. Wie auch immer, tolle Kommentare, danke, verstanden.

Verwandte Themen