Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-code authored Jan 16, 2025
1 parent f3e8cc9 commit c93bf76
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1575,23 +1575,19 @@ def _superdot():
,,, # cd ../../../
```
### Python sugar: inline import
### Xonsh sugar: inline import
```xsh
# Run it or add to ~/.xonshrc
imp = type('ImpCl', (object,), {'__getattr__':lambda self, name: __import__(name) })()
Use `__xonsh__.imp` as inline importer (xonsh >= 0.18.2):
# Use `imp` as inline import sugar
imp.json.loads('{"a":1}')
```xsh
__xonsh__.imp.json.loads('{"a":1}')
# {'a': 1}
imp.datetime.datetime.now().isoformat()
__xonsh__.imp.datetime.datetime.now().isoformat()
# '2024-02-12T15:29:57.125696'
imp.hashlib.md5(b'Hello world').hexdigest()
__xonsh__.imp.hashlib.md5(b'Hello world').hexdigest()
# '3e25960a79dbc69b674cd4ec67a72c62'
```
*In the xonsh > 0.18.0 this will be accessible in xonsh core: `__xonsh__.imp`.*
### Transparent callable environment variables
For example, you want to have the current timestamp in every command but instead of nesting like `@(dt())` you want sugar:
Expand Down

0 comments on commit c93bf76

Please sign in to comment.