• 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

Internal error.

Oops! Looks like something went wrong!