Python教程
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客户端代码”
:
-
python判断远程端口是否打开,下面的代码判断指定网站的80端口是否打开 import socket sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(1) try: sk.connect((‘www.open-open.com’,80)) print ‘Server port 80 OK!’ except Exception: print ‘Server port 80 not connect!’ sk. … 继续阅读“python判断远程端口是否打开”
:
-
一个python自定义的加密解密函数,下面的代码实现了对字符串的加密盒解密,调用简单 def encrypt(key, s): b = bytearray(str(s).encode("gbk")) n = len(b) # 求出 b 的字节数 c = bytearray(n*2) j = 0 for i in range(0, n): b1 = b[i] b2 = b1 ^ key # b1 = b2^ key c1 = b2 % 16 c2 = b2 // 16 # b2 … 继续阅读“python 一个python自定义的加密解密函数”
:
-
引入ftplib模块通过ftp发送文件的方法 import ftplib # We import the FTP module session = ftplib.FTP(‘myserver.com’,’login’,’passord’) # Connect to the FTP server myfile = open(‘toto.txt’,’rb’) # Open the file to send session.storbinary(‘STOR toto.txt’, myfile) # Se … 继续阅读“python通过ftp上传文件”
:
-
# -*- coding: utf-8 -*- import os import time import datetime rootDir = "I:/1/" dic={} for dirName,subDirs,fileList in os.walk(rootDir): print dirName for fn in fileList: fnpath=dirName+fn st = os.stat(fnpath) mode, ino, dev, nlink, uid, gi … 继续阅读“python 文件按照日期命名”
: