본문 바로가기
WEB/Python

[Python] 파일목록 읽기 - listdir, 반복문 - for

by Ellen571 2020. 8. 23.

[생활코딩] 활용 - 반복문을 이용해서 글목록 구현

 

 

파일 목록 읽기 listdir()

import os   # os모듈 가져오기
files = os.listdir('data')   # 메소드 listdir는 디렉토리안 파일명을 반환함

 

반복문으로 리스트 만들기 for (value) in (values) :

liststr = ''
for item in files:
    liststr = liststr + '<li><a href="index.py?id={name}">{name}</a></li>'.format(name=item)
반응형

'WEB > Python' 카테고리의 다른 글

[Python] 업데이트하기(input, format, rename)  (0) 2020.08.23
[Python] form 값 처리하기(FieldStorage, open, Location)  (0) 2020.08.23
[Python] 파일 읽기 open().read()  (0) 2020.08.22
[Python] cgi.FieldStorage()  (0) 2020.08.22
CGI?  (0) 2020.08.21