Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Steve Holden
Adekoba wrote:
> On Feb 24, 1:06 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
>> Adekoba wrote:
>>> food.py
>>> food/
>>>   __init__.py
>>>   ham.py
>>>   cheese.py
>>> where food.py is a script that uses the package food. Is it possible
>>> for this to work in any way? Every time I try to run food.py, python
>>> tries to import everything from the script instead of from the
>>> package. How can I fix this?
>> Move the code from food.py to food/__init__.py. You can't have a package
>> and a module with the same name.
>>
>> Christian
> 
> So it is not possible?
> 
> I don't think moving food.py's code to __init__.py would work out to
> well, because then how would I run the script?

You run food/__init__.py with the following statement:

import food

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
On Feb 24, 3:21 pm, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080224 20:01], Adekoba ([EMAIL PROTECTED]) wrote:
>
> >I don't think moving food.py's code to __init__.py would work out to
> >well, because then how would I run the script?
>
> import food
>
> Which in turn has something like this in food/__init__.py:
>
> from food.cheese import gouda
> from food.ham import parma
>
> __all__ = ['gouda', 'parma']
>
> and in turn in your script you can now use food.gouda and food.parma.
>
> Unless I totally misunderstood what you are trying to achieve.
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/
> We have met the enemy and they are ours...

I was just curious if I could get a script name to be the same name as
the package directory, but apparently it is not possible. Instead I
think I am going to do something like:

setup.py
food/
  __init__.py
  ham.py
  cheese.py
scripts/
  food

and just set my PYTHONPATH to the parent directory. I have never done
a full scale project before in python, but I think this is probably on
track with what most people would do.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Jeroen Ruigrok van der Werven
-On [20080224 20:01], Adekoba ([EMAIL PROTECTED]) wrote:
>I don't think moving food.py's code to __init__.py would work out to
>well, because then how would I run the script?

import food

Which in turn has something like this in food/__init__.py:

from food.cheese import gouda
from food.ham import parma

__all__ = ['gouda', 'parma']

and in turn in your script you can now use food.gouda and food.parma.

Unless I totally misunderstood what you are trying to achieve.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
We have met the enemy and they are ours...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
On Feb 24, 1:06 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
> Adekoba wrote:
> > food.py
> > food/
> >   __init__.py
> >   ham.py
> >   cheese.py
>
> > where food.py is a script that uses the package food. Is it possible
> > for this to work in any way? Every time I try to run food.py, python
> > tries to import everything from the script instead of from the
> > package. How can I fix this?
>
> Move the code from food.py to food/__init__.py. You can't have a package
> and a module with the same name.
>
> Christian

So it is not possible?

I don't think moving food.py's code to __init__.py would work out to
well, because then how would I run the script?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Techniques (and naming conventions)

2008-02-24 Thread Christian Heimes
Adekoba wrote:
> food.py
> food/
>   __init__.py
>   ham.py
>   cheese.py
> 
> where food.py is a script that uses the package food. Is it possible
> for this to work in any way? Every time I try to run food.py, python
> tries to import everything from the script instead of from the
> package. How can I fix this?

Move the code from food.py to food/__init__.py. You can't have a package
and a module with the same name.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Developing Techniques (and naming conventions)

2008-02-24 Thread Adekoba
I have some questions... Say we have a package "food"

food/
  __init__.py
  ham.py
  cheese.py

Is it possible to have a file named "food.py" in the package and have
non-referential imports work? i.e., for ham.py to have a line "import
food.food". From my experience, python will not work with this.


Alright, new scenario. Say we had:

food.py
food/
  __init__.py
  ham.py
  cheese.py

where food.py is a script that uses the package food. Is it possible
for this to work in any way? Every time I try to run food.py, python
tries to import everything from the script instead of from the
package. How can I fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list