Re: module import questions and question about pytest and module imports

2014-12-08 Thread Ian Kelly
On Sun, Dec 7, 2014 at 9:50 AM, sam pendleton wrote: > Having to put the garage package on the sys.path seems a little off, > why wouldn't relative imports work? Relative imports are relative to a package's hierarchy of namespaces, not relative to the file system. As such, you can't perform a rel

Re: module import questions and question about pytest and module imports

2014-12-08 Thread Jean-Michel Pichavant
- Original Message - > From: "sam pendleton" > Having to put the garage package on the sys.path seems a little off, > why wouldn't relative imports work? > > Do most people somehow put their packages in sys.path when bundling > their python packages up to be shared with setuptools or othe

Re: module import questions and question about pytest and module imports

2014-12-08 Thread Dave Angel
On 12/07/2014 11:50 AM, sam pendleton wrote: Thanks for getting back with me! On Sun, Dec 7, 2014 at 11:26 AM, Dave Angel wrote: On 12/05/2014 11:50 PM, sam pendleton wrote: garage/ |- __init__.py |- cars/ |- __init__.py |- hummer.py tests/ |- test_cars.

Re: module import questions and question about pytest and module imports

2014-12-08 Thread sam pendleton
Thanks for getting back with me! On Sun, Dec 7, 2014 at 11:26 AM, Dave Angel wrote: > On 12/05/2014 11:50 PM, sam pendleton wrote: >> >> garage/ >> |- __init__.py >> |- cars/ >> |- __init__.py >> |- hummer.py >> tests/ >> |- test_cars.py >> >> at the top of test_c

Re: module import questions and question about pytest and module imports

2014-12-07 Thread Dave Angel
On 12/05/2014 11:50 PM, sam pendleton wrote: garage/ |- __init__.py |- cars/ |- __init__.py |- hummer.py tests/ |- test_cars.py at the top of test_cars.py, there is this: from garage.cars import hummer pytest is on this import statement, so i guess it's inc

module import questions and question about pytest and module imports

2014-12-07 Thread sam pendleton
garage/ |- __init__.py |- cars/ |- __init__.py |- hummer.py tests/ |- test_cars.py at the top of test_cars.py, there is this: from garage.cars import hummer pytest is on this import statement, so i guess it's incorrect. what should it be? if i open a python repl

Map-based module imports with import hook

2011-08-01 Thread mpj
Hi, I've experience working at companies where, because of the network set up, having a long PYTHONPATH and searching it is quite a heavy task and can slow down the start up of the interpreter when there are lots of imports. As a proof of concept I wanted to look at a map-based approach. The theo

Re: module imports and st_mtime

2009-11-10 Thread Aahz
In article , tow wrote: > >Does anyone have any ideas what might be going on, or where further to >look? I'm at a bit of a loss. Try asking on pythonmac-...@python.org -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers

Re: module imports and st_mtime

2009-11-04 Thread Carl Banks
On Nov 4, 4:08 pm, tow wrote: > Does anyone have any ideas what might be going on, or where further to > look? I'm at a bit of a loss. Does Mac OS have a concept of process-local filesystem modification? I.e. when loading the library does it create a process-local copy of the file with an updated

module imports and st_mtime

2009-11-04 Thread tow
I'm seeing a very strange effect which is confusing me - in brief, one python process appears to temporarily affect the os.stat results of another - perhaps someone can enlighten me. This is on Mac OS X Leopard, using the system python (2.5) The issue arises using Django. The default Django http

Re: confusion about package/module imports

2008-01-01 Thread Scott David Daniels
Jugdish wrote: > Thanks very much for your helpful response! > >> You'll see that b is executed (making module __main__), >> (1) it imports pkg.subpkg.a, >> (2) which is accomplished by importing pkg (successfully), >> (3)then by importing pkg.subpkg >> (4)

Re: confusion about package/module imports

2008-01-01 Thread Jugdish
Thanks very much for your helpful response! > You'll see that b is executed (making module __main__), > (1) it imports pkg.subpkg.a, > (2) which is accomplished by importing pkg (successfully), > (3)then by importing pkg.subpkg > (4) which imports pkg

Re: confusion about package/module imports

