2016-10-31 3 views
0

을 코드 (py3과 함께 설치됨) 용 라이브러리 모듈로 사용하고 있습니다. 따라서 모듈에 대한 쓰기 권한이 없습니다.모듈에 정의 된 python3 세트에 액세스하여 업데이트하십시오.

그러나 standard_types에 정의 된대로 사용하는 세트는 https://github.com/sciunto/python-bibtexparser/blob/master/bibtexparser/bibdatabase.py입니다.

호출 코드에서 세트를 재정의하거나 추가 할 수 있습니까? 예 :

#foo.py 
import bibtexparser 

#redefine standard_types 
bibtexparser.STANDARD_TYPES = set([the complete set I need]) 

#or append the standard_types 
bibtexparser.STANDARD_TYPES.update = set([append to the set]) 

?

업데이트 : 사실 변수 STANDARD_TYPES에 액세스 할 수 없습니다.

from bibtexparser import bibdatabase as bd 

class Window(Gtk.ApplicationWindow): 
    def __init__(self, application, giofile=None): 
     Gtk.ApplicationWindow.__init__(self, 
             application=application, 
             default_width=1000, 
             default_height=200, 
             border_width=5) 


     print(bd) 
     print(bd.STANDARD_TYPES) 

산출되는 : 내가 할 노력하고 그냥 그것을 대체 할 수 있도록 패키지의 다른 부분처럼 보이는

<module 'bibtexparser.bibdatabase' from '/usr/lib/python3.5/site-packages/bibtexparser/bibdatabase.py'> 
...... 
     print(bd.STANDARD_TYPES) 
    AttributeError: module 'bibtexparser.bibdatabase' has no attribute 'STANDARD_TYPES' 
+0

가능성이 있습니다. 시도 해봐! 추가를 위해서'| = '연산자를 사용하십시오. – wim

답변

0

from bibtextparser import STANDARD_TYPES을 수행; 이미 가져온 모듈은 이전 버전을 유지합니다. 말했다

bibtexparser.STANDARD_TYPES.update({append to the set}) 

BibTexParserignore_nonstandard_types=True을 통과 초기화 할 수 있습니다 것 같습니다, 그것도 당신이 정말로 원하는 아마도 무엇 인 STANDARD_TYPES을 확인하지 않습니다; update를 사용하면 당신의 구문을 수정해야하지만 잘 작동 할 것 그것은 hacky monkey-patching을 전혀 포함하지 않습니다.

+0

안녕하세요, 회신 해 주셔서 감사합니다. 하지만, 내가''bibtexparser.bibdatabase import STANDARD_TYPES'에서 그것의 에러를 보여 준다면 : 'print (bibtexparser.STANDARD_TYPES) ​​ AttributeError : 'bibtexparser'모듈에 'STANDARD_TYPES'속성이 없습니다. – BaRud

+0

내가 어떻게 접근 할 수 있는지 보여줄 수 있습니까? 가치? – BaRud

+0

@BaRud :'from x import y' 구문을 사용했습니다. 이름을 한정하지 마십시오. 'print (STANDARD_TYPES)'가 작동합니다. – ShadowRanger

관련 문제