Re: Transistion from module to package and __init__.py

2021-05-05 Thread Dieter Maurer
Chris Nyland wrote at 2021-5-4 22:20 -0400: > ... >So for a while now I have taken to converting >my module, in this example database.py, to the __init__.py of the package. >I remember reading years back that having code in the __init__.py was bad >practice but I can't reme

Re: Transistion from module to package and __init__.py

2021-05-05 Thread Ethan Furman
> Either of these still leaves a database.database namespace laying about and > to me it just seems untidy. So for a while now I have taken to converting > my module, in this example database.py, to the __init__.py of the package. > So I was hoping to get > feed back from a wider aud

Transistion from module to package and __init__.py

2021-05-04 Thread Chris Nyland
naturally I make a package folder called database, put and empty __init__.py, in goes my database module and all resource files. Here is where I my primary design question comes in. As organized now as described to import and use the package I need from database import database or I have to put in

Re: Why not being able to call modules from lib folder into test folder although I have __init__.py file both?

2019-04-26 Thread Arup Rakshit
On 26/04/19 11:14 AM, dieter wrote: Arup Rakshit writes: I am not able to call modules from lib folder in my test folder, but outside of tests folder I can access them. How should I fix this? Mocks$ tree . . ├── lib │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc

Re: Why not being able to call modules from lib folder into test folder although I have __init__.py file both?

2019-04-25 Thread dieter
Arup Rakshit writes: > I am not able to call modules from lib folder in my test folder, but outside > of tests folder I can access them. How should I fix this? > > Mocks$ tree . > . > ├── lib > │ ├── __init__.py > │ ├── __pycache__ > │ │

Why not being able to call modules from lib folder into test folder although I have __init__.py file both?

2019-04-25 Thread Arup Rakshit
I am not able to call modules from lib folder in my test folder, but outside of tests folder I can access them. How should I fix this? Mocks$ tree . . ├── lib │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── product.cpython-37.pyc │ └── product.py

Re: Using __init__.py

