473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Feb 3 '07 #1
3 1673
fa**********@yahoo.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
Feb 3 '07 #2
On Feb 3, 4:12 am, fatwallet...@yahoo.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:
http://diveintopython.org/object_oriented_framework/
importing_modules.html
http://www.python.org/doc/current/tut/
node8.html#SECTION008100000000000000000

And more generally maybe:
http://www.ferg.org/projects/python_...e-by-side.html
http://dirtsimple.org/2004/12/python-is-not-java.html

Happy coding - Paddy.

Feb 3 '07 #3
fa**********@yahoo.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.getLogger()
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.getContentType'.

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

Feb 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve Holden | last post by:
I'm trying to load module code from a database, which stores for each module its full name, code, load date and a Boolean indicating whether it's a package or not. The following simple program:...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
8
by: Philippe C. Martin | last post by:
Hi, I'm getting pretty desperate here: The code below crashes on the last line (but works from a shell). The class 'BC' exists and the loop on self.__BC_EXEC_LIST passes fine. It's got to...
3
by: Mudcat | last post by:
I have a directory structure that contains different modules that run depending on what the user selects. They are identical in name and structure, but what varies is the content of the functions....
7
by: per9000 | last post by:
Dear Black Knight, I have no quarrel with you sir Knight, but I must import your parents. SHORT VERSION: I tried three variants of "from ../brave.py import sir_robin", one works. I want...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
6
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am...
5
by: W. Watson | last post by:
Is there a single source that explains these statements? ------------------------------ from Tkinter import * from Numeric import * import Image import ImageChops import ImageTk import time...
10
by: nisp | last post by:
Hi all ! I'm trying to capture stderr of an external module I use in my python program. I'm doing this by setting up a class in my module overwriting the stderr file object method write. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.