It would be nice if the Black formatter could be added natively to Pythonista.
For those who don't know about Black: this is a code formatter that makes your code PEP8 compatible and very consistent: highly recommended. See https://black.readthedocs.io/en/stable/ for details.
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.

Best posts made by upwart
-
Feature request: Native support for Black
-
Any chance that the greenlet module would be supported in Pythonista?
I am developing a package which uses the excellent greenlet module (https://pypi.org/project/greenlet/).
Alas, this seems not to be supported by Pythonista.
Can we expect this to be included in a future version? -
RE: Change black linelength
This is to tell that I have managed to get black to use an alternative line length (160 in my case), by pip installing black. It will be installed in the site-packages (user) folder. And there, I can just patch the const.py file.
It seems to work perfectly. Hooray! -
RE: iOS 13
And PyTo is open source, so even if the developer is not anymore supporting the product (like seems the case with Pythonista) others can continue the product (at least in theory).
-
RE: Properties that are more fun
@mikael
Thanks for this great idea.
I have renamed your decorator to getter_setter, to make the purpose of it more clear.Thus we define a decorator function:
def getter_setter(func): return property(func, func)
and then we can redo the example as:
class Example:
@getter_setter def my_property(self, *value): if value: self._my_property = value[0] else: return self._my_property
or EAFP style:
class Example: @getter_setter def my_property(self, *value): try: self._my_property = value[0] except IndexError: return self._my_property
Optionally, we could define two more decorators for getter only and setter only properties:
def getter(func): def raise_attribute_error(*args): raise AttributeError("can't set attribute") return property(func, raise_attribute_error) def setter(func): def raise_attribute_error(*args): raise AttributeError("can't get attribute") return property(raise_attribute_error, func)
Here is an example of a Circle class demonstrating the three decorators.
radius can be used to get the radius and set the radius (thus updating the _area attribute)
area can be used to get the area only. Setting will raise an error.
diameter can only be used to set the radius. You can’t get it.Here is an implementation with getter_setter only:
import math class Circle: def __init__(self, radius): self.radius = radius @getter_setter def radius(self, *value): if value: self._radius = value[0] self._area = math.pi * self._radius ** 2 else: return self._radius @getter_setter def area(self, *value): if value: raise AttributeError("can't set attribute") else: return self._area @getter_setter def diameter(self, *value): if value: self.radius = value[0] / 2 else: raise AttributeError("can't get attribute") And if we use getter and setter as well: import math class Circle: def __init__(self, radius): self.radius = radius @getter_setter def radius(self, *value): if value: self._radius = value[0] self._area = math.pi * self._radius ** 2 else: return self._radius @getter def area(self): return self._area @setter def diameter(self, value): self.radius = value / 2
-
RE: Load PIL image in scene with retina resolution
@mikael
I just found out that if change the file format from PNG to BMP speeds up the animation significantly: from 4 to > 16 fps.
Latest posts made by upwart
-
RE: Pandas
The latest version of Python definitely contains pandas. It is version 1.4.4.
Highly recommended! -
RE: PySimpleGUI wrapper for Pythonista...?
It would indeed be nice, if we had PySimpleGUI basic functionality (what is that?) in Pythonista. But, that would be quite a job, although not impossible.
BTW, Although PySimpleGUI claims to be cross-GUI, in fact it only runs properly under tkinter. So, if we would have tkinter at our disposal under Pythonista, we could run PySimpleGUI as well. But, it's quite unlikely that we will ever see tkinter running under Pythonista or on an iPad in general (unless we get full Linux one day). Just dreaming .... -
RE: Any chance that the greenlet module would be supported in Pythonista?
@cvp
Thanks.
I was already afraid of that. -
Any chance that the greenlet module would be supported in Pythonista?
I am developing a package which uses the excellent greenlet module (https://pypi.org/project/greenlet/).
Alas, this seems not to be supported by Pythonista.
Can we expect this to be included in a future version? -
RE: Bizarre bug in Pythonista 3.4
@cvp
12 till 17 (including 13) causes crash here. -
Very minor bug in Pythonista 3.4
When I run this code
import inspect class X: ... sig = inspect.signature(X)
on Pythonista 3.4, a
ValueError : No signature for builtin <class 'object'>
exception is raised.This did not happen on Pythonista 3.3 and not on a Windows machine running Python 3.10.4 (same version as Pythonista 3.4).
If I add an__init__
method, the exception is not raised anymore,Of course, I can just use a try/except block to solve the problem, but it is very strange.
-
Bizarre bug in Pythonista 3.4
I ran into a bizarre bug with the latest version of Pythonista.
It took me quite a long time to discover the cause of a Pythonista crash.
Here's a MWE (minimal working example), showing the bug:from PIL import ImageFont, Image, ImageDraw font = ImageFont.truetype(font="calibri.ttf", size=15) im = Image.new("RGBA", (100, 100), (0, 0, 0, 0)) draw = ImageDraw.Draw(im) draw.text(xy=(0, 0), text="a", font=font) print("never reached")
In this script, a text is written into a Pillow message.
When I run this, the system crashes and the crash log shows:Fatal Python error: Aborted Current thread 0x000000016d847000 (most recent call first): File "/var/containers/Bundle/Application/A061EDB8-1B89-41D2-B706-1F4E042DE8E4/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageFont.py", line 666 in getmask2 File "/var/containers/Bundle/Application/A061EDB8-1B89-41D2-B706-1F4E042DE8E4/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageDraw.py", line 429 in draw_text File "/var/containers/Bundle/Application/A061EDB8-1B89-41D2-B706-1F4E042DE8E4/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageDraw.py", line 484 in text File "/private/var/mobile/Containers/Shared/AppGroup/11021B83-B419-4F67-A331-D54B9BAFC718/Pythonista3/Documents/salabim/a1_1.py", line 6 in <module> Extension modules: pykit_io, _ui, _appex, _frameworksimporter, console, _debugger_ui (total: 6)
The strange thing is that this seems to happen only with this specific font (
calibri.ttf
) and only with font sizes between13
and17
!
The code used to run fine on Python 3.3 and works well on all other platforms, I have used.I found a workaround by using the Arial font instead of
calibri.ttf
. But it is very strange! -
RE: Change black linelength
@cvp
Thanks for thinking with me.
I know how to add the Black section to pyproject.toml. Just can't work out where to put it in Pythonista to work with reformat.
Anyway, I've it working now via a user installation of Back. -
RE: Change black linelength
@ccc
What do you mean with ruff.toml?
I tried pyproject.toml, but could get that working.