2017-09-06 Thread nopsidy
oss-platform) project. On linux system, the imprts work >> fine, but in windows I get imort error (I have no idea why. I tried searching >> everywhere, but couldn't get it to work). Anyways, the issue seem to be >> resolved by adding project directory to sys.path(). >> &

Re: Using __init__.py

2017-09-06 Thread Steve D'Aprano
esolved by adding project directory to sys.path(). > > I wanted to know that can I use __init__.py file for adding a project > directory to sys.path (sys.path.insert(0, directory))? That is the wrong way to fix this problem. It might work, for a little while, but then something w

Using __init__.py

2017-09-06 Thread Kryptxy via Python-list
ed to know that can I use __init__.py file for adding a project directory to sys.path (sys.path.insert(0, directory))? -- https://mail.python.org/mailman/listinfo/python-list

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-24 Thread Chris Angelico
On Sat, Sep 24, 2016 at 9:32 PM, Brendan Abel <007bren...@gmail.com> wrote: >> Splitting it up would make it slower to load. > > It's usually the opposite. When packages are split up, you only have to > load the specific portions you need. Putting it all in a single module > forces you to always

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-24 Thread Brendan Abel
> Splitting it up would make it slower to load. It's usually the opposite. When packages are split up, you only have to load the specific portions you need. Putting it all in a single module forces you to always load everything. On Fri, Sep 23, 2016 at 11:59 PM, Lawrence D’Oliveiro < lawrenced.

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-24 Thread Steve D'Aprano
On Sat, 24 Sep 2016 04:59 pm, Lawrence D’Oliveiro wrote: > On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico > wrote: >> It's a large and complex module, and about at the boundary of being >> broken up a bit. > > Splitting it up would make it slower to load. Would it? You've b

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-24 Thread Lawrence D’Oliveiro
On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico wrote: > It's a large and complex module, and about at the boundary of being > broken up a bit. Splitting it up would make it slower to load. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-23 Thread Chris Angelico
On Sat, Sep 24, 2016 at 11:42 AM, Lawrence D’Oliveiro wrote: > On Friday, September 23, 2016 at 4:25:21 AM UTC+12, Chris Angelico wrote: >> For reference, the Decimal module (ignoring the C accelerator) is over six >> thousand lines of code, as a single module. Now, that might be pushing the >> bo

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-23 Thread Lawrence D’Oliveiro
On Friday, September 23, 2016 at 4:25:21 AM UTC+12, Chris Angelico wrote: > For reference, the Decimal module (ignoring the C accelerator) is over six > thousand lines of code, as a single module. Now, that might be pushing the > boundaries a bit ... What “boundaries” do you think that might be pu

Automated refactoring tools (was: How to import all things defined the files in a module directory in __init__.py?)

2016-09-22 Thread Ben Finney
Peng Yu writes: > Is there such a good automated tool for python refactoring? This sounds like a job for — Bicycle Repair Man! Watch him extract jumbled code into well ordered classes. Gasp, as he renames all occurrences of a method. Thank You Bicycle Repair Man! http://bicyc

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Peng Yu
On Thu, Sep 22, 2016 at 8:35 PM, Ben Finney wrote: > Peng Yu writes: > >> On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney >> wrote: >> > [Importing ‘*’ from a module] will also make the names in the code >> > impossible to automatically match against where they came from. >> > Explicit is better t

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Ben Finney
Peng Yu writes: > On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney > wrote: > > [Importing ‘*’ from a module] will also make the names in the code > > impossible to automatically match against where they came from. > > Explicit is better than implicit; you are proposing to make an > > unknown horde

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Chris Angelico
On Fri, Sep 23, 2016 at 1:50 AM, Peng Yu wrote: > > This will make refactoring easy. If everything is explicit, when one > do refactoring, at two places need to be changed which can be a > burden. So you want it to be easy to move stuff around between files in a package? Sounds like you don't act

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Peng Yu
On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney wrote: > Peng Yu writes: > >> I want to import all the thing (or the ones available in the >> respective __all__) defined in each of the file by putting the >> following lines in __init__.py >> >> from file1 i

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-21 Thread Ben Finney
Peng Yu writes: > I want to import all the thing (or the ones available in the > respective __all__) defined in each of the file by putting the > following lines in __init__.py > > from file1 import * > > from filen import * > > However, I don't want to har

How to import all things defined the files in a module directory in __init__.py?

2016-09-21 Thread Peng Yu
Hi, Suppose that I have file1.py, ..., filen.py in a module directory. I want to import all the thing (or the ones available in the respective __all__) defined in each of the file by putting the following lines in __init__.py from file1 import * from filen import * However, I don't

Re: Python: package root, root-node, __init__.py in the package root

2014-11-13 Thread dieter
/python3.2/foo-1.0.0/ on the file-system > and this is referred to the root of the pkg. > > 2. Can, foo-1.0.0 contain __init__.py or do i have to do: > foo-1.0.0/foo/__init__.py ? > > > Take a look at what this guy is saying on his blog: > http://blog.habnab.it/blog/2013/07/21/p

Python: package root, root-node, __init__.py in the package root

2014-11-13 Thread Veek M
is referred to the root of the pkg. 2. Can, foo-1.0.0 contain __init__.py or do i have to do: foo-1.0.0/foo/__init__.py ? Take a look at what this guy is saying on his blog: http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/ --- (bottom of the page) "Your project

Re: opposite of __init__.py

2013-08-19 Thread Dave Angel
Tamer Higazi wrote: > Hi people! > > I have asked myself a question, if there is a opposite of "__init__.py" > like "__del__.py" ?! Others have answered your question, but I wanted to correct a misunderstanding: > > I want, that when the application end

Re: opposite of __init__.py

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 18:48:19 +0200, Tamer Higazi wrote: > Hi people! > > I have asked myself a question, if there is a opposite of "__init__.py" > like "__del__.py" ?! No. If you want to run code when your application is shutting down, run it just befo

Re: opposite of __init__.py

2013-08-19 Thread Ian Kelly
Yes, see the atexit module: http://docs.python.org/3/library/atexit.html On Mon, Aug 19, 2013 at 10:48 AM, Tamer Higazi wrote: > Hi people! > > I have asked myself a question, if there is a opposite of "__init__.py" > like "__del__.py" ?! > > I want, t

opposite of __init__.py

2013-08-19 Thread Tamer Higazi
Hi people! I have asked myself a question, if there is a opposite of "__init__.py" like "__del__.py" ?! I want, that when the application ends, certain functions are executed. I know I could make a constructor and a destructor, but I simply want to know if there is a o

Re: Accessing variables in __init__.py

2012-10-16 Thread Gaudha
On Tuesday, October 16, 2012 3:41:55 PM UTC+5:30, Marco Nawijn wrote: > On Tuesday, October 16, 2012 10:48:17 AM UTC+2, Gaudha wrote: > > > my_package/ > > > > > > __init__.py > > > > > > my_module1.py > > &

Re: Accessing variables in __init__.py

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 10:48:17 AM UTC+2, Gaudha wrote: > my_package/ > > __init__.py > > my_module1.py > > my_module2.py > > variables.py > > > > I want to define common variables in __init__.py and use the namespace in > my_module1

Accessing variables in __init__.py

2012-10-16 Thread Gaudha
my_package/ __init__.py my_module1.py my_module2.py variables.py I want to define common variables in __init__.py and use the namespace in my_module1.py or my_module2.py. Defining it is not a problem. How can call it from my modules? If I define them in a module (say, variables.py), I

Re: from import and __init__.py

2010-03-26 Thread Gregory Ewing
egbert wrote: Yes, you are right. And I can reach everything with modules['some_package'] or variants thereof. Although note that the usual way to get it would be to simply do import some_package -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: from import and __init__.py

2010-03-25 Thread egbert
On Thu, Mar 25, 2010 at 12:43:13PM -0400, Terry Reedy wrote: > On 3/25/2010 6:16 AM, egbert wrote: > >When I do 'from some_package import some_module' > >the __init__.py of some_package will be run. > >However, there will not be anything like a package-module, &g

Re: from import and __init__.py

2010-03-25 Thread Terry Reedy
On 3/25/2010 6:16 AM, egbert wrote: When I do 'from some_package import some_module' the __init__.py of some_package will be run. However, there will not be anything like a package-module, and the effects of __init__.py seem all to be lost. Is that true ? No. If you do from

Re: from import and __init__.py

2010-03-25 Thread Steve Holden
egbert wrote: > When I do 'from some_package import some_module' > the __init__.py of some_package will be run. > However, there will not be anything like a package-module, > and the effects of __init__.py seem all to be lost. Is that true ? > Or can I still do somethin

from import and __init__.py

2010-03-25 Thread egbert
When I do 'from some_package import some_module' the __init__.py of some_package will be run. However, there will not be anything like a package-module, and the effects of __init__.py seem all to be lost. Is that true ? Or can I still do something useful with __init__.py ? e -- Egbe

Re: Re: Problem with __init__.py in Python3.1

2010-02-22 Thread hidura
For finnished the subject i resolve the problem using the PEP-328, i was using the old kind of imports :s On Feb 4, 2010 10:10pm, Hidura wrote: Thanks i middle resolve the problem, and i going to read the PEP-366 i've been read the 328, i will kept informed of the progresses. Thanks again

Re: Problem with __init__.py in Python3.1

2010-02-04 Thread Hidura
Thanks i middle resolve the problem, and i going to read the PEP-366 i've been read the 328, i will kept informed of the progresses. Thanks again for the help [?] On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney > wrote: > "Gabriel Genellina" writes: > > > If you directly run a script from inside a

Re: Problem with __init__.py in Python3.1

2010-02-04 Thread Ben Finney
"Gabriel Genellina" writes: > If you directly run a script from inside a package, Python does not > know that it belongs to a package, and treats it as a simple, lonely > script. In that case, relative imports won't work. Which I consider to be a bug. Fortunately, it's already addressed in PEP 3

Re: Problem with __init__.py in Python3.1

2010-02-04 Thread Gabriel Genellina
ll glad to read opinions. [?] You say that Writer is a package, but apparently Python disagrees. A package is not just "a directory containing an __init__.py file", this is half the truth. Python must be *aware* of such file, and this happens when you import the package. If you d

Re: Problem with __init__.py in Python3.1

2010-02-04 Thread Hidura
contains Writer the second package, >> Writers >> contain the module tagmanip(What is imported in the best way inside the >> __init__.py of the Writer), when i make the import inside the writer >> everything is ok, but from the Utilities package the errors says: >> &qu

Re: Problem with __init__.py in Python3.1

2010-02-03 Thread Gabriel Genellina
the module tagmanip(What is imported in the best way inside the __init__.py of the Writer), when i make the import inside the writer everything is ok, but from the Utilities package the errors says: "ImportError: No module named tagsmanip". I don't understand why this is happening, if

Problem with __init__.py in Python3.1

2010-02-03 Thread Hidura
__init__.py of the Writer), when i make the import inside the writer everything is ok, but from the Utilities package the errors says: "ImportError: No module named tagsmanip". I don't understand why this is happening, if somebody could help me i will glad to hear any suggestion.

