• JonB

    You can't put this sort of loop inside a button action, unless the action has in_background.

    posted in Pythonista read more
  • JonB

    Button actions stop the entire display thread until the function exits, unless you use @in_background

    Solution:. Wrap your function with the in_background decorator. Note however that only one in_background gets executed at a time, in order.

    posted in Pythonista read more
  • JonB

    @Maz don't name your script turtle.py, unless you intend to replace the built in turtle module.

    posted in Pythonista read more
  • JonB

    ICloud folders are funny, and not a subfolder of pythonista.

    Try having a script in the main path, which you can then use cd or sys.path.insert to add the iCloud path, and maybe runpy or import, etc.

    posted in Pythonista read more
  • JonB

    There are a few ways, depending on what you are trying to do.

    If you want to read tabular type data, csv is a fine option. For saving python variables, marshall or pickle are good, and json or yaml also read into dicts, and produce readable files. If you literally just want to store one double per line without any context, you could simply call float. Or, if you are using format to write each line, use parse as the inverse of format.

    For just reading/writing your own format, you can use

             for line in f:
                 my_num=float(line)
                 #do something with my_num...
    

    posted in Pythonista read more
  • JonB

    If you type from math import *, then you can use the symbols without typing math.

    Or you can import specific names.

    Eg

    from math import pi
    Or
    from math import *
    

    Both would expose pi

    While

    import math
    

    Means you must use math.pi

    Often, it is considered bad form to use import *, because then it can be hard to tell where some attribute or function comes from. By being explicit, your code will be easier to follow.

    Usually, if you have imports that can be used in multiple functions , import at the top of the file.. if you have one import that is used in one function, and it is a big import, and the function is rarely used, then it can sometimes make sense to import inside a function.
    .

    posted in Pythonista read more
  • JonB

    I think compact is for watchOS, Pro for iOS.

    Does UIFont have a .fontName() method?

    posted in Pythonista read more
  • JonB

    Try

    ".SFCompactText-Bold"
    

    Or

    ".SFProText-Bold"
    

    Also-- the "Text" part of the name can be replaced with Rounded, or Display. Apparently Text is supposed to used under 19pt, Display for 20pt+. I'm not sure what Rounded is for -- looks a little more informal.

    I think apple tried to obfuscate system font names so people used their new API in iOS13, to prevent people hard coding fonts that might change later. Hence reason that .SFUI doesnt work

    I assume draw_string is using UIFont.fontWithName_size_

    posted in Pythonista read more
  • JonB

    So, a way that should work would be to use UIFont to find the system font name, and then create a bold version, then find the name of that... Just an idea, have not pursued it yet

    posted in Pythonista read more
  • JonB

    In python3, StringIO is contained in io.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!