Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

pawamoy@fosstodon.orgP

pawamoy@fosstodon.org

@pawamoy@fosstodon.org
About
Posts
4
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

View Original

Posts

Recent Best Controversial

  • Go draw a horse and watch it run - this is the kind of silliness the internet was originally made for ...
    pawamoy@fosstodon.orgP pawamoy@fosstodon.org

    @Natasha_Jay I'm not good at drawing horses.

    Link Preview Image
    Uncategorized

  • Can someone explain this #Python import behavior
    pawamoy@fosstodon.orgP pawamoy@fosstodon.org

    @bmispelon OK no it's much simpler, module a is simply partially initialized. By the time b imports it, it's not re-executed since it exists in sys.modules, and b imports every existing (yet) symbols within A. from a import A would work too.

    Uncategorized python

  • Can someone explain this #Python import behavior
    pawamoy@fosstodon.orgP pawamoy@fosstodon.org

    @bmispelon by the way I'm not sure to understand why the circular import works. I think Python has special handling for some cases where it's able to tell the circular import is "safe" somehow (like "a is almost finished, there's only * to import from b", meaning b can import from a again, and when b is finisehd a is updated again with any symbols declared in b). Tried to find an actual answer in the past but didn't find anything. Maybe should read the sources!

    Uncategorized python

  • Can someone explain this #Python import behavior
    pawamoy@fosstodon.orgP pawamoy@fosstodon.org

    @bmispelon

    Got it! Did it in my head then verified with an interpreter πŸ™‚

    There's nothing weird here. Python executes stuff sequentially, so:

    - in πŸ˜„ from a import A
    - in a: A = 1
    - in a: from b import *
    - in b: from a import * (so we have A = 1 in b)
    - in b: A += 1 (so we have A = 2 in b)
    - in a: finishing previous import, so we now have A = 2 in a
    - in πŸ˜„ finishing previous import, so we now have A = 2 in C
    - in πŸ˜„ print(A) -> 2!

    Uncategorized python
  • Login

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups