|
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 ????鵽??????????????????з?????????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