• dgelessus

    You can use the following commands in the Pythonista 3 Python console to copy the folder back:

    >>> import os, shutil
    >>> shutil.copytree(os.path.expanduser("~/Documents/foldername"), os.path.expanduser("~/../Documents/foldername"))
    

    where foldername is the name of the folder you want to copy (assuming that it's in the root of Pythonista 3's local files). You can also use shutil.move instead of shutil.copytree if you want to move the folder rather than copy it (which may be a good idea if it's very big).

    By the way, is there any reason in particular why you're still using Pythonista 2? Pythonista 3 supports both Python 2 and 3, so there's generally no need for Pythonista 2 if you have Pythonista 3. In fact Pythonista 2 can no longer be bought on the App Store and won't receive any more updates.

    posted in Pythonista read more
  • dgelessus

    The twitter module no longer works on recent iOS versions, because iOS no longer has any special native support for Twitter. Quoting the in-app docs for the twitter module:

    Warning: Unfortunately, this module no longer works on iOS 11 and later because the underlying APIs have been removed from iOS.

    posted in Pythonista read more
  • dgelessus

    I don't think sys.displayhook would be very helpful here - it only affects how the final evaluated object is displayed, it does not change anything about how the typed-in Python code is executed. In particular, print would not be affected by sys.displayhook, because print always returns None.

    If you want to affect print output specifically, you can define your own function called print that does what you want, or you can replace sys.stdout with a custom file-like object.

    If you want to affect the code execution even more than that, you're probably better off writing your own REPL, perhaps based on the standard code module or simply eval. This lets you run the entered code in a different environment (by passing a dict to eval) and you can even analyze and modify the code before it gets run (although that might be overkill depending on what you want to do).

    posted in Pythonista read more
  • dgelessus

    There are two possibilities I can think of:

    1. Do you have a file called numpy.py in Pythonista? If so, you need to rename it - otherwise import numpy as np will import your numpy.py and not the standard numpy module.
    2. Try restarting Pythonista (swipe up from the bottom of the screen to open the app switcher, then swipe Pythonista upwards to close it, then reopen the app). It is possible that the numpy module isn't loaded completely; this can happen if you stop your script while the import numpy statement is running. By restarting Pythonista, you can bring the Python environment back into a clean state.

    posted in Pythonista read more
  • dgelessus

    Normal Markdown doesn't have any native syntax for underlining - __underline__ produces underline, i. e. bold text. In standard Markdown, __bold__ is equivalent to **bold**, and _italic_ is the same as *italic*.

    Chat applications like Discord, Slack and Mattermost support syntax that is similar to normal Markdown, but isn't completely compatible (they include some custom features that don't exist in Markdown, and don't understand all standard Markdown syntax). Discord's underline feature is an example of that.

    posted in Editorial read more
  • dgelessus

    @omz I just played around a little and found that #LyX at the start of a Python script apparently guarantees file to recognize it as a LyX document, overriding all of the Python code detection patterns. I'm still on OS X 10.11, but I have a newer file version (5.35) installed through MacPorts, so hopefully its behavior is close to the version that 10.14 has.

    I don't quite understand how magic file entries are prioritized and why exactly this works. I'm guessing it's because the LyX pattern looks for a literal string at byte 0, whereas the "smart" Python code detection patterns do a string search over a byte range, so the LyX rule is preferred because it's simpler.

    @JonB ~/.magic is documented in the manpage of my MacPorts version of file, but not in the OS X default version's manpage. Maybe it's just a version difference, in which case it should work on 10.14. A custom magic file would probably be the best solution, so we don't have to keep looking for new ways to trick file every time they improve their Python patterns.

    posted in Pythonista read more
  • dgelessus

    @ttobias said:

    General question: Does the TestFlight Beta override the installed app or is this separated?

    The beta replaces the App Store version. If you already have the App Store version installed and then install the beta through TestFlight, you'll get a warning message saying that you may lose your data - this is generally not the case for Pythonista. (I've been in the Pythonista TestFlight beta since the beginning, and installing a beta has never overwritten my data. But if possible you should make an iTunes backup beforehand, just in case.)

    You can also go back to the latest App Store release at any time, by going into your purchases and redownloading Pythonista there. This will replace the beta version, but also leaves your data intact (except perhaps for features that were introduced in the beta).

    posted in Pythonista read more
  • dgelessus

    @mikael said:

    Being an objc muddler myself, I am wondering why your method and selector do not need to have the trailing underscore/colon.

    Objective-C's requirements about where to put colons are only enforced at compile time (they are a part of the language syntax). At runtime it doesn't matter if the colons match up with the method arguments (at that point everything has been translated to regular C function pointer calls), so the runtime never checks the selector names in any way. It's similar to how Python lets you say setattr(obj, "funny attribute name!", 42), even though you can't use funny attribute name! as an attribute in your source code.

    The underscores in the function name do matter to create_objc_class, it counts the number of underscores in the name to figure out how many parameters the method has. So even though controlTouchEvent_sender_event is not really a correct Objective-C method name, it has two underscores, which matches the number of arguments that the Python function takes (in addition to _self and _cmd), so the call works in the end.

    @shinyformica said:

    I didn't even fully grasp how the parameters needed to be defined or named in my function...

    The example method ((IBAction)doSomething:(id)sender forEvent:(UIEvent *)event) would translate to doSomething:forEvent: as a selector, or doSomething_event_ as a Python function name. Only the word to the left of each colon is part of the selector. The word to the right of each parameter type is the internal parameter name - this only matters if you're implementing the method in Objective-C source code, you can ignore it when translating the method name to objc_util.

    In this case it doesn't matter though what exactly the method name is. You only need to make sure that the underscore/colon count in your function name matches how many arguments the function takes, otherwise objc_util won't call your function with the correct number of arguments.

    posted in Pythonista read more
  • dgelessus

    IIRC block invoke functions take the block itself as an implicit first argument (basically like self). So you probably need to add an extra c_void_p in your InvokeFuncType's argument list, and add blk as the first argument in your blk.invoke call. Nevermind, decision_handler and blk both refer to the block.

    posted in Pythonista read more
  • dgelessus

    Also, regardless of whether I like Reddit or not, there are a few things that I think should be considered before moving the community to Reddit:

    • @omz You should probably get in touch with the /r/Pythonista moderator and see if you can also become a moderator. (Might be a good idea to mention your Reddit username in a post here, so they can verify that it's actually you contacting them on Reddit.)
    • What happens with the existing forum posts? Reddit doesn't support "importing" content, and automatically reposting all forum threads onto Reddit wouldn't work well (everything would be under one account, linear forum threads don't translate well to Reddit's tree-style replies, and this sort of mass posting would probably be considered spam). I suppose the existing threads could be converted to static pages and hosted in place of the forum.
    • Could the community be realistically migrated off of Reddit again? Of course there's no "export" feature either, so the content would need to be downloaded some other way (I'm sure there are already tools for that). However there would be no way to redirect old links to the new location.

    Also, another thing about Reddit that I forgot to mention in my previous post: after some time, Reddit posts are "archived", which means that they can't be voted or commented on anymore. This would be a problem for threads that are not updated often (for example threads about a specific project that are only updated when a new version is released). I don't know how exactly the archive mechanic works though - if the archive delay is based on the initial post date or the last comment date, or if it can be changed or disabled by moderators in any way.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!