玩Python的日子也不算短了,正儿八经的东西也没见作出来一个。不过有什么关系呢,脚本语言么,给自己带来方便才是真的。
Python除了作为可以编写程序之外,利用它的强大函数库,用交互模式来快速的完成一些小任务,也是不错的选择。
1、转换big5文件为utf-8
上次下载了一个电影字幕,big5编码的,看着是乱码。所以用Python转了一下:
>>> src = open("1.srt").read()
>>> dest = unicode(src, "big-5").encode("utf-8")
>>> open("2.srt", "w").write(dest)
2、查看quoted编码。
有人问RescoViewer_v4%5b1%5d.30.3%bc%f2%cc%e5%d6%d0%ce%c4%b0%e6这个是什么意思?
用Python看看吧:
>>> import urllib
>>> print urllib.unquote("RescoViewer_v4%5b1%5d.30.3%bc%f2%cc%e5%d6%d0%ce%c4%b0%e6")
RescoViewer_v4[1].30.3简体中文版
3、为文件加上HTML段落标记
用FireFox写文章就是要自己一段一段的分段比较不爽(我不爱用FCKEditor)。用Python试试吧:
>>> lines = open("test.txt").readlines()
>>> fp = open("output.txt", "w")
>>> for line in lines:
... fp.write("<p>%s</p>" % line)
...
>>> fp.close()
4、把CSV格式的文件转换成TAB排版格式
>>> lines = open("aaa.csv").readlines()
>>> fp = open("output.txt", "w")
>>> for line in lines:
... fp.write('\t'.join(line.split(',')))
>>> fp.close()
分享到:
相关推荐
Pymacs is a powerful tool which, once started from Emacs, allows two-way communication between Emacs Lisp and Python. Pymacs aims to employ Python as an extension language for Emacs rather than the ...
to know it to be able to pick it up as a tool and wield it on important projects to deliver real value. From the applied perspective, gradient boosting is quite a shallow field and a motivated ...
Selenium is a very useful tool but it is not an easy tool which lets us use it as soon as we learn it. Practice is necessary but it is not desirable to use the real website running in the internet for...
In the realm of financial technology (FinTech), Python has emerged as a powerful tool for analyzing big financial data. The book "Python for Finance" by Yves Hilpisch is a comprehensive guide that ...
You can think of Python as your tool to solve problems that are far beyond the capability of a spreadsheet. It is an easy-to-use and easy-to learn programming language that is freely available on ...
and the principles of perception Understand why Python is an effective tool for numerical computation much like MATLAB, and explore some interesting data structures that come with it Use various ...
Python started as a general purpose language. Around ten years ago, in 2006, the first version of NumPy was released, which made Python a first class language for numerical computing and laid the ...
Gradient Boosting does have a some fascinating math under the covers, but you do not need to know it to be able to pick it up as a tool and wield it on important projects to deliver real value....
Completely updated for version 3.x, Programming Python also delves into the language as a software development tool, with many code examples scaled specifically for that purpose. Topics include: ...
Master over 170 recipes that will help you turn QGIS from a desktop GIS tool into a powerful automated geospatial framework About This Book Delve into the undocumented features of the QGIS API Get a...
Python started as a general purpose language. Around ten years ago, in 2006, the rst version of NumPy was released, which made Python a rst class language for numerical computing and laid the ...
Python is an effective tool to use when coupling scientific computing and mathematics and this book will teach you how to use it for linear algebra, arrays, plotting, iterating, functions, ...
detail how to use the Inkscape drawing tool to convert shapes traced from a photographic image into a sequence of points which reproduce the shape in Python. Once a line is expressed as a Python ...
- Explore Python’s major built-in object types such as numbers, lists, and dictionaries - Create and process objects with Python statements, and learn Python’s general syntax model - Use functions ...
If you are a programmer or a data analyst familiar with the Python programming language and want to perform analyses of your social data to acquire valuable business insights, this book is for you....