Python教程
Python教程:包含了所有代写案例以及部分答案
-
def mxrange(start,end=0,step=1): (start,end) = start>end and (end,start) or (start,end) while start < end: yield start start+=step print [i for i in xrange(5)],[i for i in mxrange(5)] print [i for i in xrange(1,5)],[i for i in mxrange(1,5)] pri … 继续阅读“python mxrange 模拟 系统 xrange”
:
-
#!/bin/env python import json import time, datetime stackP = open("./outLog") for eachLine in stackP: result = eachLine.find("signalingDomain") if result == -1: continue stringStart = eachLine.find(‘{‘) stringEnd = eachLine.rfind( … 继续阅读“python 分析日志”
:
-
#socket_server.py import socket import os import sys def work(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((‘0.0.0.0’,1000)) sock.listen(5) while True: try: conn, addr = sock.accept() ret = conn.recv(2048) result = os.popen(r … 继续阅读“python 使用socket远程发送命令并获得执行结果”
:
-
#!/usr/bin/python def sqrt_iter(guess,x): if(good_enough(guess, x)): print guess else: sqrt_iter(improve(guess, x),x) def improve(guess, x): return average(guess, x/guess) def average(x,y): return (x+y)/2 def good_enough(guess,x): if(abs(guess * gues … 继续阅读“python newton method 求解平方根”
:
-
[Python]代码 “` python import subprocess import re keydic = {“MemTotal”:”总内存(单位G)”, “MemFree”:”剩余内存(单位G)”, “MemAvailable”:”可用内存(单位G)”, “Cached”:”缓存内存(单位G)&# … 继续阅读“Python获取Linux系统内存情况”
:
-
import os print ‘setenv…’, print os.environ[‘USER’] # show current shell variable value os.environ[‘USER’] = ‘Brian’ # runs os.putenv behind the scenes os.system(‘python echoenv.py’) os.environ[‘USER’] = ‘Arthur’ # changes passed to spawned program … 继续阅读“python设置进程的环境变量”
:
-
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import ConfigParser # Open a configuration file config = ConfigParser.SafeConfigParser() config.read("config.ini") # Read the whole configuration file for section in config.sections(): print &q … 继续阅读“python读取ini配置文件”
:
-
import re import os import urllib.request # 小说目录 home = "http://www.23zw.com/olread/9/9068/" if __name__ == ‘__main__’: url = home + "index.html" page = urllib.request.urlopen(url).read() page = page.decode("gbk") prin … 继续阅读“python 下载小说到本地”
:
-
#coding=UTF-8 import poplib import re import string import time from subprocess import Popen from subprocess import PIPE import win32api import win32con ####第一部分:收取邮件,获取最新一封的标题,使用poplib模块#### host=’pop3.163.com’ #这里以163邮箱举例 username=’邮箱账号’ password=’ … 继续阅读“python 利用手机远程控制电脑干坏事”
:
-
本代码演示了python的urllib2模块如何使用代理,以及需要登录验证的proxy # The proxy address and port: proxy_info = { ‘host’ : ‘proxy.myisp.com’, ‘port’ : 3128 } # We create a handler for the proxy proxy_support = urllib2.ProxyHandler({"http" : "http://%(host)s:%( … 继续阅读“python urllib2使用代理服务器”
: