1. 程式人生 > 其它 >【python】python刪去檔案中的回車、空格等

【python】python刪去檔案中的回車、空格等

技術標籤:pythonpython

文章目錄

英語渣在看外國文獻時喜歡谷歌成段直接翻譯,但是pdf文字直接貼上存在換行符,谷歌翻譯不能識別,所以用python刪去。
這個故事告訴大家要好好學英語。

參考

連結1中的大哥寫的已經完全能夠實現功能了,但是可能python版本比較老所以報了好多提示,因此做了一些修改。(python 3.8 PEP8)

原始碼

def strip_file(old_f_name, new_f_name):
    """remove the space or Tab or enter in a file,and output to a new file in the same folder"""
    fp = open(old_f_name, 'r', encoding='gb18030')
    new_fp = open(new_f_name, "w")
    for each_line in fp.readlines(
): # newStr = each_line.replace(" ", "").replace("\t", "").strip() new_str = each_line.replace("\n", " ") # print "Write:",newStr new_fp.write(new_str) fp.close() new_fp.close() if __name__ ==
"__main__": oldName = input("input file name:") nameList = oldName.split(".") newName = "%s%s%s" % (nameList[0], "_new.", nameList[1]) strip_file(oldName, newName) print("finish output to new file:", newName)

使用

  • 輸入檔名(eg. 123.txt)
This book deals with the problem of trajectory planning, i.e. of the
computation of desired motion profiles for the actuation system of automatic
machines. Because of their wide use, only electric drives are
considered here, and their motion is defined in the context of the realtime
control of automatic machines with one or more actuators, such
as packaging machines, machine-tools, assembly machines, industrial
robots, and so on. In general, for the solution of this problem some
specific knowledge about the machine and its actuation system is also
required, such as the kinematic model (direct and inverse) (usually
the desired movement is specified in the operational space, while the
motion is executed in the actuation space and often these domains
are different) and the dynamic model of the system (in order to plan
suitable motion laws that allow to execute the desired movement with
proper loads and efforts on the mechanical structure). Moreover, for
the real-time execution of the planned motion, it is necessary to define
proper position/velocity control algorithms, in order to optimize
the performances of the system and to compensate for disturbances
and errors during the movements, such as saturations of the actuation
system. Several techniques are available for planning the desired
movement, each of them with peculiar characteristics that must be well
known and understood. In this book, the most significant and commonly
adopted techniques for trajectory planning are illustrated and
analyzed in details, taking into account the above mentioned problems.
  • 生成123_new.txt
This book deals with the problem of trajectory planning, i.e. of the computation of desired motion profiles for the actuation system of automatic machines. Because of their wide use, only electric drives are considered here, and their motion is defined in the context of the realtime control of automatic machines with one or more actuators, such as packaging machines, machine-tools, assembly machines, industrial robots, and so on. In general, for the solution of this problem some specific knowledge about the machine and its actuation system is also required, such as the kinematic model (direct and inverse) (usually the desired movement is specified in the operational space, while the motion is executed in the actuation space and often these domains are different) and the dynamic model of the system (in order to plan suitable motion laws that allow to execute the desired movement with proper loads and efforts on the mechanical structure). Moreover, for the real-time execution of the planned motion, it is necessary to define proper position/velocity control algorithms, in order to optimize the performances of the system and to compensate for disturbances and errors during the movements, such as saturations of the actuation system. Several techniques are available for planning the desired movement, each of them with peculiar characteristics that must be well known and understood. In this book, the most significant and commonly adopted techniques for trajectory planning are illustrated and analyzed in details, taking into account the above mentioned problems.

後續

複製貼上過程還是過於繁瑣,需求簡化。