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 (Darkly)
  • No Skin
Collapse
Brand Logo
Timothée Mazzucotelli :python:P

pawamoy@fosstodon.org

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

View Original

Posts

Recent Best Controversial

  • Can someone explain this #Python import behavior
    Timothée Mazzucotelli :python:P Timothée Mazzucotelli :python:

    @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
    Timothée Mazzucotelli :python:P Timothée Mazzucotelli :python:

    @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
    Timothée Mazzucotelli :python:P Timothée Mazzucotelli :python:

    @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

  • Don't have an account? Register

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