N
N
Nikita2014-07-24 09:05:54
Python
Nikita, 2014-07-24 09:05:54

How to properly import a module in python?

just started learning python and according to Lutz's book I'm trying to import
the threenames.py module

a = 'parrot'
b = 'carrot'
c = 'same thing'
print (a,b,c)

I launch cmd, go to the folder with the threenames.py file, enter python into cmd, 3 standard lines appear and the command prompt ">>>" appears.
then I enter import threename.py on which an error appears:
>>> import threenames.py
parrot carrot same thing
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'threenames.py'; 'threenames' is not a package
>>>

tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Heafy, 2014-07-24
@Freeddi

>>> import threenames
try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question