본문 바로가기

분류 전체보기980

Python 모듈 이름 MySQLdb이 없습니다., No module named MySQLdb 질문 나는 Python 버전 2.5.4를 사용하고 MySQL 버전 5.0과 Django를 설치했습니다. Django는 Python과는 잘 작동하지만 MySQL은 작동하지 않습니다. 나는 Windows Vista에서 사용하고 있습니다. 답변 다음 중 하나의 명령을 사용해야 합니다. 어떤 명령을 사용해야 하는지는 사용 중인 운영 체제와 소프트웨어에 따라 다릅니다. easy_install mysql-python (다양한 운영 체제) pip install mysql-python (다양한 운영 체제/ python 2) pip install mysqlclient (다양한 운영 체제/ python 3) apt-get install python-mysqldb (Linux Ubuntu, ...) cd /usr/ports.. 2023. 10. 12.
Python 객체의 특성 목록 [중복], List attributes of an object [duplicate] 질문 클래스의 인스턴스에 존재하는 속성 목록을 가져올 방법이 있을까요? class new_class(): def __init__(self, number): self.multi = int(number) * 2 self.str = str(number) a = new_class(2) print(', '.join(a.SOMETHING)) 원하는 결과는 "multi, str"이 출력되는 것입니다. 이것은 스크립트의 다양한 부분에서 현재 속성을 확인하기 위해 원합니다. 답변 >>> 클래스 new_class(): ... def __init__(self, 숫자): ... self.multi = int(숫자) * 2 ... self.str = str(숫자) ... >>> a = new_class(2) >>> a.__di.. 2023. 10. 12.
Python 싱글톤을 정의하는 간단하고 우아한 방법이 있을까요? [중복됨], Is there a simple, elegant way to define singletons? [duplicate] 질문 파이썬에서 싱글톤을 정의하는 다양한 방법이 있는 것 같습니다. Stack Overflow에서는 합의된 의견이 있을까요? 답변 I don't really see the need, as a module with functions (and not a class) would serve well as a singleton. All its variables would be bound to the module, which could not be instantiated repeatedly anyway. If you do wish to use a class, there is no way of creating private classes or private constructors in Python, so you ca.. 2023. 10. 12.
Python 파이썬에서 XML을 예쁘게 출력하기, Pretty printing XML in Python 질문 파이썬에서 XML을 예쁘게 출력하는 가장 좋은 방법(또는 다양한 방법)은 무엇인가요? 답변 import xml.dom.minidom dom = xml.dom.minidom.parse(xml_fname) # 또는 xml.dom.minidom.parseString(xml_string) pretty_xml_as_string = dom.toprettyxml() 2023. 10. 12.