I think I found a mistake in the official language referencedocumentation -- or I am missing somethi

I

Igor Soares

Reading the section "6.11. The import statement"
http://docs.python.org/py3k/reference/simple_stmts.html#the-import-statement

I found:
"""
Import statements are executed in two steps: (1) find a module, and
initialize it if necessary; (2) define a name or names in the local
namespace (of the scope where the import statement occurs).
(...)
The first form (without from) repeats these steps for each identifier
in the list. The form with from performs step (1) once, and then
performs step (2) repeatedly.
"""
In the last sentence, isn't it the opposite?
With the "from" form it would find/initialize all the modules and
define just the name after "from".
Or am I missing something?????
 
K

Ken Watford

Reading the section "6.11. The import statement"
http://docs.python.org/py3k/reference/simple_stmts.html#the-import-statement

I found:
"""
Import statements are executed in two steps: (1) find a module, and
initialize it if necessary; (2) define a name or names in the local
namespace (of the scope where the import statement occurs).
(...)
The first form (without from) repeats these steps for each identifier
in the list. The form with from performs step (1) once, and then
performs step (2) repeatedly.
"""
In the last sentence, isn't it the opposite?
With the "from" form it would find/initialize all the modules and
define just the name after "from".
Or am I missing something?????

Judging only by what you've quoted, the forms would be:

1) import os, sys, glob
2) from os.path import exists, split, join

In the first form, one or more modules come after the 'import'. In the
second form, a single module comes after the 'from', and then multiple
names from within that module come after the 'import'. Looks fine to
me.
 
I

Igor Soares

Judging only by what you've quoted, the forms would be:

1) import os, sys, glob
2) from os.path import exists, split, join

In the first form, one or more modules come after the 'import'. In the
second form, a single module comes after the 'from', and then multiple
names from within that module come after the 'import'. Looks fine to
me.

Ooops... yeah, i got somthing wrong
Well, I've got a strange example running in windows, IDLE, and python
2.7.1

running this:
"import pkg1.pkg2.mod1"
defined all theese names ("pkg1", "pkg2" and "mod1") in the local
scope

But now, at home, running python 2.6.6 with Debian (without IDLE) it
doesn't work
I'll try again tomorow (maybe its IDLE)

Thanks
 
M

MRAB

Reading the section "6.11. The import statement"
http://docs.python.org/py3k/reference/simple_stmts.html#the-import-statement

I found:
"""
Import statements are executed in two steps: (1) find a module, and
initialize it if necessary; (2) define a name or names in the local
namespace (of the scope where the import statement occurs).
(...)
The first form (without from) repeats these steps for each identifier
in the list. The form with from performs step (1) once, and then
performs step (2) repeatedly.
"""
In the last sentence, isn't it the opposite?
With the "from" form it would find/initialize all the modules and
define just the name after "from".
Or am I missing something?????

The "from" form is like:

from monty import spam, eggs

The steps are:

1. find module "monty", and initialize it if necessary

2. define name "spam" in the local namespace

3. define name "eggs" in the local namespace

Also note that the name "monty" itself never enters the local namespace.
 
I

Igor Soares

The "from" form is like:

     from monty import spam, eggs

The steps are:

1. find module "monty", and initialize it if necessary

2. define name "spam" in the local namespace

3. define name "eggs" in the local namespace

Also note that the name "monty" itself never enters the local namespace.

My mistake...
I got confused with wrong code in IDLE...
I also didn't understand that section ( 6.11 ) at first

Thank you guys for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top