2008-01-01 Thread Scott David Daniels
Jugdish wrote: > Why doesn't the following work? > ... [well boiled-down code skipped] setenv PYTHONPATH $HOME:$PYTHONPATH python $HOME/pkg/subpkg/b.py > Traceback (most recent call last): > File "pkg/subpkg/b.py", line 1, in ? > import pkg.subpkg.a > File "$HOME/pkg/subpkg/__

confusion about package/module imports

2008-01-01 Thread Jugdish
Why doesn't the following work? >>> ls $HOME $HOME/pkg/__init__.py $HOME/pkg/subpkg/__init__.py $HOME/pkg/subpkg/a.py $HOME/pkg/subpkg/b.py >>> cat $HOME/pkg/__init__.py # empty >>> cat $HOME/pkg/subpkg/__init__.py import a import b >>> cat $HOME/pkg/subpkg/a.py class A: pass >>> cat $HOME

Re: Automatically organize module imports

2007-10-17 Thread Andrew Durdin
On 10/15/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > Pyflakes will tell you which imports aren't being used (among other > things). I don't know if an existing tool which will automatically > rewrite your source, though. I'll second that recommendation of Pyflakes -- as the interpreter

Re: Automatically organize module imports

2007-10-16 Thread Alexandre Badez
On Oct 16, 12:08 pm, Thomas Wittek <[EMAIL PROTECTED]> wrote: > Great. It has a warning about unused imports. Perfect. > (Though, it was a bit tricky to install as easy_install didn't get the > dependencies right on Win XP) > > Thank you! > -- > Thomas Wittek > Web:http://gedankenkonstrukt.de/ > Ja

Re: Automatically organize module imports

2007-10-16 Thread Thomas Wittek
Alexandre Badez: > If you're using Eclipse + PyDev, I strongly recommend you to give a > try to PyLint ("http://www.logilab.org/857";). Great. It has a warning about unused imports. Perfect. (Though, it was a bit tricky to install as easy_install didn't get the dependencies right on Win XP) Thank

Re: Automatically organize module imports

2007-10-16 Thread Alexandre Badez
On Oct 16, 8:52 am, Thomas Wittek <[EMAIL PROTECTED]> wrote: > Jean-Paul Calderone: > > > On Mon, 15 Oct 2007 20:52:11 +0200, Thomas Wittek > > <[EMAIL PROTECTED]> wrote: > >> Is there a tool that can organize my import section? > > > Pyflakes will tell you which imports aren't being used (among ot

Re: Automatically organize module imports

2007-10-15 Thread Thomas Wittek
Jean-Paul Calderone: > On Mon, 15 Oct 2007 20:52:11 +0200, Thomas Wittek > <[EMAIL PROTECTED]> wrote: >> Is there a tool that can organize my import section? > > Pyflakes will tell you which imports aren't being used (among other > things). I don't know if an existing tool which will automaticall

Re: Automatically organize module imports

2007-10-15 Thread Jean-Paul Calderone
On Mon, 15 Oct 2007 20:52:11 +0200, Thomas Wittek <[EMAIL PROTECTED]> wrote: >Hi! > >Is there any possibility/tool to automatically organize the imports at >the beginning of a module? > >I don't mean automatic imports like autoimp does as I like seeing where >my objects/functions really come from.

Automatically organize module imports

2007-10-15 Thread Thomas Wittek
Hi! Is there any possibility/tool to automatically organize the imports at the beginning of a module? I don't mean automatic imports like autoimp does as I like seeing where my objects/functions really come from. For the same reason I don't like "from foo import *". The downside is that you have

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Gabriel Genellina
En Wed, 05 Sep 2007 11:45:11 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribi�: > Thank you for the explanation > > It seems that python behaves different for variables created in the > toplevel namespace, versus deeper namespaces. Yes. Older Python versions had only two scopes: local and g

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Peter Otten
Am Wed, 05 Sep 2007 14:45:11 + schrieb [EMAIL PROTECTED]: > So now get back to my exec code in the previous post. > The exec applies a mixture of both rules > 1. The exec looks at its namespace to apply the rule for globals(). > Since I'm not at top-level, variables are not auto-populated in t

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread [EMAIL PROTECTED]
Hi Thank you for the explanation It seems that python behaves different for variables created in the toplevel namespace, versus deeper namespaces. CODE: def g(): a=2 print "a in LOC:",locals().has_key('a') print "a in GLO:",globals().has_key('a') def f(): print "a in LOC:",locals().

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Peter Otten
Am Wed, 05 Sep 2007 13:12:24 + schrieb [EMAIL PROTECTED]: > I am completely puzzled why the following exec code does not work: > > mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" > def execute(): > exec mycode > execute() > > > I get the error: > > [EMAIL PROTECTED]

