Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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