ActivityPub Viewer

A small tool to view real-world ActivityPub objects as JSON! Enter a URL or username from Mastodon or a similar service below, and we'll send a request with the right Accept header to the server to view the underlying object.

Open in browser →
{ "@context": [ "https://join-lemmy.org/context.json", "https://www.w3.org/ns/activitystreams" ], "type": "Page", "id": "https://lemmy.world/post/22282165", "attributedTo": "https://lemmy.world/u/raldone01", "to": [ "https://lemmy.ml/c/programmerhumor", "https://www.w3.org/ns/activitystreams#Public" ], "name": "Using comments as arguments in python.", "cc": [], "content": "<p>Python allows programmers to pass additional arguments to functions via comments.\nNow armed with this knowledge head out and spread it to all code bases.</p>\n<p>Feel free to use the code I wrote in your projects.</p>\n<p>Link to the source code: <a href=\"https://github.com/raldone01/python_lessons_py/blob/v2.0.0/lesson_0_comments.ipynb\">github.com/raldone01/…/lesson_0_comments.ipynb</a></p>\n<h3>Image transcription:</h3>\n<pre style=\"background-color:#ffffff;\">\n<span style=\"font-style:italic;color:#969896;\"># First we have to import comment_arguments from arglib\n</span><span style=\"font-style:italic;color:#969896;\"># Sadly arglib is not yet a standard library.\n</span><span style=\"font-weight:bold;color:#a71d5d;\">from </span><span style=\"color:#323232;\">arglib </span><span style=\"font-weight:bold;color:#a71d5d;\">import </span><span style=\"color:#323232;\">comment_arguments\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">\n</span><span style=\"font-weight:bold;color:#a71d5d;\">def </span><span style=\"font-weight:bold;color:#323232;\">add</span><span style=\"color:#323232;\">(</span><span style=\"font-weight:bold;color:#a71d5d;\">*</span><span style=\"color:#323232;\">args, </span><span style=\"font-weight:bold;color:#a71d5d;\">**</span><span style=\"color:#323232;\">kwargs):\n</span><span style=\"color:#323232;\"> c_args, c_kwargs </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#323232;\">comment_arguments()\n</span><span style=\"color:#323232;\"> </span><span style=\"font-weight:bold;color:#a71d5d;\">return </span><span style=\"color:#62a35c;\">sum</span><span style=\"color:#323232;\">([</span><span style=\"color:#0086b3;\">int</span><span style=\"color:#323232;\">(i) </span><span style=\"font-weight:bold;color:#a71d5d;\">for </span><span style=\"color:#323232;\">i </span><span style=\"font-weight:bold;color:#a71d5d;\">in </span><span style=\"color:#323232;\">args </span><span style=\"font-weight:bold;color:#a71d5d;\">+ </span><span style=\"color:#323232;\">c_args])\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">\n</span><span style=\"font-style:italic;color:#969896;\"># Go ahead and change the comments.\n</span><span style=\"font-style:italic;color:#969896;\"># See how they are used as arguments.\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">result </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#323232;\">add() </span><span style=\"font-style:italic;color:#969896;\"># 1, 2\n</span><span style=\"color:#62a35c;\">print</span><span style=\"color:#323232;\">(result)\n</span><span style=\"font-style:italic;color:#969896;\"># comment arguments can be combined with normal function arguments\n</span><span style=\"color:#323232;\">result </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#323232;\">add(</span><span style=\"color:#0086b3;\">1</span><span style=\"color:#323232;\">, </span><span style=\"color:#0086b3;\">2</span><span style=\"color:#323232;\">) </span><span style=\"font-style:italic;color:#969896;\"># 3, 4\n</span><span style=\"color:#62a35c;\">print</span><span style=\"color:#323232;\">(result)\n</span></pre>\n<hr />\n<h4>Output:</h4>\n<pre style=\"background-color:#ffffff;\">\n<span style=\"color:#323232;\">3\n</span><span style=\"color:#323232;\">10\n</span></pre>\n<p>This is version <code>v2.0.0</code> of the post: <a href=\"https://github.com/raldone01/python_lessons_py/tree/v2.0.0\">github.com/raldone01/python_lessons_py/…/v2.0.0</a></p>\n<p>Note:</p>\n<p><code>v1.0.0</code> of the post can be found here: <a href=\"https://github.com/raldone01/python_lessons_py/tree/v1.0.0\">github.com/raldone01/python_lessons_py/…/v1.0.0</a></p>\n<p>Choosing <code>lib</code> as the name for my module was a bit devious.\nI did it because I thought if I am creating something cursed why not go all the way?</p>\n<p>Regarding misinformation:</p>\n<p>I thought simply posting this in programmer humor was enough.\nAnyways, the techniques shown here are not yet regarded best practice.\nDecide carefully if you want to apply the shown concepts in your own code bases.</p>\n", "mediaType": "text/html", "source": { "content": "Python allows programmers to pass additional arguments to functions via comments.\nNow armed with this knowledge head out and spread it to all code bases.\n\nFeel free to use the code I wrote in your projects.\n\nLink to the source code: https://github.com/raldone01/python_lessons_py/blob/v2.0.0/lesson_0_comments.ipynb\n\n### Image transcription:\n```python\n# First we have to import comment_arguments from arglib\n# Sadly arglib is not yet a standard library.\nfrom arglib import comment_arguments\n\n\ndef add(*args, **kwargs):\n c_args, c_kwargs = comment_arguments()\n return sum([int(i) for i in args + c_args])\n\n\n# Go ahead and change the comments.\n# See how they are used as arguments.\n\nresult = add() # 1, 2\nprint(result)\n# comment arguments can be combined with normal function arguments\nresult = add(1, 2) # 3, 4\nprint(result)\n```\n\n---\n\n#### Output:\n```\n3\n10\n```\n\nThis is version `v2.0.0` of the post: https://github.com/raldone01/python_lessons_py/tree/v2.0.0\n\nNote:\n\n`v1.0.0` of the post can be found here: https://github.com/raldone01/python_lessons_py/tree/v1.0.0\n\nChoosing `lib` as the name for my module was a bit devious.\nI did it because I thought if I am creating something cursed why not go all the way?\n\nRegarding misinformation:\n\nI thought simply posting this in programmer humor was enough.\nAnyways, the techniques shown here are not yet regarded best practice.\nDecide carefully if you want to apply the shown concepts in your own code bases.", "mediaType": "text/markdown" }, "attachment": [ { "href": "https://lemmy.world/pictrs/image/a21be7f6-46cc-4f8c-bfc1-e3ecaf826c51.png", "type": "Link" } ], "image": { "type": "Image", "url": "https://lemmy.world/pictrs/image/7738b919-cbff-429a-9a4d-62a0bb9be98b.png" }, "commentsEnabled": true, "sensitive": false, "published": "2024-11-21T15:09:26.108175Z", "updated": "2024-11-25T17:21:09.186097Z", "language": { "identifier": "en", "name": "English" }, "audience": "https://lemmy.ml/c/programmerhumor" }