This topic created in 3037 days ago, the information mentioned may be changed or developed.
菜鸟习作,仅是可用而已,欢迎改善指正
➜ ~ ./replaceblank.py replaceblank.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
if sys.argv[1]:
----path = sys.argv[1]
----myfile = open(path)
----try:
--------for line in myfile:
------------newline = ''
------------for c in line:
----------------if c == ' ':
--------------------newline += '-'
----------------else:
--------------------break
------------newline += line.strip()
------------print(newline)
----finally:
--------myfile.close()
9 replies • 2018-02-07 15:45:58 +08:00
 |
|
1
flyingghost Feb 6, 2018
#!/usr/bin/python # * coding: UTF 8 *
import sys
if sys.argv[1]: path = sys.argv[1] myfile = open(path) try: for line in myfile: newline = '' for c in line: if c == ' ': newline += '-' else: break newline += line.strip() print(newline) finally: myfile.close()
|
 |
|
3
flyingghost Feb 6, 2018
#!/usr/bin/python # -*- coding: UTF-8 -*-
import sys
if sys.argv[1]: path = sys.argv[1] myfile = open(path) try: for line in myfile: newline = '' for c in line: if c == ' ': newline += '-' else: break newline += line.strip() print(newline) finally: myfile.close()
|
 |
|
4
flyingghost Feb 6, 2018
嗯。。。换成全角空格稍微好看一点。 虽然和-号一样不能复制。
|
 |
|
5
twor Feb 6, 2018
@ flyingghost 具体怎么把半角空格怎么替换成全角空格呢? 我搜了一下 newline += u'\u3000' 好像替换后,贴到这里,是乱的
|
 |
|
6
8023 Feb 6, 2018 via Android
emmm 为啥不用 gist 呢?
|
 |
|
9
congeec Feb 7, 2018 1
用 vim 插件 identLine 可破
|