相关疑难解决方法(0)

rstrip没有删除换行符char我做错了什么?

把我的头发拉到这里......在最后一小时里一直在玩这个但是我不能让它做我想做的事,即.删除换行序列.

def add_quotes( fpath ):

        ifile = open( fpath, 'r' )
        ofile = open( 'ofile.txt', 'w' )

        for line in ifile:
            if line == '\n': 
                ofile.write( "\n\n" )
            elif len( line ) > 1:
                line.rstrip('\n')
                convertedline = "\"" + line + "\", "
                ofile.write( convertedline )

        ifile.close()
        ofile.close()
Run Code Online (Sandbox Code Playgroud)

python newline

12
推荐指数
1
解决办法
3万
查看次数

标签 统计

newline ×1

python ×1