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.


    import question

    Pythonista
    3
    5
    2137
    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.
    • donnieh
      donnieh last edited by

      What's the different between the two?

      import random
      

      and

      from random import random
      
      1 Reply Last reply Reply Quote 0
      • polymerchm
        polymerchm last edited by

        import random

        imports the entire module in its own namespace, so you must access all its methods via

        random.some_method_name()

        so to access its random method, you need to say:

        number = random.random()

        The method random.random() is just one of many methods in this module. If you only need a subset of the methods in a module, you can use;

        from random import method_1, method_2, ......

        These methods appear in the current namespace and are referenced as method_1(), method_1() etc.

        so

        from random import random

        provides you just with module's random method and is accessed without needing the module name as in

        number = random()

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

          That's was a great reply. Thank you.

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

            Excercising my dusty Professor circuits. Your welcome.

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

              Great answer for me also.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors