472,114 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

hiding modules in __init__.py

How would I implement something equivalent to java's package private in
python?

Say if I have

package/__init__.py
package/utility_module.py

and utility_module.py is an implementation detail subject to change.

Is there some way to use __init__.py to hide modules that I don't want
clients to see? Or is the best practice just to name the module you don't
want clients to use _utility_module and have it private by convention?

Thanks,
Brendan
Oct 18 '08 #1
2 7512
On Sat, Oct 18, 2008 at 12:03 PM, Brendan Miller <ca******@catphive.netwrote:
How would I implement something equivalent to java's package private in
python?

Say if I have

package/__init__.py
package/utility_module.py

and utility_module.py is an implementation detail subject to change.

Is there some way to use __init__.py to hide modules that I don't want
clients to see? Or is the best practice just to name the module you don't
want clients to use _utility_module and have it private by convention?
Generally the latter on account of Python's "we are all consenting
adults here" philosophy.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>
Thanks,
Brendan
--
http://mail.python.org/mailman/listinfo/python-list
Oct 20 '08 #2
En Sat, 18 Oct 2008 16:03:19 -0300, Brendan Miller <ca******@catphive.net>
escribió:
How would I implement something equivalent to java's package private in
python?

Say if I have

package/__init__.py
package/utility_module.py

and utility_module.py is an implementation detail subject to change.

Is there some way to use __init__.py to hide modules that I don't want
clients to see? Or is the best practice just to name the module you don't
want clients to use _utility_module and have it private by convention?
If you don't import utility_module in __init__ (or delete the name after
using it), it won't show up if someone does "from package import *", nor
in dir(package). Plus if you don't menction it in the docs, the only way
to discover it would be to look at the directory contents - to "peek the
implementation", I'd say.
You could always name it _utility_module.py if you want to make perfectly
clear that it's for internal use only, but I've seldom seen such module
names.

--
Gabriel Genellina

Oct 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Nick Coghlan | last post: by
2 posts views Thread by Negroup | last post: by
1 post views Thread by tsuraan | last post: by
3 posts views Thread by schpok | last post: by
1 post views Thread by Juan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.