Author Anthony Sottile
Recipients Anthony Sottile
Date 2017-01-13.04:47:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484282874.75.0.69511180509.issue29258@psf.upfronthosting.co.za>
In-reply-to
Content
PEP420 makes __init__.py files optional: https://docs.python.org/3/whatsnew/3.3.html#pep-420-implicit-namespace-packages

Though it seems without them, pkgutil.walk_packages does not function as desired: https://docs.python.org/3/library/pkgutil.html#pkgutil.walk_packages

Consider the following example:

```
$ tree foo
foo
├── bar
│   ├── baz.py
│   └── __init__.py
├── __init__.py
└── womp.py
```

And a test script

# test.py
```
import pkgutil

import foo


for _, mod, _ in pkgutil.walk_packages(foo.__path__, foo.__name__ + '.'):
    print(mod)
```

In both python2 and python3 I get the following output:

```
$ python2.7 test.py
foo.bar
foo.bar.baz
foo.womp
$ python3.5 test.py
foo.bar
foo.bar.baz
foo.womp
```

Removing the __init__.py files and only using python3, I get this:

```
$ find -name '__init__.*' -delete
$ python3.5 test.py
foo.bar
```

The modules are definitely importable:

```
$ python3.5 -c 'import foo.bar.baz'
$
```

Originally asked as a question on stackoverflow: http://stackoverflow.com/questions/41203765/init-py-required-for-pkgutil-walk-packages-in-python3
History
Date User Action Args
2017-01-13 04:47:54Anthony Sottilesetrecipients: + Anthony Sottile
2017-01-13 04:47:54Anthony Sottilesetmessageid: <1484282874.75.0.69511180509.issue29258@psf.upfronthosting.co.za>
2017-01-13 04:47:54Anthony Sottilelinkissue29258 messages
2017-01-13 04:47:53Anthony Sottilecreate