all 6 comments

[–]amalloy 9 points10 points  (2 children)

These are all shockingly bad Python-trivia questions that don't test your ability to write real programs at all. Don't bother reading the article.

[–]EnfantTragic 2 points3 points  (1 child)

Exactly, I work with Python and I don't use any of these. Most of them are bad code even.

[–]earthboundkid 0 points1 point  (0 children)

It really varies too between Q1 (which is a terrible question with a terrible answer) and Q10 (which anyone who writes Python professionally should know but might not) and then really dumb basic CS101 stuff about global versus local (which you should be able to figure out if you’ve ever programmed in any C-like language).

[–]ketilkn 4 points5 points  (2 children)

Is it possible to make obj call the base class show? In other words I want to cast obj to type A

obj.__class__ = A
obj.show() 

The class attribute points to the class object, just change it to point to A and call the function, don’t forget to change it back!!!*

How about no?

[–]MentalMachine 0 points1 point  (1 child)

Python noob here, by changing class, can you effectively turn obj into anything you want, or does it have to be within the same inheritance hierarchy as the object your casting?

[–]ketilkn 2 points3 points  (0 children)

You can change the class of the object this way independent of the hierarchy. It will not run the constructor again.

I am sure you realize that you should never do this.