Re: python exec behaves inconsistent with respect to module imports

2007-09-05 Thread Daniel Larsson
On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello > > I am completely puzzled why the following exec code does not work: > > mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" > def execute(): > exec mycode > execute() > > > I get the error: > > [EMAIL PROTECTED

python exec behaves inconsistent with respect to module imports

2007-09-05 Thread [EMAIL PROTECTED]
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\nprint math.floor(y)\nf(3.14)" def execute(): exec mycode execute() I get the error: [EMAIL PROTECTED]:/opt/qbase# python error1.py Traceback (most recent call last): File "error

Re: Module imports during object instantiation

2007-08-16 Thread Ritesh Raj Sarraf
Steve Holden wrote: > Ritesh Raj Sarraf wrote: >> On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: >>> On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>> > [...] >> Oops!!! Looks like I completely missed this. It _did_ print the error >> message. >> Apologies to all

Re: Module imports during object instantiation

2007-08-15 Thread Steve Holden
Ritesh Raj Sarraf wrote: > On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: >> On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> [...] > Oops!!! Looks like I completely missed this. It _did_ print the error > message. > Apologies to all for not keeping a close eye on

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
On Aug 16, 12:16 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > > > Or am I terribly missing something that you are trying to tell ? > > > I didn't see log = Log() in

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > > Or am I terribly missing something that you are trying to tell ? > > I didn't see log = Log() in your example. Sorry for the > excursion. > > Are you sure os.name is 'posix

Re: Module imports during object instantiation

2007-08-15 Thread Neil Cerutti
On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > >>> >>> Doesn't __init__ get called automatically ? >> >> It gets called automatically when you construct an instance of >> the class in which it's defined. > > I am a little confused by your statements now. > > In

Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
Neil Cerutti wrote: >> >> Doesn't __init__ get called automatically ? > > It gets called automatically when you construct an instance of > the class in which it's defined. I am a little confused by your statements now. In my earlier posts in the same thread, I gave some code example which was s

Re: Module imports during object instantiation

2007-08-14 Thread Neil Cerutti
On 2007-08-14, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > >> If you want an import inside an __init__ to run, you must call >> the __init__ function that contains it. > > Doesn't __init__ get called automatically ? It gets called automatically when you construct an instan

Re: Module imports during object instantiation

2007-08-14 Thread Ritesh Raj Sarraf
Neil Cerutti wrote: > If you want an import inside an __init__ to run, you must call > the __init__ function that contains it. Doesn't __init__ get called automatically ? I thought __init__ was required to be called explicitly only when you were doing inheritance and wanted to pass separate value

Re: Module imports during object instantiation

2007-08-14 Thread Neil Cerutti
On 2007-08-14, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Bruno Desthuilliers wrote: > What's leading you to conclude the import isn't being executed? You realise, I trust, that the module's code will only be executed on the first call to __init__()? >>> >>> Well. Putting i

Re: Module imports during object instantiation

2007-08-14 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: >>> What's leading you to conclude the import isn't being executed? You >>> realise, I trust, that the module's code will only be executed on the >>> first call to __init__()? >>> >> >> Well. Putting it in a "try" inside __init__() doesn't do anything. > > This would b

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Steve Holden wrote: (snip) >> What's leading you to conclude the import isn't being executed? You >> realise, I trust, that the module's code will only be executed on the >> first call to __init__()? >> > > Well. Putting it in a "try" inside __init__() doesn't do an

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Bruno Desthuilliers wrote: > >> Ritesh Raj Sarraf a écrit : >>> if lock is None or lock != 1: >>> self.DispLock = False >>> else: >>> self.DispLock = threading.Lock() >>> self.lock = True >>> >>> if os.name =

Re: Module imports during object instantiation

