본문 바로가기

파이썬2271

파이썬 x 초마다 함수를 반복적으로 실행하는 가장 좋은 방법은 무엇입니까? while True: # Code executed here time.sleep(60) 이 코드에 예상 할 수있는 문제가 있습니까? 해결 방법 import sched, time s = sched.scheduler(time.time, time.sleep) def do_something(sc): print("Doing stuff...") # do your stuff s.enter(60, 1, do_something, (sc,)) s.enter(60, 1, do_something, (s,)) s.run() asyncio , trio , tkinter , PyQt5 , 와 같은 이벤트 루프 라이브러리를 이미 사용중인 경우 gobject , kivy 및 기타 여러 가지-대신 기존 이벤트 루프 라이브러리의 메서드를 .. 2020. 10. 14.
파이썬 "x for x in"구문은 무엇을 의미합니까? 이 코드가 실행될 때 실제로 일어나는 일 : text = "word1anotherword23nextone456lastone333" numbers = [x for x in text if x.isdigit()] print(numbers) [] 는 목록을 만들고, .isdigit () 는 문자열 (텍스트)의 요소가 숫자이면 True 또는 False를 확인합니다. 그러나 다른 단계에 대해 잘 모르겠습니다. 특히 "x"가 for 루프 앞에서 무엇을합니까? 출력이 무엇인지 (아래) 알고 있지만 어떻게 수행됩니까? Output: ['1', '2', '3', '4', '5', '6', '3', '3', '3'] 해결 방법 이것은 표준 파이썬 목록 이해입니다. 더 긴 for 루프를 작성하는 다른 방법입니다. 문자열의 모.. 2020. 10. 14.
파이썬 Python에서 기본 클래스 메서드 호출 두 개의 클래스 A와 B가 있고 A는 B의 기본 클래스입니다. 파이썬의 모든 메서드는 가상이라는 것을 읽었습니다. 그렇다면 기본 메서드를 호출하려고 할 때 파생 클래스의 메서드가 예상대로 호출되기 때문에 어떻게 기본 메서드를 호출합니까? >>> class A(object): def print_it(self): print 'A' >>> class B(A): def print_it(self): print 'B' >>> x = B() >>> x.print_it() B >>> x.A ??? 해결 방법 >>> class A(object): ... def print_it(self): ... print 'A' ... >>> class B(A): ... def print_it(self): ... print 'B' .... 2020. 10. 14.
파이썬 keras의 preprocess_input () 메서드 아래 keras 문서 페이지에서 샘플 keras 코드를 시도하고 있습니다. 아래 코드에서 keras 모듈의 preprocess_input (x) 기능은 무엇입니까? preprocess_input () 메서드에 전달되기 전에 expand_dims (x, axis = 0) 를 수행해야하는 이유는 무엇입니까? from keras.applications.resnet50 import ResNet50 from keras.preprocessing import image from keras.applications.resnet50 import preprocess_input import numpy as np model = ResNet50(weights='imagenet') img_path = 'elephant.jpg' i.. 2020. 10. 14.
파이썬 Python에서 이미지의 exif 데이터를 어떻게 읽습니까? PIL을 사용하고 있습니다. 그림의 EXIF ​​데이터를 사전으로 바꾸려면 어떻게합니까? 해결 방법 PIL 이미지의 _getexif () 보호 메소드를 사용할 수 있습니다. import PIL.Image img = PIL.Image.open('img.jpg') exif_data = img._getexif() 이렇게하면 EXIF ​​숫자 태그로 색인화 된 사전이 제공됩니다. 실제 EXIF ​​태그 이름 문자열로 사전을 색인화하려면 다음과 같이 시도하십시오. import PIL.ExifTags exif = { PIL.ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in PIL.ExifTags.TAGS } 참조 페이지 https://stackoverf.. 2020. 10. 14.
파이썬 for 루프 감소 다음과 같이 for 루프를 갖고 싶습니다. for counter in range(10,0): print counter, 출력은 109876543 2 1이어야합니다. 해결 방법 a = " ".join(str(i) for i in range(10, 0, -1)) print (a) 참조 페이지 https://stackoverflow.com/questions/4767401 2020. 10. 14.
파이썬 How to break a line of chained methods in Python? 다음 코드 줄이 있습니다 (이름 지정 규칙을 비난하지 마십시오. subkeyword = Session.query( Subkeyword.subkeyword_id, Subkeyword.subkeyword_word ).filter_by( subkeyword_company_id=self.e_company_id ).filter_by( subkeyword_word=subkeyword_word ).filter_by( subkeyword_active=True ).one() 나는 그것이 어떻게 보이는지 (너무 가독성이 좋지 않음) 마음에 들지 않지만이 상황에서 줄을 79 자로 제한하는 더 좋은 아이디어가 없습니다. 그것을 깨는 더 좋은 방법이 있습니까 (가급적 백 슬래시없이)? 해결 방법 추가 괄호를 사용할 수 있습니다.. 2020. 10. 14.
파이썬 How do I do greater than/less than using MongoDB? pymongo 드라이버를 사용하고 있습니다. 누군가 pymongo를보고 더 큰 일을하는 방법을 말해 줄 수 있습니까? 나는 모든 일에 익숙합니다. 해결 방법 >>> d = datetime.datetime(2009, 11, 12, 12) >>> for post in posts.find({"date": {"$lt": d}}).sort("author"): ... post ... {u'date': datetime.datetime(2009, 11, 10, 10, 45), u'text': u'and pretty easy too!', u'_id': ObjectId('...'), u'author': u'Eliot', u'title': u'MongoDB is fun'} {u'date': datetime.datetime(.. 2020. 10. 14.
파이썬 FutureWarning : issubdtype의 두 번째 인수를`float`에서`np.floating`으로 변환하는 것은 더 이상 사용되지 않습니다. FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters 2018-01-19 17:11:38.695932: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports inst.. 2020. 10. 14.
파이썬 Python 생성자 및 기본값 어떻게 든 아래의 Node 클래스에서 wordList 및 adjacencyList 변수는 Node.js의 모든 인스턴스간에 공유됩니다. >>> class Node: ... def __init__(self, wordList = [], adjacencyList = []): ... self.wordList = wordList ... self.adjacencyList = adjacencyList ... >>> a = Node() >>> b = Node() >>> a.wordList.append("hahaha") >>> b.wordList ['hahaha'] >>> b.adjacencyList.append("hoho") >>> a.adjacencyList ['hoho'] 생성자 매개 변수에 대해 기본값 (이 경우.. 2020. 10. 14.