Anaconda3 基本命令
系统当前已有的Python环境,执行命令:conda info --envs
添加一个Python2.7的环境:conda create --name python36 python=3.6
查看当前已安装的环境 conda env list
查看当前使用的Python版本,执行命令:python --version
conda remove --name python36 --all,进行删除
python中字符串与(列表、元组、集合、字典)间的转换
字符串 -->
转换成列表:list()
转换成元组:tuple(),zip()
转换成集合:set()
转换成字典:dict()
(列表、元组、集合、字典)
转换成字符串:join()
强大的字符串表达式函数:eval()
生成一维矩阵:
l = [0 for j in range(N)]
l =[] 序列
生成2维矩阵:n*m
matrix = [[0]*m for i in range(n)]
# float 数取2位小数
num2 = float('%.2f' %num)
# 向csv文件中写入/读取数据,csv文件中的数据,可直接导入到excel中,数字与表格一一对应
import csv
import numpy as np
file2 = open("E:\Desk\MyProjects\Python\Web_Scraping_with_python/ff",'a+')
M =np.array( [[1,2,3,4],
[3,4,5,6],
[7,8,9,0]])
M = np.array(M)
with file2 as ff:
# delimiter 以空格划分各个数据 (也可以 ,;)
test_writer = csv.writer (ff, delimiter=' ', quotechar='"')
# np.size(M,0) 行数, np.size(M,1)列数
for i in range (np.size(M,0)):
# 写入 csv 文件 M[][] 二维矩阵
test_writer.writerow (M[i])
# 可直接加载 .csv 文件
m = np.loadtxt('ff')
import re
a = """ hellofeawfa/n\nworld hahahahh
afehh123/nef'a\nj'faew """
注意:只有三单引或者三双引号的情况下,可以直接回车(\n)换行写。其他双引号,单引号写法不同。
b = re.findall ('hello(.*?)world', a)
c = re.findall ('hello(.*?)world', a, re.S)
在字符串a中,包含换行符\n,在这种情况下:
如果不使用re.S参数,则只在每一行内进行匹配,如果一行没有,就换下一行重新开始。
而使用re.S参数以后,正则表达式会将这个字符串作为一个整体,在整体中进行匹配。
print ('b is ', b)
print ('c is ', c)
# 输出结果:
# b is []
# c is ['feawfa/n\n']