Re: imports in __init__.py

2009-12-26 Thread lotrpy
me’ is a module in that package, the module's namespace is > available to you via ‘packagename.modulename’. it looks that one need put the "import modulename" line in __init__.py or "import packagename.modulename" in the user clent script explicitly. or else, just '

Re: imports in __init__.py

2009-12-18 Thread Peter Otten
Phil wrote: > I wrote my last message late last night. When I said "I am unable to > import a module from the package without an import error.", I did mean > the 'modulename' module. > > However, I just set up a Debian VM with Python 2.5.2 and what I was > trying to do works. So it is either some

Re: imports in __init__.py

2009-12-18 Thread Phil
I wrote my last message late last night. When I said "I am unable to import a module from the package without an import error.", I did mean the 'modulename' module. However, I just set up a Debian VM with Python 2.5.2 and what I was trying to do works. So it is either something that changed with P

Re: imports in __init__.py

2009-12-18 Thread sKeeZe
I wrote my last message late last night. When I said "I am unable to import a module from the package without an import error.", I did mean the 'modulename' module. However, I just set up a Debian VM with Python 2.5.2 and what I was trying to do works. So it is either something that changed with P

Re: imports in __init__.py

2009-12-17 Thread Phil
x27;, it defines the 'application' class in 'application.py'. And in web's __init__.py it has... from application import * And in whatever app you are creating, it has... import web app = web.application(params) That being said, I can't get similar functi

Re: imports in __init__.py

2009-12-17 Thread Ben Finney
Phil writes: > I use distutils / setup.py to install 'packagename', where... > /packagename > __init__.py > modulename.py > > modulename.py has a class named 'classname'. As per PEP 8, it's best if user-defined classes are named with Titl

imports in __init__.py

2009-12-17 Thread Phil
I use distutils / setup.py to install 'packagename', where... /packagename __init__.py modulename.py modulename.py has a class named 'classname'. >From an arbitrary python module, I 'import packagename'. In said module, I want to use the 'classna

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

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 >> 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 programme

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 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 class per file. I.e.

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 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 local search-and-replace over just

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 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 misunderstood me. >> >> If there are

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 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 class per > file. > >> I.e.,

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
>>> feel the existence of module A and B. I want them feel exact like >>>> class A and B are defined in module 'test' instead of feeling two >>>> modules A and B are in package 'test'. >>> >>> >>> Inside test/__init__.py: &g

Identifiers exposed by a package (was: How to import only one module in a package when the package __init__.py has already imports the modules?)

2009-10-31 Thread Ben Finney
Robert Kern writes: > If you are going to expose symbols in your __init__.py, they should > not have the same name as any of the modules in the package. Would I be correct in assuming you make an exception for the package importing one of the modules in the package, and thereby makin

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 'spam.spam

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 > variable

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
;> class A and B are defined in module 'test' instead of feeling two >>> modules A and B are in package 'test'. >> >> >> Inside test/__init__.py: >> >> from A import A  # class A from file A.py >> from B import B  # class B from 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
something like 'from spam import spam' or 'spam.spam()', or accept that the filename is not the same as the class/function name. Inside test/__init__.py: from a import A # class A from file a.py from b import B # class B from file b.py If you are going to expose symbols in

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
nction per file? I.e., I have to use something like 'from spam import spam' or 'spam.spam()', or accept that the filename is not the same as the class/function name. Inside test/__init__.py: from a import A # class A from file a.py from b import B # class B from file b.py -- http://mail.python.org/mailman/listinfo/python-list

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 wrote: > Peng Yu wrote: >> >> On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland >> wrote: >> >>> >>> On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: >>> On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern wrote: >>> >>> [ snip ] >>> >>

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 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 functions are too > big and need

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 stran

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
parrot(): >    spam() >    ham() >    cheeseshop() > > > This is not an advantage! I would say this is the disadvantage of python, if there is no walkaround to avoid using 'from spam import spam'. As this can be handled in C++ with walkaround. So far the best soluti

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
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' instead of feeling two modules A >> and B

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
lass > A and B are defined in module 'test' instead of feeling two modules A > and B are in package 'test'. Inside test/__init__.py: from A import A # class A from file A.py from B import B # class B from file B.py or better still: from a import A # class A fro

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 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, n

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 wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern wrote: [ snip ] I know that multiple classes or functions are typically defined in one file (i.e. mod

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 wrote: > On Sat, Oct 31, 2009 at 18:29 -0500, Peng Yu wrote: >> On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland >> wrote: >> > On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: > >> > Are you serious? Do you *really* put each function in its o

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 se

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 > 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 the readability of 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 5:45 PM, Wolodja Wentland wrote: > On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: >> On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern wrote: > > [ snip ] > >> I know that multiple classes or functions are typically defined in one >> file (i.e. module in python). 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 Robert Kern
d to use different patterns. Of course, to really take advantage of that feature in C++ requires some careful coding and use of patterns like pimpl. That often negates any readability benefits. You could probably hack something (and people have), but it makes your code harder to understand becaus

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 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. Therefore, I insist o

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
what I am asking can be easily implemented, because the namespace and the directory hierachy is not bind to each other. However, the binding between the namespace and the directory hierachy make this difficult to implement. I don't know if it is not impossible, but I'd hope 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 Robert Kern
from having to figure out which you are referring to when reading the code. Personally, I like to keep my __init__.py files empty such that I can import exactly what I need from the package. This allows me to import exactly the module that I need. In large packages with extension modules that can be

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 wrote: > Peng Yu 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 >

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 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 import adds the

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 r

Re: PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread wgw
On Aug 15, 2:19 pm, Christian Heimes wrote: > wgw wrote: > > I don't understand why the __file__ value in my installation of PyQt > > would not give a proper, full path. > > > I'm guessing that I did not install pyqt properly (I'm on Ubuntu > > Hardy, trying to install QT4.5), but before redoing t

Re: PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread Christian Heimes
wgw wrote: I don't understand why the __file__ value in my installation of PyQt would not give a proper, full path. I'm guessing that I did not install pyqt properly (I'm on Ubuntu Hardy, trying to install QT4.5), but before redoing the install, I want to see if there is a quicker fix. Some ve

PyQt4.__file__ gives PyQt4/__init__.py as value

2009-08-15 Thread wgw
I don't understand why the __file__ value in my installation of PyQt would not give a proper, full path. I'm guessing that I did not install pyqt properly (I'm on Ubuntu Hardy, trying to install QT4.5), but before redoing the install, I want to see if there is a quicker fix. Also, though PyQt4/ i

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Carl Banks
On Feb 23, 5:41 pm, Michael Crute wrote: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? I know this is subjective so I'm just looking for the general > consensus. I've heard both sides of the story and I personally feel > its okay if the code

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
On Mon, Feb 23, 2009 at 9:41 PM, Benjamin Peterson wrote: > Michael Crute gmail.com> writes: >> On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden holdenweb.com> >> wrote: >> > No, it's absolutely fine. One common usage is to import symbols from >> > sub-modules so that they are available from a sim

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread alex23
convenience sake (as mentioned by Steve). I don't expect a class to define its method within its __init__, so I'd find it unusual for a package to be defining any kind of functionality within its __init__.py. I wouldn't _not_ use your code, but I might eye it warily... :) -- http://mai

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Ben Finney
Michael Crute writes: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? No, it's good form, but *only* for code that truly pertains to the entire package. Anything that can reasonably be in a module other than ‘__init__’, should be. That leaves the follo

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Benjamin Peterson
Michael Crute gmail.com> writes: > On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden holdenweb.com> > wrote: > > No, it's absolutely fine. One common usage is to import symbols from > > sub-modules so that they are available from a simple import of the package. > > Yeah, I use it often for that I'm

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden wrote: > Michael Crute wrote: >> Is it bad form (i.e. non-pythonic) to have code in your __init__.py >> files? I know this is subjective so I'm just looking for the general >> consensus. I've heard both sides of the sto

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Steve Holden
Michael Crute wrote: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? I know this is subjective so I'm just looking for the general > consensus. I've heard both sides of the story and I personally feel > its okay if the code pertains to the wh

Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
Is it bad form (i.e. non-pythonic) to have code in your __init__.py files? I know this is subjective so I'm just looking for the general consensus. I've heard both sides of the story and I personally feel its okay if the code pertains to the whole module but have an open mind about the

Re: __init__.py and package help

2009-01-05 Thread TechieInsights
> > > Simple example of what isn't working... > > Structure- > > > > pytest/ Root directory of package > > __init__.py- code: __all__ = ['folder'] > > folder/ Another folder in the package > > __init__.py- code: __all

Re: __init__.py and package help

2009-01-05 Thread J. Cliff Dyer
;t working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = ['folder'] > folder/ Another folder in the package > __init__.py- code: __all__ = ['hello'] > hello.py- code: print('He

Re: __init__.py and package help

2009-01-05 Thread TechieInsights
documents I could find. I am > running Python 2.6 on windows. The problem I am having with packages > is that they don't show up! > > Simple example of what isn't working... > Structure- > > pytest/ Root directory of package > __init__.py- code: __all__ = [&#x

__init__.py and package help

2009-01-05 Thread TechieInsights
Ok I have read all of the tutorials and documents I could find. I am running Python 2.6 on windows. The problem I am having with packages is that they don't show up! Simple example of what isn't working... Structure- pytest/ Root directory of package __init__.py- code: __all__

Re: getting error...... Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\xlrd\__init__.py", line 370, in open_workbook biff_version = bk.getb

2008-12-10 Thread JodyGnumeric
>>> import xlrd > > > > >>>> book=xlrd.open_workbook("C:\\a.xls") > > > > > > i am getting the following error.. > > > > > > *Traceback (most recent call last): > > > > >   File "", line 1, in >

Re: getting error...... Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\xlrd\__init__.py", line 370, in open_workbook biff_version = bk.getb

2008-12-08 Thread John Machin
; > > > > i am getting the following error.. > > > > > *Traceback (most recent call last): > > > >   File "", line 1, in > > > >   File "C:\Python25\Lib\site-packages\xlrd\__init__.py", line 370, in > > > > open_w

  1   2   >