返回列表 发帖
回复 13# netbenton


    如果行尾有tab或者空格时,程序就不行了

TOP

"""
python文本内容居中显示.py
http://bbs.bathome.net/thread-1289-1-1.html
2016年5月2日 04:51:33 codegay
"""
with open("a.txt") as f:
    txt=[r.strip() for r in f]
    w=max([len(r) for r in txt])+10
    [print(r.center(w)) for r in txt]COPY
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

本帖最后由 taofan712 于 2017-3-1 11:06 编辑
@echo off
setlocal enabledelayedexpansion
set "kong=    "
for /f "delims=" %%a in (a.txt) do (
setlocal
for %%b in (%%a) do set /a n+=1
set /a num=80-n*4
set /a num=num/8
for /l %%c in (1,1,!num!) do set/p=%kong%<nul
set/p=%%a<nul
for /l %%c in (1,1,!num!) do set/p=%kong%<nul
echo;
endlocal
)
pauseCOPY
取近似值做的,平均每个单词4个字母。效果不错。
重要的是我想借此问一下,我第八行set /a num=num/8为什么不能跟第七行写一起set /a num=(80-n*4)/8 会报错。

TOP

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,40) do set "space=!space! "
for /f "tokens=1* delims=:" %%a in ('findstr /o .* 1.txt') do (
    if defined num2 (
        set /a "num1=(%%a-!num2!)/2"
        call echo,%%str:~!num1!%%
    )
    set num2=%%a
    set str=!space!%%b
)
pauseCOPY

TOP

返回列表