Ex 48 - basic questions

Hi all,

I’m new to Python coding and working through LPTHW and am struggling with Ex 48. Any help would be appreciated. I’ll try to describe my problems below:

I think I have set up my project directory correctly as per the previous exercises. It appears like this:

ex48/
bin
docs
ex48/
init.py
lexicon.py
tests/
init.py
lexicon_tests.py
setup.py

The setup.py file mirrors Zed’s, the lexicon_test.py mirrors the first 6 lines from Zed’s pre-written code in the exercise, and my lexicon.py file contains

I’m watching the video ( LPy3THW Ex48) and at 9:48 Zed types nosetests .\lexicon_tests.py but when I try this an error (ERROR: Failure: ImportError (No module named ’ ')) occurs.

I’m sure it something very obvious but I can’t work out what I’m doing wrong. Any ideas?

Hello @KSBM and welcome to the forum.

It´s good that you showed your skeleton for this project.
I want to suggest that you wrap it ( and all code ) between square brackets with the word “code” at top and “/code” below. You type like this:

[code]
ex48/
bin
docs
ex48/
__init__ .py
lexicon.py
tests/
__init__.py
lexicon_tests.py
setup.py
[/code]

And it will look like this. Then one can copy and paste into an editor and try your code to see why there is a problem.

ex48/
bin
docs
ex48/
__init__ .py
lexicon.py
tests/
__init__.py
lexicon_tests.py
setup.py

When I see your skeleton it looks like setup.py is in the test folder.
Is that so? I guess that can be a reason for your error.

It is also good to tell which OS you have. (Windows, Mac, Linux)
The version of Python is sometimes good to know.

I also want to suggest Pytest for testing the code. It is much easier to use.

Thanks Ulfen69 and apologies for not bracketing the code!

To answer your questions: no, the setup.py is in the main project folder (i.e. not in any subfolder).

I am running Mac OS 10.15.5 with Python3.6.

I seemed to get it to work but simply by typing nose tests whilst in the project folder without including [.\lexicon_tests.py].

I will certainly take your advice and try Pytest once I’ve finished LPTHW.

Thank you.

A free service run by Zed A. Shaw for learncodethehardway.org.