#author: 54yuri
import os
import sys
def read_file( file_path ):
fd = open( file_path, "r" )
fd.seek( 0, os.SEEK_SET )
content = fd.read()
fd.close()
return content
def write_file( file_path, content ):
fd = open( file_path, "w" )
fd.seek( 0, os.SEEK_SET )
fd.write( content )
fd.flush()
fd.close()
def trim_trailling_spaces( old_content ):
new_content = ""
for line in old_content.splitlines():
line = line.rstrip(" ")
new_content += ( line + "\n" )
return new_content
def replace_tab_sign_with_spaces( old_content ):
new_content = ""
for line in old_content.splitlines():
line = line.replace( "\t", " " )
new_content += ( line + "\n" )
return new_content
def open_files( base_dir, file_ext_name ):
content = ""
for root, dirs, files in os.walk( base_dir ):
for file_name in files:
#print file_name
if ( os.path.splitext( file_name )[1] == file_ext_name ):
file_path = root + "/" + file_name
content = read_file( file_path )
print "%s need to be adjusted"%file_path
content = replace_tab_sign_with_spaces( content )
content = trim_trailling_spaces( content )
write_file( file_path, content )
def test1( ):
base_dir = "/tmp/abc"
file_ext_name = ".py"
open_files( base_dir, file_ext_name )
if __name__ == '__main__':
test1( )
分享到:
相关推荐
Introduction to Python Programming and developing GUI applications with PyQT.pdf 作者B.M. Harwani © 2012 Course Technology, a part of Cengage Learning. ISBN-13: 978-1-4354-6097-3 ISBN-10: 1-4354-6097...
idf_monitor also has a range of features to decode crash output and interact with the device. Check the documentation page for details. Exit the monitor by typing Ctrl-]. To build, flash and ...
Through exposure to the news and social media, you are probably aware of the fact that machine learning has become one of the most exciting technologies of our time and age. Large companies, such as ...
firstly, we focus on detailed coverage of deep learning (DL) and transfer learning, comparing and contrasting the two with easy-to-follow concepts and examples. The second area of focus is real-world...
14. If the two ISPs do not peer with each other, then when they send traffic to each other they have to send the traffic through a provider ISP (intermediary), to which they have to pay for carrying ...
are interested in learning how to create a low-cost supercomputer and get started with scientific programming at very low cost. However, this book is not for people completely new to the world of ...
Py2neo is a simple and pragmatic Python library that provides access to the popular graph database Neo4j via its RESTful web service interface. This brings with it a heavily refactored core, a cleaner...
《Search and Replace 6.4 汉化零售版》是一款功能强大的文本处理工具,专为需要在大量文件中执行搜索和替换操作的用户设计。它简化了在多个文档中同步修改文本的工作流程,极大地提高了效率。这款软件的汉化零售版...
Through exposure to the news and social media, you are probably aware of the fact that machine learning has become one of the most exciting technologies of our time and age. Large companies, such as ...
on recipes to advance your web scraping skills to expert levelAddress complex and challenging web scraping tasks using PythonUnderstand the web page structure and collect meaningful data from the ...
If you re already familiar with SVMpython, it s possible to get a pretty good idea of how to use the package merely by browsing through svmstruct.py and multiclass.py. This document provides a more ...
这就是Python可视化打包工具如`auto-py-to-exe`和`pyinstaller`的作用。它们可以将Python脚本转换为跨平台的exe文件,使得Windows用户无需安装Python环境即可运行。 `auto-py-to-exe`是一个基于图形用户界面(GUI)...
项目中使用的是1.4.7,作为...Change the format of a Subversion working copy to that of SVN_VERSION. --skip-unknown-format : skip directories with unknown working copy format and continue the update
The Rust build system uses a Python script called x.py to build the compiler, which manages the bootstrapping process. It lives at the root of the project. It also uses a file named config.toml to ...
After consolidating the basics, you will use TensorFlow to build a practical image-recognition model that you will deploy to a web server using Flask, making it accessible over the Internet....
安装JayDeBeApi时,如果报错,提示:error: Could not find suitable distribution for Requirement.parse('py4j') 需要先安装这个py4j
2 I run the two py file code in two machines,first, you should get to know the ip address of server machine, and replace the HOST constant with your own server ip, then type message firstly on ...
The `elasticsearch-py` library provides a Python client to interact with Elasticsearch, enabling developers to harness the full power of Elasticsearch through Python applications. This document will ...
geographic data science with pysal and thie pydata stack