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

  1. Home
  2. Uncategorized
  3. Using many names from a #Python module?

Using many names from a #Python module?

Scheduled Pinned Locked Moved Uncategorized
python
2 Posts 2 Posters 2 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • reuven@fosstodon.orgR This user is from outside of this forum
    reuven@fosstodon.orgR This user is from outside of this forum
    reuven@fosstodon.org
    wrote last edited by
    #1

    Using many names from a #Python module? Import them all:

    from MODNAME import *

    Wait: This is usually a TERRIBLE idea!

    • Potential namespace collisions
    • Less readable code
    • Module upgrades affect globals in your program

    I know, it's tempting — but don't!

    Link Preview Image
    cazabon@mindly.socialC 1 Reply Last reply
    1
    0
    • reuven@fosstodon.orgR reuven@fosstodon.org

      Using many names from a #Python module? Import them all:

      from MODNAME import *

      Wait: This is usually a TERRIBLE idea!

      • Potential namespace collisions
      • Less readable code
      • Module upgrades affect globals in your program

      I know, it's tempting — but don't!

      Link Preview Image
      cazabon@mindly.socialC This user is from outside of this forum
      cazabon@mindly.socialC This user is from outside of this forum
      cazabon@mindly.social
      wrote last edited by
      #2

      @Reuven

      ➕

      It's also a violation of the Zen of Python - "namespaces are one honking great idea -- let's do more of those"!

      I'd also add that sometimes you want to do this within your own packages - like keeping all the magic constants in a sub-module, but you don't want to have to refer to them as `constants.foo` all through the rest of the code. In this case, use the `__all__` definition in constants.py to explicitly export only the names you want used this way.

      1 Reply Last reply
      1
      0
      • R relay@relay.publicsquare.global shared this topic
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

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