Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative import with Python 3 from folder containing a dot

Say I have the following structure:

main.py
.folder/
    a.py
    b.py

and using Python 3 and being currently in main.py I want to import * from a.py.

  • I assume from .folder.a import * is wrong as that ignores that the folder is actually named .folder, not folder
  • I assume from ..folder.a import * is wrong as I'm not targeting a relative parent directory called folder, but a folder named .folder within the same directory as main.py
like image 858
k2104710 Avatar asked Sep 03 '26 09:09

k2104710


1 Answers

You can't do this; names of packages and modules need to be valid Python identifiers, which .folder is not. You should rename your directory.

like image 64
Daniel Roseman Avatar answered Sep 04 '26 23:09

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!