Everyone can benefit from this implementation! #1343
-
Hello, @willmcgugan! First of all, I can't say thank you enough to you for this brilliant creation(rich). It helps me to debug my code and, My way of doing things on the command prompt is changed completely. Okay!, Coming to the point, I am here to ask you to implement my idea in a rich library. The idea is about how we can store the most frequently used methods, classes, and attributes in a JSON format(or some other format) whenever we run a code. Most of the time, We can't remember all these methods and, it is frustrating for us to go through the documentation again or previous projects to check out what methods we have used to implement a certain logic. So, To solve this issue, I have created a function called Finally, To see the result, I have added a new keyword argument called import json
import rich
from rich import print, inspect
>>> from rich import remember <<<
# remember('load', 'dump', modulename = json)
>>> remember('print', 'inspect', modulename = rich) # Usage: remember(args, modulename=<modulename>)
Behind the scenes:
remember.json file content
{
"rich": {
"methods": [
"print",
"inspect"
],
"private": [],
"dunder": []
}
}
def load_data():
"""Read json file"""
with open("test.json", 'r') as rf:
>>> remember('load', modulename = json) # Usage: remember(args, modulename=<modulename>)
data = json.load(rf)
return data
def dump_data():
"""Add content to json file"""
with open("test.json", 'w') as wf:
>>> remember('dump', modulename = json) # Usage: remember(args, modulename=<modulename>)
data = {'function_name': 'remember'}
json.dump(data, wf)
return 'Data is stored!'
print(load_data())
print(dump_data())
Behind the scenes:
remember.json file content
{
"rich": {
"methods": [
"print",
"inspect"
],
"private": [],
"dunder": []
},
"json": {
"methods": [
"load",
"dump"
],
"private": [],
"dunder": []
}
}
>>> print(inspect(json, f_methods=True)) # f_methods - frequently used methods
Result:
┌─ Frequently used json methods ─┐
│ load │
│ dump │
│ │
└────────────────────────────────┘
>>> print(inspect(rich, f_methods=True)) # f_methods - frequently used methods
Result:
┌─ Frequently used rich methods ─┐
│ print │
│ inspect │
│ │
└────────────────────────────────┘ Maybe this is not a correct approach to doing it. But, We can save a lot of time with this implementation, Mainly beginners can benefit from this feature if we can implement this in a rich library. Thank you for your time @willmcgugan :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think it’s an interesting idea! Probably not something that belongs in the core library. You might want to implement it yourself and perhaps publish it on PyPi. |
Beta Was this translation helpful? Give feedback.
I think it’s an interesting idea! Probably not something that belongs in the core library. You might want to implement it yourself and perhaps publish it on PyPi.