私はPythonでプログラミングしていますが、解決できないわずかな問題が発生しました! 問題は、テキスト ファイルに出力すると、出力全体のうち 1 行しか出力されないことです。それ以外の場合は動作します! この作業を行うには助けが必要です!
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()