[Tutor] Python Error Message

Alan Gauld alan.gauld at btinternet.com
Wed Jan 27 17:56:19 EST 2021


On 27/01/2021 17:39, Nirel Leitman wrote:
> I renamed the folder degrees and inside this folder contains 2
> folders: small and large that consist of data. 

Good so far.

> When I go to properties on the degrees.py it shows
> this: C:\Users\leitm\Desktop\AI\degrees and
> not C:\Users\leitm\Desktop\AI\degrees\degrees.py

How are you going to the properties of degrees.py?

Is it in your IDE/Editor or are you using the OS/File manager?

I think the safest way to make this work is to open your python file in
the editor then choose Save As...  and save it in the degrees folder
as degrees.py.

Then exit the editor completely and try running the newly saved file.


> I have also adjusted the degrees.py code as I noticed it was incorrect
> and not finished.

To be honest not being finished doesn't matter. most professional
programmers
don't even try to create a finished program in one go. They start
with one function and get it working(*). In your case they would probably
just have the load_data function. and a few print statements to prove
it worked. Only after the data is loading properly would you proceed to
build the next function (shortest_path say, or maybe person_id. It doesn't
matter too much which so long as you can think of a way of calling it
with different test conditions(including errors!)) .

That way you always know where the new bugs lie - because you
know the folder code works, so it must be the new stuff! If you try to
write the whole program before testing it you have no idea where
the bugs are hiding.

(*)In fact many modern programmers don;t even wait till they have
written a function to start testing. They will deliberately try to run
unwritten
code to ensure it fails in the way they expect. Then fix the bugs by
writing
the code - often just a few lines at a time. However, that's quite
intensive
and requires a lot of experience of how to test. For now a few print
statements
is probably close enough!

Incidentally, your code just screams out "Use OOP"!" You have at least
two obvious class candidates (Person, Movie) and instantiating objects of
those classes and building collections of them would simplify your top
level code
significantly. However, if you are not yet familiar with classes and
objects don't worry, your approach will still work, it just takes a little
bit more code.

-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list