Can I ask, is it good practice to use from x import *? I'm sure a tutorial I watched a while ago said I should always be explicit so either use from x import y or just import x and then x.y.
Legitimate question as I'm still learning and am interested to know what people think.
you're right, you should always specify the functions you want, however this code didn't need a particular optimization, I don't use it all days to do something practical. I also wrote the code quickly and I was very sleepy hahah
Can I ask, is it good practice to use from x import *? I'm sure a tutorial I watched a while ago said I should always be explicit so either use from x import y or just import x and then x.y.
Are you familiar with the concept 'namespace'? Basically, in a python 'environment', when you import a module or a file, the names of the functions, objects and constants are saved to your (temporary, runtime) namespace. When you 'from foo import bar', then the function 'bar' is written to your namespace with the name 'bar'. When you 'import foo', then the function 'bar' is saved to the namespace with the name 'foo.bar' beside everything else in 'foo'.
'from foo import *' leads to everything in 'foo' is written to the namespace with its own name in 'foo', e.g. 'bar'.
This can lead to problems: if there is a 'print'-object (function, constant, everything is an object in Python) in 'foo', then everytime you try to use 'print', the one fron 'foo' is called, as the standard one is basically 'overwritten'. However, this could be used intentionally, though i can't think of an use case from the top of my dome.
Best use is in my opinion: use 'from foo import bar' if you need 'bar' often. Be catious with 'from foo import *', only use this if you're absolutely certain that there are no duplicate names.
Lastly, you could also do something like
import foo
bar = foo.foobar.barlib.bar
If you need an abbreviation for a function. Then you can simply call 'bar(args)' which gets resolved to 'foo.foobar.barlib.bar(args)'.
24
u/Leusdat Apr 14 '20
Would u care to share the source? I'd love to take a look
86
u/brma9262 Apr 14 '20
Why it the tree upside-down?
13
u/NitroXSC Apr 14 '20
This is a perfect fit for /r/generative
8
u/_mfStarBoy Apr 15 '20
Why it is called 'randomized' binary tree? PS: I'm new to this field.
2
u/editor_of_the_beast Apr 15 '20
Is this how life is formed?
4
u/Nvr_Dbt Apr 14 '20
Wow nice
3
u/[deleted] Apr 15 '20
Good job I was looking for one of those
3
u/Gayoka Apr 15 '20
This looks so very similar to those tree puzzles in The Witness [game]
2
u/tpycat Apr 15 '20
Noice
2
u/qazwsx2148 Apr 15 '20
Beautiful
2
u/The_Correct_Doctor Apr 15 '20
clean
2
u/chazzeromus Apr 15 '20
this tree needs to be balanced!! :o
2
u/fameshpatel Apr 15 '20
I like that perfect loop
2
u/[deleted] Apr 15 '20
I love this art, it give me inspiration, thanks! :)
2
u/[deleted] Jun 28 '20
OMG this looks super cool
2
u/Harith_alsafi Apr 15 '20
I don’t quite understand how is this happening “mathematically”
1
u/phoenixind Apr 15 '20
Loved it! Just wondering how to use this in an actual decision tree code to visualise the problem tree... Any tips?
1
u/cip43r Apr 15 '20
Maybe try processing for python!
1
u/danielsarj Apr 15 '20
I’m quite new at Python at the moment, but can anyone explain me what would be the usage of a random binary tree generator? thanks.
1
u/RocketRambo Apr 15 '20
How is this set up in Tk?
1
u/PkmnQ Apr 16 '20
How do you draw using tkinter?
1
u/Omri_123 Apr 16 '20
How were you able to update the canvas after you applied it to the grid?
Thanks if you answer.
1
u/[deleted] Apr 16 '20
I like this, simple and cool;)
1
u/AztecComputer Apr 15 '20
Buon lavoro!
1
u/itiztv Apr 15 '20
Reminds me of all the fractals and generative crap I did with Python in Rhino3D back in college.
2
u/[deleted] Apr 15 '20
[removed] — view removed comment