2014-04-21 5 views
1

내가 commamd 프롬프트에서 비단뱀 스크립트를 실행할 때 CSV 파일을 생성하지만 exe로 스크립트를 변환하면 CSV file.can을 생성하지 못합니다. 문제?비단뱀 exe는 CSV 파일을 생성 할 수 없습니다

import os 
import csv 
import time 
import ftplib 
import threading 
import database.db as db 
from threading import Timer 
import initial.global_variables as gv 

class Csv_generator(): 

    def __init__(self): 
     self.__db_conn = db.db_conn() 
     self.__file_name = None 
     self.__file_path = None 
     self.__file_path_prefix = os.path.dirname(os.path.abspath(__file__)) 
    def __get_meter_data(self): 
     #get the kwh data from the meters from the database 
     localtime = time.localtime(time.time()) 
     sys_time = "%s-%s-%s %s_00_00" %(localtime.tm_year,localtime.tm_mon,localtime.tm_mday,localtime.tm_hour) 
     self.__file_name = "%s_%s.csv" %(gv.org_name,sys_time) 
     self.__file_path = self.__file_path_prefix+ "/%s" %(self.__file_name) 
     self.__db_conn.cursor.execute(" SELECT m.`meter_id`FROM meter_data as m") 
     numrow = int(self.__db_conn.cursor.rowcount) 
     result=self.__db_conn.cursor.fetchall() 

     for x in range(0, numrow): 
      self.__generate_file(self.__file_path,sys_time,result[x][0]) 


    def __generate_file(self,file_path,time,m_id,m_name,m_location,m_kwh,m_updated): 

     file_exist = os.path.exists(file_path) 
     file_ptr = open(file_path,'ab') 
     writer = csv.writer(file_ptr) 
     if file_exist == False: 
      writer.writerow(( "METER_TIMESTAMP", 
           "METER_ID" 
           ) 
     writer.writerow((m_updated,m_id) 


    def start(self): 
     if gv.db_connected==1: 
      self.__db_conn.connect() 
      self.__get_meter_data() 
      self.__db_conn.close() 

     hour = int(time.strftime("%H", time.localtime())) 
     minute = int(time.strftime("%M", time.localtime())) 
     second = int(time.strftime("%S", time.localtime())) 
     for x in range(1,gv.upload_freq+1): 
      if int(hour) == 23: 
       hour = 0 
       break 
      if int(hour) < int(int(24/gv.upload_freq)*x): 
       hour = int((int(24/gv.upload_freq)*x) - int(hour) -1) 
       break 
     second = hour*3600 + (59 - minute)*60 + (60 - second) 
     timer_thread = Timer(second, self.start) 
     timer_thread.start() 

추신 : 여기

은 csv 파일을 생성하는 코드입니다 클래스 전역 변수를 내 프로젝트에 대해 정의 된 변수를 포함하고

+0

정확하게 EXE로 변환하는 방법은 무엇입니까? – Amazingred

+0

pywin32-216.win32-py2.7.exe를 사용하십시오. –

답변

1

의 문제는 내가 해결했다 없다 문제. 오류가 자체 .__ file_path_prefix에 있었으므로 대신 os.getcwd()이되어야합니다.