BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / soft-design / #29672同步于 2008/9/5
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖

python学习交流

yanqiang
2008/9/5镜像同步10 回复
经过这段时间的摸索,以及论坛上各位校友的帮助,鄙人差不多python入门了,现将自己的一些总结以及整理的一些资料写在了百度空间里http://hi.baidu.com/buptyq,以备自己将来再用或者初学者参考 有误之处还望各位不吝赐教 python平台在windows系统上的安装 step-1:安装python 目前最新版本是2.5,x86系列cpu装python-2.5.2.msi,AMD系列CPU装:python-2.5.2.amd64.msi Python在Windows上安装后并没有自动注册环境变量,所以在命令行里直接键入Python并不会启动 Python命令行程序,此时需要在系统中注册Python环境变量。 Python的安装路径为 C:\Python25 环境变量注册: 我的电脑->属性->高级->环境变量->系统变量 双击PATH项,修改PATH的值为 C:\Python25; 检测是否安装成功 运行-cmd,输入python,如果顺利进入python则说明安装成功 step-2:安装GUI设计工具 wxPython 2.8(ps:官方网站上的安装文件有问题),win32系统下的wxPython runtime安装包wxPython2.8-win32-unicode-2.8.8.1-py25.exe wxPython demo安装包 win32-docs-demos 到此,用wxPython来开发一般的程序已经足够了,当然如果想加入开源代码开发的行列,或者想开发网络应用程序,则还需要安装一下程序 uTidylib-0.2.1.win32.exe PS:A quorum of developers have pitched in on a SourceForge project to maintain and further develop Dave Raggett's excellent HTML Tidy program. We have two primary goals. First, to provide a home where all the patches and fixes that folks contribute can be collected and incorporated into the program. Second, a library form of Tidy has been created to make it easier to incorporate Tidy into other software 现在,你可以python在windows系统上开发程序了
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
yanqiang机器人#1 · 2008/9/5
Python的特色 简单————Python是一种代表简单主义思想的语言。阅读一个良好的Python程序就感觉像是在读英语一样,尽管这个英语的要求非常严格!Python的这种伪代码本质是它最大的优点之一。它使你能够专注于解决问题而不是去搞明白语言本身。 易学————就如同你即将看到的一样,Python极其容易上手。前面已经提到了,Python有极其简单的语法。 免费、开源————Python是FLOSS(自由/开放源码软件)之一。简单地说,你可以自由地发布这个软件的拷贝、阅读它的源代码、对它做改动、把它的一部分用于新的自由软件中。FLOSS是基于一个团体分享知识的概念。这是为什么Python如此优秀的原因之一——它是由一群希望看到一个更加优秀的 Python的人创造并经常改进着的。 高层语言————当你用Python语言编写程序的时候,你无需考虑诸如如何管理你的程序使用的内存一类的底层细节。 可移植性————由于它的开源本质,Python已经被移植在许多平台上(经过改动使它能够工作在不同平台上)。如果你小心地避免使用依赖于系统的特性,那么你的所有Python程序无需修改就可以在下述任何平台上面运行。这些平台包括Linux、Windows、FreeBSD、Macintosh、 Solaris、OS/2、Amiga、AROS、AS/400、BeOS、OS/390、z/OS、Palm OS、QNX、VMS、Psion、Acom RISC OS、VxWorks、PlayStation、Sharp Zaurus、Windows CE甚至还有PocketPC! 解释性————这一点需要一些解释。 一个用编译性语言比如C或C++写的程序可以从源文件(即C或C++语言)转换到一个你的计算机使用的语言(二进制代码,即0和1)。这个过程通过编译器和不同的标记、选项完成。当你运行你的程序的时候,连接/转载器软件把你的程序从硬盘复制到内存中并且运行。 而Python语言写的程序不需要编译成二进制代码。你可以直接从源代码 运行程序。在计算机内部,Python解释器把源代码转换成称为字节码的中间形式,然后再把它翻译成计算机使用的机器语言并运行。事实上,由于你不再需要担心如何编译程序,如何确保连接转载正确的库等等,所有这一切使得使用Python更加简单。由于你只需要把你的Python程序拷贝到另外一台计算机上,它就可以工作了,这也使得你的Python程序更加易于移植。 面向对象————Python即支持面向过程的编程也支持面向对象的编程。在“面向过程”的语言中,程序是由过程或仅仅是可重用代码的函数构建起来的。在“面向对象”的语言中,程序是由数据和功能组合而成的对象构建起来的。与其他主要的语言如C++和Java相比,Python以一种非常强大又简单的方式实现面向对象编程。 可扩展性————如果你需要你的一段关键代码运行得更快或者希望某些算法不公开,你可以把你的部分程序用C或C++编写,然后在你的Python程序中使用它们。 可嵌入性————你可以把Python嵌入你的C/C++程序,从而向你的程序用户提供脚本功能。 丰富的库————Python标准库确实很庞大。它可以帮助你处理各种工作,包括正则表达式、文档生成、单元测试、线程、数据库、网页浏览器、CGI、 FTP、电子邮件、XML、XML-RPC、HTML、WAV文件、密码系统、GUI(图形用户界面)、Tk和其他与系统有关的操作。记住,只要安装了 Python,所有这些功能都是可用的。这被称作Python的“功能齐全”理念。除了标准库以外,还有许多其他高质量的库,如wxPython、 Twisted和Python图像库等等。 概括————Python确实是一种十分精彩又强大的语言。它合理地结合了高性能与使得编写程序简单有趣的特色。 Python在编程语言中的定位 很多大规模软件开发计划例如 Zope, Mnet 及 BitTorrent. Google都在广泛地使用它。 通常认为,Python是一种解释性的语言,但是这种说法是不正确的,实际上,Python在执行时,首先会将.py文件中的源代码编译成Python的 byte code(字节码),然后再由Python Virtual Machine来执行这些编译好的byte code。这种机制的基本思想跟Java,.NET是一致的。然而,Python Virtual Machine与Java或.NET的Virtual Machine不同的是,Python的Virtual Machine是一种更高级的Virtual Machine。这里的高级并不是通常意义上的高级,不是说Python的Virtual Machine比Java或.NET的功能更强大,而是说和Java 或.NET相比,Python的Virtual Machine距离真实机器的距离更远。或者可以这么说,Python的Virtual Machine是一种抽象层次更高的Virtual Machine。 基于C的Python编译出的字节码文件,通常是.pyc格式。 在实际开发中,python常被昵称为胶水语言,这不是说他会把你的手指粘住,而是说他能够很轻松的把用其他语言制作的各种模块(尤其是C/C++)轻松地联结在一起。常见的一种应用情形是,使用python快速生成程序的原型(有时甚至是程序的最终界面),然后对其中有特别要求的部分,用更合适的语言改写,比如3D游戏中的图形渲染模块,速度要求非常高,就可以用C++重写。 Python的不适之处 虽然Python是一个非常成功的语言,但对于习惯其他语言的程序员,有两个地方会让他们感觉略有不适。 1. 强制缩进 这也许不应该被称为局限,但是它用缩进来区分语句关系的方式还是给很多初学者带来了困惑。即便是很有经验的Python程序员,也可能陷入陷阱当中。最常见的情况是tab和空格的混用会导致错误,而这是用肉眼无法分别的。 2. 单行语句和命令行输出问题 很多时候不能将程序连写成一行,如import sys;for i in sys.path:print i。而perl和awk就无此限制,可以较为方便的在shell下完成简单程序,不需要如Python一样,必须将程序写入一个.py文件。(对很多用户而言这也不算是限制)
yanqiang机器人#2 · 2008/9/5
简明python教程http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/ 如果你有C编程基础,而且还学过其他的脚本语言,则花3-4个小时读一下该教程,应该就可以应付一般的python编程需要了
yanqiang机器人#3 · 2008/9/5
ansi 1个字节 美国标准 utf-8 可变长编码 当表示亚洲中日韩文字时,用2个自己 欧洲标准 GB2312(其改进版gbk,在程序里标识cp936) 2个字节 中国标准 unicode 4个字节 国际标准 因为unicode是用4个字节表示一个字符,所以unicode完全可以对世界上所有的字符进行编码,由此人们将各个字符对应unicode码称为该字符的原码,各字符对应的ansi,utf-8,cp936码,称为采用相应的编码方式进行的编码。 另外ansi,utf-8,cp936编码后的字符统称byte string, unicode编码后的字符被称为unicode string 所以byte string--》unicode string的过程,称之为解码(decode),例如:s="中国",假设程序采用cp936编码,则u_s=s.decode("cp936"),u_s对应便是"中国"的unicode 所以unicode string--》byte string的过程,称之为编码(encode),例如:u_s=u"中国",u_s对应"中国"的unicode,如果采用cp936编码,则s=u_s.encode("cp936");如果采用utf-8编码,则s=u_s.encode("utf-8")
yanqiang机器人#4 · 2008/9/5
File Management in Python (Page 1 of 5 ) File management is a basic function, and an important part of many applications. Python makes file management surprisingly easy, especially when compared to other languages. Peyton McCullough explains the basics. Introduction The game you played yesterday uses files to store game saves. The order you placed yesterday was saved in a file. That report you typed up this morning was, obviously, stored in a file as well. File management is an important part of many applications written in nearly every language. Python is no exception to this. In this article, we will explore the task of manipulating files using several modules. We'll read, write to, append and do other strange things to files. Let's get started. Reading and Writing The most basic tasks involved in file manipulation are reading data from files and writing data to files. This is a very simple task to learn. Let's open a file for writing: fileHandle = open ( 'test.txt', 'w' ) The "w" indicates that we will be writing to the file, and the rest is pretty simple to understand. The next step is to write data to the file: fileHandle.write ( 'This is a test.\nReally, it is.' ) This will write the string "This is a test." to the file's first line and "Really, it is." to the file's second line. Finally, we need to clean up after ourselves and close the file: fileHandle.close() As you can see, it's very easy, especially with Python's object orientation. Note that when you use the "w" mode to write to the file again, all its contents will be deleted. To get past this, use the "a" mode to append data to a file, adding data to the bottom: fileHandle = open ( 'test.txt', 'a' ) fileHandle.write ( '\n\n\nBottom line.' ) fileHandle.close() Now let's read our file and display the contents: fileHandle = open ( 'test.txt' ) print fileHandle.read() fileHandle.close() This will read the entire file and print the data within it. We can also read a single line in the file: fileHandle = open ( 'test.txt' ) print fileHandle.readline() # "This is a test." fileHandle.close() It is also possible to store the lines of a file into a list: fileHandle = open ( 'test.txt' ) fileList = fileHandle.readlines() for fileLine in fileList: print '>>', fileLine fileHandle.close() When reading a file, Python's place in the file will be remembered, illustrated in this example: fileHandle = open ( 'test.txt' ) garbage = fileHandle.readline() fileHandle.readline() # "Really, it is." fileHandle.close() Only the second line is displayed. We can, however, get past this by telling Python to resume reading from a different position: fileHandle = open ( 'test.txt' ) garbage = fileHandle.readline() fileHandle.seek ( 0 ) print fileHandle.readline() # "This is a test." fileHandle.close() In the above example, we tell Python to continue reading from the first byte in the file. Thus, the first line is printed. We can also request Python's place within the file: fileHandle = open ( 'test.txt' ) print fileHandle.readline() # "This is a test." print fileHandle.tell() # "17" print fileHandle.readline() # "Really, it is." It is also possible to read the file a few bytes at a time: fileHandle = open ( 'test.txt' ) print fileHandle.read ( 1 ) # "T" fileHandle.seek ( 4 ) print FileHandle.read ( 1 ) # "T" When working with Windows and Macintosh, sometimes you are required to read and write files in binary mode, such as images or executional files. To do this, simply append "b" to the file mode: fileHandle = open ( 'testBinary.txt', 'wb' ) fileHandle.write ( 'There is no spoon.' ) fileHandle.close() fileHandle = open ( 'testBinary.txt', 'rb' ) print fileHandle.read() fileHandle.close()
Wing机器人#5 · 2008/9/5
教程还是推荐《Python核心编程》,有点长,不过讲得挺详细的 附件(2.9MB)
Wing机器人#6 · 2008/9/5
附件(1.9MB)
junepy机器人#7 · 2008/9/5
我也来赞一下,去开版吧,嗯。
BookMoth机器人#8 · 2008/9/5
据说而已。你可以去baidu一下原帖。 反对dive into的主要原因是思想跳跃性大,显得思维混乱。不适合初学者入门。反对贴是个号称python从业者写的。说所有的Pyhon从业者都不是从dive into入门的。手册的入门那章比较适合初学。 【 在 ericyosho 的大作中提到: 】 : dive into很垃圾么? : 很多老毛子写书,都引用或者提到这本的。 : 至少我是从这本书上知道, : ...................
wks机器人#9 · 2008/9/5
不推荐dive。新手还是学官方的tutorial比较好。就是Windows版带的那个手册。 正在学ruby的飘...