|
Python ??? |
|
?????1. ??¦È?? ?????Python ??? Next: 3. ????????????
???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????????????????????????????????????????§µ?????????????????????
???y????????????????????????????????sys.argv????????§Ò????§ß??????????????????????????sys.argv[0]??????????????????????‘
-
’???????????????sys.argv[0]???????‘
-
’?????
-c
??????sys.argv[0]???Ú…?‘
-c
’??
-c
???????????????
Python
?????????????????????????????sys.argv
?§µ???????????????
??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!
?§Õ?????????????????????????????????????????????????????¡ê??????????????????????????????§µ??????????????????????????????????????try????§Ö?except???????????????????????????§Ö????????? ???§»??????????????¡¤????????????????????????¨¬???????????¨À????§Ö?????????§Õ????????????????????§Ö???????§Õ?????????
???????????????????????§Ø?????????Control-C or DEL?????????????????????????§³?2.1????????????????§Ø?????????? KeyboardInterrupt ???????????try?????
BSD???§µ?Python?????????Shell????????????§µ?????????????§Õ???????????????????
#! /usr/bin/env python(?????¡¤??????????) “#!”????????????????????????§»?????????§Ò?????Unix?????§ß???????“\n”??????????????Mac??“\r”????Windows??“\r\n”??????????????“#”??Python?????????????????
?????????? chmod ????????????????????
$ chmod +x myscript.pyPython???????????????????? 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?????????????????????????????????‰^
???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)
|
Python ??? |
|
?????1. ??¦È?? ?????Python ??? Next: 3. ????????????
Release 2.3, documentation updated on July 29, 2003.
See About this document... for information on suggesting changes. ?????, @ssv