Python¶
Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python’s design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
Others¶
File I/O¶
readline()
코드
f = open("C:/doit/새파일.txt", 'r') line = f.readline() print(line) f.close()
참조
readlines()
기본적인 방법
코드
f = open("C:/doit/새파일.txt", 'r') lines = f.readlines() for line in lines: print(line) f.close()
참조
Remove ‘n’ from readlines
코드
>>> filelist = open("file.txt").readlines() ['a\n', 'b\n', 'c\n', 'd\n'] >>> open("file.txt").read().splitlines() ['a', 'b', 'c', 'd']
참조
listdir()
코드
from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
참조
Reference