본문 바로가기

개발/Python

(25)
파이썬 정규식 정리 정규식 간단요약 ^ 라인의 처음을 매칭 $ 라인의 끝을 매칭 . 임의의 문자를 매칭 (와일드 카드) \s 공백 문자를 매칭 \S 공백이 아닌 문자를 매칭 * 바로 앞선 문자에 적용되고 0 혹은 그 이상의 앞선 문자와 매칭을 표기함. *? 바로 앞선 문자에 적용되고 0 혹은 그 이상의 앞선 문자와 매칭을 탐욕적이지 않은 방식으로 표기함. + 바로 앞선 문자에 적용되고 1 혹은 그 이상의 앞선 문자와 매칭을 표기함 +? 바로 앞선 문자에 적용되고 1 혹은 그 이상의 앞선 문자와 매칭을 탐욕적이지 않은 방식으로 표기함. [aeiou] 명세된 집합 문자에 존재하는 단일 문자와 매칭. “a”, “e”, “i”, “o”, “u” 문자만 매칭되는 예제 [a-z0-9] - 기호로 문자 범위를 명세할 수 있다. 소문자이..
파이참에서 32bit, 64bit 가상환경 설정 후 손쉽게 interpreter 바꾸기 파이참 우측 하단의 요걸 눌러주면 된다. 누르고 나서 터미널은 껐다 켜줘야 적용된다! 가상 환경 만드는 방법은 아래 참고. * 가상 환경? 가상환경(Virtual Environment)이란 자신이 원하는 Python 환경을 구축하기 위해 필요한 모듈만 담아 놓는 바구니 각 가상환경은 독립적으로 관리됩니다. 각 모듈은 다른 모듈에 대한 의존성(dependency)이 다르기 때문에 각 프로젝트 별로 별개의 가상환경을 만들어놓고 사용하는 것을 추천 * 환경 세팅 - 텐서플로우는 파이썬 64비트에서만 동작, 키움증권 openapi는 파이썬 32비트에서만 동작 이를 위해 아나콘다 32비트를 삭제 후 64비트로 설치 32비트, 64비트 모두 가상환경을 만들어준다. (32비트 anaconda에서는 64비트 가상환경을..
py4e 9.4 who has sent the greatest number of mail messages? 9.4 Write a program to read through the mbox-short.txt and figure out who has sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file. After the dictionary is produced..
파이썬 무료 강의 추천 : 모두를 위한 파이썬 Python for everybody www.edwith.org/pythonforeverybody 모두를 위한 프로그래밍 : 파이썬 강좌소개 : edwith - 커넥트재단 www.edwith.org Cousera의 Python for everybody를 네이버 커넥트 재단에서 번역해 무료로 제공하고 있다. www.coursera.org/specializations/python 모두를 위한 Python Offered by 미시건 대학교. This Specialization builds on the success of the Python for Everybody course and will introduce fundamental programming concepts including data structures, networked applica..
py4e 8.5 From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 8.5 Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line:From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. Hint: make sure not to include ..
py4e exercise 7.2 밤에 3강 들었더니 졸렸는지 예제 보는데 하나도 기억이 안 났다. 파일 열고 처리하는 문법 찾아보고 끙끙대다가 그냥 3강 동영상 다시 복습하고 중간중간 나오는 코드 받아적으면서 하니까 스택오버플로우의 도움 없이 풀 수 있었다!!! 야호... 시간은 다른 예제들보다 엄청 걸렸지만(다른 예제들은 복습을 안하고 하다 정 안되면 구글링해봤기 때문...) 괜히 뿌듯하다. 앞으로도 안 풀리면 IDLE 열고 받아적으면서... ㅎ 예제 돌아가는지 체크해봐야지. # Use the file name mbox-short.txt as the file name fname = input("Enter file name: ") fh = open('mbox-short.txt') total = 0 count = 0 # inp = fh...
py4e Assignments 3.3 3.3 Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: Score Grade >= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85. try와 except을 배워 적용하는 문제다. 배운 대로 해봤으나..
class, function, object, instance, parameter, variable #클래스 정의 class 사람(): def 함수1 (self, 파라미터): self.인스턴스변수 = 파라미터 print(self.인스턴스변수) def 함수2 (self): print(self.인스턴스변수) #클래스 인스턴스 생성 jake = 사람() #클래스 인스턴스의 메서드 2개 호출 & 인스턴스 변수 출력 jake.함수1("지금 넘겨주는 파라미터는 인스턴스 변수가 되서 다른 메서드에서도 사용 가능하게 될거야!") jake.함수2() print(jake.인스턴스변수) parameter는 함수 내에서만 사용 가능한 지역 변수variable다. 각 함수인 method를 나가는 순간 쓸 수 없다. instance variable는 class 내의 다른 함수에서도 사용 가능한 광역 변수다. self.param..