Hi again folks. Stuck again. Doing problem set 11 from the 2011 course. I've gotten stuck on something that I can't get past. I've checked everything I can think of and have printed out the contents of self.nodes and src and dest. They print out as the same thing but if src in self.nodes and if dest in self.nodes is returning false. Any help please
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
Are you saying that when you call load_map() that you are getting an Exception at lines 56 and 57 when it tries to add an edge?
1st - at line 97 you assign a Digraph class instance to map
map() is a Python builtin function - this is a very bad
practice. you should use a different name
Your sypmtom has to do with the way you are comparing things.
Each time you create a class instance you create a new object.
Even though a class defines an __eq__() method that would return
True with instance1 == instance2; instance1 and instance2 are not
the same object - you can see this with the id() function.
The in and is operators test for identity.
The shell is a great place to play around to see how things work
Not the answer you are looking for? Search for more explanations.
Ah. I feel like swearing. Thanks for your response. Just spotted I wasn't using the nodes I was creating to instantiate the edges. That's what I get for trying to do it at 5 in the morning I guess. Pretty basic error :)
On a side note. Dear bwCA, I must confess I spotted your solution to this problem in a question we both responded to a while back. I noticed you have an exception handler
except ValueError as e. What does the 'as e' part of this do? I googled it but couldn't find the answer. Thanks again
well e is the Exception object - i'll try to find an explanation for the 'as' something idiom/syntax
or about half-way down (just before 8.4) of this page
its kinda like a backwards assignment - the thing on the left is assigned to the thing on the right