반응형
반응형

[여행] 2024-07-26~28, 대전, 무주, 금산


반응형
반응형

일본 시즈오카 하비 쇼 2024 정보. 내년에 도전? 

https://hobby.watch.impress.co.jp/docs/news/1569176.html

 

模型玩具のビッグイベント「第62回 静岡ホビーショー」は5月8日から開催! 一般公開は11・12日

 静岡模型教材協同組合は、模型玩具の製品見本市「第62回 静岡ホビーショー」を、5月8日より開催する。一般公開は5月11・12日の2日間。入場料は無料だが、4月1日より始まる事前登録が必須

hobby.watch.impress.co.jp

https://hobby.watch.impress.co.jp/

 

HOBBY Watch

プラモデル、フィギュア、ゲームグッズ、TCG、ボードゲーム、トイガン、RC、プライズ、食玩、知育など、あらゆるホビー情報を扱うホビーの総合情報サイト

hobby.watch.impress.co.jp

 

반응형
반응형

도토리에서
떡잎들이 나왔네

나는 떡갈나무가 될 거야
나는 신갈나무가 될 거야
나는 상수리나무가 될 거야
아름드리나무가 되어서
다람쥐들에게 도토리를 두루 나눠 줄 거야

그래그래 우리 나중에
다람쥐들한테 도토리 많이 나눠주자


- 최승호의 시집 《부처님의 작은 선물》 에 실린
  시 〈도토리〉 중에서 -


* 저희 옹달샘에도
도토리나무가 많습니다.
떡갈나무, 신갈나무, 상수리나무, 이파리 모양에
따라 이름이 다르지만 모두 도토리나무로 통합니다.
도토리 떡잎에 다람쥐의 생존이 달려 있습니다.
떡잎이 튼실할수록 큰 나무로 자라 더 많은
도토리가 열리고, 더 많은 다람쥐들이
그 혜택을 누릴 것입니다. 그것이
자연의 순리입니다.

반응형

'아침편지' 카테고리의 다른 글

똘레랑스  (0) 2024.07.29
아이들의 감정 변화  (0) 2024.07.29
기쁨과 행복을 길어 올리는 두레박  (2) 2024.07.24
통찰력 있는 질문  (0) 2024.07.23
자기 존엄  (0) 2024.07.22
반응형

1. Creating a List

To conjure a list into being:

# A list of mystical elements
elements = ['Earth', 'Air', 'Fire', 'Water']

2. Appending to a List

To append a new element to the end of a list:

elements.append('Aether')

3. Inserting into a List

To insert an element at a specific position in the list:

# Insert 'Spirit' at index 1
elements.insert(1, 'Spirit')

4. Removing from a List

To remove an element by value from the list:

elements.remove('Earth')  # Removes the first occurrence of 'Earth'

5. Popping an Element from a List

To remove and return an element at a given index (default is the last item):

last_element = elements.pop()  # Removes and returns the last element

6. Finding the Index of an Element

To find the index of the first occurrence of an element:

index_of_air = elements.index('Air')

7. List Slicing

To slice a list, obtaining a sub-list:

# Get elements from index 1 to 3
sub_elements = elements[1:4]

8. List Comprehension

To create a new list by applying an expression to each element of an existing one:

# Create a new list with lengths of each element
lengths = [len(element) for element in elements]

9. Sorting a List

To sort a list in ascending order (in-place):

elements.sort()

10. Reversing a List

To reverse the elements of a list in-place:

elements.reverse()

 

 
반응형
반응형

 

1. Basic GET Request

To fetch data from an API endpoint using a GET request:

import requests
response = requests.get('https://api.example.com/data')
data = response.json()  # Assuming the response is JSON
print(data)

2. GET Request with Query Parameters

To send a GET request with query parameters:

import requests
params = {'key1': 'value1', 'key2': 'value2'}
response = requests.get('https://api.example.com/search', params=params)
data = response.json()
print(data)

3. Handling HTTP Errors

To handle possible HTTP errors gracefully:

import requests
response = requests.get('https://api.example.com/data')
try:
    response.raise_for_status()  # Raises an HTTPError if the status is 4xx, 5xx
    data = response.json()
    print(data)
except requests.exceptions.HTTPError as err:
    print(f'HTTP Error: {err}')

4. Setting Timeout for Requests

To set a timeout for API requests to avoid hanging indefinitely:

