python·那些不值钱的经验
阅读原文时间:2023年07月11日阅读:1
  • 时间:2018-11-22 整理:byzqy

python读写文本文件

1 # -*- coding: utf-8 -*-
2
3 def read_file(file):
4 with open(file, 'r') as f:
5 print(f.read())
6 f.close()
7
8 def write_file(file):
9 with open(file, 'a') as f:
10 for i in range(10):
11 f.write(str(i) + '\n')
12 f.close()
13
14 file = 'test.txt'
15 write_file(file)
16 read_file(file)

转自:https://blog.csdn.net/u010429424/article/details/76136727

python字符串拼接

1 # python中字符串拼接的方法
2
3 # 1. 加号
4 print 'Python' + 'Tab'
5 ==>PythonTab
6
7 # 2. 逗号
8 print 'Python','Tab'
9 ==>Python Tab
10
11 # 3. 直接连接
12 print 'Python''Tab'
13 ==>PythonTab
14 print 'Python' 'Tab'
15 ==>PythonTab
16
17 # 4. 格式化
18 print '%s %s'%('Python', 'Tab')
19 ==>Python Tab
20
21 # 5. join
22 str_list = ['Python', 'Tab']
23 a = ''
24 print a.join(str_list)
25 ==>PythonTab
26
27 # 6. 多行字符串拼接()
28 s = ('select *'
29 'from atable'
30 'where id=888')
31 print s, type(s)
32 ==>select *from atablewhere id=888
33
34 # 7. 使用单引号(''' ''')或者双引号(""" """)
35 name = input("Please input your name: ")
36 age = input("Please input your age: ")
37 sex = input("Please input your sex: ")
38
39 message = '''
40 Information of %s:
41 Name:%s
42 Age:%s
43 Sex:%s
44 '''%(name,name,age,sex)
45 print(message)
46 ==>Information of Alex:
47 Name:Alex
48 Age:38
49 Sex:girl

源自:https://www.cnblogs.com/bigtreei/p/7892113.html

源自:http://www.cnblogs.com/gengcx/p/6710914.html

python字符串操作之字符串分割

1 #定义一个字符串str1
2 >>> str1 = "3w.gorly.test.com.cn"
3
4 #使用默认分隔符分割字符串str1
5 >>> print str1.split()
6 ['3w.gorly.test.com.cn']
7
8 #指定分隔符为'.',进行分割字符串str1
9 >>> print str1.split('.')
10 ['3w', 'gorly', 'test', 'com', 'cn']
11
12 #指定分隔符为'.',并且指定切割次数为0次
13 >>> print str1.split('.',0)
14 ['3w.gorly.test.com.cn']
15
16 #指定分隔符为'.',并且指定切割次数为1次
17 >>> print str1.split('.',1)
18 ['3w', 'gorly.test.com.cn']
19
20 #指定分隔符为'.',并且指定切割次数为2次
21 >>> print str1.split('.',2)
22 ['3w', 'gorly', 'test.com.cn']
23
24 #这种分割等价于不指定分割次数str1.split('.')情况
25 >>> print str1.split('.',-1)
26 ['3w', 'gorly', 'test', 'com', 'cn']
27
28 #指定分隔符为'.',并取序列下标为0的项
29 >>> print str1.split('.')[0]
30 3w
31
32 #指定分隔符为'.',并取序列下标为4的项
33 >>> print str1.split('.')[4]
34 cn

转自:https://www.cnblogs.com/justdo-it/articles/8297303.html (转)

python操作yaml文件

转自:https://blog.csdn.net/lmj19851117/article/details/78843486(python yaml用法详解)

参考:https://blog.csdn.net/legendary_Dragon/article/details/80927881(如何安装Python的yaml包)

python操作json文件

转自:https://www.cnblogs.com/tjuyuan/p/6795860.html(python json模块 超级详解)

python实现计算机屏幕水印

地址:https://blog.csdn.net/kk185800961/article/details/79296315

利用Python爬取网页图片

地址:https://www.cnblogs.com/dearvee/p/6558571.html

python爬虫

地址:https://blog.csdn.net/jsmok_xingkong/article/details/78448932

地址:https://blog.csdn.net/csqazwsxedc/article/details/68498842

python爬虫常用第三方库

地址:https://blog.csdn.net/woshisunchi/article/details/60877817

[python]pip常用命令

地址:https://www.cnblogs.com/xueweihan/p/4981704.html

非官方的Windows二进制文件Python扩展包(★★★★☆)

地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/

Python正则表达式指南

地址:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

Python的.py文件打包成exe可执行文件

地址:https://www.cnblogs.com/dearvee/p/6580370.html

--the end--