473,545 Members | 4,914 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 2161
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
3882
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
2693
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...
1
2589
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
5406
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
1845
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
2344
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
2138
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
1972
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
1668
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
7396
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...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
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...
0
5968
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...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
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...
1
1874
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
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.