Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Will McGugan: What's the quickest way to get the result of your Python app or script online?

$
0
0

There a few options, but I'm going to suggest using the inthing Python module.

First install inthing with PIP. You'll probably know if you need to use sudo or not:

pip install inthing

Now fire up Python, and enter the following (copy and paste each line after the >>> prompt):

>>> from inthing import Stream
>>> stream = Stream.new()

So far so good. We now have a Stream object called stream, with a corresponding live page on the web. We'll have a look at that later, but lets first do something interesting with it. Enter the following function (copy and paste all the text after the >>>):

>>> def mandel(xsize=80, ysize=20, max_iteration=50):
    chars = " .,~:;+*%@##"
    rows = []
    for pixy in xrange(ysize):
        y0 = (float(pixy) / ysize) * 2 - 1
        row = ""
        for pixx in xrange(xsize):
            x0 = (float(pixx) / xsize) * 3 - 2
            x = 0
            y = 0
            iteration = 0
            while (x * x + y * y < 4) and iteration < max_iteration:
                xtemp = x * x - y * y + x0
                y = 2 * x * y + y0
                x = xtemp
                iteration += 1
            row += chars[iteration % 10]
        rows.append(row)
    return "```\n{}\n```\n#mandlebrot".format('\n'.join(rows))

If that pasted correctly, we should have a function that generates the Mandlebrot set in ASCII. Add it to the stream with the following:

>>> stream.text(mandel(), title="Mandlebrot Set!")

Finally, to get the URL of the stream, do this:

>>> print(stream.url)

If you visit that URL, you should see the Mandlebrot set you just generated.

Update: You can see mandlebrot sets as they are posted on the #mandlebrot tag page.

What else can it do?

So inthing.io is still in beta and is actively being worked on, but can already do some interesting things. For instance, you can take screenshots with this:

>>> stream.screenshot(title="This is my work")

More to come...


Viewing all articles
Browse latest Browse all 22462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>