2007-08-14 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Bruno Desthuilliers wrote: > >> Ritesh Raj Sarraf a écrit : >> >> The initializer will be called *each time* you instanciate the class. >> And nothing prevents client code from calling it explicitelly as many >> times as it wants - ok, this would be rather strange, b

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
s that I have in the module. Not everything from the top level imports is required for the class Log (Say, just one module is what is required). So when I do a `from module import Log`, do all the modules at the top level get imported? My understanding says Yes, and if that's true, that's ba

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: > Ritesh Raj Sarraf a écrit : > > The initializer will be called *each time* you instanciate the class. > And nothing prevents client code from calling it explicitelly as many > times as it wants - ok, this would be rather strange, but this is still > technically possi

Re: Module imports during object instantiation

2007-08-13 Thread Ritesh Raj Sarraf
Bruno Desthuilliers wrote: > Ritesh Raj Sarraf a écrit : >> >> if lock is None or lock != 1: >> self.DispLock = False >> else: >> self.DispLock = threading.Lock() >> self.lock = True >> >> if os.name == 'posix': >>self.platf

Re: Module imports during object instantiation

2007-08-13 Thread Steve Holden
Ritesh Raj Sarraf wrote: > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: > self.VERBOSE = True >

Re: Module imports during object instantiation

2007-08-13 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > On Aug 11, 3:17 am, James Stroud <[EMAIL PROTECTED]> wrote: >> You do realize your import statement will only be called for nt and dos >> systems don't you? >> > > Yes. I would like to load a Windows Python Module (which is, say a > specific implementation for Windows

Re: Module imports during object instantiation

2007-08-13 Thread Bruno Desthuilliers
Ritesh Raj Sarraf a écrit : > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: Don't use an identity test here. There

Re: Module imports during object instantiation

2007-08-11 Thread Ritesh Raj Sarraf
On Aug 11, 3:17 am, James Stroud <[EMAIL PROTECTED]> wrote: > You do realize your import statement will only be called for nt and dos > systems don't you? > Yes. I would like to load a Windows Python Module (which is, say a specific implementation for Windows only) in such a condition where I find

Re: Module imports during object instantiation

2007-08-10 Thread James Stroud
Ritesh Raj Sarraf wrote: > Hi, > > I've been very confused about why this doesn't work. I mean I don't see any > reason why this has been made not to work. > > class Log: > > def __init__(self, verbose, lock = None): > > if verbose is True: > self.VERBOSE = True >

Module imports during object instantiation

2007-08-10 Thread Ritesh Raj Sarraf
Hi, I've been very confused about why this doesn't work. I mean I don't see any reason why this has been made not to work. class Log: def __init__(self, verbose, lock = None): if verbose is True: self.VERBOSE = True else: self.VERBOSE = False if lock is

Re: Module imports fine from interactive, not from script

2007-05-24 Thread Joshua J. Kugler
On Thursday 24 May 2007 08:32, Steve Holden wrote: > The directory containing the script you are executing is also added to > sys.path. Since you are executing a script called planet ... Ah! That's it. That had never occurred to me, as I was under the impression that your current *working* direct

Re: Module imports fine from interactive, not from script

2007-05-24 Thread Steve Holden
Joshua J. Kugler wrote: > Yes, I've read this: > http://mail.python.org/pipermail/python-list/2006-August/395943.html > That's not my problem. > > I installed PlanetPlanet via the > package's "setup.py install" command (as root). planet.py will not run, > however, g

Re: Module imports fine from interactive, not from script

2007-05-24 Thread Paul Moore
On 23 May, 02:20, "Joshua J. Kugler" <[EMAIL PROTECTED]> wrote: > Yes, I've read > this:http://mail.python.org/pipermail/python-list/2006-August/395943.html > That's not my problem. > > I installed PlanetPlanet via the > package's "setup.py install" command (as root)

Module imports fine from interactive, not from script

2007-05-24 Thread Joshua J. Kugler
Yes, I've read this: http://mail.python.org/pipermail/python-list/2006-August/395943.html That's not my problem. I installed PlanetPlanet via the package's "setup.py install" command (as root). planet.py will not run, however, giving me this error: Traceback (most

Re: Module imports

2006-01-30 Thread Gary Herron
[EMAIL PROTECTED] wrote: >I have written a number of functions and stored them in a file named >myFunctions.py. This keeps all my functions under one roof, and if I >want to use or one or more of them in a program, I can start the >program off with > >from myFunctions import f1,f2 > >Some of these

Module imports

