• Niklas

    @cvp, my intention was to do as much as possible in Pythonista, since I find Shortcuts so slow. Your question got me to think and I went with your suggestion instead. 🙂 Also, I already had a shortcut that did most of what I wanted.

    @mikael, thanks for suggesting tobytes. I will try to keep that in mind for another time. 🙂

    posted in Pythonista read more
  • Niklas

    A related question:

    If I get a jp2 image from Shortcuts via the clipboard, can I save it to Files in Pythonista? When I try to do it with image.save(image-to-save) I get an OSError: encoder jpeg2k not available, which I can understand. I think there should be a way to disregard the file type and save it the way it came, without making any changes other than the file name.

    Is this possible?

    posted in Pythonista read more
  • Niklas

    I tried to read and follow what they did there, but it was above my knowledge level. Thanks anyway! 🙂

    posted in Pythonista read more
  • Niklas

    Thank you! I’m thinking of doing something like that, but more or less only do the .jp2 conversion in Shortcuts and everything else in Pythonista. 🙂

    What I meant by the sentence you quoted, is that I hope Pythonista will get built-in support for webp and jpeg2000 conversions in the future. Since that is what Google recommends if you want high website rankings in their search results, I think Pythonista would be a good place to have it on iPad.

    posted in Pythonista read more
  • Niklas

    Thank you, @mikael, doing it in Shortcuts worked perfectly! 🙂 Like you, I tested different ways of making it work in Pythonista, but gave up. If someone else needs it, the shortcuts is here:

    https://www.icloud.com/shortcuts/de01f3230990494b85129535fa855d5d

    You can pick images from Photos or Files and it converts them to jpeg2000. Then you can save them back to Photos or Files.

    Hopefully it will be possible to do this in Pythonista eventually. 🙂

    posted in Pythonista read more
  • Niklas

    Thank you, I will try to make that work! 🙂

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    Hi!

    Is it possible to convert images from png or jpg format to webp or jpeg2000 in Pythonista? I have Googled and tested different ways but can’t get it to work. Anyone else here who has managed to do it?

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    I'm not sure if the external keyboard matters. It's the same if I switch the keyboard off and use the native copy/cut and paste. Strange. If I'm the only one experiencing this it's probably a local thing on my iPad. Thanks anyway! 🙂

    posted in Pythonista read more
  • Niklas

    Thanks! That looked even easier than I had anticipated. 😀 I love Python.

    posted in Pythonista read more
  • Niklas

    Hello!

    Lately I have had trouble pasting text in Pythonista. Sometimes it works, but often it doesn’t. There is no difference if I copy from inside Pythonista or if it’s from another app. The copying seems to always work, but pasting doesn’t. If I use Cmd + V on an external keyboard, nothing happens, and if I tap to get the context menu, there’s no “paste” option.

    Is this something you have experienced? Is there a solution?

    I use the latest iPadOS version (13.6.1 I think) on an old iPad Pro 10.5.

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    Hi!

    I use dictionaries for translating texts between languages. They typically look like this:

    trans_en_sv = { 'parish': 'socken', 'county': 'län', 'municipality': 'kommun', 'rune stone': 'runsten', 'rock carving': 'hällristning', 'rune inscribed boulder': 'runhäll', 'runic inscription': 'runinskrift' } 
    

    This one is from English to Swedish. If I want to use the same dictionary for translating the other way, is there a smarter way than looping through it and create a new dictionary? I have a feeling there should be some way to just flip around the keys and values on the fly. 🤔

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    Thanks! That looks promissing. I will try it out. 🙂

    posted in Pythonista read more
  • Niklas

    Thank you, that was very helpful! 😀 👍🏻

    posted in Pythonista read more
  • Niklas

    Hello!

    I want to import one or more images from iCloud. I have tried dialogs.pick_document(types=['public.image']), but can't get it to accept multiple images. Is it possible to do that? Is there a better way to do this?

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    After having thought about this some more, I think it might be better to re-structure the script and do it another way instead. 🙂

    posted in Pythonista read more
  • Niklas

    Hello!

    I am building a website generation engine. In it I have html strings that also contain variable names. I want to replace the variable names with other data and I am trying to do that using replace.

    Here is a simplified excerpt from the code:

    # translation engine
    def trans(string, translations):
        for key, value in translations.items():
            string = string.replace(key, str(value))
        return string
    
    # html formatting variable
    pg = '<div class="content">$variable</div>'
    
    # content variables
    variable = ''
    description = 'ABC'
    find_on_map = ''
    
    # translation dictionary 
    place_hold_repl = {'$description': description, '$find_on_map': find_on_map, '$variable': variable}
    
    # variable for testing
    variable = 'abcdef'
    
    # calling translation
    find_on_map = trans(pg, place_hold_repl)
    
    print(find_on_map)
    

    Actual result: <div class="content"></div>

    Expected result: <div class="content">abcdef</div>

    I must have misunderstood something because the variable names are replaced, but with nothing instead of the variable values. It is as if it uses the variable content like it was when the placeholder dictionary was created. If so, is there a way to have it use the variable contents as they are at the time of calling the translation function without moving the dictonary down the code? Or perhaps an even better way to do the whole thing?

    Best regards, Niklas

    posted in Pythonista read more
  • Niklas

    Thanks to both of you! 🙂

    @mikael, I think I may be able to use sorting on the “sv_runinskr_fnrtdb” values. As far as I can see, it will work for the remaining part of the dictionary as well. I also think I understand what is going on in your code. 🙂

    @7upser, I like that your solution use the “sv_runinskr_trim” values. However, it seems that it sorts on numbers only. Since all of my values contain letters first, not just M, Sö, and U, as in the example, I also want them sorted on the letters. Therefore your solution will not work in my particular case. I like your variable naming skills, though. 😉

    posted in Pythonista read more
  • Niklas

    Hi!

    I have a nested dictionary with string values containing both letters and numbers. I want to sort them using natural sorting (”M1, M2, M10, Sö202” instead of ”M1, M10, M2, Sö202”).

    Despite reading a lot on StackOverflow and other places, I still haven’t managed to get it right. I find parts of answers here and there, but some are for Python 2, some Python 3, some use modules I don’t have, and so on.

    This is a very small part of the dictionary:


    dict_nested = {'Tynderö 163': {'lamnings_id_raa': 'L1934:1839', 'fid': 184092, 'sv_runinskr_fnrtdb': 'Sö 9', 'sv_runinskr_trim': 'Sö9', 'obj_id_fnrtdb': '', 'signum_fnrtdb': 'Sö 9 $'}, 'Härnösand 148': {'lamnings_id_raa': 'L1934:2591', 'fid': 150041, 'sv_runinskr_fnrtdb': 'Sö 11', 'sv_runinskr_trim': 'Sö11', 'obj_id_fnrtdb': '', 'signum_fnrtdb': 'Sö 11 +'}, 'Njurunda 807': {'lamnings_id_raa': 'L1934:374', 'fid': 149317, 'sv_runinskr_fnrtdb': 'U 215', 'sv_runinskr_trim': 'U215', 'obj_id_fnrtdb': '', 'signum_fnrtdb': 'U 215 $'}, 'Skön 70:1': {'sv_runinskr_fnrtdb': 'M 5', 'sv_runinskr_trim': 'M5', 'signum_fnrtdb': 'M 5', 'lamnings_id_raa': {}, 'fid': {}, 'obj_id_fnrtdb': '10249200700001'}, 'Skön 70:2': {'sv_runinskr_fnrtdb': 'M 16', 'sv_runinskr_trim': 'M16', 'signum_fnrtdb': 'M 16', 'lamnings_id_raa': {}, 'fid': {}, 'obj_id_fnrtdb': '10249200700002'}, 'Skog 7:4': {'lamnings_id_raa': 'L1935:1941', 'fid': 42683, 'sv_runinskr_fnrtdb': '', 'sv_runinskr_trim': '', 'obj_id_fnrtdb': '', 'signum_fnrtdb': ''}, 'Njurunda 173:1': {'sv_runinskr_fnrtdb': 'M 10', 'sv_runinskr_trim': 'M10', 'signum_fnrtdb': 'M 10 $', 'lamnings_id_raa': {}, 'fid': {}, 'obj_id_fnrtdb': '10248101730001'}, 'Njurunda 116:1': {'sv_runinskr_fnrtdb': 'M 1', 'sv_runinskr_trim': 'M1', 'signum_fnrtdb': 'M 1 $', 'lamnings_id_raa': {}, 'fid': {}, 'obj_id_fnrtdb': '10248101160001'}}


    I want to sort the values for the ”sv_runinskr_trim” key. This is something I need to do all the time. Can anyone help me make a breaktrough here? Ideally I would also like to understand what I’m doing. 🙂

    Best regards, Niklas

    (The dictionary is for a website about Swedish rune stones.)

    posted in Pythonista read more
  • Niklas

    Yes, that's exactly what I wanted. Thank you very much for your help! :-)

    posted in Editorial read more
  • Niklas

    Not quite. That one extracts all links from a text and makes it a nice list. I am looking for one that just replaces URL:s with MD links and leaves the rest of the text intact.

    Best regards, Niklas

    posted in Editorial read more
Internal error.

Oops! Looks like something went wrong!