[root@localhost /]# cat key.py #!/bin/pythonfrom random import *import refrom collections import Countera=[randint(1,15) for _ in range(20)]b=dict.fromkeys(a,0)for i in b: b[i]+=1e=[(k,v) for k,v in b.items()]print(sorted(e))c=Counter(a)d=c.most_common(3)print aprint ...【阅读全文】
[root@localhost /]# cat list.py #!/bin/pythonfrom random import randintd=[randint(-10,10) for _ in range(10)]s={'student%d' %i:randint(-10,10) for i in range(10)}t=[x for x in d if x >=0]#if (4,3)>(3,4):# print 'aaaaaaaaaaaa'r=[(y,x) for x,y in s.items()]print sprint rpr...【阅读全文】
[root@localhost ~]# python test.py请输入qwerTraceback (most recent call last): File "test.py", line 3, in <module> a = input('请输入') File "<string>", line 1, in <module>NameError: name 'qwer' is not definedtest.py文件内容如下[root@localhost ~]# cat test.py...【阅读全文】
[root@server testpython]# python server.py File "server.py", line 8SyntaxError: Non-ASCII character '\xe7' in file server.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details报错原因:因为Python在默认状态下不支持源文件中的编码所致解决办法:#!/us...【阅读全文】
centos7中编辑python脚本时,导入了psutil模块,在执行时出错[root@server ~]# ./hello.pyTraceback (most recent call last): File "./hello.py", line 2, in import psutilModuleNotFoundError: No module named 'psutil'【阅读全文】
最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了。首要条件,python版本必须是2.7以上(huodie安装的系统为CentOS Linux release 7.4.1708(Core))。 出自:https://www.cnblogs.com/lxmhhy/p/6029465.html...【阅读全文】