«python» 태그된 질문

파이썬은 다 패러다임, 동적 타입, 다용도 프로그래밍 언어입니다. 깨끗하고 균일 한 구문을 빠르게 배우고 이해하며 사용하고 적용 할 수 있도록 설계되었습니다. Python 2는 01-01-2020부터 공식적으로 지원되지 않습니다. 그래도 버전 별 Python 질문의 경우 [python-2.7] 또는 [python-3.x] 태그를 추가하십시오. Python 변형 또는 라이브러리 (예 : Jython, PyPy, Pandas, Numpy)를 사용하는 경우 태그에 포함 시키십시오.

11
파일이 유효한 이미지 파일인지 확인하는 방법은 무엇입니까?
현재 PIL을 사용하고 있습니다. from PIL import Image try: im=Image.open(filename) # do stuff except IOError: # filename not an image file 그러나 이것은 대부분의 경우를 충분히 포함하지만 xcf, svg 및 psd와 같은 일부 이미지 파일은 감지되지 않습니다. Psd 파일에서 OverflowError 예외가 발생합니다. 어떻게 든 그들을 포함시킬 수 있습니까?

14
Python 로깅 모듈을 사용할 때 중복 로그 출력
파이썬 로거를 사용하고 있습니다. 다음은 내 코드입니다. import os import time import datetime import logging class Logger : def myLogger(self): logger = logging.getLogger('ProvisioningPython') logger.setLevel(logging.DEBUG) now = datetime.datetime.now() handler=logging.FileHandler('/root/credentials/Logs/ProvisioningPython'+ now.strftime("%Y-%m-%d") +'.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) return logger 내가 가진 문제는 각 logger.info호출 에 대해 로그 파일에 여러 항목이 …
105 python 


3
SQLAlchemy : 날짜 필드를 필터링하는 방법?
다음은 모델입니다. class User(Base): ... birthday = Column(Date, index=True) #in database it's like '1987-01-17' ... 예를 들어 18 ~ 30 년 간격으로 모든 사용자를 선택하기 위해 두 날짜 사이를 필터링하고 싶습니다. SQLAlchemy로 구현하는 방법은 무엇입니까? 내 생각 엔: query = DBSession.query(User).filter( and_(User.birthday >= '1988-01-17', User.birthday <= '1985-01-17') ) # means …
105 python  sql  database  orm  sqlalchemy 

3
Python에서 기본 클래스의 클래스 메서드 호출
다음 코드를 고려하십시오. class Base(object): @classmethod def do(cls, a): print cls, a class Derived(Base): @classmethod def do(cls, a): print 'In derived!' # Base.do(cls, a) -- can't pass `cls` Base.do(a) if __name__ == '__main__': d = Derived() d.do('hello') > $ python play.py > In derived! > <class '__main__.Base'> msg 에서 Derived.do어떻게 …


6
두 데이터 프레임을 결합하려면 어떻게합니까?
Pandas 데이터 프레임을 사용하고 있습니다. 초기 데이터 프레임이 D있습니다. 다음과 같이 두 개의 데이터 프레임을 추출합니다. A = D[D.label == k] B = D[D.label != k] 그런 다음 레이블을 변경 A하고B A.label = 1 B.label = -1 A와 B를 결합하여 통합 연산과 같은 하나의 데이터 프레임으로 만들 수 있습니다. 데이터의 …
105 python  pandas 

3
파이썬에서 두 개의 정렬 된 목록을 어떻게 비교할 수 있습니까?
긴 목록이 하나있는 경우 : myList = [0,2,1,0,2,1]두 목록으로 나뉩니다. a = [0,2,1] b = [0,2,1] 이 두 목록을 비교하여 두 목록이 모두 같거나 같은지, 같은 순서에 있어야한다는 제약 조건이 있는지 어떻게 확인할 수 있습니까? 두 목록을 정렬하여 비교하라는 질문을 보았지만 특정 경우에는 정렬 된 비교가 아니라 동일한 목록 비교를 …
105 python 

3
Python 사전의 스레드 안전성
사전이있는 수업이 있습니다. class OrderBook: orders = {'Restaurant1': None, 'Restaurant2': None, 'Restaurant3': None, 'Restaurant4': None} @staticmethod def addOrder(restaurant_name, orders): OrderBook.orders[restaurant_name] = orders 그리고 메서드를 호출하는 4 개의 스레드 (각 레스토랑에 대해 하나씩)를 실행하고 있습니다 OrderBook.addOrder. 다음은 각 스레드에서 실행되는 함수입니다. def addOrders(restaurant_name): #creates orders ... OrderBook.addOrder(restaurant_name, orders) 안전합니까, 아니면 전화하기 …

4
목록 색인을 기반으로 Pandas 행 선택
데이터 프레임 df가 있습니다. 20060930 10.103 NaN 10.103 7.981 20061231 15.915 NaN 15.915 12.686 20070331 3.196 NaN 3.196 2.710 20070630 7.907 NaN 7.907 6.459 그런 다음 목록에 표시된 특정 시퀀스 번호를 가진 행을 선택하고 여기에 [1,3]이 있다고 가정하고 왼쪽 : 20061231 15.915 NaN 15.915 12.686 20070630 7.907 NaN 7.907 6.459 …
105 python  pandas 


6
여러 줄 텍스트 블록과 일치하는 정규식
여러 줄에 걸친 텍스트와 일치시킬 때 Python 정규식을 작동시키는 데 약간의 문제가 있습니다. 예제 텍스트는 다음과 같습니다 ( '\ n'는 개행) some Varying TEXT\n \n DSJFKDAFJKDAFJDSAKFJADSFLKDLAFKDSAF\n [more of the above, ending with a newline]\n [yep, there is a variable number of lines here]\n \n (repeat the above a few hundred …
105 python  regex  multiline 

6
include ()에서 네임 스페이스를 사용할 때 app_name에 대한 ImproperlyConfiguredError
나는 현재 Django를 시험하고 있습니다. urls.py namespace의 내 include()s 중 하나 에서 인수를 사용합니다. 서버를 실행하고 찾아 보려고하면이 오류가 발생합니다. File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", line 39, in include 'Specifying a namespace in include() without providing an app_name ' django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set …


14
Django, 사용자 지정 500/404 오류 페이지 만들기
여기에 있는 튜토리얼을 정확히 따르면 사용자 지정 500 또는 404 오류 페이지를 만들 수 없습니다. 잘못된 URL을 입력하면 페이지에 기본 오류 페이지가 표시됩니다. 사용자 정의 페이지가 표시되지 않도록 확인해야 할 사항이 있습니까? 파일 디렉토리 : mysite/ mysite/ __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc polls/ templates/ admin/ base_site.html 404.html …

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.