2009/03/20

谁来帮我解决这个混蛋

Last login: Sun Mar  8 23:31:13 on ttys000
linjie-macmini-2:~ kindy$ #!/usr/bin/python
linjie-macmini-2:~ kindy$ # user_input.py
linjie-macmini-2:~ kindy$  
linjie-macmini-2:~ kindy$ def reverse(text):
-bash: syntax error near unexpected token `('
linjie-macmini-2:~ kindy$     return text[::-1]
-bash: return: text[::-1]: numeric argument required
-bash: return: can only `return' from a function or sourced script
linjie-macmini-2:~ kindy$  
linjie-macmini-2:~ kindy$ def is_palindrome(text):
-bash: syntax error near unexpected token `('
linjie-macmini-2:~ kindy$     return text == reverse(text)
-bash: syntax error near unexpected token `('
linjie-macmini-2:~ kindy$  
linjie-macmini-2:~ kindy$ something = input('Enter text: ')
-bash: syntax error near unexpected token `('
linjie-macmini-2:~ kindy$ if (is_palindrome(something)):
-bash: syntax error near unexpected token `something'
linjie-macmini-2:~ kindy$     print("Yes, it is a palindrome")
-bash: syntax error near unexpected token `"Yes, it is a palindrome"'
linjie-macmini-2:~ kindy$ else:
-bash: else:: command not found
linjie-macmini-2:~ kindy$     print("No, it is not a palindrome")
-bash: syntax error near unexpected token `"No, it is not a palindrome"'
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ #1/usr
linjie-macmini-2:~ kindy$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.py
import site # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.py
import os # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.pyc
import posix # builtin
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py
import posixpath # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/stat.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/stat.py
import stat # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/stat.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/UserDict.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/UserDict.py
import UserDict # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/UserDict.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/copy_reg.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/copy_reg.py
import copy_reg # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/copy_reg.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/types.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/types.py
import types # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/types.pyc
import _types # builtin
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/warnings.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/warnings.py
import warnings # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/warnings.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/linecache.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/linecache.py
import linecache # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/linecache.pyc
import encodings # directory /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/__init__.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/__init__.py
import encodings # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/__init__.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py
import codecs # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.pyc
import _codecs # builtin
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/aliases.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/aliases.py
import encodings.aliases # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/aliases.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/utf_8.pyc has bad mtime
import encodings.utf_8 # from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/utf_8.py
# can't create /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/utf_8.pyc
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so
>>> print 'hello world'
hello world
>>> $ python 
  File "", line 1
    $ python
    ^
SyntaxError: invalid syntax
>>> /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so 
  File "", line 1
    /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so 
    ^
SyntaxError: invalid syntax
>>> $ python -v python 2.5
  File "", line 1
    $ python -v python 2.5
    ^
SyntaxError: invalid syntax
>>> python -v
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'python' is not defined
>>> open
>>> python
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'python' is not defined
>>> iwork
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'iwork' is not defined
>>> dd
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'dd' is not defined
>>>  python
  File "", line 1
    python
    ^
IndentationError: unexpected indent
>>> python-v
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'python' is not defined
>>> #!/usr/bin/python
... # Filename : helloworld.py
... print 'Hello World'
Hello World
>>> python helloworld.py
  File "", line 1
    python helloworld.py
                    ^
SyntaxError: invalid syntax
>>> #!/usr/bin/python
... # Filename : helloworld.py
... print 'Hello World'
Hello World
>>> 
>>> $ chmod a+x helloworld.py
  File "", line 1
    $ chmod a+x helloworld.py
    ^
SyntaxError: invalid syntax
>>> $ ./helloworld.py
  File "", line 1
    $ ./helloworld.py
    ^
SyntaxError: invalid syntax
>>> Hello World$ env PYTHONDOCS=/usr/share/doc/python-docs-2.4.3/html/python
  File "", line 1
    Hello World$ env PYTHONDOCS=/usr/share/doc/python-docs-2.4.3/html/python
              ^
SyntaxError: invalid syntax
>>> Python 2.3.4 (#1, Jul 26 2006, 16:42:40)
  File "", line 1
    Python 2.3.4 (#1, Jul 26 2006, 16:42:40)
             ^
SyntaxError: invalid syntax
>>> [GCC 3.4.2 20050110 (Red Hat 3.4.2-6.fc3)] on linux2
  File "", line 1
    [GCC 3.4.2 20050110 (Red Hat 3.4.2-6.fc3)] on linux2
           ^
SyntaxError: invalid syntax
>>> Type "help", "copyright", "credits" or "license" for more information.
  File "", line 1
    Type "help", "copyright", "credits" or "license" for more information.
              ^
SyntaxError: invalid syntax
>>> >>> help('print')
  File "", line 1
    >>> help('print')
     ^
SyntaxError: invalid syntax
>>> ^D
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] site
# cleanup[1] encodings
# cleanup[1] _codecs
# cleanup[1] zipimport
# cleanup[1] warnings
# cleanup[1] encodings.utf_8
# cleanup[1] codecs
# cleanup[1] readline
# cleanup[1] types
# cleanup[1] _types
# cleanup[1] signal
# cleanup[1] linecache
# cleanup[1] posix
# cleanup[1] encodings.aliases
# cleanup[1] exceptions
# cleanup[2] copy_reg
# cleanup[2] posixpath
# cleanup[2] os.path
# cleanup[2] stat
# cleanup[2] UserDict
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 7 unfreed ints in 1 out of 5 blocks
# cleanup floats
linjie-macmini-2:~ kindy$ 
linjie-macmini-2:~ kindy$ #!/usr/bin/python
linjie-macmini-2:~ kindy$ # Filename : helloworld.py
linjie-macmini-2:~ kindy$ print 'Hello World'python helloworld.py
-bash: print: command not found
linjie-macmini-2:~ kindy$ $ chmod a+x helloworld.py
-bash: $: command not found
linjie-macmini-2:~ kindy$ $ ./helloworld.py
-bash: $: command not found
linjie-macmini-2:~ kindy$ Hello World


电脑真讨厌。这个提示到底问题出在哪里?


“在命令行的shell提示符下键入python,启动解释器。现在输入print 'Hello World',然后按Enter键。你应该可以看到输出的单词Hello World”  这句话运行后都正常。

“$ python
Python 2.4.3 (#1, Jul 26 2006, 16:42:40)
[GCC 3.4.2 20050110 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello world'
hello world
>>>”

这段句子也运行的正常。



“挑选一个编辑器

         在我们开始讲述以源文件方式编写Python程序之前,我们需要一个编辑器来写源文件。挑选一个编辑器确实是极其重要的。你挑选一个编辑器就如同你挑选一辆你将购买的轿车一样。一个好的编辑器会帮助你方便地编写Python程序,使你地编程旅程更加舒适,帮助你更加快捷安全地到达目的地(实现目标)。

         对于编辑器的基本要求之一是语法加亮功能,利用这一功能,你的Python程序的不同部分被标以不同的颜色,这样你可以更好 看清楚 你的程序,使它的运行显得形象化。”

但是这段话,我根本就找不到去哪里找这个编译器。我执行不了。后面还有更麻烦的问题。