# Import behaviour

**URL:** <https://discuss.python.org/t/import-behaviour/7088>\
**Category:** Python Help\
**Tags:** help\
**Created:** [February 8, 2021, 4:32pm UTC](https://discuss.python.org/t/import-behaviour/7088 "2021-02-08T16:32:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickster555](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rickster555/32/3454_2.png) [@rickster555](https://discuss.python.org/u/rickster555)\
**Post date:** [February 8, 2021, 4:32pm UTC](https://discuss.python.org/t/import-behaviour/7088/1 "2021-02-08T16:32:14Z")

</div>

I’m trying to port a game from the 1980’s (GW\_Basic).  
in IDLE, after ‘import startrader\_defines\_base’, nothing is defined: variables, classes, etc.  
eg., \>\>\> **starfile**  
Traceback (most recent call last):  
File “\<pyshell#19\>”, line 1, in   
**starfile** is not defined

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![bheesham](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bheesham/32/2114_2.png) [@bheesham](https://discuss.python.org/u/bheesham)\
**Post date:** [February 8, 2021, 4:54pm UTC](https://discuss.python.org/t/import-behaviour/7088/2 "2021-02-08T16:54:51Z")

</div>

Hey Rick,

`starfile` isn’t in the current scope, but `startrader_defines_base` is. Maybe you meant to try:

```python
import startrader_defines_base
startrader_defines_base.starfile

# Or, to import just starfile from the module:
from startrader_defines_base import starfile
starfile

# Or, maybe the following to import everything within the module:
from startrader_defines_base import *
starfile

```

You can inspect what’s in a module by running:

```auto
import startrader_defines_base
dir(startrader_defines_base)

```

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 8, 2021, 9:21pm UTC](https://discuss.python.org/t/import-behaviour/7088/3 "2021-02-08T21:21:00Z")

</div>

Firstly, names starting and ending with two underscores, like  
` __starfile__ `, are reserved for Python’s own use. You should name your  
variables differently.

Secondly, after importing a module, to access the module’s contents, you  
need to access the module first:

```
>>> import math
>>> pi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pi' is not defined
>>> math.pi
3.141592653589793

```

You can import a module with a shorter name:

```
import startrader_defines_base as base

```

or you can import the contents directly:

```
from startrader_defines_base import starfile, spam, eggs, aardvark

```

With care, you can even tell Python to import “everything”, although  
this is not good practice and you should generally be very careful about  
doing this:

```
from startrader_defines_base import *
```

---

<div class="post-metadata">

**Author:** ![rickster555](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rickster555/32/3454_2.png) [@rickster555](https://discuss.python.org/u/rickster555)\
**Post date:** [February 9, 2021, 11:41am UTC](https://discuss.python.org/t/import-behaviour/7088/4 "2021-02-09T11:41:45Z")

</div>

Thanks for the reminder about dunders, and the ‘module.property’ format.
