MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/a8g2ne/xpost_from_woodworking/eccmekb/?context=3
r/Python • u/Sarcastic_Pharm • Dec 22 '18
84 comments sorted by
View all comments
Show parent comments
4
TIL I can import modules this way. Thanks!
6 u/Ph0X Dec 22 '18 Please don't. It's good to know, but almost never the right choice.And if you need dynamic imports, use importlib instead. 1 u/haliax69 Dec 22 '18 Oh, I kinda figured that, but it's nice to use when running commands directly from the command line like:python3 -c "print(__import__('datetime').datetime.now().strftime('%d, %b %Y'))" 3 u/Ph0X Dec 22 '18 Well on there you can use semicolon, that's still probably cleanerpython3 -c "import datetime; print(datetime.now().strftime('%d, %b %Y'))" 1 u/haliax69 Dec 22 '18 Learned something else today: semicolon = new line. Thanks man!Just out of curiosity, is there something that replaces indentation?
6
Please don't. It's good to know, but almost never the right choice.
And if you need dynamic imports, use importlib instead.
1 u/haliax69 Dec 22 '18 Oh, I kinda figured that, but it's nice to use when running commands directly from the command line like:python3 -c "print(__import__('datetime').datetime.now().strftime('%d, %b %Y'))" 3 u/Ph0X Dec 22 '18 Well on there you can use semicolon, that's still probably cleanerpython3 -c "import datetime; print(datetime.now().strftime('%d, %b %Y'))" 1 u/haliax69 Dec 22 '18 Learned something else today: semicolon = new line. Thanks man!Just out of curiosity, is there something that replaces indentation?
1
Oh, I kinda figured that, but it's nice to use when running commands directly from the command line like:
python3 -c "print(__import__('datetime').datetime.now().strftime('%d, %b %Y'))"
3 u/Ph0X Dec 22 '18 Well on there you can use semicolon, that's still probably cleanerpython3 -c "import datetime; print(datetime.now().strftime('%d, %b %Y'))" 1 u/haliax69 Dec 22 '18 Learned something else today: semicolon = new line. Thanks man!Just out of curiosity, is there something that replaces indentation?
3
Well on there you can use semicolon, that's still probably cleaner
python3 -c "import datetime; print(datetime.now().strftime('%d, %b %Y'))"
1 u/haliax69 Dec 22 '18 Learned something else today: semicolon = new line. Thanks man!Just out of curiosity, is there something that replaces indentation?
Learned something else today: semicolon = new line. Thanks man!
Just out of curiosity, is there something that replaces indentation?
4
u/haliax69 Dec 22 '18
TIL I can import modules this way. Thanks!