
Python............
Marvin_wu
这个作者很懒,什么都没留下…
展开
-
python 删除文本中的特定行
目标:删除文本中e-14,e-15...等字符所在行#!/usr/bin/pythonfile=open('./a.dspf')lines=file.readlines()c=[]keyword=['e-14','e-15','e-16','e-17','e-18','e-19','e-20','e-21']for x in lines: flag=0 for y in keyword: if y in x:原创 2021-04-21 13:45:22 · 2856 阅读 · 0 评论 -
Python 爬虫网页抓图保存
网站选择桌面壁纸网站的汽车主题:下面的两个print在调试时打开#print tag#print attrs#!/usr/bin/env pythonimport reimport urllib2import HTMLParserbase = "http://desk.zol.com.cn"path = '/home/mk/cars/'star = ''def get_原创 2014-11-16 22:25:12 · 4264 阅读 · 1 评论 -
Beginning Python From Novice to Professional (8) - 文件方法
文件方法读写:#!/usr/bin/env pythonf = open('somefile.txt','w')f.write('Hello,')f.write('World!')f.close()f = open('somefile.txt','r')print f.read(5)Hello使用基本文件方法:#!/usr/bin/env pythonf = open(r原创 2014-11-15 15:29:08 · 846 阅读 · 0 评论 -
Beginning Python From Novice to Professional (9) - Socket
Socket小型服务器:#!/usr/bin/env pythonimport sockets = socket.socket()host = socket.gethostname()port = 1234s.bind((host,port))s.listen(5)while True: c,addr = s.accept() print 'Got connection原创 2014-11-15 17:24:43 · 886 阅读 · 0 评论 -
Beginning Python From Novice to Professional (7) - 类
类创建简单类:#!/usr/bin/env python__metaclass__ = typeclass Person: def setName(self,name): self.name = name def getName(self): return self.name def greet(self): print "Hello,world! I'm %s."原创 2014-11-13 17:29:15 · 871 阅读 · 0 评论 -
Beginning Python From Novice to Professional (6) - 函数使用
函数使用定义函数:原创 2014-11-13 13:56:28 · 901 阅读 · 0 评论 -
Beginning Python From Novice to Professional (3) - 列表操作
列表操作list函数:>>> list('hello')['h', 'e', 'l', 'l', 'o']改变列表:>>> x=[1,1,1]>>> x[1]=2>>> x[1, 2, 1]删除元素:>>> names = ['wu','li','zhao','qian']>>> del names[1]>>> names['wu', 'zhao', 'qian']分原创 2014-11-12 14:00:33 · 1134 阅读 · 0 评论 -
Beginning Python From Novice to Professional (4) - 字符串格式示例
$ gedit price.py#!/usr/bin/env pythonwidth = input('Please enter width: ')price_width = 10item_width = width - price_widthheader_format = '%-*s%*s'format = '%-*s%*.2f'print '=' * width原创 2014-11-12 15:48:47 · 843 阅读 · 0 评论 -
Beginning Python From Novice to Professional (5) - 条件与循环
条件与循环条件执行:name = raw_input('What is your name? ')if name.endswith('Gumby'): print 'Hello, Mr.Gumby'What is your name? GumbyHello, Mr.Gumbyname = raw_input('What is your name? ')if name.endswit原创 2014-11-12 18:00:45 · 795 阅读 · 0 评论 -
Beginning Python From Novice to Professional (1) - 数字和表达式
数字和表达式加减乘除:>>> 2+24>>> 100-5050>>> 3*515>>> 1/20>>> 1.0/2.00.5求余、乘方:>>> 1%21>>> 10%31>>> 2**38>>> -3**2-9>>> (-3)**29十六进制、八进制:>>> 0xff255>>> 02016变量:>>> x=3>>> x*26获取输原创 2014-11-12 11:45:48 · 1316 阅读 · 0 评论 -
Beginning Python From Novice to Professional (2) - 命令行运行Python脚本
命令行运行Python脚本Linux下先创建一个hello.py$ gedit hello.py输入:#!/usr/bin/env pythonprint 2+2保存退出,运行:$ python hello.py 4我们也可以让它变得和普通程序一样执行执行之前,让脚本文件具备可执行属性:$ chmod a+x hello.py运行脚本:$ ./hello.py原创 2014-11-12 12:53:23 · 1321 阅读 · 0 评论