我正在用python编程但是我遇到了一个我无法解决的小故障!问题是当它在文本文件中打印出来时,它只打印整个输出的一行!否则它工作!请我需要帮助才能完成这项工作!
import sys, bz2, string, os
#instead of hardcoding filename, get it from arguments
#filename = os.getcwd()
filename = raw_input("Enter the path of bz2 document e.g. files/access_log-20130301.bz2: ")
print "Using file : " + filename
source_file = bz2.BZ2File(filename, "r")
for line in source_file:
#Extract the date and put into a variable
logdate = string.split(line)[3][1:12]
#Extract movie name and put into variable movie
movie = string.split(line)[6]
#extract who read the movie username =
usernames = string.split(line)[2]
#Only process the movie line if we have /media/movie in it.
if movie.find('media/movies') > 0:
#Prints all things prosscesed
print "User:" + usernames + " On:" + logdate + " Was watching:"+ movie
#p=open(filename+"record.txt", "w")
fp=open(filename+"record.txt", "wb+")
fp.write("User: " + usernames + " On: " + logdate + " Was watching: "+ movie+" File from:"+filename+"\n")
sys.exit()