随笔分类 - python
摘要:001、 >>> str1 = "ab_cd ef_gh ij_kl" ## 测试字符串 >>> str1.split(" ") ## 一句空格进行拆分 ['ab_cd', 'ef_gh', 'ij_kl'] >>> import re >>> re.split("[_| ]",str1) ## 同
阅读全文
摘要:001、 >>> import sys >>> print(sys.version) 2.7.5 (default, Jun 28 2022, 15:30:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
阅读全文
摘要:001、python报错 >>> dict1 = {"aa":300, "bb":500, "cc":400, "dd":700} >>> dict1 {'aa': 300, 'bb': 500, 'cc': 400, 'dd': 700} >>> dict1.keys() dict_keys(['
阅读全文
摘要:001、python报错如下: >>> dict1 = {"aa":700, "bb":400, "cc":300, "dd":600} >>> dict1.values().index(300) Traceback (most recent call last): File "<stdin>",
阅读全文
摘要:001、 >>> dict1 = {"aa":500, "bb":400, "cc":700, "dd":300} >>> dict1 {'aa': 500, 'cc': 700, 'dd': 300, 'bb': 400} >>> dict1.keys()[dict1.values().index
阅读全文
摘要:两者都返回首次匹配字符串的索引,re.match函数只从头开始匹配, re.search函数不限制只从头开始匹配。 001、re.match函数 [root@PC1 test2]# python3 Python 3.10.9 (main, Mar 1 2023, 18:23:06) [GCC 11.
阅读全文
摘要:001、 [root@PC1 test3]# ls a.txt [root@PC1 test3]# cat a.txt ## 测试文件 10 2 3 0 3 6 6 12 1 1 5 1 2 2 2 4 2 26 8 3 33 34 5 3 [root@PC1 test3]# python ## 启
阅读全文
摘要:001、 [root@PC1 ~]# pip config list 002、 [root@PC1 ~]# cd ~ [root@PC1 ~]# ls -a . .bash_history .bashrc .cshrc Documents .ICEauthority Music Public .tc
阅读全文
摘要:python2.7中安装pip命令 001、 [root@PC1 test]# pip bash: pip: command not found... 002、 [root@PC1 test]# cat /etc/redhat-release 003、 [root@PC1 software]# cu
阅读全文
摘要:001、 >>> import re >>> tmp = re.match(r'^([^\s]+)\s(.*)', "ab cd") >>> tmp <re.Match object; span=(0, 5), match='ab cd'> >>> tmp.group(1) 'ab' >>> tmp
阅读全文
摘要:001、re.match >>> re.match("ab", "abcdefgab") ## 在字符串abcdefgab中查找字符串ab, 返回索引 <re.Match object; span=(0, 2), match='ab'> >>> re.match("xy", "abcdefgab")
阅读全文
摘要:001、 (base) [root@PC1 test3]# ls ## 测试数据及脚本 a.txt test.py (base) [root@PC1 test3]# cat test.py ## 复制程序 import os os.popen('cp a.txt b.txt') ## windows
阅读全文
摘要:001、python报错 SyntaxError: Non-ASCII character '\xe8' in file test.py on line 6 原因:注释行中出现了中文 ,而python支持的ASCII码不支持中文。 002、解决方法 在头文件中增加: # -*- coding: ut
阅读全文
摘要:001、 方法1 >>> list1 = [] >>> for i in range(5): ... list1.append("value") ... >>> list1 ['value', 'value', 'value', 'value', 'value'] 002、方法2 >>> list1
阅读全文
摘要:001、 [root@PC1 test]# ls outcome.map test.py [root@PC1 test]# cat outcome.map ## 测试数据 55910 85204 jj 122948 yy kk 203750 rr ee ss 312707 dd ff 356863
阅读全文
摘要:001、查看系统 [root@PC1 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) 002、安装环境依赖 yum -y install gcc install zlib zlib-devel bzip2-devel
阅读全文
摘要:001、python3.11编译报错 /home/software/python/Modules/_ctypes/_ctypes.c:118:17: fatal error: ffi.h: No such file or directory 002、解决方法 [root@PC1 python]# y
阅读全文
摘要:001、 问题 >>> from Bio import SeqIO 002、解决方法 pip3 install biopython -i https://pypi.douban.com/simple 003、测试效果 from Bio import SeqIO
阅读全文
摘要:001、 [root@pc1 test2]# ls a.txt test.py [root@pc1 test2]# cat a.txt ## 测试序列 AGCTTCCCC [root@pc1 test2]# cat test.py ## 测试程序 #!/usr/bin/python in_file
阅读全文
摘要:001、match >>> import re >>> str1 = "www.baidu.com" ## 测试字符串 >>> re.match("www", str1) <re.Match object; span=(0, 3), match='www'> >>> re.match("www",
阅读全文