import requests
try:
    response = requests.get('https://api.example.com/data', timeout=5)  # Timeout in seconds
    data = response.json()
    print(data)
except requests.exceptions.Timeout:
    print('The request timed out')

5. Using Headers in Requests

To include headers in your request (e.g., for authorization):

import requests
headers = {'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
response = requests.get('https://api.example.com/protected', headers=headers)
data = response.json()
print(data)

6. POST Request with JSON Payload

To send data to an API endpoint using a POST request with a JSON payload:

import requests
payload = {'key1': 'value1', 'key2': 'value2'}
headers = {'Content-Type': 'application/json'}
response = requests.post('https://api.example.com/submit', json=payload, headers=headers)
print(response.json())

7. Handling Response Encoding

To handle the response encoding properly:

import requests
response = requests.get('https://api.example.com/data')
response.encoding = 'utf-8'  # Set encoding to match the expected response format
data = response.text
print(data)

8. Using Sessions with Requests

To use a session object for making multiple requests to the same host, which can improve performance:

import requests
with requests.Session() as session:
    session.headers.update({'Authorization': 'Bearer YOUR_ACCESS_TOKEN'})
    response = session.get('https://api.example.com/data')
    print(response.json())

9. Handling Redirects

To handle or disable redirects in requests:

import requests
response = requests.get('https://api.example.com/data', allow_redirects=False)
print(response.status_code)

10. Streaming Large Responses

To stream a large response to process it in chunks, rather than loading it all into memory:

import requests
response = requests.get('https://api.example.com/large-data', stream=True)
for chunk in response.iter_content(chunk_size=1024):
    process(chunk)  # Replace 'process' with your actual processing function

 

https://blog.stackademic.com/ultimate-python-cheat-sheet-practical-python-for-everyday-tasks-c267c1394ee8

반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] TIOBE Index for August 2024, Python 1st  (0) 2024.08.09
[python] Working With Lists  (0) 2024.07.24
[python] Working With Files  (0) 2024.07.24
[python] Pandas cheat sheet  (0) 2024.07.19
[python] 변수 scope, LEGB Rule  (0) 2024.07.15
반응형

1. Reading a File

To read the entire content of a file:

with open('example.txt', 'r') as file:
    content = file.read()
    print(content)

2. Writing to a File

To write text to a file, overwriting existing content:

with open('example.txt', 'w') as file:
    file.write('Hello, Python!')

3. Appending to a File

To add text to the end of an existing file:

with open('example.txt', 'a') as file:
    file.write('\nAppend this line.')

4. Reading Lines into a List

To read a file line by line into a list:

with open('example.txt', 'r') as file:
    lines = file.readlines()
    print(lines)

5. Iterating Over Each Line in a File

To process each line in a file:

with open('example.txt', 'r') as file:
    for line in file:
        print(line.strip())

6. Checking If a File Exists

To check if a file exists before performing file operations:

import os
if os.path.exists('example.txt'):
    print('File exists.')
else:
    print('File does not exist.')

7. Writing Lists to a File

To write each element of a list to a new line in a file:

lines = ['First line', 'Second line', 'Third line']
with open('example.txt', 'w') as file:
    for line in lines:
        file.write(f'{line}\n')

8. Using With Blocks for Multiple Files

To work with multiple files simultaneously using with blocks:

with open('source.txt', 'r') as source, open('destination.txt', 'w') as destination:
    content = source.read()
    destination.write(content)

9. Deleting a File

To safely delete a file if it exists:

import os
if os.path.exists('example.txt'):
    os.remove('example.txt')
    print('File deleted.')
else:
    print('File does not exist.')

10. Reading and Writing Binary Files

To read from and write to a file in binary mode (useful for images, videos, etc.):

# Reading a binary file
with open('image.jpg', 'rb') as file:
    content = file.read()
# Writing to a binary file
with open('copy.jpg', 'wb') as file:
    file.write(content)

https://blog.stackademic.com/ultimate-python-cheat-sheet-practical-python-for-everyday-tasks-c267c1394ee8

반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] Working With Lists  (0) 2024.07.24
[python] Working With Simple HTTP APIs  (0) 2024.07.24
[python] Pandas cheat sheet  (0) 2024.07.19
[python] 변수 scope, LEGB Rule  (0) 2024.07.15
[python] deepcopy  (0) 2024.07.04

+ Recent posts