python输出问题

2025-06-26 10:57:26
推荐回答(2个)
回答1:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2015��3��24��

@author: qcq
'''

def deal_with(file_in, file_out):

    with open(file_in,'r+') as filename1:
        with open(file_out, 'w') as filename2:
            for line in filename1:
                # space as split string. you can also use re module
                tmp = line.split(' ')
                print tmp[2],tmp[-2]
                filename2.write(tmp[2] + '\t' + tmp[-2] + '\n')
if __name__ == '__main__':
    #give the in file
    infile = raw_input('infilename:')
    # give the file which you want to store, such as :C:\1.txt
    outfile = raw_input('outfile:')
    deal_with(infile, outfile)

回答2:

有什么问题么?