Re: [Tutor] Should a "data" directory have a __init__.py file?

2016-01-18 Thread Oscar Benjamin
On 18 January 2016 at 04:27, Ben Finney  wrote:
>
> The module import system will only recognise a directory as a “package”
> (Python's technical term for “a point in the import hierarchy which
> contains other things to import”) if that directory contains a file
> named ‘__init__.py’. If you do not need the directory to also be
> recognised as a package, it should not have such a file.

That was the case prior to 3.3. However (I can't immediately test this
but) now a directory without an __init__.py can be an implicit
namespace package if it contains importable modules:

https://www.python.org/dev/peps/pep-0420/

--
Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Should a "data" directory have a __init__.py file?

2016-01-17 Thread Ben Finney
boB Stepp  writes:

> I can see no reason why I would need an __init__.py file for a data
> directory. Yes, files will be read there, but there will be no code
> there. Is this correct?

That is correct. A directory of files is accessed just fine using the
normal filesystem access features.

What's more, I would say that if a directory is not positively intended
to be a Python package, that directory *should not* contain any
‘__init__.py’ file.

The module import system will only recognise a directory as a “package”
(Python's technical term for “a point in the import hierarchy which
contains other things to import”) if that directory contains a file
named ‘__init__.py’. If you do not need the directory to also be
recognised as a package, it should not have such a file.

See  for
the full details of how Python recognises and uses packages in the
import system.

Also be aware Python's use of “package” conflicts with the broader
computing use of that term (“a unit of software to install on the
operating system”); but it's too late to change either of them,
unfortunately.

-- 
 \“The deepest sin against the human mind is to believe things |
  `\   without evidence.” —Thomas Henry Huxley, _Evolution and |
_o__)Ethics_, 1893 |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Should a "data" directory have a __init__.py file?

2016-01-17 Thread boB Stepp
Py 3.4.4; W7-64-bit

I've been reviewing all of the posts relevant to questions I asked
last year on Python project directory structures.  I was wondering
about a data directory nested under the program's top-level directory.
I can see no reason why I would need an __init__.py file for a data
directory.  Yes, files will be read there, but there will be no code
there.  Is this correct?

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor