Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Loubot

  • one year ago

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

  • This Question is Closed
  1. Loubot
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://pastebin.com/0NMmmimz

  2. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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?

  3. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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 http://dpaste.com/1076817/ http://docs.python.org/2.7/reference/expressions.html#not-in http://effbot.org/pyref/in.htm http://effbot.org/pyref/is.htm

  4. Loubot
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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 :)

  5. Loubot
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  6. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    well e is the Exception object - i'll try to find an explanation for the 'as' something idiom/syntax http://dpaste.com/1077342/ or about half-way down (just before 8.4) of this page http://docs.python.org/2/tutorial/errors.html

  7. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://mail.python.org/pipermail/python-dev/2006-March/062449.html its kinda like a backwards assignment - the thing on the left is assigned to the thing on the right

  8. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.