2006-01-30 Thread tkpmep
I have written a number of functions and stored them in a file named myFunctions.py. This keeps all my functions under one roof, and if I want to use or one or more of them in a program, I can start the program off with from myFunctions import f1,f2 Some of these functions require various math ro

Re: Cross-module imports?

2006-01-23 Thread Matthias Kaeppler
Ant wrote: > If you have to trick the compiler like this though, I'd take a good > look at *why* you want to couple the modules so tightly in the first > place! Yeah, you're right. I think loosening up the coupling by introducing a module which holds common shared data is probably a good idea any

Re: Cross-module imports?

2006-01-23 Thread Ant
You are always likely to have problems of one sort or another if you are using circular references like this. It would be a much better situation redesigning your modules so that they didn't depend on each other. The interpreter is complaining, since it is trying to compile A, hits the line 'impor

Cross-module imports?

2006-01-22 Thread Matthias Kaeppler
Hi, I am getting strange errors when I am importing modules cross-wise, like this: # module A import B var1 = "x" B.var2 = "y" # module B import A var2 = "z" print A.var1 The error messages are not even sane, for example the interpreter complains about not finding 'var1' in module A. Is ther

Re: Mutual module imports

2005-10-17 Thread George Sakkis
"Tony Nelson" <[EMAIL PROTECTED]> wrote: > [snipped] > > I have written a Python module that uses some C functions. I wrote the > module in two parts, one Python, one Pyrex (C). They need to share some > globals. > > [snipped] > > Now the Python modu

Re: Mutual module imports

2005-10-17 Thread Tuvas
The trick is via something called Extending. Pyrex just makes extending a bit easier, but, depending on the complexity of the function, it might be easier just to extend it yourself. Basically you make a function that translates python into C. There are some instructions on the Python website, http

Mutual module imports

2005-10-17 Thread Tony Nelson
What happened reminded me that there are also other ways modules can be imported under different names, so I tried a different approach. Now the Python module imports the Pyrex module and just shoves references to its globals into the Pyrex module (the Pyrex module defines them as None). T

Re: module imports and memory usage

2004-12-01 Thread Carlos Ribeiro
On Tue, 30 Nov 2004 16:46:43 -0500, Brad Tilley <[EMAIL PROTECTED]> wrote: > I discovered that when I wrap my code up in a function def and call it > that it uses around 4.6 MB of RAM all the time... even while sleeping. > However, when I don't put it in a function def it uses around 2.6MB of > dat

Re: module imports and memory usage

2004-11-30 Thread Brad Tilley
Brad Tilley wrote: When memory usage is a concern, is it better to do: from X import Y or import X Also, is there a way to load and unload modules as they are needed. I have some scripts that sleep for extended periods during a while loop and I need to be as memory friendly as possible. I can pos

Re: module imports and memory usage

2004-11-30 Thread David Bolen
Brad Tilley <[EMAIL PROTECTED]> writes: > When memory usage is a concern, is it better to do: > > from X import Y > > or > > import X Depending on "Y", the latter can technically use less memory, but it's likely to be fairly small and depends on how many symbols from that module you want to ha

Re: module imports and memory usage

2004-11-30 Thread Brad Tilley
Jp Calderone wrote: On Tue, 30 Nov 2004 10:02:27 -0500, Brad Tilley <[EMAIL PROTECTED]> wrote: When memory usage is a concern, is it better to do: from X import Y or import X There is no difference. If you are concerned about memory usage, you probably need to take a look at the data structure

Re: module imports and memory usage

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 10:02:27 -0500, Brad Tilley <[EMAIL PROTECTED]> wrote: >When memory usage is a concern, is it better to do: > > from X import Y > > or > > import X There is no difference. If you are concerned about memory usage, you probably need to take a look at the data structures ho

Re: module imports and memory usage

2004-11-30 Thread Istvan Albert
Brad Tilley wrote: Also, is there a way to load and unload modules as they are needed. I have some scripts that sleep for extended periods during a while loop and I need to be as memory friendly as possible. I can post a detailed script that currently uses ~ 10MB of memory if anyone is interest

module imports and memory usage

2004-11-30 Thread Brad Tilley
When memory usage is a concern, is it better to do: from X import Y or import X Also, is there a way to load and unload modules as they are needed. I have some scripts that sleep for extended periods during a while loop and I need to be as memory friendly as possible. I can post a detailed scrip