전체 글
-
[Python] Windows OS Disk Usage Check. (윈도우 운영체제 디스크 사용량 체크)Python/Python Programming 2019. 10. 18. 21:40
import shutil.disk_usage(drive) : 드라이브의 전체용량, 사용량, 잔여량 정보를 리턴 import shutil drive = 'c:' c = dict([x for x in zip(['total','used','free'], shutil.disk_usage(drive))]) print(c) print(drive,'Partition used %d %%' %(c['used']/c['total']*100)) ----------------------------------------------------------------------------- {'total': 255005159424, 'used': 224621703168, 'free': 30383456256} c: Partition ..
-
[Python] Extract directory and filename. (디렉토리와 파일명 추출하기)Python/Python Programming 2019. 10. 18. 14:00
os.path.split : 디렉토리 경로와 파일명을 튜플로 리턴 os.path.dirname : 디렉토리 경로를 리턴 os.path.basename : 파일명을 리턴 경로와 파일명이 모두 필요하면 split 을 사용하면 되고, 각각의 정보가 필요하면 dirname과 basename을 쓰면 된다 os.path.split from os.path import split filename = 'C:\\test\\text.txt' os.path.split(filename) ------------------------------------------ ('C:\\test', 'text.txt') os.path.dirname from os.path import dirname filename = 'C:\\test\\te..
-
[Python] Directory make and remove with subdirectories. (하위 디렉토리 포함 생성과 삭제)Python/Python Programming 2019. 10. 18. 10:57
makedirs : 하위 디렉토리를 포함하여 생성 removedirs : 하위 디렉토리를 포함하여 삭제. (파일이 존재하면 [WinError 145] 에러 발생) from os import makedirs from os import removedirs from os.path import isdir dirname = 'test/test' def dircheck(): res = 'Directory Exist' if isdir(dir) else 'Directory Not Exist' return res makedirs(dirname) # make with subdirectories print(dircheck()) removedirs(dirname) # remove with subdirectories print..
-
[Python] Directory make and remove. (디렉토리 생성과 삭제)Python/Python Programming 2019. 10. 18. 10:39
mkdir : 디렉토리를 생성. (하위 디렉토리까지는 생성이 않된다) rmdir : 디렉토리를 삭제. (하위 디렉토리가 존재하면 [WinError 145] 에러 발생) from os import mkdir from os import rmdir from os.path import isdir dirname = 'test' def dircheck(): res = 'Directory Exist' if isdir(dir) else 'Directory Not Exist' return res mkdir(dirname) # create dir print(dircheck()) rmdir(dirname) # remove dir print(dircheck()) -----------------------------------..
-
Linux Access log 일 단위 자동압축 쉘 스크립트Linux/Shell Script 2019. 10. 16. 20:53
리눅스 파일시스템 용량이 넉넉하면 괜찬지만 지속적인 용량관리가 필요하다면 로그를 압축보관할 필요가 있다. 이번 포스팅은 엑세스 로그가 일 단위로 생성되면, 전일(yesterday) 로그를 자동으로 백업할 수 있는 간단한 쉘 스크립트를 알아보겠다. date명령어를 이용하여 전일 날짜를 출력 date명령어의 -d 옵션을 이용하여 전일 날짜 출력. (현재일 2019년 10월 16일 기준) # date -d 'yesterday' Tue Oct 15 07:37:07 EDT 2019 로그포맷(yyyy-dd-mm)에 맞게 출력 # date +%Y'-'%m'-'%d -d 'yesterday' 2019-10-15 로그포맷에 맞는 gzip 압축 명령어 완성하기 대상파일 : localhost_access_log.2019-1..
-
[Python] index 함수 - 배열에서 원하는 값의 위치 찾기Python/Python Programming 2019. 10. 16. 19:26
index 함수는 배열에서 값의 위치를 찾아주는 함수리며, 중복된 값이 있으면 가장 최소의 위치를 리턴 a 리스트에서 10의 위치 찾기. (최소값인 1이 출력) a = [11,10,12,13,20,31,11,10,10,11] print(a.index(10)) ----------------------------------- 1 a 리스트에서 2번째 ~ 9번째 위치에서 10의 위치 찾기. (최소값인 7이 출력) a = [11,10,12,13,20,31,11,10,10,11] print(a.index(10,2,9)) # index(value, start, end) ---------------------------------------------------- 7 a 문자열에 '1' 이라는 문자 위치 찾기 a =..
-
[Python] isalnum 문자열에 숫자 또는 알파벳만 있는지 확인하는 메소드Python/Python Programming 2019. 10. 15. 22:44
isalnum() : 문자열이 숫자 또는 문자이면 True를 반환 문자열이 숫자로만 구성시 True 리턴 '12345'.isalnum() ----------------- True 문자열이 알파벳로만 구성시 True 리턴 'abcde'.isalnum() ----------------- True 문자열이 한글로만 구성시 True 리턴 '한글'.isalnum() ---------------- True 문자열이 알파벳과 숫자 구성시 True 리턴 'abcde12345'.isalnum() ---------------------- True 문자열이 알파벳과 특수문자 구성시 False 리턴 'abcde@'.isalnum() ------------------ False 문자열이 알파벳과 공백 구성시 False 리턴 '..
-
[Python] isdigit - Decide if only numbers exist. (문자열에 숫자만 있는지 확인하는 메소드)Python/Python Programming 2019. 10. 15. 22:05
isdigit() : 문자열이 숫자로만 구성되어 있으며, 빈칸이 없으면 True를 반환 문자열이 숫자로만 구성시 True 리턴 '12345'.isdigit() ------------------ True 문자열이 숫자와 문자로 구성시 False 리턴 '12345abc한글'.isdigit() ------------------------ False 문자열이 숫자와 특수기호로 구성시 False 리턴 '12345@'.isdigit() ------------------ False 문자열이 숫자와 공백 구성시 False 리턴 '12345 '.isdigit() ------------------ False 활용. (모든 리스트의 요소들이 숫자인지 확인) list_A = [ 1, 12, 43, 4, 15 ] ''.join..