![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python学习
emmajinxin
程序媛,算法攻城狮
展开
-
pyltp postagger 运行过程中报错Process finished with exit code -1073740791 (0xC0000409)
pyltp postagger 运行过程中报错Process finished with exit code -1073740791 (0xC0000409)解决方案原创 2022-10-28 14:52:37 · 732 阅读 · 1 评论 -
pytorch 安装
anaconda 安装bash Anaconda3-2020.02-Linux-x86_64.shsource ~/.bashrcconda create -n pytorch python=3.7source activate pytorch 或者 condaactivate pytorch官网安装合适版本的pytorchconda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytor...转载 2021-12-01 21:10:25 · 223 阅读 · 0 评论 -
SyntaxError: Non-ASCII character '\xe4' in file test.py on line 3, but no encoding declared
转自: https://www.cnblogs.com/KarryWang/p/3260858.html 第一种:1 #!/usr/bin/python2 #coding:utf-83 print "你好吗" 第二种:1 #!/usr/bin/python2 #-*-coding:utf-8 -*-3 print "你好吗" 第三种:1 #!/usr/b...转载 2018-10-09 21:10:17 · 290 阅读 · 0 评论 -
yield 与yield 文件读取 与generator 生成器
生成器:https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138681965108490cb4c13182e472f8d87830f13be6e88000yield : https://blog.csdn.net/zhangpinghao/article/details/1...转载 2018-10-30 11:48:25 · 574 阅读 · 0 评论 -
python 变量初始化空列表
python 不能写new_loss=old_loss=[]这样 两个变量实际上是同一个list要分开写new_loss=[]Old_loss=[]以下列数据文件为例:def analyze_mmr(fn): #初始化方法一 new_loss = [] old_loss = [] #初始化方法二 new_loss = old_loss ...原创 2018-11-21 17:33:27 · 9539 阅读 · 0 评论 -
【python】【剑指offer】复杂链表的复制
在用python实现复杂链表复制的时候,在最后一步分离原链表与复制的链表时,一开始用的是如下代码“”“”中的部分,但是会报错,因为没有写if判断语句,有可能p已经是最后一个节点,这样p.next.next就为空.# -*- coding:utf-8 -*-# class RandomListNode:# def __init__(self, x):# self.l...原创 2019-07-13 19:32:12 · 199 阅读 · 0 评论 -
【python】【剑指offer】判断平衡二叉树
按照剑指offer复现python版本的平衡二叉树的题时,发现无法通过,代码如下:class Solution: def IsBalanced_Solution(self, pRoot): # write code here d = 0 return self.isBalanced(pRoot,d) def isBalanced...原创 2019-09-08 19:15:26 · 243 阅读 · 0 评论 -
python udf 读取hive 传入的map & python udf 返回hive map
参考:hive之Python UDF函数操作map数据 详解 全是干货 - colby_chenlun的博客 - CSDN博客 https://blog.csdn.net/colby_chenlun/article/details/78140033str_to_map hive 字符串转为map格式 - yuanyangsdo的博客 - CSDN博客 https://blog.csdn.net...原创 2019-09-11 15:03:51 · 1195 阅读 · 0 评论 -
python eval函数--将字符串存储的json格式可以直接转化为map
python eval函数可以将json格式的string 转化为map原创 2019-09-25 23:39:41 · 2029 阅读 · 0 评论 -
python 说明中中括号[]的含义
L.index(value, [start, [stop]]),这里的中括号表示:start和stop是可选参数。可选参数通常都这么写,用的时候别带中括号。如:12l = [1,2,3,4,5,6]l.index(1, 0, 4)start和stop表示搜索的起点和终点。参考链接:https://zhidao.baidu.com/question/568231085.html ...原创 2018-04-24 17:31:35 · 13047 阅读 · 2 评论 -
[python] 取出字典中值最大的2个元素(键-值)
基本思想:先根据字典值的大小对字典进行排序,再遍历取出前2个元素。1.字典排序。可以利用内置sorted()函数按照值的顺序进行排序。#举例:>>>d = {'b':4,'a':1,'c':2}#按值的大小排序:>>>sorted(d.items(),key = lambda d:d[1],reverse=True) #按键的大小由大到小排序,输出为列表。#输出为原创 2018-02-07 21:34:39 · 20797 阅读 · 0 评论 -
【python】输出列表元素,以空格/逗号为分隔符
输出列表元素,以空格/逗号为分隔符原创 2017-08-12 19:34:00 · 157581 阅读 · 11 评论 -
python 判断txt文件的编码格式
import chardetf = open('/path/file.txt',r)data = f.read()print(chardet.detect(data))返回值会是类似这样的 一个是检测的可信度,另外一个就是检测到的编码:{'confidence': 0.99, 'encoding': 'utf-8'}参考链接: 用Python chardet库来判断文件编码原创 2018-01-21 19:34:42 · 13327 阅读 · 1 评论 -
运行cmd时 如何复制路径
运行cmd、打开目录文件、运行程序、复制路径_百度经验 https://jingyan.baidu.com/article/f71d603777237b1ab641d19d.html打开cmd,本人常用两种方式打开,1、在开始按钮搜索程序和文件处输入cmd打开;2;WIN(Alt旁边的按键)+R打开;注:(一般需要用管理员身份打开cmd命转载 2018-01-13 14:57:16 · 2369 阅读 · 0 评论 -
python 3 UnicodeDecodeError: ‘gbk’ codec can’t decode bytes in position 2-3: illegal multibyte
出现错误的情景:读取文件时: with open(path,'r','utf8') as fp: content=fp.read()分析及解决方案:【Python中如何处理UnicodeDecodeError和UnicodeEncodeError】简答:1.仔细分析错误的类型2.搞清自己处理的字符串是什么类型的3.然后换用原创 2018-01-22 10:45:51 · 1822 阅读 · 0 评论 -
PDFSyntaxError: No /Root object! - Is this really a PDF?
在利用适用于python3的pdfminer3k模块将pdf转化为txt时,运行程序出现错误:PDFSyntaxError: No /Root object! - Is this really a PDF?错误原因:pdf是图片格式。正常pdf(比如由word转化的)是可以转换的。原创 2018-01-14 11:35:39 · 5588 阅读 · 4 评论 -
python reload(sys)找不到
python2中,默认输出格式为ASCII,可以通过如下代码#配置utf-8输出环境reload(sys)sys.setdefaultencoding("utf-8")然而,上述代码在python3中运行如上代码会提示:提示 name ‘reload’ is not defined因为:1. Python 3 与 Python 2 有很大的区别,其中Python原创 2018-01-16 20:51:37 · 1289 阅读 · 0 评论 -
python文件绝对路径写法(windows)
python在描述路径时有两种方式:'d:\\a.txt',转义的方式 r'd:\a.txt',声明字符串不需要转义 (使用raw string,也就是在string'前面加r,告诉python不需要转义)推荐使用此写法“/",可以避免很多异常:C:/Users/Administrator/Desktop/python/t1.txt原创 2018-01-14 16:56:32 · 6215 阅读 · 0 评论 -
将UCS-2 Little Endian(即 utf-16)编码的txt文件批量转化为utf-8编码(python)
折腾了好久,终于搞定了。参考链接:python使用codecs模块进行文件操作-读写中英文字符 - CSDN博客 http://blog.csdn.net/chenyxh2005/article/details/72465758#t0代码:import osimport codecspath = 'D:\\yangnian\\Project\\Test\\motor_control'#tx原创 2018-01-18 16:55:10 · 7027 阅读 · 0 评论 -
【python】 文本挖掘预处理之TF-IDF
转自: 文本挖掘预处理之TF-IDF - 刘建平Pinard - 博客园 https://www.cnblogs.com/pinard/p/6693230.html 在文本挖掘预处理之向量化与Hash Trick中我们讲到在文本挖掘的预处理中,向量化之后一般都伴随着TF-IDF的处理,那么什么是TF-IDF,为什么一般我们要加这一步预处理呢?这里就对TF-IDF的原理做一个总结。转载 2018-01-26 16:51:30 · 789 阅读 · 0 评论 -
解决方案:[Errno 10048] error while attempting to bind on address ('127.0.0.1', 9000):
基于python复现廖大神的web系统,在运行,停止(ctrl+c),再运行时会出现:[Errno 10048] error while attempting to bind on address ('127.0.0.1', 9000): 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。解决方案: 关闭编辑器,再次启动编辑器,运行即可。。我用ananconda原创 2017-06-19 15:59:53 · 15115 阅读 · 0 评论