易截截图软件、单文件、免安装、纯绿色、仅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的sort()

之前学习第九章的排序小结的时候,对sort()排序方法不理解,因为括号里面带了自定义的比较函数。
后来查手册,才发现sort()里面本来就带了这样的参数。能够自定义比较方法,确实很灵活。
不仅如此,在网上查到一个博客,作者不单停留在这表面,还查究了sort()的排序算法,确实有意思。
全文抄录如下:
http://blog.done ......

Python 3.x (1):入门

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

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

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

网站模拟登陆备忘(php + python)

 php版:
<?php
$cookie_file = fopen('cookie.txt','w');//dirname(__FILE__)."/cookie_".md5(basename(__FILE__)).".txt"; // 设置Cookie文件保存路径及文件名

function vlogin($url,$data){ // 模拟登录获取Cookie函数
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($cur ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号