Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Last active August 29, 2015 14:09

Revisions

  1. naiquevin revised this gist Nov 9, 2014. 4 changed files with 15 additions and 6 deletions.
    10 changes: 7 additions & 3 deletions a.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    import d

    x = 10


    def f(n):
    return x + n


    print 'f(2) called directly in module a [x = 10]'
    print f(2)
    print 'f(2) called directly in module a [a.x = 10]'
    print f(2)

    print 'f(2) called indirectly in module a by passing to d.h [d.x = 1000]'
    print d.h(f)
    4 changes: 2 additions & 2 deletions b.py
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,5 @@ def g(func):
    return func(2)


    print 'a.f(2) called indirectly in module b by passing it to g [x = 100]'
    print g(a.f)
    print 'a.f(2) called indirectly in module b by passing it to g [b.x = 100]'
    print g(a.f)
    2 changes: 1 addition & 1 deletion c.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    import b
    import a

    print 'a.f(2) called indirectly in module c by passing it to b.g'
    print 'a.f(2) called indirectly in module c by passing it to b.g [no c.x]'
    print b.g(a.f)
    5 changes: 5 additions & 0 deletions d.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    x = 1000


    def h(func):
    return func(2)
  2. naiquevin created this gist Nov 9, 2014.
    9 changes: 9 additions & 0 deletions a.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    x = 10


    def f(n):
    return x + n


    print 'f(2) called directly in module a [x = 10]'
    print f(2)
    12 changes: 12 additions & 0 deletions b.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import a


    x = 100


    def g(func):
    return func(2)


    print 'a.f(2) called indirectly in module b by passing it to g [x = 100]'
    print g(a.f)
    5 changes: 5 additions & 0 deletions c.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    import b
    import a

    print 'a.f(2) called indirectly in module c by passing it to b.g'
    print b.g(a.f)