Re: [Tutor] __init__.py question

2011-06-02 Thread Marilyn Davis
Thank you for your careful explanation, Steven. I guess there's nothing more for me to know. While I think it is a mistake to put directories in your package directory structure that aren't part of the package, that seems to be all it's about. Well, I guess I don't feel quite so stupid. Thank y

Re: [Tutor] __init__.py question

2011-06-01 Thread Steven D'Aprano
Marilyn Davis wrote: [...] There's something I'm missing because I think you simply can't call something string.py unless you are willing to give up the library string.py. No, you're right about that. Python's search path is "first match wins". Whether it's a package or a module, it will match

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/6/1 Marilyn Davis : > Maybe I'm getting what you say, Alexandre and Ramit. > > When you import logging, it imports string, but it won't if you have a > string of your own already imported. > > So, when logging depends on string, it'll get mine and crash. > > But __init__.py helps what in this

Re: [Tutor] __init__.py question

2011-06-01 Thread Marilyn Davis
Maybe I'm getting what you say, Alexandre and Ramit. When you import logging, it imports string, but it won't if you have a string of your own already imported. So, when logging depends on string, it'll get mine and crash. But __init__.py helps what in this scenario? The only scenario it helps,

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
As a side note, remember that imported modules are cached under sys.modules. If you import something, it will be looked up in sys.modules and use the one in memory if it exists. If it doesn't exist, it will iterate over sys.path and look for your module/package. If it doesn't find it, you will get

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/5/31 Marilyn Davis : > I don't really understand why __init__.py is necessary -- except that it > makes the packaging scheme work. > > The Python Manual by Guido van Rossum and Fred L. Drake says: > > ... this is done to prevent directories with a common name, such as > string, from unintentio

Re: [Tutor] __init__.py question

2011-06-01 Thread Prasad, Ramit
I wonder if this is so that it can ignore directories on sys.path. I assume that the path passed to python can be quite verbose depending on the OS's handling of path and environment variables. This is also a way to have Python ignore Python scripts in directories on the path that are not meant

Re: [Tutor] __init__.py question

2011-06-01 Thread Marilyn Davis
Thank you Válas Péter. I still don't get it, or how __init__.py alters the scenario you describe. I know that sometimes I'm really dense so please be patient with me. If I have a string.py in my local directory, it will be imported when I "import string" because the search path, sys.path, (which

Re: [Tutor] __init__.py question

2011-06-01 Thread Válas Péter
I think it means that you may have a subdirectory named "string" in your actual directory where you store e.g. your string-related scripts, and you have a Python package named "string" _somewhere_else_, but in the module search path. The subdirectory of the actual directory will have priority bacau

[Tutor] __init__.py question

2011-05-31 Thread Marilyn Davis
I don't really understand why __init__.py is necessary -- except that it makes the packaging scheme work. The Python Manual by Guido van Rossum and Fred L. Drake says: ... this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur

Re: [Tutor] __init__.py for running a file from commandline?

2006-12-07 Thread Marcus Goldfish
On 11/27/06, Michael P. Reilly <[EMAIL PROTECTED]> wrote: When you type something from the command-line, you are at the whims of the WinXP command shell. You have to follow its rules, not Python's. It would need to have "python" in %PATH%, and then it would need to have to run "python C:\path\

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Michael P. Reilly
Marcus, When you type something from the command-line, you are at the whims of the WinXP command shell. You have to follow its rules, not Python's. It would need to have "python" in %PATH%, and then it would need to have to run "python C:\path\to\pyroot\utils\commands\mygrep.py". The arguments

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Kent Johnson
Marcus Goldfish wrote: > > > On 11/11/06, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > Marcus Goldfish wrote: > > Hoping someone can help with this... > > > > I have a logical python namespace using a directory tree and > __init__.py > >

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Marcus Goldfish
On 11/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and __init__.py > files. For example, PYTHONPATH points to ~pyroot, and I have the following: > > ~pyroot/ > ~pyroot/ut

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-11 Thread Kent Johnson
Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and __init__.py > files. For example, PYTHONPATH points to ~pyroot, and I have the following: > > ~pyroot/ > ~pyroot/utils/ > ~pyroot/utils/commands/mygrep.py > > Which ma

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-10 Thread Luke Paireepinart
Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and > __init__.py files. For example, PYTHONPATH points to ~pyroot, and I > have the following: > > ~pyroot/ > ~pyroot/utils/ > ~pyroot/utils/commands/mygrep.py > > Which ma

[Tutor] __init__.py for running a file from commandline?

2006-11-10 Thread Marcus Goldfish
Hoping someone can help with this...I have a logical python namespace using a directory tree and __init__.py files.  For example, PYTHONPATH points to ~pyroot, and I have the following:~pyroot/~pyroot/utils/ ~pyroot/utils/commands/mygrep.pyWhich makes it nice to code:# some python scriptimport util

[Tutor] __init__.py not working?

2005-07-08 Thread Bernard Lebel
Hello, In my script library, one directory is named "rendering". When I try to import a module from this directory, I always get this error: #ImportError: dynamic module does not define init function (initrendering) However, there is an __init__.py file in there, and also the pyc version. All ot

Re: [Tutor] __init__.py

2005-05-23 Thread Alan G
HI Joseph, > I've seen many (python) "plugins" (some located in site-packages [windows > here]) with the name __init__.py. init.py is the file that controls the behaviour of python packages - that is collections of modules used as a single entity. Read the python docs for the fine detail, but e

Re: [Tutor] __init__.py

2005-05-22 Thread Lee Cullens
Joseph, I'm relatively new to Python, but I might be able to help with your question. First, think of the convention "self" (or sometimes "me" in other languages) as a reference to a specific instance derived from a class. When you reference an inherited class method of an instance, the

Re: [Tutor] __init__.py

2005-05-22 Thread Joseph Quigley
>__init__.py will be executed when a package is imported. Oh. So it will (for instance) compile .py to .pyc after the installation is finished. Nice. Thanks, JQ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/

Re: [Tutor] __init__.py

2005-05-22 Thread Shidai Liu
On 5/23/05, Joseph Quigley <[EMAIL PROTECTED]> wrote: I've seen many (python) "plugins" (some located in site-packages [windowshere]) with the name __init__.py.What's their use?class foo:def __init__:print "this starts first" def foo1():print "this co

[Tutor] __init__.py

2005-05-22 Thread Joseph Quigley
I've seen many (python) "plugins" (some located in site-packages [windows here]) with the name __init__.py. What's their use? class foo: def __init__: print "this starts first" def foo1(): print "this comes later. Init initializes the chain of funct