2015-01-06 8 views

답변

2

ExclusiveSqlConnection 요구의 생성자 (__init__ 방법)는 path 매개 변수를 사용하기 :이 프로그램을 실행할 때 나는 오류, 그러나

import sqlite3 as sql 

class ExclusiveSqlConnection(object): 
    """meant to be used with a with statement to ensure proper closure""" 
    def __enter__(self, path): 
     self.con = sql.connect(path, isolation_level = "EXCLUSIVE") 
     self.con.execute("BEGIN EXCLUSIVE") 
     self.cur = self.con.cursor() 
     return self 

    def __exit__(self): 
     self.con.commit() 
     self.con.close() 

: 여기

는 클래스입니다.

한편, __enter__self 이외의 매개 변수를 취하지 않습니다.

import sqlite3 as sql 

class ExclusiveSqlConnection(object): 
    """meant to be used with a with statement to ensure proper closure""" 

    def __init__(self, path): 
     self.path = path 

    def __enter__(self): 
     self.con = sql.connect(self.path, isolation_level = "EXCLUSIVE") 
     self.con.execute("BEGIN EXCLUSIVE") 
     self.cur = self.con.cursor() 
     return self 

    def __exit__(self, exception_type, exception_val, trace): 
     self.con.commit() 
     self.con.close()