Python教程
Python教程:包含了所有代写案例以及部分答案
-
import os def get_cpu_load(): """ Returns a list CPU Loads""" result = [] cmd = "WMIC CPU GET LoadPercentage " response = os.popen(cmd + ‘ 2>&1′,’r’).read().strip().split("\r\n") for load i … 继续阅读“python计算windows的cpu使用率”
:
-
# Import python libs import os def is_writeable(path, check_parent=False): ”’ Check if a given path is writeable by the current user. :param path: The path to check :param check_parent: If the path to check does not exist, check for the ability to w … 继续阅读“python验证文件是否可读可写”
:
-
#coding: UTF-8 def arrage(temp_list): num = len(temp_list) for i in range(1,num): for j in range(i): if temp_list[i] >= temp_list[j] and j == (i-1): break elif temp_list[i] <= temp_list[j] and j == 0: temp_list.insert(0,temp_list.pop(i)) elif t … 继续阅读“python实现插入排序”
:
-
目前处在学习python的阶段,昨天看到了python的socket模块,分别实现TCP、UDP时间戳回显。 1、tcp通信server和client代码 # tcpServer.py #!/usr/bin/python # -*- coding: utf-8 -*- from socket import * from time import ctime HOST = ” PORT = 21156 BUFSIZE = 1024 ADDR = (HOST,PORT) tcpServerSock … 继续阅读“Python的socket编程”
:
-
class ShoppingCart(object): """Creates shopping cart objects for users of our fine website.""" items_in_cart = {} def __init__(self, customer_name): self.customer_name = customer_name def add_item(self, product, price): … 继续阅读“python 学习,使用类模拟购物车代码”
:
-
from graphics import * from math import * def gobangwin(): win=GraphWin("this is a gobang game",400,400) #ÖÆ×÷21×21µÄÆåÅÌ win.setBackground("yellow") i1=0 while i1<401: l=Line(Point(i1,0),Point(i1,400)) l.draw(win) i1=i1+20 i2= … 继续阅读“python 五子棋”
:
-
#!/usr/bin/env python # -*- coding:utf-8 -*- from gevent import monkey monkey.patch_all() from gevent.pool import Pool import requests import sys import os def download(url): chrome = ‘Mozilla/5.0 (X11; Linux i86_64) AppleWebKit/537.36 ‘ + \ ‘(KHTML, … 继续阅读“python 批量下载文件”
:
-
下面的python代码通过MySQLdb模块链接mysql数据库,然后打开数据库,并通过sql语句查询mysql的版本号,最后关闭数据库连接 #!/usr/bin/python import MySQLdb # Open database connection db = MySQLdb.connect("localhost","testuser","test123","TESTDB" ) # prepare a cu … 继续阅读“python操作mysql数据库的简单示例”
:
-
#水仙花数 #narcissistic number #水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。 #(例如:1^3 + 5^3+ 3^3 = 153) import math import string for x in range(1,10): a=x*x*x for y in range(0,10): b=y*y*y for z in range(0,10): c=z*z*z d=a+b+c w=’%d’ %x+’%d’ %y+’%d’ %z … 继续阅读“python 水仙花数”
: