易截截图软件、单文件、免安装、纯绿色、仅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学习

3. Dictionaries 字典类型
     Python中,字典类型并不是顺序容器,而类似c++中的关联容器(map),Dictionaries中存储的是键/值 对,和map不同的是,Python的Dictionaries中可以存任意对象类型。Dictionaries类型也是可变的,和Lists一样,可以原地修改(通过下标修改)。
    下面通 ......

python学习

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

Python 3.x (1):入门

 
1 你好
#打开新窗口,输入:
#! /usr/bin/python
# -*- coding: utf8 -*- 
s1=input("Input your name:")
print("你好,%s" % s1)
'''
知识点:
    * input("某字符串")函数:显示"某字符串",并等待用户输入.
    ......

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快捷键汇集


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