Python教程
Python教程:包含了所有代写案例以及部分答案
-
#!/usr/bin/env python #coding:utf-8 import os,time,random,threadpool,sys from progressbar import * COUNT=0 tit=1000 PINGIP=[] def main(): ipd=None if len(sys.argv)==2: ipd=sys.argv[1] a=os.popen("ifconfig en0|grep ‘inet ‘|awk ‘{print $2’}") … 继续阅读“python ping网段设备”
:
-
# coding=utf-8 __author__ = ‘Administrator’ import os tab=’ ‘*4+"|" blank=" "*5 # 存放当前级别目录个数 dict={} # 探测目录深度 def deep(path=None): if path==None: return 0 if path.__len__()==0: return 0 arr = path.split(os.sep) return arr.__len__( … 继续阅读“python 打印目录树”
:
-
这段python代码首先从www.beijing-time.org上获取标准的北京时间,然后同步获取的北京时间到本地 # -*- coding: utf-8 -*- import time,httplib import threading def getBeijinTime(): try: conn = httplib.HTTPConnection("www.beijing-time.org") conn.request("GET", "/tim … 继续阅读“python代码定时同步本机的北京时间”
:
-
class offer_book: def replaceBlank( p_str, rpl_str ): blank = ‘ ‘ numOfBlank = 0 originalLen = len( p_str ) for char in p_str: if char == blank: numOfBlank += 1 originalIndex = originalLen – 1 newLen = originalLen + numOfBlank * ( len( rpl_str ) – le … 继续阅读“python o(n)时间复杂度替换字符串中空格为%20”
:
-
# encoding=utf-8 def printInfo(info): print unicode(info, ‘utf-8’).encode(‘gbk’) class Person(): name = "" def __init__(self, name): self.name = name; return; def Show(self): printInfo("zhuangbanhao%s" % self.name) class Finery(Pe … 继续阅读“python的设计模式”
:
-
相比于Django而言,bottle显得非常轻量级。短短几行代码即可快速搭建一个简易的httpserver。提供了PythonWeb开发中需要的基本支持:URL路由,Request/Response对象封装,模板支持,与WSGI服务器集成支持。使用方法确实非常简便。“`python import simplejson as son from bottle import Bottle, route, run, request, response, get, post app = But … 继续阅读“python bottle—Python的轻量级http server”
:
-
#!/usr/bin/env python # -*- coding: utf-8 -*- ‘ a test module ‘ __author__ = ‘test’ import sys def test(): args = sys.argv if len(args)==1: print ‘Hello, world!’ elif len(args)==2: print ‘Hello, %s!’ % args[1] else: print ‘Too many arguments!’ if __n … 继续阅读“python helloworld”
:
-
import subprocess command = "pip list –outdated" outdatelist = subprocess.Popen (command, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell = True).stdout.readlines() updatelist = [x.split("(")[0] for x in outdatelist ] for x … 继续阅读“python 双击更新所有已安装的python模块”
:
-
#!/usr/bin/python # -*- coding: utf-8 -*- import ftplib import os import socket HOST = ‘ftp.mozilla.org’ DIRN = ‘pub/mozilla.org/webtools’ FILE = ‘bugzilla-3.6.9-to-3.6.10-nodocs.diff.gz’ def writedata(data): f = open(FILE,’wb’) try: f.write(data) fi … 继续阅读“python 一个简单python ftp客户端代码”
: