易截截图软件、单文件、免安装、纯绿色、仅160KB

用python的cmd模块写一个简单的shell

 from cmd import *
class MyShell(Cmd):
    def preloop(self):
        print "print this line before entering the loop"
            
    def postloop(self):
        print "print this line after leaving the loop"
    
    def precmd(self, line):
        print "print this line before do a command"
        return Cmd.precmd(self, line)
    
    def postcmd(self, stop, line):
        print "print this line after do a command"
        return Cmd.postcmd(self, stop, line)   
            
    def do_test(self, line):
        ''' test command, just print the arguments except some special ones'''
        if line == "exit":
            exit()
        else:
            print line
    
MyShell().cmdloop()
#继承cmd模块的Cmd类实现
#shell中的命令xx在类中对应的函数名为do_xx
#line是shell中输入的命令行参数


相关文档:

python学习

 4、Tuples 元组
     元组和Lists相似,但它是immutable,初始化后不能改变其内容,这在程序中有时候很有用,可以用来防止定义的变量内容被意外改变。
5、Files 文件
    文件操作和c语言比较接近,下面只通过代码演示:
>>> f = open('data.txt','w')
>>> ......

Python笔记(二)——python调用C/C++模块

前一篇讲了简单的C/C++调用Python脚本模块(.py)。既然是用于诸多游戏程序的脚本语言,那肯定是缺不了互调(礼尚往来)。因此,本篇讲一个简单的python调用C/C++写的DLL模块,对Python进行功能扩展。这里写一个简单的例子,主要就为了了解下这么用Python来调用C/C++写的DLL库。好了,切入正题:
 首先,我是用VS2003 ......

python如何连接MySQL数据库

 
#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE  : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#================ ......

python 3.0与python 2.x的区别

 正在阅读最新版的《A byte of Python》。发现Python3.0在某些地方还是有些改变的。准备慢慢的体会,与老版本的《A byte of Python》做对比,最后再去查阅官方网站的文档。
1.
如果你下载的是最新版的Python,就会发现所有书中的Hello World例子将不再正确。
Old:
print "Hello World!" #打印字符串
New:
......

python快捷键汇集


Ctrl+3            行注释
Ctr+\               去行注释
Ctrl+Shift+3   去行注释
Ctrl+4            块注释
Ctrl+5         & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号