Comments (3)
Hi @mandaris.
While there is a sharp increase in difficulty during "about_none" it needs to be early in the koans as it covers fundamentals. I've always meant to put together a screencast and/or wiki page for this one, but just never got around to it.
I'm guessing the koan that is giving you problems is the 3rd one:
test_what_exception_do_you_get_when_calling_nonexistent_methods
To make more sense of it I recommend opening a python console (IDLE) and trying out some ideas there. The part that is confusing here is understanding what ex._class.__name do.
ex is an exception so it's not quite so easy to grab it and start playing with. Try playing with a piece of text (like
"hello") instead.
First off we need to know what class does. All python objects what are a type of class have a class attribute.
"hello".class gives us this:
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> "Hello".__class__
<type 'str'>
So class apparently gives is information about the datatype (class) of the code on the left of the period.
However it returns <type 'str'> which isn't very convienent for use in an assertEquals statement:
>>> "Hello" == <type 'str'>
File "<stdin>", line 1
assert "Hello" == <type 'str'>
^
SyntaxError: invalid syntax
This doesn't work because <type 'str'> is just a textual representation of "str"
>>> "Hello".__class__ == str
True
So to make it more obvious we can call .name on the str to turn it into plain text:
>>> "Hello".__class__.__name__
'str'
So if there was an assert it would look like this:
self.assertEquals('str', "Hello".class.name)
Notice I have single quotes around 'str'? Thats vital.
So how does this apply to the koan?
Well currently the error you should be seeing when running the Koans is this:
You have not yet reached enlightenment ...
AssertionError: '-=> FILL ME IN! <=-' != 'AttributeError'
The right hand side of the assert that evaluates ex.class.name is giving the string 'AttributeError'. Thats the class name of the Exception, turned into text. You just need to replace the "__" part of the assert with the same.
Hope that helps.
Additional hints:
A great number of students actually commit their answers to github. If you click on the Network button on the github page you can look through the graph, find a fork that has answers and see how another student is tacking the problem. For example:
https://github.com/Matt-Stevens/python_koans/blob/matts/python2/koans/about_none.py
In these circumstances its perfectly ok to be cheating as long as you're learning from the answers and not just blindly copying... :)
There is even an "answers" branch in the original python_koans. Only thing is it's a little out of date.
from python_koans.
Thank you, Greg!
That was exactly the one that I was having problems with. I started to panic and replaced the ex.class.name with ex.class.name and other things.
Bah!
After I see the answer, it becomes so obvious.
Of course…. it is afterwards…
Onward!
Valediction,
Mandaris Moore III
On Apr 29, 2013, at 4:51 AM, Greg Malcolm [email protected] wrote:
Hi @mandaris.
While there is a sharp increase in difficulty during "about_none" it needs to be early in the koans as it covers fundamentals. I've always meant to put together a screencast and/or wiki page for this one, but just never got around to it.
I'm guessing the koan that is giving you problems is the 3rd one:
test_what_exception_do_you_get_when_calling_nonexistent_methods
To make more sense of it I recommend opening a python console (IDLE) and trying out some ideas there. The part that is confusing here is understanding what ex._class.__name do.
ex is an exception so it's not quite so easy to grab it and start playing with. Try playing with a piece of text (like
"hello") instead.First off we need to know what class does. All python objects what are a type of class have a class attribute.
"hello".class gives us this:
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information."Hello".class
<type 'str'>
So class apparently gives is information about the datatype (class) of the code on the left of the period.However it returns which isn't very convienent for use in an assertEquals statement:
"Hello" == <type 'str'>
File "", line 1
assert "Hello" == <type 'str'>
^
SyntaxError: invalid syntax
This doesn't work because is just a textual representation of "str""Hello".class == str
True
So to make it more obvious we can call .name on the str to turn it into plain text:"Hello".class.name
'str'
So if there was an assert it would look like this:
self.assertEquals('str', "Hello".class.name)Notice I have single quotes around 'str'? Thats vital.
So how does this apply to the koan?
Well currently the error you should be seeing when running the Koans is this:You have not yet reached enlightenment ...
AssertionError: '-=> FILL ME IN! <=-' != 'AttributeError'
The right hand side of the assert that evaluates ex.class.name is giving the string 'AttributeError'. Thats the class name of the Exception, turned into text. You just need to replace the "__" part of the assert with the same.Hope that helps.
Additional hints:
A great number of students actually commit their answers to github. If you click on the Network button on the github page you can look through the graph, find a fork that has answers and see how another student is tacking the problem. For example:
https://github.com/Matt-Stevens/python_koans/blob/matts/python2/koans/about_none.pyIn these circumstances its perfectly ok to be cheating as long as you're learning from the answers and not just blindly copying... :)
There is even an "answers" branch in the original python_koans. Only thing is it's a little out of date.
—
Reply to this email directly or view it on GitHub.
from python_koans.
NP!
from python_koans.
Related Issues (20)
- Travis failing on older Pythons HOT 4
- Improvement at tuples test. HOT 2
- about scope HOT 2
- Malika M. H/W HOT 1
- Removing python2 HOT 1
- Suzann Adams python_koans hw HOT 2
- Suzann Adams Python Koans HOT 2
- f-strings in AboutStringManipulation HOT 1
- [feature]: Hope only shows passed test functions in this run HOT 1
- About String Manipulation -> test_raw_strings_do_not_interpret_escape_characters HOT 1
- test_dictionary_is_unordered in about_dictionaries.py doesn't test what it says it tests HOT 3
- This is a great program HOT 1
- SyntaxWarning: "is not" with a literal. Did you mean "!="? HOT 5
- AboutClassAttributes: Order of definition matters
- AboutAttributeAccess: super would resolve to object
- AboutRegex: Unclear Instruction HOT 3
- Thinking _FailedTest not found
- 你用的真是TDD吗?
- AboutStrings: Unclear testing purpose HOT 3
- How to skip lessons
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python_koans.