一 环境简要说明
Windows系统下面搭建Python脚本编辑运行环境,所需工具平台如下。
1.1Python 下载官网www.python.org.有2.x和3.x版本。自己选择,语法上略有差异。
1.2eclipse eclipse-jee-kepler-SR2-win32-x86_64或者eclipse-jee-luna-SR2-win32-x86_64版本。
1.3 Oracle 官网下载jdk jre
1.4 http://www.pydev.org/ 下载插件
具体怎么安装网上一大堆。百度,谷歌即可。
二 辅助工具说明。
本人在win8 64位系统所用python3.4和Eclipse pydev插件搭建构成编辑运行环境。
特别说明一个工具,本人亲测实用。可以将py脚本文件转化为windows系统平台下面的
PE程序。cx_Freeze-4.3.3.win-amd64-py3.4.exe使用此工具在命令行模式下转化。使用前记得环境变量添加。(本人安装在C:\\python34\\scripts\\目录下命令:
C:\Python34\Scripts>pythoncxfreeze -h
Usage: cxfreeze[options] [SCRIPT]
Freeze a Pythonscript and all of its referenced modules to a base
executable which canthen be distributed without requiring a Python
installation.
Options:
--version show program's version number andexit
-h, --help show this help message and exit
-O optimize generated bytecodeas per PYTHONOPTIMIZE; use
-OO in order to removedoc strings
-c, --compress compress byte code in zip files
-s, --silent suppress all output except warningsand errors
--base-name=NAME file on which to base the target file; ifthe name of
the file is not anabsolute file name, the
subdirectory bases(rooted in the directory in which
the freezer is found)will be searched for a file
matching the name
--init-script=NAME script which will be executed upon startup;if the
name of the file is notan absolute file name, the
subdirectoryinitscripts (rooted in the directory in
which the cx_Freezepackage is found) will be searched
for a file matching thename
--target-dir=DIR, --install-dir=DIR
the directory in whichto place the target file and
any dependent files
--target-name=NAME the name of the file to create instead ofthe base
name of the script andthe extension of the base
binary
--no-copy-deps do not copy the dependent files(extensions, shared
libraries, etc.) to thetarget directory; this also
modifies the defaultinit script to ConsoleKeepPath.py
and means that thetarget executable requires a Python
installation to executeproperly
--default-path=DIRS list of paths separated by the standard pathseparator
for the platform whichwill be used to initialize
sys.path prior to running themodule finder
--include-path=DIRS list of paths separated by the standard pathseparator
for the platform whichwill be used to modify sys.path
prior to running themodule finder
--replace-paths=DIRECTIVES
replace all the pathsin modules found in the given
paths with the givenreplacement string; multiple
values are separated bythe standard path separator
and each value is ofthe form path=replacement_string;
path can be * whichmeans all paths not already
specified
--include-modules=NAMES
comma separated list ofmodules to include
--exclude-modules=NAMES
comma separated list ofmodules to exclude
--ext-list-file=NAME name of file in which to place the list ofdependent
files which were copied into the targetdirectory
-z SPEC, --zip-include=SPEC
name of file to add tothe zip file or a specification
of the formname=arcname which will specify the
archive name to use; multiple --zip-includearguments
can be used
--icon=ICON name of the icon file for theapplication
C:\Python34\Scripts>
//使用实例
python cxfreezehello.py --target-dir DESTDIR //将hello.py文件转化成pe文件。
生成的是一个win32的console控制台程序。要生成窗体程序需要修改setup.py文件。
此文件时安装cx_freeze产生。
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected,but it might need fine tuning.
build_exe_options = {"packages":["os"], "excludes": ["tkinter"]}
# GUI applications require a different baseon Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "console"
setup( name = "hello",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("hello.py", base=base)])
三 代码测试
3.1输出
print ("HELLO WORLD") //单双引号都行
3.2 输入
iNum = int(input()) //转化
3.3 循环
for i in range(n): //0-----n-1范围
3.4 函数定义
3.5 类定义
四 说明
Python语言的基本类型属于一种弱类型。在语句块上面,根据换行和回车,对其来严格判断。所以必须严格自己定义的编写的模块。