diffrent import statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveen0437
    New Member
    • Mar 2007
    • 8

    diffrent import statements

    there are different type of import what does they differ

    import cPickle as pickle

    from some_window import *

    import os is nothing but importing os module
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by praveen0437
    there are different type of import what does they differ
    import cPickle as pickle
    Call this "making an alias. you can shorten the actual name of the module to something else that you'd rather use.
    from some_module import *
    Import all names defined in the module into the namespace of the importing module. names that start with _ are not imported this way.
    import os
    This is the best import. You now call os module functions like this:
    Code:
    os.tempfile()

    Comment

    • praveen0437
      New Member
      • Mar 2007
      • 8

      #3
      Originally posted by bartonc
      Call this "making an alias. you can shorten the actual name of the module to something else that you'd rather use.

      Import all names defined in the module into the namespace of the importing module. names that start with _ are not imported this way.

      This is the best import. You now call os module functions like this:
      Code:
      os.tempfile()

      but cpickle and pickle both are predefined modules for serialization how can we alias cpickle for pickle

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by praveen0437
        but cpickle and pickle both are predefined modules for serialization how can we alias cpickle for pickle
        It's all about namespaces. when you
        Code:
        import cpickle as pickle
        you could still
        Code:
        import pickle as slowpickle
        because import is using the argument to search for a file name "pickle" which IS NOT the (newly imported namespace) pickle). Try it:

        >>> os = 1
        >>> import os
        >>> help(os)
        Help on module os:

        NAME
        os - OS routines for Mac, DOS, NT, or Posix depending on what system we're on.

        FILE
        d:\python24\lib \os.py

        The argument to import is converted to a string first.

        Comment

        Working...