longgb246的博客


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 公益404

  • 搜索
close
longgb246的博客

os/sys 模块 python操作文件路径

发表于 2017-01-12 | 分类于 Python |

当前路径:

1
2
3
# -*- coding: utf-8 -*-
import sys, os
pwd = sys.path[0] # 获取当前执行脚本的位置

参数:

  • `file`:当前文件完整路径,包括文件名
  • os.path.dirname(file): 某个文件所在的目录路径
  • os.path.join(a, b, c,….): 路径构造 a/b/c
  • os.path.abspath(path): 将path从相对路径转成绝对路径
  • os.pardir: Linux下相当于”../“,上一级目录的标志
阅读全文 »
longgb246的博客

matplotlib 画图风格

发表于 2016-12-25 | 分类于 Python |
1
2
3
import matplotlib.style as mstyle
print mstyle.available
plt.style.use('seaborn-darkgrid')
阅读全文 »
longgb246的博客

matplotlib 使用中文

发表于 2016-12-25 | 分类于 Python |

一、颜色调整

绿色:#6AB27B
土色:#a27712
浅紫色:#8172B2
蓝色:#4C72B0
红色:#C44E52

二、使用中文

1
2
3
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei'] # 使用中文
mpl.rcParams['axes.unicode_minus'] = False # 解决负号问题
阅读全文 »
longgb246的博客

chardet 模块 编码检测

发表于 2016-12-25 | 分类于 Python |

一、基本用法

使用detect函数

输入字符串,输出检测的编码和置信度。

1
2
3
4
5
6
import urllib
rawdata = urllib.urlopen('http://yahoo.co.jp/').read()
import chardet
chardet.detect(rawdata)
[out] {'encoding': 'EUC-JP', 'confidence': 0.99}

阅读全文 »
longgb246的博客

ANSII码和进制转换

发表于 2016-12-25 | 分类于 Python |

一、进制转换

bin():其他进制数值 —> 二进制字符串

1
2
3
[10=>2]: bin(10)
[8 =>2]: bin(012)
[16=>2]: bin(0xa)

oct():其他进制数值 —> 八进制字符串

1
2
3
[10=>8]: oct(10)
[2 =>8]: oct(0b1010)
[16=>8]: oct(0xa)

阅读全文 »
1…91011
longgb246

longgb246

这个人太懒了,什么都没有留下...

52 日志
9 分类
24 标签
RSS
GitHub 微博 简书 CSDN 经管之家
我的好友
  • 大抹茶君
© 2017 longgb246
由 Hexo 强力驱动
主题 - NexT.Pisces