zoukankan      html  css  js  c++  java
  • python3 from Tkinter import * 和import Tkinter as tk两个区别import Tkinter

    原文https://stackoverflow.com/questions/15974787/difference-between-import-tkinter-as-tk-and-from-tkinter-import

    from Tkinter import * imports every exposed object in Tkinter into your current namespace. 

    import Tkinter imports the "namespace" Tkinter in your namespace and import Tkinter as tkdoes the same, but "renames" it locally to 'tk' to save you typing

    let's say we have a module foo, containing the classes A, B, and C.

    Then import foo gives you access to foo.A, foo.B, and foo.C.

    When you do import foo as x you have access to those too, but under the names x.A, x.B, and x.C. from foo import * will import A, B, and C directly in your current namespace, so you can access them with A, B, and C.

    There is also from foo import A, C wich will import A and C, but not B into your current namespace.

    You can also do from foo import B as Bar, which will make B available under the name Bar (in your current namespace).

    So generally: when you want only one object of a module, you do from module import object or from module import object as whatiwantittocall.

    When you want some modules functionality, you do import module, or import module as shortname to save you typing.

    from module import * is discouraged, as you may accidentally shadow ("override") names, and may lose track which objects belong to wich module.

  • 相关阅读:
    值得学习:低成本创业的成功案例
    观川剧变脸绝技有感
    庸人、常人、能人和人才,你是哪一种?
    游黄浦江有感
    首出四川有感
    一个容易被人遗忘的管理技巧
    妈妈,对不起
    ora00600[kkocxj:pjpCtx]内部错误一例
    How to troubleshooting RAC Vip Problem
    TSM配置导致RMAN备份expired
  • 原文地址:https://www.cnblogs.com/itfat/p/9114982.html
Copyright © 2011-2022 走看看