In "Learning python the hard way" the author states we can import a script without having to use python ex25.py
. We can do import ex25
and the script will run.
When I do this, I get:
>>> import ex25
Traceback (most recent call last):
File "<stdin>", line 1, in <modul
ImportError: No module named ex25
The author states it will look like this
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ex25
>>> sentence = "All good things come to those who wait."
>>> words = ex25.break_words(sentence)
>>> words
['All', 'good', 'things', 'come', 'to', 'those', 'who', 'wait.']
>>> sorted_words = ex25.sort_words(words)
>>> sorted_words
['All', 'come', 'good', 'things', 'those', 'to', 'wait.', 'who']
>>> ex25.print_first_word(words)
All
>>> ex25.print_last_word(words)
wait.
>>> wrods
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'wrods' is not defined
>>> words
['good', 'things', 'come', 'to', 'those', 'who']
>>> ex25.print_first_word(sorted_words)
All
>>> ex25.print_last_word(sorted_words)
who
>>> sorted_words
It seems that Python is not able to find ex25
. Perhaps I need to place it in the Python 27 directory? However, how then, do I keep a clean directory if I need to place all my .py
files there?
When I don't get the first challenge (can't find file), I get:
>>> import ex25
>>>
Seems like nothing is happening.