1.Python保存字符串到文件 2.dir()函数 3.jieba分词 4.WordCloud词云包的安装

1.记录一下Python保存字符串到文件的方法:

def save_to_file(file_name, contents):
    fh = open(file_name, 'w')
    fh.write(contents)
    fh.close()

save_to_file('mobiles.txt', 'your contents str')

 

 

2.

dir() 函数

 dir([object]) 会返回object所有有效的属性列表。示例如下:

复制代码

$ python
Python 2.7.8 (default, Sep 24 2015, 18:26:19) 
[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> mser = cv2.MSER()
>>> dir(mser)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'detect', 'empty', 'getAlgorithm', 'getBool', 'getDouble', 'getInt', 'getMat', 'getMatVector', 'getParams', 'getString', 'paramHelp', 'paramType', 'setAlgorithm', 'setBool', 'setDouble', 'setInt', 'setMat', 'setMatVector', 'setString']

复制代码

3.jieba分词

pip intall jieba

4.WordCloud词云包的安装

1,下载

https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud

2,安装    (window环境安装)

找的下载文件的路径   

安装  

1

pip install wordcloud-1.3.2-cp36-cp36m-win_amd64.whl

  

 

3,验证是否安装成功

添加英文数据的文件,比如我的是testfile.txt

文件内容为英文,比如

Devouring Time, blunt thou the lion's paws,

And make the earth devour her own sweet brood;

Pluck the keen teeth from the fierce tiger's jaws,

And burn the long-lived phoenix in her blood;
。。。。。。。。

运行python:

1

2

3

4

5

6

7

8

9

10

from wordcloud import WordCloud

 

f = open(u'D:\PythonWorkspace\AI/testfile.txt''r').read()

 

wordcloud = WordCloud(background_color="white", width=1000, height=860, margin=2).generate(f)

import matplotlib.pyplot as plt

 

plt.imshow(wordcloud)

plt.axis("off")

plt.show()wordcloud.to_file('test1.png')//保存图片

 

结果

 

哈哈哈哈,就这么解决了。。。双击66666666666666666666666666666666666666

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值