模块zlib 压缩与解压

模块zlib用来解压和压缩字符串或者文件,能够自动识别压缩格式来自动解压。

字符串的解压与字符串:

Read more

Python递归实现字典中的Unicode转换成str

由于josn库的loads方法会把类型全部转换成 Unicode。如果想要变成str对象的话,就要自己去encode。

试试如下代码:

1
2
3
4
5
6
7
8
9
def byteify(input):
if isinstance(input, dict):
return {byteify(key): byteify(value) for key, value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input

Python 列出当前目录的文件和文件夹

只获取当前目录的文件和文件夹

1
2
3
4
5
6
7
list = os.listdir(rootdir)#列出目录下的所有文件和目录
for line in list:
filepath = os.path.join(rootdir,line)
if os.path.isdir(filepath):#如果filepath是目录
print "dir:" + filepath
else:
print "file:" + filepath
Read more

Python中执行 Sehll 命令

在日常的使用中,会经常遇到需要执行 Shell 命令的情况,但是很多时候,在 Python 下执行也是很方便的。下面介绍四种方法以供参考。

Read more

使用 Runfus 为 Windows10 创建 USB 启动盘

Rufus 是一个可以帮助格式化和创建可引导USB闪存盘的工具,比如 USB 随身碟,记忆棒等等。

在如下场景中会非常有用:

  • 你需要把一些可引导的ISO格式的镜像(Windows,Linux,UEFI等)创建成USB安装盘的时候
  • 你需要使用一个还没有安装操作系统的设备的时候
  • 你需要从DOS系统刷写BIOS或者其他固件的时候
  • 你需要运行一个非常底层的工具的时候
Read more

让 MacBook 读取 txt 文本

请问如何让 MacBook 读取Windows 下的 txt 文本?很多时候,每次打开都是乱码。

这个就是一个编码转换的问题。Linux 和 MacBook 都提供了一个强大的命令行命令:iconv

Read more

sshpass 的使用

​ ssh远程连接时,每次都提示需要输入密码。需要ssh到多台机器时很不方便。sshpass可以解决这个问题。sshpass可以实现ssh的自动的登录。直接在命令里输入密码,但是安全性的问题需要自己判断。

Read more

Python Pip 使用警告

在macOS更新完pip(9.0.1)之后使用会出现如下警告:

1
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.

虽然不影响使用,但是还是要解决。方法如下:

Read more
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×