Python教程
Python教程:包含了所有代写案例以及部分答案
-
from pymongo import MongoClient client = MongoClient(‘localhost’, 27017) #建立和数据库系统的连接,创建Connection时,指定host及port参数 db_auth = client.admin db_auth.authenticate("account", "password") #admin 数据库有帐号,连接-认证-切换库 db = client.dbname #连接数据库 … 继续阅读“Python数据库-链接mongodb带用户验证”
:
-
import ftplib, sys ftp1 = ftplib.FTP(‘127.0.0.1’, ‘book’, ‘bookpw’) ftp1.cwd(‘/Dir’) ftp2 = ftplib.FTP(‘www.holdenweb.com’, ‘bookuser’, ‘bookpw’) ftp2.cwd(‘/public’) sock1 = ftp1.transfercmd(‘RETR a.zip’) sock2 = ftp2.transfercmd(‘STOR b.zip’) flen = … 继续阅读“python实现ftp传输”
:
-
#!/usr/bin/env python # -*- coding: utf-8 -*- def is_chinese(uchar): """判断一个unicode是否是汉字""" if uchar >= u’\u4e00′ and uchar <= u’\u9fa5′: return True else: return False def fill_text_to_print_width(text, width): st … 继续阅读“python中英文混合字符串对齐输出”
:
-
# encoding:utf-8 import sys reload(sys) sys.setdefaultencoding("utf8") import urllib, urllib2 from pprint import pprint from collections import Counter, OrderedDict from bs4 import BeautifulSoup from jinja2 import Environment, PackageLoader … 继续阅读“python 抓取期货咨询供分析”
:
-
#网上代码 def open_httptxt(): #打开TXT文本写入数组 st=time.clock() try: passlist = [] list_passlist=[] xxx = file(‘http.txt’, ‘r’) for xxx_line in xxx.readlines(): #past.append(xxx_line) passlist.append(xxx_line) xxx.close() for i in passlist: #python 列表去重 if i … 继续阅读“python 对比list的处理速度”
:
-
#!/usr/bin/python2.7 # -*- coding:utf-8 -*- import urllib,urllib2 import re import subprocess import sys output=” def html(html): #print str response=urllib2.urlopen(html) return str(response.readlines()) def getpage(html): pattern=re.compile(" … 继续阅读“python ip反查”
:
-
有了pywin32是不是就能在Windows上为所欲为了? 是的。 # -*- coding: cp936 -*- # import os import pythoncom from win32com.shell import shell from win32com.shell import shellcon def set_shortcut(filename,lnkname,iconname):#如无需特别设置图标,则可去掉iconname参数 shortcut = pythoncom.CoC … 继续阅读“python创建桌面快捷方式的代码”
:
-
#打印斐波拉契数列 #!/usr/bin/python def feibolaqi(n): if n == 0 or n == 1: return n else: return feibolaqi(n-1) + feibolaqi(n-2) num = int(raw_input(‘please input a int:’)) if num >= 0: print ‘feibolaqi(%d) is %d’ % (num,feibolaqi(num)) else: print ‘input … 继续阅读“python 打印斐波拉契数列”
:
-
该脚本作用用于查询日志过去一分钟内的并发量,并发单位位1分钟,结果打印在标准输出中,可以配合一些软件实现日志的并发实时监控,比如zabbix。“`python ! /usr/local/bin/python3 import sys import re import datetime import os def generate_previous_minutes(): format=’%d/%b/%Y:%H:%M’ return (datetime.dateti … 继续阅读“python 用python脚本监控并发量”
:
-
# -*- coding: cp936 -*- #python读取excel import xlrd def main(): xls=xlrd.open_workbook("d:\\11.xls") try: mysheet=xls.sheet_by_name("Sheet1")#找到名为Sheet1的工作表。区分大小写 except: print("没有此工作表") return print("共有 %d 行, %d 列。& … 继续阅读“python 利用xlrd模块实现Python读取Excel文档”
: