Re: [Tutor] importing modules and packages

2011-10-31 Thread neubyr
On Mon, Oct 31, 2011 at 4:38 AM, Steven D'Aprano wrote: > neubyr wrote: >> >> Is it possible to tell whether import statement is importing a module >> or package?  I am going through some example code with some import >> statements - like 'import os, sys, time', 'import packed'. I know os, >> sys

Re: [Tutor] importing modules and packages

2011-10-31 Thread Steven D'Aprano
neubyr wrote: Is it possible to tell whether import statement is importing a module or package? I am going through some example code with some import statements - like 'import os, sys, time', 'import packed'. I know os, sys and time are (built-in) modules and 'packed' is a package here . But can

Re: [Tutor] Importing Modules

2006-04-25 Thread Kent Johnson
John Connors wrote: > G'day, > > I'm having trouble understanding the difference between, > > import sys > and > from sys import * The second style is strongly discouraged. As Alan pointed out, it can lead to surprises when you import more than you expect. I was once surprised to find out that

Re: [Tutor] Importing Modules

2006-04-24 Thread ->Terry<-
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tomorrow (Apr 25, 2006) at 8:53am, John Connors spoke these wise words: - ->G'day, - -> - ->I'm having trouble understanding the difference between, - -> - ->import sys - ->and - ->from sys import * - -> - ->It seems to me they both do the same thing

Re: [Tutor] Importing Modules

2006-04-24 Thread Alan Gauld
> I'm having trouble understanding the difference between, > > import sys This brings the *name* "sys" into your module. It does not give you access to any of the names inside sys itself (such as exit for example). To access those you need to prefix them with sys, as in sys.exit() > from sys im

Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Bill Campbell
On Fri, Oct 07, 2005, Kent Johnson wrote: >Pierre Barbier de Reuille wrote: >> (never import >> a module in a small function likely to be called in an inner-loop !) > >That's good advice, but I would say "in a *time-critical* inner-loop". After >the first import, importing a module is fast, it is

Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Kent Johnson
Pierre Barbier de Reuille wrote: > (never import > a module in a small function likely to be called in an inner-loop !) That's good advice, but I would say "in a *time-critical* inner-loop". After the first import, importing a module is fast, it is just a few dictionary lookups (looking up the m

Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Pierre Barbier de Reuille
Kent Johnson a écrit : > Daniel Watkins wrote: > >[...] > >>However, someone (I don't recall who) said that there were occasions >>when it would be appropriate to import modules the former way. I was >>just wondering under what circumstances importing should be done this >>way? > > > That was

Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Eric Walker
That was me using the import within the class. I only did it due to my ignorance. I am not advanced enough to use it like that and know what I am doing, so as suggested I just moved all of my imports to the top. Python Newbie. On Thursday 06 October 2005 08:21 pm, Kent Johnson wrote: > Danie

Re: [Tutor] Importing Modules Within Classes

2005-10-06 Thread Kent Johnson
Daniel Watkins wrote: > Recently, there has been an example of someone importing modules within > a class definition. eg: > > class Exemplar: > import re > ...use re... > > It seems obvious to me that this is incorrect, though more through > training than actual observation on my part

Re: [Tutor] Importing modules/classes

2005-09-16 Thread Jacob S.
> You need to call the init method of the inherited class(es) from > within your init. It's conventional to call the superclass > constructor > before doing your own initialisation so it should look like: > >def __init__(self, num): >Thread.__init__(self) >print "__init__: Num =

Re: [Tutor] Importing modules/classes

2005-08-25 Thread Johan Geldenhuys
thread.start() AssertionError: Thread.__init__() not called >>> Which __init__ method is it referring to? Thanks in advance for your help (and time). U guys are awesome :) -Original Message- From: Danny Yoo [mailto:[EMAIL PROTECTED] Sent: Thursday, 25 August 2005 12:17 p.m.

Re: [Tutor] Importing modules/classes

2005-08-25 Thread Alan Gauld
> class show_num(threading.Thread): > >def __init__(self, num): >print "__init__: Num = ", num > > show_num_thread = show_num(742) > show_num_thread.start() > > ---><- > > Throws an error > > __init__: Num = 742 > > Traceback (most recent call last): > File "H:/Docs/PyScripts

Re: [Tutor] Importing modules/classes

2005-08-24 Thread Alan G
> Am trying to get my head around classes in python. Looks like you have the classes bit figured out! :-) > import dummy_class > d=dummy_class() But you have a problem with namespaces. the class 'dummy_class' is inside the module 'dummy_class' So when you import the module that allows you to

Re: [Tutor] Importing modules/classes

2005-08-24 Thread Hans Dushanthakumar
or your help (and time). U guys are awesome :) -Original Message- From: Danny Yoo [mailto:[EMAIL PROTECTED] Sent: Thursday, 25 August 2005 12:17 p.m. To: Hans Dushanthakumar Cc: Tutor Subject: Re: [Tutor] Importing modules/classes > class dummy_class: > def __init__(self): >

Re: [Tutor] Importing modules/classes

2005-08-24 Thread Danny Yoo
> class dummy_class: > def __init__(self): > print "__init__" > > def run(self): > print "run" > > > Now, I have another file test_dummy.py, which only has the foll 2 lines > > import dummy_class > d=dummy_class() Hi Hans, In Python, modules are containers. They can co