솔밭
솔바람이 분다
'아침편지' 카테고리의 다른 글
빛과 어둠 (0) | 2024.08.27 |
---|---|
당신이 행복하면 나도 행복하다 (0) | 2024.08.26 |
비교를 하면 할수록 (0) | 2024.08.23 |
참나 리더십 (0) | 2024.08.22 |
노년의 '회복탄력성' (0) | 2024.08.21 |
솔밭
솔바람이 분다
빛과 어둠 (0) | 2024.08.27 |
---|---|
당신이 행복하면 나도 행복하다 (0) | 2024.08.26 |
비교를 하면 할수록 (0) | 2024.08.23 |
참나 리더십 (0) | 2024.08.22 |
노년의 '회복탄력성' (0) | 2024.08.21 |
[텃밭] 2024-08-24, 밭 갈고 퇴비 주기
반야심경 한글 번역, 摩訶般若波羅蜜多心經 마하반야바라밀다심경 (0) | 2024.08.28 |
---|---|
돼, 되 절대 안 틀리는 법, 하면 돼지, 하면 되지 (0) | 2024.08.26 |
2024년 WHO 선정한 장수 비결 (0) | 2024.08.12 |
정신건강에 도움이 되는 생각 10개 (0) | 2024.08.12 |
아내의 사촌여동생의 신랑 호칭 (0) | 2024.08.09 |
[python] Working With Mathematical Operations and Permutations. 수학적 연산과 순열
Ultimate Python Cheat Sheet: Practical Python For Everyday Tasks
(My Other Ultimate Guides)
blog.stackademic.com
sum = 7 + 3 # Addition
difference = 7 - 3 # Subtraction
product = 7 * 3 # Multiplication
quotient = 7 / 3 # Division
remainder = 7 % 3 # Modulus (Remainder)
power = 7 ** 3 # Exponentiation
z = complex(2, 3) # Create a complex number 2 + 3j
real_part = z.real # Retrieve the real part
imaginary_part = z.imag # Retrieve the imaginary part
conjugate = z.conjugate() # Get the conjugate
import math
root = math.sqrt(16) # Square root
logarithm = math.log(100, 10) # Logarithm base 10 of 100
sine = math.sin(math.pi / 2) # Sine of 90 degrees (in radians)
from itertools import permutations
paths = permutations([1, 2, 3]) # Generate all permutations of the list [1, 2, 3]
for path in paths:
print(path)
from itertools import combinations
combos = combinations([1, 2, 3, 4], 2) # Generate all 2-element combinations
for combo in combos:
print(combo)
import random
num = random.randint(1, 100) # Generate a random integer between 1 and 100
from fractions import Fraction
f = Fraction(3, 4) # Create a fraction 3/4
print(f + 1) # Add a fraction and an integer
import statistics
data = [1, 2, 3, 4, 5]
mean = statistics.mean(data) # Average
median = statistics.median(data) # Median
stdev = statistics.stdev(data) # Standard Deviation
import math
angle_rad = math.radians(60) # Convert 60 degrees to radians
cosine = math.cos(angle_rad) # Cosine of the angle
import math
infinity = math.inf # Representing infinity
not_a_number = math.nan # Representing a non-number (NaN)
[python] html table을 Markdown으로 변경하기. (0) | 2024.09.04 |
---|---|
[python] Why Ibis? (2) | 2024.09.02 |
[python] 폴더 안의 파일들 이름의 공백 또는 - 를 언더바로 변경하는 프로그램 (0) | 2024.08.23 |
[python] Working With The Operating System (0) | 2024.08.13 |
[python] Working With Dictionaries (0) | 2024.08.12 |
[python] 폴더 안의 파일들 이름의 공백 또는 - 를 언더바로 변경하는 프로그램
공백( ) 또는 하이픈(-)을 언더바(_)로 변경하는 프로그램을 작성할 수 있습니다. 이 프로그램은 지정된 폴더 내 모든 파일의 이름을 확인하고, 공백 또는 하이픈이 포함된 경우 이를 언더바로 대체하여 이름을 변경합니다.
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다.
import os
from pathlib import Path
# src 상위 폴더를 실행폴더로 지정하려고 한다.
###real_path = Path(__file__).parent.parent
real_path = Path(__file__).parent
print(real_path)
#작업 디렉토리 변경
os.chdir(real_path)
def replace_spaces_in_filenames(folder_path):
# 폴더 내 모든 파일을 반복
for filename in os.listdir(folder_path):
# 파일의 전체 경로 생성
old_file_path = os.path.join(folder_path, filename)
# 파일 이름에 공백이 있는지, -도 _로 변경 확인
if ' ' in filename or '-' in filename:
# 공백을 언더바로 대체
new_filename = filename.replace(' ', '_').replace('-', '_')
new_file_path = os.path.join(folder_path, new_filename)
# 파일이 존재할경우 덮어쓸지, 빠져나갈지
if os.path.exists(new_file_path):
overwrite = input(f"'{new_file_path}' already exists. Overwrite? (y/n): ")
if overwrite.lower() == 'y':
os.remove(new_file_path)
else:
print("Operation canceled.")
exit()
# 파일 이름 변경
os.rename(old_file_path, new_file_path)
print(f"Renamed: '{filename}' -> '{new_filename}'")
else:
print(f"No change: '{filename}'")
# 사용 예시
folder_path = 'path_to_your_folder' # 여기에 폴더 경로를 입력하세요
replace_spaces_in_filenames(folder_path)
폴더 경로를 지정하여 프로그램을 실행하면, 그 폴더 안의 모든 파일 이름에서 공백 또는 하이픈이 언더바로 변경됩니다. 예를 들어, path_to_your_folder가 C:/Users/YourName/Documents/TestFolder인 경우:
[python] Why Ibis? (2) | 2024.09.02 |
---|---|
[python] Working With Mathematical Operations and Permutations. 수학적 연산과 순열 (0) | 2024.08.23 |
[python] Working With The Operating System (0) | 2024.08.13 |
[python] Working With Dictionaries (0) | 2024.08.12 |
[python] 폴더 안의 .webp 이미지를 .png 로 변환 (0) | 2024.08.12 |
비교를 하면 할수록
기분만 나빠진다. 하지만 사실 우리는
다른 사람들 삶에서 무슨 일이 일어나는지 잘 모른다.
계속 남과 비교만 하면 본인의 꿈, 자율권, 행복에서
점점 멀어지게 된다. 남과 자신을 비교하다 보면
다른 사람 일에 끼어들게 되고 남의 일에
참견하다 보면 정작 중요한 자기 일은
나 몰라라 하게 된다. 부디 자기
일에만 신경 쓰면서
본인에게 집중하자.
- 트레이시 리트의 《당신은 꽤 괜찮은 사람입니다》 중에서 -
* 누구나 자신만의 향기가 있습니다.
심지어 일란성 쌍둥이도 취문(臭紋)이 다릅니다.
각자는 모두 특별하며 비교 대상이 결코 아닙니다.
그는 그의 우주에서, 나는 나의 우주에서 살아갈
뿐입니다. 그러기에 남과 비교하며 살 필요가
없습니다. 그 시간에 자신을 잘 가꾸어가면
됩니다. 어제의 나와 비교하며
더 정진하는 것입니다.
당신이 행복하면 나도 행복하다 (0) | 2024.08.26 |
---|---|
솔밭 (0) | 2024.08.26 |
참나 리더십 (0) | 2024.08.22 |
노년의 '회복탄력성' (0) | 2024.08.21 |
노화를 물리치려는 폭발적 노력 (0) | 2024.08.20 |
let array = [1,2,3,4,5];
array = []
console.log(array) // []
단순하게 빈 배열 대입하여 배열을 비울 수 있습니다.
let array = [1,2,3,4,5]
array.length = 0
console.log(array) // []
배열의 길이를 0으로 수정하면 배열을 비울 수 있습니다.
※ 배열의 길이를 수정하면 해당 길이만큼 배열의 크기가 바꿔지며
현재 길이보다 크게 변경 할 경우 해당 자리에 빈 값이 들어가며 sparse Array가 됩니다.
let array = [1,2,3,4,5]
array.splice(0)
console.log(array) // []
splice 함수를 사용하면 해당 배열에서 설정한 크기만큼 잘라 반환합니다.
따라서 splice(0)을 사용하면 처음부터 끝까지 자르기 때문에 array가 비어지는 효과가 나타나게 됩니다.
let array = [1,2,3,4,5]
while(array.length > 0){
array.shift() 또는 array.pop()
}
배열의 shift() 또는 pop() 함수를 이용하여 요소들을 하나씩 직접 반환하는 방법입니다.
※ shift() - FIFO 먼저 들어온 요소 반환, pop() - LIFO 마지막에 들어온 요소 반환
[javascript] input 정규식 사용시 모바일 천지인 키보드 입력(여예요) 안될 경우 (0) | 2024.12.18 |
---|---|
45 JavaScript Super Hacks Every Developer Should Know (3) | 2024.10.21 |
[javascript] 새로운 자바스크립트가 이전 자바스크립트와 다른 11가지 이유 (0) | 2024.08.09 |
[javascript] 입력값 체크(한글, 영문, 특수문자, 공백 정규식 활용) (0) | 2024.05.22 |
[javascript] NaN - Not a Number (0) | 2024.03.22 |