Django 학습 노트(36): Django가 파일 내용을 읽고 조작한 후에 텍스트를 쓴다

1620 단어 Django
#            static          
_change_status_root = os.path.join(STATIC_ROOT,'player_status')
#mkdirs()       
mkdirs(_change_status_root)
#         error.txt
error_file_path = os.path.join(_change_status_root,'error.txt')
#           player.txt
push_file_path = os.path.join(_change_status_root,'player.txt')


@Route(r'^log/change_neibuhao_status$')
@notauth
def change_neibuhao_status(request):
    '''
    :param request:            
    :return:       
    '''
    error_ls = []
    try:
        #  player.txt  
        with open(push_file_path , 'r') as pfp:
            #          
            for line in pfp.readlines():
                #           
                player_neibu = int(line.replace('
', '')) server_neibu = player_neibu >> 20 print player_neibu, server_neibu # conn = Server.get_conn(server_neibu) cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor) sql = '''UPDATE player_%s SET user_type = 1 WHERE player_id = %d ''' % ( server_neibu, player_neibu) cur.execute(sql) conn.close() with open(error_file_path, 'w') as efp: for v in error_ls: efp.write('%s
' % v) efp.flush() efp.close() except Exception as e: print e return HttpResponse('success')

좋은 웹페이지 즐겨찾기