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
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
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
-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
> 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
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
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
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
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
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
> 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 =
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.
> 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
> 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
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):
>
> 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
16 matches
Mail list logo