Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python examples #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Python Examples

// to do
40 changes: 40 additions & 0 deletions examples/date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from datetime import datetime, timedelta

now = datetime.now()

first_day_week = now - timedelta(days=now.weekday())

currently_day = int(now.strftime("%d"))
currently_month = int(now.strftime("%m"))
currently_year = int(now.strftime("%Y"))

current_date = datetime(currently_year, currently_month, currently_day)

_date = now.strftime("%d-%m-%Y")
_time = now.strftime("%H:%M:%S")
week_number_iso = current_date.isocalendar()[1]
week_number_sunday = current_date.strftime("%U")
week_number_monday = current_date.strftime("%W")
year = current_date.strftime("%Y")
month = current_date.strftime("%m")
day = current_date.strftime("%j")
week = current_date.strftime("%A")
satuday = first_day_week + timedelta(days=5)
sunday = first_day_week + timedelta(days=6)

print()
print()
print(f"Currenty date: {_date}")
print(f"Currenty time: {_time}")
print(f"Week number [ISO format]: {week_number_iso}")
print(f"Week number [starts on Sunday]: {week_number_sunday}")
print(f"Week number [starts on Monday]: {week_number_monday}")
print(f"Year: {year}")
print(f"Month: {month}")
print(f"Day of the year: {day}")
print(f"Currently day of the week: {week}")
print(f"Saturday of the currently week: {satuday.strftime('%Y-%m-%d')}")
print(f"Sunday of the currently week: {sunday.strftime('%Y-%m-%d')}")
print()
print()

4 changes: 4 additions & 0 deletions python-blogs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- [Duck Typing in Python: Writing Flexible and Decoupled Code](https://realpython.com/duck-typing-python/)
- [Python's pathlib Module: Taming the File System](https://realpython.com/python-pathlib/)
- [What Are Python Wheels and Why Should You Care?](https://realpython.com/python-wheels/)
- [Python Closures: Common Use Cases and Examples](https://realpython.com/python-closure/)
- [Python '!=' Is Not 'is not': Comparing Objects in Python](https://realpython.com/python-is-identity-vs-equality/)

## Mathspp
> Website: https://mathspp.com
Expand All @@ -49,6 +51,7 @@


- [`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding](https://www.thepythoncodingstack.com/p/bytes-python-built-in-unicode-utf-8-encoding)
- [After You. No, I Insist, You Go First • Python's Operator Precedence](https://www.thepythoncodingstack.com/p/python-operator-precedence-after-you-no-i-insist)

## Python Engineer
> Website: https://www.python-engineer.com
Expand All @@ -67,6 +70,7 @@
- [Data structures contain pointers](https://www.pythonmorsels.com/data-structures-contain-pointers/)
- [Converting a string to a datetime](https://www.pythonmorsels.com/converting-a-string-to-a-datetime/)
- [Find your strptime/strftime format](https://www.pythonmorsels.com/strptime/#formats)
- [Python's pathlib module](https://www.pythonmorsels.com/pathlib-module/)

## Test Driven
> Website: https://testdriven.io/
Expand Down
6 changes: 6 additions & 0 deletions python-packaging/uv.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Install a specific Python version:
uv python install 3.12
```

Update uv to the latest version:
```shell
uv self update
```

### Source

- Website: https://docs.astral.sh/uv/
Expand All @@ -36,3 +41,4 @@ uv python install 3.12
- [Docker images using uv's python](https://mkennedy.codes/posts/python-docker-images-using-uv-s-new-python-features/)
- [Production-ready Docker Containers with uv](https://hynek.me/articles/docker-uv/)
- [Switching from virtualenvwrapper to direnv, Starship, and uv](https://treyhunner.com/2024/10/switching-from-virtualenvwrapper-to-direnv-starship-and-uv/)
- [A comprehensive guide to python project management and packaging concepts illustrated with uv part 1](https://reinforcedknowledge.com/a-comprehensive-guide-to-python-project-management-and-packaging-concepts-illustrated-with-uv-part-i/)