My take would be to ignore this specific line with a magic comment. Or, if
you really donʼt want to d that, a

from importlib import import_module # isnʼt that line wonderful?
Gtk = import_module('gi.repository.Gtk')

might do the trick.

(Note that I wrote it without having Python at hand; maybe you have to
import gi.repository, and do getattr(repository, Gtk) instead.)

Best,
Gergely

On Fri, Jun 1, 2018, 14:47 <c.bu...@posteo.jp> wrote:

> How do I make PyGObject code PEP8 konform?
>
> e.g.
>
> #!/usr/bin/env python3
> import gi
> gi.require_version('Gtk', '3.0')
> from gi.repository import Gtk
>
> This code causes
> E402 module level import not at top of file
> E402 module level import not at top of file
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to