Skip to content

Instantly share code, notes, and snippets.

@wieczorek1990
Last active May 20, 2016 09:00
Show Gist options
  • Save wieczorek1990/e18a8c8c8934e682296c8f49591e8103 to your computer and use it in GitHub Desktop.
Save wieczorek1990/e18a8c8c8934e682296c8f49591e8103 to your computer and use it in GitHub Desktop.
Circular imports in Python & Ruby
./ruby/a.rb
require_relative 'b'
class B; end
class A
@b = B.new
end
./ruby/main.rb
require_relative 'a'
require_relative 'b'
puts A.new.object_id
puts B.new.object_id
./ruby/b.rb
require_relative 'a'
class A; end
class B
@a = A.new
end
###
./python/main.py
from a import A
from b import B
print id(A())
print id(B())
./python/a.py
from b import B
class A:
b = B()
./python/b.py
from a import A
class B:
a = A()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment