https://github.com/nightmachinery/pynight
My Python utility library.
https://github.com/nightmachinery/pynight
Last synced: 9 months ago
JSON representation
My Python utility library.
- Host: GitHub
- URL: https://github.com/nightmachinery/pynight
- Owner: NightMachinery
- Created: 2021-09-28T09:45:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T17:21:49.000Z (about 1 year ago)
- Last Synced: 2024-10-25T21:21:58.748Z (about 1 year ago)
- Language: Python
- Size: 349 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.org
Awesome Lists containing this project
README
#+TITLE: PyNight
* Install
#+begin_example zsh
pip install -U pynight
#+end_example
Or install the latest version directly from git:
#+begin_example zsh
pip install git+https://github.com/NightMachinery/PyNight.git
#+end_example
To reinstall the latest version:
#+begin_example zsh
pip install git+https://github.com/NightMachinery/PyNight.git
pip install --no-deps --force-reinstall git+https://github.com/NightMachinery/PyNight.git
#+end_example
* =pynight.common_dynamic=
#+begin_src jupyter-python :kernel py_base :session emacs_py_1 :async yes :exports both
from pynight.common_dynamic import (
DynamicVariables,
DynamicObject,
dynamic_set,
dynamic_get,
)
dynamic_dict = {}
obj = DynamicObject(dynamic_dict, default_to_none_p=True)
obj.x = -13
obj.z = 72
print(
f"x: {obj.x}, z: {obj.z}, nonexistent_attribute: {obj.nonexistent_attribute or 'some_default_value'}"
)
#: x: -13, z: 72, nonexistent_attribute: some_default_value
with DynamicVariables(obj, x=10):
print(f"x: {obj.x}, z: {obj.z}") #: x: 10, z: 72
with DynamicVariables(obj, x=20):
print(f"x: {obj.x}, z: {obj.z}") #: x: 20, z: 72
obj.x = 99
obj.y = 81
obj.z = -6
print(f"x: {obj.x}, y: {obj.y}, z: {obj.z}")
#: x: 99, y: 81, z: -6
print(f"x: {obj.x}, y: {obj.y}, z: {obj.z}")
#: x: 10, y: 81, z: -6
#: z and y did NOT get reset as they were not explicitly set in the previous context manager.
obj.y = 560
print(f"x: {obj.x}, y: {obj.y}, z: {obj.z}")
#: x: -13, y: 560, z: -6
#+end_src
#+RESULTS:
: x: -13, z: 72, nonexistent_attribute: some_default_value
: x: 10, z: 72
: x: 20, z: 72
: x: 99, y: 81, z: -6
: x: 10, y: 81, z: -6
: x: -13, y: 560, z: -6
* =pynight.common_tqdm=
** =tqdm_telegram=
#+begin_src jupyter-python :kernel py_base :session /jpy:127.0.0.1#6035:orgk1/ :async yes :exports both
from os import environ
environ['TQDM_TELEGRAM_TOKEN'] = 'xxx'
environ['TQDM_TELEGRAM_CHAT_ID'] = 'xxx'
#+end_src
#+RESULTS:
#+begin_src jupyter-python :kernel py_base :session /jpy:127.0.0.1#6035:orgk1/ :async yes :exports both
from pynight.common_tqdm import tqdm, trange
import time
for i in tqdm(range(100)):
# print(i)
time.sleep(0.1)
#+end_src
* =rtl_iterfzf=
#+begin_src python :eval never
from pynight.common_fzf import rtl_iterfzf
from pynight.common_rtl import rtl_reshaper_v1
# Your iterable of items
iterable_items = [
"سلام دنیا", # Persian for "Hello World"
"Hello World",
"مرحبا بالعالم", # Arabic for "Hello World"
"Bonjour le monde",
]
# Use the rtl_iterfzf function
result = rtl_iterfzf(
iterable_items,
reshaper_func=rtl_reshaper_v1,
multi=True, # Set to True if you want to select multiple items
# You can pass additional iterfzf options here
)
if result:
print("Selected Items:", result.selected)
print("Indices:", result.indices)
else:
print("No selection made.")
#+end_src