473,721 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why have to "from compiler import *"

Hi, why does
>>import compiler
compileFile(" foo.py")
complain name 'compileFile' not defined. But
>>>from compiler import *
works. Why? (I did read the tutorial, it seems to say "import module"
should work.

Thank you, Mark

Sep 5 '06 #1
5 2185
On Mon, 2006-09-04 at 21:40 -0700, ma************* ********@yahoo. com
wrote:
Hi, why does
>import compiler
compileFile("f oo.py")

complain name 'compileFile' not defined. But
Because 'compileFile' is not defined. But I think you'll find that
compiler.compil eFile IS defined.

John Purser

>
>>from compiler import *

works. Why? (I did read the tutorial, it seems to say "import module"
should work.

Thank you, Mark
Sep 5 '06 #2
ma************* ********@yahoo. com wrote:
Hi, why does
>>>import compiler
compileFile( "foo.py")

complain name 'compileFile' not defined.
Probably because it's not ?

import <modulenameimpo rts the name <modulenamein the current
namespace. Then <modulenamele t you access all the names defined in
<modulenamename space. So in you're case, it should be:
>>>import compiler
compiler.com pileFile("foo.p y")
But
>>from compiler import *

works.
"from <modulenameimpo rt <somename>" directly loads <somenameinto the
current namespace. The 'import *' loads all public names from
<modulename>. And FWIW it's usually considered bad style (potential
name clash, and can makes hard to tell where a name is defined...)

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Sep 5 '06 #3
ma************* ********@yahoo. com wrote:
Hi, why does
>import compiler
compileFile("f oo.py")

complain name 'compileFile' not defined. But
>>from compiler import *

works. Why? (I did read the tutorial, it seems to say "import module"
should work.

Thank you, Mark
I did some ascii art to show what happenss to your namespace as you
import from a module in a few ways. (You'll need to view this in a
NON-proportional font).

You say you've read the docs at: http://docs.python.org/tut/node8.html
or http://docs.python.org/ref/import.html

Heres my 'art':

module1.py:
O-----------------O
|moduleFunc1 |
|moduleClass1 |
| class1Method1 |
| class1Method2 |
|moduleFunc2 |
|moduleVar1 |
|moduleVar2 |
O-----------------O

# Empty namespace:
\-----------------/
| |
| |
| |
| |
| |
| |
| |
/-----------------\
import module1
# namespace becomes:
\-------------------------/
|module1.module Func1 |
|module1.module Class1: |
| class1Method1 |
| class1Method2 |
|module1.module Func2 |
|module1.module Var1 |
|module1.module Var2 |
/------------------------\

from module1 import *
# namespace becomes:
\-----------------/
|moduleFunc1 |
|moduleClass1 |
| class1Method1 |
| class1Method2 |
|moduleFunc2 |
|moduleVar1 |
|moduleVar2 |
/-----------------\

from module1 import moduleFunc1, muduleVar2
# namespace becomes:
\-----------------/
|moduleFunc1 |
|moduleVar2 |
| |
/-----------------\

from module1 import moduleClass1 as C1
# namespace becomes
\-----------------/
|C1 | # C1 === module1.moduleC lass1
| |
/-----------------\

- Paddy.
P.S. I'm playing with http://www.jave.de
The Java Ascii Versatile Editor.

Sep 5 '06 #4
"Paddy" <pa*******@nets cape.netwrote:
>
import module1
# namespace becomes:
\-------------------------/
|module1.module Func1 |
|module1.module Class1: |
| class1Method1 |
| class1Method2 |
|module1.module Func2 |
|module1.module Var1 |
|module1.module Var2 |
/------------------------\
It would be more accurate to say:
# namespace becomes
\-----------------/
|module1 |
| |
/-----------------\
Sep 5 '06 #5
Duncan Booth wrote:
"Paddy" <pa*******@nets cape.netwrote:

import module1
# namespace becomes:
\-------------------------/
|module1.module Func1 |
|module1.module Class1: |
| class1Method1 |
| class1Method2 |
|module1.module Func2 |
|module1.module Var1 |
|module1.module Var2 |
/------------------------\

It would be more accurate to say:
# namespace becomes
\-----------------/
|module1 |
| |
/-----------------\
Possibly, although I purposely wanted to give a flavour of how things
might be accessed.

- Paddy

Sep 5 '06 #6

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

Similar topics

3
3908
by: gerald.maher | last post by:
Hi, I am trying to excuate the follwong code: I get the following error: Here is my Lib path:
0
2720
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
1
2597
by: Xiao Jianfeng | last post by:
Hello, In pymol I can use "from chempy import Atom" but "import chempy.Atom" doesn't work. It says,"ImportError: No module named Atom". What is going wrong ? Thanks
3
5427
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. They will only need to be run once per execution. Example (directory level): Sys1: A B C
2
1858
by: mithrond | last post by:
i can't use "from __future__ import ..." statement import two statesments in the same time. for the simple code: from __future__ import with_statement, division with file('url.txt','r') as f: for line in f: print line it can't run until i change the first sentence to below from __future__ import with_statement
1
2351
by: lemke_juergen | last post by:
Hi everyone, I define some vars and functions in a "support" module which gets called from my main app module. Using Python 2.5. I import all symbols in the support module at the top of the main module through: from support import *
1
2151
by: Malcolm Greene | last post by:
Is there any consensus on what "from __future__ import" options developers should be using in their Python 2.5.2 applications? Is there a consolidated list of "from __future__ import" options to choose from? Thank you, Malcolm
1
1995
by: Eric Hanchrow | last post by:
(This is with Python 2.5.2, on Ubuntu Hardy, if it matters.) This seems so basic that I'm surprised that I didn't find anything about it in the FAQ. (Yes, I am fairly new to Python.) Here are three tiny files: ==== mut.py ==== import system
3
1694
by: J. Cliff Dyer | last post by:
On Thu, 2008-05-08 at 12:00 -0700, Eric Hanchrow wrote: It's the same reason as this: 5 5 6 5 Python "variables" are just names that point at objects. When you
0
8852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8736
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9373
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9081
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5992
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3206
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2590
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.