• omz

    @Phuket2 I tested with Python 3. I think Python 2 is still faster in most benchmarks.

    posted in Pythonista read more
  • omz

    1. Why doesn't the color work on my plot class?

    You're not setting color as an instance attribute, but the color class attribute you're creating "shadows" the normal property. You should set color and anchor_point in an __init__ method, as you've done (in part) with the pt class.

    It should look roughly like this:

    class plot (SpriteNode):
        def __init__(self, **kargs):
            SpriteNode.__init__(self, **kargs)
            self.anchor_point = (0, 0)
            self.color = '#8989ff'
    1. Why isn't the plot 50 px from the lower left corner?

    Basically the same answer as for the previous question, the anchor_point had no effect in your code.

    1. Why are the x gifs not half size?

    First of all, the attributes you're looking for are called x_scale and y_scale, not scale_x and scale_y. Furthermore, if you set both to the same value anyway, you can just use scale.

    1. Why doesn't the plot Sprite clip its children?

    Because that's just the way sprite nodes behave. Almost no kind of node clips its children. You could use an EffectNode with the crop_rect property set for this purpose though, if you really need clipping behavior.

    posted in Pythonista read more
  • omz

    iPad Pro 10.5" (Pythonista 3): 146,820 pystones/second

    MacBook Pro 13", 2.9 Ghz i5 (Python 3.5): 70,019 pystones/second

    posted in Pythonista read more
  • omz

    You need to return the array as a pointer:

    return ns([action]).ptr

    posted in Pythonista read more
  • omz

    This generates some interesting, pseudo-random text from Tolstoi's Anna Karenina:

    # Adapted from this blog post: http://agiliq.com/blog/2009/06/generating-pseudo-random-text-with-markov-chains-u/
    import random
    import os
    import urllib.request
    class Markov(object):
        def __init__(self, open_file):
            self.cache = {}
            self.open_file = open_file
            self.words = self.file_to_words()
            self.word_size = len(self.words)
        def file_to_words(self):
            data = self.open_file.read()
            words = data.split()
            return words
        def triples(self):
            """ Generates triples from the given data string. So if our string were
                    "What a lovely day", we'd generate (What, a, lovely) and then
                    (a, lovely, day).
            if len(self.words) < 3:
            for i in range(len(self.words) - 2):
                yield (self.words[i], self.words[i+1], self.words[i+2])
        def database(self):
            for w1, w2, w3 in self.triples():
                key = (w1, w2)
                if key in self.cache:
                    self.cache[key] = [w3]
        def generate_markov_text(self, size=25):
            while True:
                seed = random.randint(0, self.word_size-3)
                seed_word = self.words[seed]
                if seed_word[0].isupper():
            seed_word, next_word = self.words[seed], self.words[seed+1]
            w1, w2 = seed_word, next_word
            gen_words = []
            while not w2.endswith('.'):
                w1, w2 = w2, random.choice(self.cache[(w1, w2)])
            return ' '.join(gen_words)
    def main():
        if not os.path.exists('anna_karenina.txt'):
            print('Downloading book...')
            urllib.request.urlretrieve('http://www.gutenberg.org/files/1399/1399-0.txt', 'anna_karenina.txt')
        with open('anna_karenina.txt', 'r', encoding='utf-') as f:
            markov = Markov(f)
    if __name__ == '__main__':

    posted in Pythonista read more
  • omz

    I have sample code for Markov chain text somewhere, just need to clean it up a bit.

    posted in Pythonista read more
  • omz

    You could also just set some flag in a global module when your view is on-screen, and clear it when the view is dismissed. Does this make sense?

    posted in Pythonista read more
  • omz

    Being able to make instances callable is such a powerful feature in Python! The whole ObjC bridging in objc_util wouldn't be possible without it, but I digress...

    posted in Pythonista read more
  • omz

    @cvp I'm not sure what you mean by that.

    posted in Pythonista read more
  • omz

    @enceladus I don't really consider this a bug. Your program shows intent by having or not having a draw or update method.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!