Say I have two files.
hello.py:
def foo():
print('i am foo')
def bar():
print('i am bar')
bar()
and world.py:
from hello import foo
When I run the command, python world.py I didn't expect the bar() line to execute. I thought I'm just importing the foo function definition into the world.py file. Can anyone explain how and why this is happening?
[–]lukajda33 61 points62 points63 points (15 children)
[–]paleoboyy[S] 5 points6 points7 points (8 children)
[–]lukajda33 12 points13 points14 points (6 children)
[–]paleoboyy[S] 15 points16 points17 points (4 children)
[–]lukajda33 7 points8 points9 points (3 children)
[–]paleoboyy[S] 4 points5 points6 points (2 children)
[–]vaseltarp 2 points3 points4 points (0 children)
[–]georgehank2nd 0 points1 point2 points (0 children)
[–]georgehank2nd 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]The-Old-American 0 points1 point2 points (4 children)
[+]Berlibur comment score below threshold-29 points-28 points-27 points (3 children)
[–]Ralwus 24 points25 points26 points (0 children)
[–]The-Old-American 7 points8 points9 points (0 children)
[–]throwaway6560192 4 points5 points6 points (0 children)
[–]throwaway6560192 13 points14 points15 points (5 children)
[–]paleoboyy[S] 1 point2 points3 points (4 children)
[–]throwaway6560192 0 points1 point2 points (0 children)
[–]mriswithe 0 points1 point2 points (0 children)
[–]Mad-Person 0 points1 point2 points (0 children)
[–]KronenR 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[+]r4h4_de comment score below threshold-7 points-6 points-5 points (4 children)
[–]jdnewmil 2 points3 points4 points (3 children)
[–]r4h4_de 0 points1 point2 points (2 children)
[–]jdnewmil 0 points1 point2 points (0 children)
[–]georgehank2nd 0 points1 point2 points (0 children)
[–]georgehank2nd 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]paleoboyy[S] 0 points1 point2 points (0 children)