Python
-
Python 문법 - Function, ModulePython 2021. 4. 26. 14:15
--> 서로 연관된 코드를 그룹핑해서 정리정돈하는데 도움 def average(a,b): --> def 함수생성, input a,b 매개변수 parameter s=a+b r=s/2 return r --> return 뒤가 함수에 대한 표현식 print(average(10, 20)) # 15 --> 10,20 인자 argument --> 서로 연관된 변수, 함수, 객체 정리정돈 도구 거대 수납상자 >math.py 생성 후 아래 함수들 저장 def average(a,b): --- def plus(a,b): --- pi = 3.14 >다른파일에 모듈가져오기 import math --> math모듈가져오기 print(math.average(1,2)) >다른파일에 함수가져오기 from math import ave..
-
python 활용 - 리팩토링, 보안, pypi, APIPython 2021. 4. 26. 13:51
중복의 제거 - view.py 생성 --> 모듈활용 import os def getList(): --> 함수활용 files = os.listdir('data') listStr='' for item in files: listStr = listStr + '{name}'.format(name=item) return listStr - index.py 파일 등 import view print(내용 . format(listStr=view.getList()) --> 보안공격의 사례 중 하나인 XSS(cross-site scripting) 글생성할때 코드를 넣어서 작동하게 만들기 description -> 다른사이트 보내버리기 등 → > description = description.replace('',..
-
python 활용Python 2021. 4. 24. 17:11
python - cgi(common gateway interface) 로 홈페이지 출력 browser HTTPD(웹서버) CGI Application CGI : 웹서버와 여러 언어 상호 연동하기위한 표준화된 약속 #!/usr/local/bin/python3 #경로설정 print("Content-Type: text/html") --> header 웹서버응답하면서 지금 보내줄건 텍스트고 html이야 알려주는것 print() --> 한줄 띄우기 print('''내용''') - URL의 query string을 입력 값으로 웹애플리케이션으로 끌어오는 방법 import cgi --> cgi 모듈 사용하겠다 form=cgi.FieldStorage() pageId= form["id"].value print('''내용..
-
python 문법 - 문자열, 제어문, List, 반복문Python 2021. 4. 24. 16:41
[문자열] Python string('',"") #escape - print("Hell'o' \"w\"orld") #newline print ('H\ne\nl\nl\no') #docstring print(''' h i ''') a= 'hello python' #length print(len(a)) -->12 #index print(a[0]) -->a #slicing strings print(a[2:5]) --> llo #repeat print((a+'\n')*2) -->hello python hello python name = 'egoing' print('to '+name+'. sdjklasj '+name+' dlskjd.') --> 중복의 제거 문자 치환 및 데이터 동적 생성 #positional fo..