<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.example {
padding: 20px;
color: white;
}
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
.example {background: red;}
}
/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
.example {background: green;}
}
/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
.example {background: blue;}
}
/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
.example {background: orange;}
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {
.example {background: pink;}
}
</style>
<script>
$( window ).resize(function() {
//창크기 변화 감지
var windowWidth = $( window ).width();
$("#width_size").val(windowWidth);
});
</script>
</head>
<body>
<h2>Typical Media Query Breakpoints</h2>
<input type="text" id="width_size" >
<p class="example">Resize the browser window to see how the background color of this paragraph changes on different screen sizes.</p>
</body>
</html>
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다.
importos
frompathlibimportPath
# src 상위 폴더를 실행폴더로 지정하려고 한다.
real_path=Path(__file__).parent.parent
print(real_path)
#작업 디렉토리 변경
os.chdir(real_path)
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다.
import os
from pathlib import Path
# src 상위 폴더를 실행폴더로 지정하려고 한다.
real_path = Path(__file__).parent.parent
print(real_path)
#작업 디렉토리 변경
os.chdir(real_path)
처리내용
os 및 os.path
pathlib
현재의 디렉토리를 취득
os.getcwd()
Path.cwd()
맨 앞의 ~를 홈 디렉토리에 치환
os.path.expanduser()
Path.expanduser(), Path.home()
경로의 존재 확인
os.path.exists()
Path.exists()
디렉토리인가를 판단
os.path.isdir()
Path.is_dir()
파일인가를 판단
os.path.isfile()
Path.is_file()
심볼릭 링크인가를 판단
os.path.islink()
Path.is_symlink()
절대경로인가를 판단
os.path.isabs()
PurePath.is_absolute()
절대경로로 변환
os.path.abspath()
Path.resolve()
status를 취득
os.stat()
Path.stat(), Path.owner(), Path.group()
경로를 연결
os.path.join()
PurePath.joinpath()
파일명을 취득
os.path.basename()
PurePath.name
새로운 디렉토리를 취득
os.path.dirname()
PurePath.parent
확장자를 분할·취득
os.path.splitext()
PurePath.suffix
Pathlib - 객체 지향 파일 시스템 경로
객체 지향 파일 시스템 경로, 즉 파일을 객체로 관리하겠다는것 같음. 아래 그림은 Pathlib 내부 객체들의 상속관계로, 가장 기본적인 객체는PurePath임을 알 수있음. 대략적인 객체간 의미와 관계를 알기 위해 라이브러리를 뜯어봄 ->pathlib.py
차이점
os.path와Pathlib의 가장 큰 차이점은, 경로를 문자열로 다루냐, 객체로 다루냐 차이인데, 모든 것이 객체로 이루어진python인 만큼,Pathlib가 자연스러운 모듈이며 객체 내부적으로 정의된 연산자를 사용할 수 있어 경로에 있어 더 자연스러운 표현이 가능함.
기본적인 사용법은 알아야, 나중에 쓸 일이 있으면 찾아보지 않고 쓸 수 있으니 대충정리해보자.
1. 탐색
논리적 경로와, 절대 경로와의 구분을 잘 해야 함. 논리 경로 상에서, 앵커나 빈 경로는 넘어갈 수 없음. 코드상으로 경로 탐색에 사용할 수 있는 것은,.parent,.parents,.iterdir()등이 있음.
상위 디렉토리로 넘어가기 위해선,.parent를 사용하나, 사용하기 전 절대경로로 바꾸고, 현재 경로가 디렉토리이면,.iterdir()를 통해 자식 경로를 얻을 수 있음.
from pathlib import Path
p = Path('.') # PosixPath('.')
p.resolve() # os.path.abspath()
p.resolve().parent
list(p.iterdir()) # iteration, list 변환, = os.listdir()
2. 연산자
연산자를 사용하여 경로 조합 가능.
from pathlib import Path
p = Path.home() # os.path.expanduser()
p_sub = p / 'foo' / 'bar' # PosixPath('/Users/kyuu/foo/bar')
p_sub = Path(p, 'foo', 'bar') # os.path.join() 모방