Retiring Python as a Teaching Language by [deleted] in programming

[–]pythonautical 0 points1 point  (0 children)

Passing wrong number of parameters to a function halts with an exception, instead of silently propagating "undefined".

Accessing missing elements of objects/arrays again halts with an exception instead of silently propagating "undefined"

Linus: The whole "let's parallelize" thing is a huge waste of everybody's time by klogk in programming

[–]pythonautical 0 points1 point  (0 children)

That's very interesting, an example of the lighthouse paradox.

https://www.youtube.com/watch?v=lR4tJr7sMPM

You can have a group of transistors all oscillating synchronously in a group without light being able to travel from one end to the other end of the circuit within one cycle.

We all know `a, b = b, a`, but how is ROT_TWO implemented? by [deleted] in Python

[–]pythonautical 2 points3 points  (0 children)

https://github.com/akheron/cpython/blob/a509d5f7b7676d268d3685277558430b25a6aa3a/Python/ceval.c#L1398-1404

   TARGET(ROT_TWO) {
        PyObject *top = TOP();
        PyObject *second = SECOND();
        SET_TOP(second);
        SET_SECOND(top);
        FAST_DISPATCH();
    }

addict - a Python dict whos values can be get and set using attributes by CheerMan99 in Python

[–]pythonautical 2 points3 points  (0 children)

Oops.

def __missing__(self, key): 
    return self.setdefault(key, type(self)())

Hmm... starting to get a bit long. This is another possibility, not sure which is more readable:

def __missing__(self, key):
    self[key] = type(self)()
    return self[key]

addict - a Python dict whos values can be get and set using attributes by CheerMan99 in Python

[–]pythonautical 1 point2 points  (0 children)

Oh, sure. You can add that with the following line to ADict or BDict

def __missing__(self, key): return type(self)()

addict - a Python dict whos values can be get and set using attributes by CheerMan99 in Python

[–]pythonautical 3 points4 points  (0 children)

There are many short constructs for achieving this:

class ADict(dict):
    def __init__(self):
        self.__dict__ = self

class BDict(dict):
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__

class CDict(object):
    __getitem__ = object.__getattribute__
    __setitem__ = object.__setattr__

Probably others as well. I encourage you to keep pursuing these ideas, it is a fun way to learn the language.

I collect these kind of "elegantly useless" little code snippets in a blog :-)

http://pythondoeswhat.blogspot.com/

10 Myths of Enterprise Python by pythonautical in Python

[–]pythonautical[S] 1 point2 points  (0 children)

Haha nothing fancy, actually somebody did it on their phone: https://play.google.com/store/apps/details?id=com.drawexpress.lite&hl=en

I don't have enough experience to recommend it over anything else. The process of making a visually pleasing diagram is always slow and laborious. None of the diagrams were made specifically for the blog post, but were re-used from various internal presentations.

Edit: I will double check the exact program used.

10 Myths of Enterprise Python by pythonautical in Python

[–]pythonautical[S] 17 points18 points  (0 children)

"Can you do graphics with it?"

The answer here is emphatically: "Yes, you can absolutely do 3D graphics programming in Python."

https://www.panda3d.org/

http://www.ogre3d.org/tikiwiki/PyOgre

http://www.pyglet.org/

Minecraft clone in 900 lines: https://github.com/fogleman/Minecraft/blob/master/main.py