omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Quick Question on importing..

    Pythonista
    moduleadoption import importshare
    3
    7
    2589
    Loading More Posts
    • 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.
    • stephen
      stephen last edited by stephen

      just my curiosity...

      Would there be any benefit from "adopting" an import from another import?

      ◈Example◈

      
      import scene
      
      from scene import ui as gui
      
      class MyView(gui.View):
          ...
      
      
      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        >>> from scene import *
        >>> ui.ACTIVITY_INDICATOR_STYLE_WHITE_LARGE
        0
        >>> ui.ACTIVITY_INDICATOR_STYLE_WHITE
        1
        >>> class MyView(ui.View):
            ...
        
        1 Reply Last reply Reply Quote 1
        • stephen
          stephen last edited by

          @ccc

          im just wondering if there is any benefit such as to overhead when doing this or if it makes no difference if i use, in this case, ui from scene or if i use scene and separate ui import?

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            Same thing either way...

            >>> import ui
            >>> id(ui)
            4543879592
            >>> from scene import ui as gui
            >>> id(gui)
            4543879592
            >>> ui == gui
            True
            >>> ui is gui
            True
            
            1 Reply Last reply Reply Quote 1
            • stephen
              stephen last edited by

              10-4 thanks @ccc

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                I think where this is usually used is when the module has a long name, and that you use a lot within your code, so for readability you use an abbreviation

                import numpy as np
                from matplotlib import pyplot as plt
                
                stephen 1 Reply Last reply Reply Quote 0
                • stephen
                  stephen @JonB last edited by

                  @JonB your statment on alias is correct 😃

                  But in this case we are speaking of Scene module importing ui and then Developer using ui module through scene with without making a separate import of ui in active script where __name__=="__main__"

                  Inside scene.py ...

                  from _scene2 import *
                  import _scene2
                  
                  from scene_drawing import *
                  
                  import math
                  from numbers import Number
                  from io import BytesIO
                  import ui
                  
                  DEFAULT_ORIENTATION = 0
                  PORTRAIT = 1
                  LANDSCAPE = 2
                  ...
                  

                  inside myScript.py ...

                  from scene import ui
                  
                  class MyView(ui.View):
                      ...
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors