def foo(): x=3 def bar
weburl = "http://www.douban.com/"content=urllib.urlopen(weburl).read()ppp=r'"(https://imor i in mind: print(i) url
import xlrdworkbooks=xlrd.open_workbook("test.xlsx")print(workbooks.sheet_names())#获取sheet页的名heet_by_name("Sheet1
1.函数中引用的全局变量始终是定义该函数模块中的全局变量。‘import sys,ossys.path.append(os.getcwd())from foo import fo_funname="Current module"def bar(): print("当前模块中函数bar:") print("变量name",name)def call_foo
class Counter: def __init__(self,x=0): self.x=xcounter=Counter()def used_iter(): counter.x+=2 return counter.xfor i in iter(used_iter,8): print("本次遍历的数值:",i)代码定义一个
import urllib.requestr = urllib.request.Request("https://www.google.com")handler = urllib.request.HTTPSHa
1.安装Mysql-Python 官网即可2.python setup.py install3.安装 VC++9.0 Compile for Python27 网址是 http
time.sleep(9)import signalprint(u"等待jieshu")dal.send_signal(signal.CTRL_C_EVENT)
import requestsheaders={"User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.3427.400 QQBrowser/9.6.12513.400"}cookie={"coo
#coding:utf-8# from HTMLParser import HTMLParserimport sqlite3connect=sqlite3.connect("test.db"
1.[A-Za-z]表示匹配其中任意一个字母,而[A-Za-z]\w+它后面跟着一个或者更多的字
#coding:utf-8from threading import Threadfrom concurrent.futures import ThreadPoolExecutorfrom threading import RLockimport requestsimport timefrom bs4 import BeautifulSoupclass Screap(Thread)
1.安装pip install guppy2.获取hpy()profile=hpy()print profile.heap()3.检测固定函数的内存消耗输出
此处的Queue可以应用到Process里面,但是不能用到进程池使用进程池应该用Manager
#coding:utf-8import paramiko""" 删除文件 root权限"""ssh=paramiko.SSHClient()ssh.set_missing_host
#coding=utf-8import xlwt,MySQLdb#第一步创建连接coon=MySQLdb.connect(host='127.0.0.1',user='host',passwd='',db='test',port=3306)#第二步创建游标cuor=coon.cursor()#插入数据cuor.execute("insert into msg (title,name,
#coding:utf-8import paramiko""" 创建文件 删除文件 root权限"""ssh=paramiko.SSHClient()sshrname="tes
>>> filename=urllib.urlretrieve(url,r"D:\code\sogou.html")>>> url2=r'http://www.baidu.com/!@#'>>> urllib.quote(url2)'http%3A//www.baidu.com/%21%40%23'>>> urllib.quote_plus(url2)'http%3A%2F%2
a=M()a.start()print dir(a)import timetime.sleep(3)import signala._Thread__stop()print a._Thread__stopped True | False
import urllib,urllib2import base64url=r"https://www.baidu.com/"base64String=base64.encodestring("bobo3520:4565892").strip()#删除换行符authheader="Basic "+base64Stringreq=urllib2.Request(url)req.add_
import queuep=queue.PriorityQueue()#优先级队列p.put((1,"alex"))p.put((0,"alex2"))p.put((3,"alex3"))print(p.get())
#urlparse主要是讲url拆分为6部分,并返回元祖url="https://www.baidu.com/user/index.html;20?name=zz&age=18#8888"parseMethod=urlparse.urlparse(url)print(parseMethod)print parseMethod[0]print parseMethod[1]print pa
def testTryAll(index,i): stulst=["John","Jenny","Tom"] try: print(len(stulst[index])/i) except IndexError: print("Error")print("Try all ... Right")testTryAll(1,2)
例子:if a>0:print('+')缩进的语句只有一条而写在同一
1.Python语言中类的属性有两类实例属性类属性
class Ant: def __init__(self,x=0,y=0,color="red"): self.x=x self.y=y self.color=color def crawl(self,x,y): self.y=y self.x=x print("爬行")
Python中类属性有类属性和实例属性之分,类的方法也有不同的种类实例方法类方法静态方法例子:class DemoMthd(): @staticmethod#静态方法 def static_mthd(): print("调用了静态方法") @classmethod#类方法 def class_mthd(cls):
class PrintA: namea="PrintA" def set_value(self,a): self.a=a def set_namea(self,namea): PrintA.namea=namea def info(self): print("PrintA:%s,%s"%(PrintA.n
Copyright © 2005-2025 51CTO.COM 版权所有 京ICP证060544号