from... import...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fatwallet961@yahoo.com

    #1

    from... import...

    what's the from ... import keyword use for?
    for example - from contenttype import getContentType

    import os
    import sys
    import getopt
    import types
    import re
    import pprint
    import logging
    from contenttype import getContentType

    In Java what kind of statement is similar this?

    thanks
  • Stargaming

    #2
    Re: from... import...

    fatwallet961@ya hoo.com schrieb:
    what's the from ... import keyword use for?
    for example - from contenttype import getContentType
    >
    import os
    import sys
    import getopt
    import types
    import re
    import pprint
    import logging
    from contenttype import getContentType
    >
    In Java what kind of statement is similar this?
    >
    thanks
    http://docs.python.org/ref/import.html ("The first form of" and
    following, sixth paragraph)

    HTH,
    Stargaming

    Comment

    • Paddy

      #3
      Re: from... import...

      On Feb 3, 4:12 am, fatwallet...@ya hoo.com wrote:
      what's the from ... import keyword use for?
      for example - from contenttype import getContentType
      >
      import os
      import sys
      import getopt
      import types
      import re
      import pprint
      import logging
      from contenttype import getContentType
      >
      In Java what kind of statement is similar this?
      >
      thanks
      Try:

      importing_modul es.html
      The official home of the Python Programming Language

      node8.html#SECT ION008100000000 000000000

      And more generally maybe:



      Happy coding - Paddy.



      Comment

      • Ben Finney

        #4
        Re: from... import...

        fatwallet961@ya hoo.com writes:
        what's the from ... import keyword use for?
        for example - from contenttype import getContentType
        >
        import os
        import sys
        import getopt
        import types
        import re
        import pprint
        import logging
        from contenttype import getContentType
        The program now can access attributes as follows:

        foo = sys.argv[1]
        bar = logging.getLogg er()
        baz = getContentType( )

        In other words, use 'from spam import eggs' when you want to refer to
        'eggs' instead of 'spam.eggs'. In the specific case you cite, probably
        the programmer knows they only want to access one attribute --
        'getContentType ' -- and would rather use that name for ease of reading
        rather than the longer 'contenttype.ge tContentType'.

        It's for this reason that many of the standard library modules have
        relatively short names, eight characters or less. It has the result
        that 'import spam' followed by access to 'spam.eggs' is both clear,
        and easy enough to read.

        To learn more, read about Python namespaces.

        --
        \ "I bought a dog the other day. I named him Stay. It's fun to |
        `\ call him. 'Come here, Stay! Come here, Stay!' He went insane. |
        _o__) Now he just ignores me and keeps typing." -- Steven Wright |
        Ben Finney

        Comment

        Working...