8000 ✨ Add `jsobj` to create dict without explicitly specifying the key-va… · pwwang/python-varname@e91916c · GitHub
[go: up one dir, main page]

Skip to content

Commit e91916c

Browse files
committed
✨ Add jsobj to create dict without explicitly specifying the key-value pairs
1 parent d9124ae commit e91916c

File tree

7 files changed

+187
-43
lines changed

7 files changed

+187
-43
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Note if you use `python < 3.8`, install `varname < 0.11`
2929

3030
- A value wrapper to store the variable name that a value is assigned to, using `Wrapper`
3131
- A decorator to register `__varname__` to functions/classes, using `register`
32+
- A helper function to create dict without explicitly specifying the key-value pairs, using `jsobj`
3233
- A `debug` function to print variables with their names and values
3334

3435
## Credits
@@ -347,6 +348,17 @@ mydict = values_to_dict(foo, bar)
347348
# {'foo': True, 'bar': False}
348349
```
349350

351+
### Creating dictionary using `jsobj`
352+
353+
```python
354+
from varname.helpers import jsobj
355+
356+
a = 1
357+
b = 2
358+
jsobj(a, b) # {'a': 1, 'b': 2}
359+
jsobj(a, b, c=3) # {'a': 1, 'b': 2, 'c': 3}
360+
```
361+
350362
### Debugging with `debug`
351363

352364
```python

README.raw.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Note if you use `python < 3.8`, install `varname < 0.11`
2929

3030
- A value wrapper to store the variable name that a value is assigned to, using `Wrapper`
3131
- A decorator to register `__varname__` to functions/classes, using `register`
32+
- A helper function to create dict without explicitly specifying the key-value pairs, using `jsobj`
3233
- A `debug` function to print variables with their names and values
3334

3435
## Credits
@@ -342,6 +343,17 @@ mydict = values_to_dict(foo, bar)
342343
# {mydict}
343344
```
344345

346+
### Creating dictionary using `jsobj`
347+
348+
```python
349+
from varname.helpers import jsobj
350+
351+
a = 1
352+
b = 2
353+
jsobj(a, b) # {_expr!r}
354+
jsobj(a, b, c=3) # {_expr!r}
355+
```
356+
345357
### Debugging with `debug`
346358

347359
```python

0 commit comments

Comments
 (0)
0