Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Peng Yu
On Sat, Oct 31, 2009 at 11:34 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: In my question, module A and B exist just for the sake of implementation. Even if I have module A and B, I don't want the user feel the existence of

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Peng Yu
On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: So python would not be able to accommodate my preference one class/function per file? Of course it does! You can do that RIGHT NOW -- just put one

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Peng Yu
On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: Variables in a function are already private.  How can the names in one function be affected by other functions in the same module? You

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Robert Kern
Peng Yu wrote: On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: Oh wait, I get it... you want to do a global search-and-replace over the entire file. *face-palm* Yes. You get it. In any capable programmer's editor, it should not be hard to do a

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Robert Kern
Peng Yu wrote: On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: So python would not be able to accommodate my preference one class/function per file? Of course it does! You can do that RIGHT NOW

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-11-01 Thread Steven D'Aprano
On Sun, 01 Nov 2009 13:46:42 -0600, Robert Kern wrote: Peng Yu wrote: On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: Oh wait, I get it... you want to do a global search-and-replace over the entire file. *face-palm* Yes. You get it. In

Function states [was Re: How to import only one module in a package when the package __init__.py has already imports the modules?]

2009-11-01 Thread Steven D'Aprano
On Sun, 01 Nov 2009 08:07:37 -0600, Peng Yu wrote: It is reasonable to assume the log of the number of states of a function or a class is proportional to it length. Hence, when a function or a class is long, you will never be able to test all its states. def f(n): return n + 5 def

How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
I have the following files, which are in the directory 'test'. The parent directory of 'test' is in $PYTHONPATH. I have 'from A import A' and 'from B import B' in '__init__.py', because I want to use 'test.A' and 'test.B' to refer to classes A and B rather than 'test.A.A' and 'test.B.B'. $ll -g

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Duncan Booth
Peng Yu pengyu...@gmail.com wrote: I'm wondering if there is a way to make the following two things hold. Thank you1 1. When I 'import test', I can refer to class A as 'test.A'. 2. When I 'import test.A', I can refer to class A as 'test.A.A' and class B shall not be imported. No. Either

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 12:47 PM, Duncan Booth duncan.bo...@invalid.invalid wrote: Peng Yu pengyu...@gmail.com wrote: I'm wondering if there is a way to make the following two things hold. Thank you1 1. When I 'import test', I can refer to class A as 'test.A'. 2. When I 'import test.A', I

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Robert Kern
On 2009-10-31 15:31 PM, Peng Yu wrote: The original problem comes from the maintenance of the package. When A and B are large classes, it is better to put them in separate files under the directory 'test' than put them in the file 'test.py'. The interface 'test.A' is used by end users. However,

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern robert.k...@gmail.com wrote: On 2009-10-31 15:31 PM, Peng Yu wrote: The original problem comes from the maintenance of the package. When A and B are large classes, it is better to put them in separate files under the directory 'test' than put them

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Wolodja Wentland
On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern robert.k...@gmail.com wrote: [ snip ] I know that multiple classes or functions are typically defined in one file (i.e. module in python). However, I feel this make the code not easy to read.

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Robert Kern
On 2009-10-31 16:53 PM, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kernrobert.k...@gmail.com wrote: On 2009-10-31 15:31 PM, Peng Yu wrote: The original problem comes from the maintenance of the package. When A and B are large classes, it is better to put them in separate files

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern robert.k...@gmail.com wrote: [ snip ] I know that multiple classes or functions are typically defined in one

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Wolodja Wentland
On Sat, Oct 31, 2009 at 18:29 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: Are you serious? Do you *really* put each function in its own file? How exactly does this enhance

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Robert Kern
On 2009-10-31 19:21 PM, Wolodja Wentland wrote: On Sat, Oct 31, 2009 at 18:29 -0500, Peng Yu wrote: And I always put a single class in a file. Why? What do you gain by that? While it's never a good idea to follow the rule slavishly, it's often a good idea. Many classes are themselves a

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 7:21 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 18:29 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: Are you

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Dave Angel
Peng Yu wrote: On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern robert.k...@gmail.com wrote: [ snip ] I know that multiple classes or

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 18:29:35 -0500, Peng Yu wrote: If two functions are too long to put in file, I generally put them in two different files. If two functions are too long for a single file, the functions are too big and need to be broken up into ten or thirty sub-functions each! Ideally, no

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 20:03:29 -0500, Peng Yu wrote: If it should ever happen that two functions are too long to put in a single file you should refactor your code. It is usually a good idea of breaking problems down into single steps (ie functions) so you never end up with a 5000 SLOC

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 16:53:50 -0500, Peng Yu wrote: I know that multiple classes or functions are typically defined in one file (i.e. module in python). However, I feel this make the code not easy to read. Therefore, I insist on one class or function per file (i.e module in python). When

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 10:03 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 16:53:50 -0500, Peng Yu wrote: I know that multiple classes or functions are typically defined in one file (i.e. module in python). However, I feel this make the code not easy to

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 9:42 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 20:03:29 -0500, Peng Yu wrote: If it should ever happen that two functions are too long to put in a single file you should refactor your code. It is usually a good idea of breaking

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Robert Kern
Peng Yu wrote: I have defined 'long' in one of my previous message. I consider a file long, when it does not fit in one or two screen. Basically, I want to get a whole picture of the file after glancing of the file. I think you are going to have to get used to the fact that you have very

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 9:34 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sat, 31 Oct 2009 18:29:35 -0500, Peng Yu wrote: If two functions are too long to put in file, I generally put them in two different files. If two functions are too long for a single file, the

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 9:18 PM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wentl...@cl.uni-heidelberg.de wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern robert.k...@gmail.com

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 10:35 PM, Robert Kern robert.k...@gmail.com wrote: Peng Yu wrote: I have defined 'long' in one of my previous message. I consider a file long, when it does not fit in one or two screen. Basically, I want to get a whole picture of the file after glancing of the file.

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Robert Kern
Peng Yu wrote: On Sat, Oct 31, 2009 at 10:35 PM, Robert Kern robert.k...@gmail.com wrote: Peng Yu wrote: I have defined 'long' in one of my previous message. I consider a file long, when it does not fit in one or two screen. Basically, I want to get a whole picture of the file after glancing

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: In my question, module A and B exist just for the sake of implementation. Even if I have module A and B, I don't want the user feel the existence of module A and B. I want them feel exact like class A and B are defined in module 'test'

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: Variables in a function are already private.  How can the names in one function be affected by other functions in the same module? You misunderstood me. If there are multiple functions or classes in a file, when I change variables in a

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: So python would not be able to accommodate my preference one class/function per file? Of course it does! You can do that RIGHT NOW -- just put one class per file. I.e., I have to use something like 'from spam import spam' or