<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    Previous Page

    Up One Level

    Next Page

    Python ???

    Contents

    ?????1. ??¦È?? ?????Python ??? Next: 3. ????????????


    ????



     
    2.
    ???Python??????

     
    2.1
    ???y?????

    ???Python?????????????????????? /usr/local/bin/python ???¡ê??? /usr/local/bin ????????UNIX Shell ??????¡¤????????????????????

    python

    ?????????????¡¤???????????????§á???????????¦Ë???????????Python????????????????????????íà/usr/local/python?????????????????

    ??????????????????UNIX????Ctrl+D??Windwos????Ctrl+Z????????????0?????????????????????????????????????????????????????????????????????????????import sys; sys.exit()??

    ?????????§Ò?????????????????Unix???????????????GNU readline ??????????????????????????????????????????????????????§Ò??????????????????????????????????Ctrl+P????????????????????????????????????????????§Ò?????????? A ????ùz??????????????????§Ù?????????P??????????????????§Ò?????????????????????????????????????

    ?????????????§»??Unix Shell?????????õô??????????????????????????????????????????????????????????????????????????õô???????????§ß????????????

    ??????????????????????“python -c command [arg] ...?????????????????????????????????????Shell?? -c??þŸ???Python?????????????????????????????????e??????????????????????

    ???“python file??“python <file?????????????????????????????????????? input() ??raw_input()????????????????????????????????????????????????????????????????????????????¦Â????????????????????????????????????????¦Ê??????Python????????????????????????????????????õô??

    ??y?????????????????§ß??????????????????????????????????-i????????????????????????????????????????§µ?????????????????????

     
    2.1.1
    ????????

    ???y????????????????????????????????sys.argv????????§Ò????§ß??????????????????????????sys.argv[0]??????????????????????‘ - ’???????????????sys.argv[0]???????‘ - ’????? -c ??????sys.argv[0]???Ú…?‘ -c ’?? -c ??????????????? Python ?????????????????????????????sys.argv ?§µ???????????????

     
    2.1.2
    ??????

    ??tty???????????????????????????????????????????????????????????§µ?????????????????????????“>>> ”????????????????????????????????????????“... ????????????????????????????????·Ú???????????

    python
    Python 2.3 (#1, Jul 30 2003, 23:22:59)
    [GCC 3.2 20020927 (prerelease)] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

    ??????§ß????????????????????íà??????? if ???

    >>> the_world_is_flat = 1
    >>> if the_world_is_flat:
    ...     print "Be careful not to fall off!"
    ... 
    Be careful not to fall off!

     
    2.2
    ?????????ƒr??

     
    2.2.1
    ??????

    ?§Õ?????????????????????????????????????????????????????¡ê??????????????????????????????§µ??????????????????????????????????????try????§Ö?except???????????????????????????§Ö????????? ???§»??????????????¡¤????????????????????????¨¬???????????¨À????§Ö?????????§Õ????????????????????§Ö???????§Õ?????????

    ???????????????????????§Ø?????????Control-C or DEL?????????????????????????§³?2.1????????????????§Ø?????????? KeyboardInterrupt ???????????try?????

     
    2.2.2
    ???Python???

    BSD???§µ?Python?????????Shell????????????§µ?????????????§Õ???????????????????

    #! /usr/bin/env python

    (?????¡¤??????????) “#!”????????????????????????§»?????????§Ò?????Unix?????§ß???????“\n??????????????Mac??“\r????Windows??“\r\n??????????????“#”??Python?????????????????

    ?????????? chmod ????????????????????

    $ chmod +x myscript.py

    2.2.3 ????????

    Python???????????????????? ASCII ???????????? ???????????? #! ?§Ü???????????????????????????????

    # -*- coding: iso-8859-1 -*-

    ?????????????Python??????§Ö??????????????????????Unicode????????§µ??????????? iso-8859-1 ???? Python ??¦Ï???? ?§á???????????????§Ò???????????ï…????????????cp-936??utf-8??????????GB??GBK??GB-18030??ISO-10646?????????????

    ????????????????UTF-8???????????????UTF-8????aka BOM - Byte Order Mark?????????????????????????????????????Jext?????????????????Vim??????????????????????????????????????????????????????????????????????IDLE????????Ú…Options/General/Default Source Encoding/UTF-8 ????????????????????Python????????????Python 2.2??????·Ú??????????????????????#!?????

    ???UTF-8?????????????????????????????????????????????????????????????????????????§Ó?????¡Â? ASCII ???????????????????§Ö??????????????????§ß?????????UTF-8?????????????????????????????????‰^

     
    2.2.4
    ?????????????????

    ???Python?????????????????????????¦Í?????????????§»???þŸ??????????????§Ñ??????????§Ö??????Ú…??????PYTHONSTARTUP ??????????????????????????????Unix shell??.profile?????

    ?????????????????????????Python?????§ß?????????????????????????????????????????????????????????????????????????§Ö??????????????????????????????????????§á???????????§Ó??????????¨¢?????????????????§Ú??sys.ps1??sys.ps2??þŸ

    ??????????????????§Ú?????????????????????????????§Þ??????????¦Ì????“if os.path.isfile('.pythonrc.py'): execfile('.pythonrc.py')”?? ????????????????????????????????????????§Õ???????????

    import os
    filename = os.environ.get('PYTHONSTARTUP')
    if filename and os.path.isfile(filename):
        execfile(filename)



    ???

    ... ???2.1
    GNU readline???????????????????????????????

    Previous Page

    Up One Level

    Next Page

    Python ???

    Contents

    ?????1. ??¦È?? ?????Python ??? Next: 3. ????????????


    Release 2.3, documentation updated on July 29, 2003.

    See About this document... for information on suggesting changes.
    ?????, @ssv 97av