473,805 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Explicit or general importing of namespaces?

Is there really a major performance difference between doing the
following:

import Tkinter as TK

TK.Label(yada yada)

OR

from Tkinter import *

Label(yada yada)

I'm unable to tell a real difference other than in the code writing
:-).

Thanks,

Harlin

Jul 18 '05
10 1430
I think the bottom line on this is using your own sense of risk/reward with
each given module imported. Some modules (Tkinter comes to mind) it makes
sense to pollute while others it doesn't.

Harlin

"Peter Hansen" <pe***@engcorp. com> wrote in message
news:4K******** ************@po wergate.ca...
Peter Mayne wrote:
Peter Hansen wrote:
and it's still a bad idea in almost all cases anyway


Since I've been playing with PyQt lately...

Is qt not one of the "almost all" cases? From the limited number of
examples I've seen, it seems to be common to do

from qt import *


This sort of thing seems common amongst large frameworks such
as PyQt or wxPython. This is unfortunate, IMHO, though it isn't
really a serious concern for most users.

I'm grateful that the most recent versions of wxPython have
abandoned that approach in favour of a nice clean "import wx",
and as far as I can tell the code does not suffer as a result,
and gains substantially in clarity. Maybe the "qt" module
defines far fewer names than the "wx" module does, but I for
one am glad not to have to worry that I won't accidentally
conflict with the hundreds that are there (in wx), nor to
worry that my code lacks in readability.
Since most of the imported names start with "Q", are called QLabel,
QSlider, etc, and are generally recognisable in context, this would seem
to be a reasonable case of namespace pollution.

I'm certainly not arguing with the general premise, just wondering if qt
is one of the sensible exceptions.


If not sensible, at least fairly widely accepted, not a serious
impediment to effective use, and definitely not without precedent.

-Peter

Jul 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2410
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In some cases there is a further complication: module importing through an indirect mechanism, like: exec "from " + xxx + " import *". A part the fact that I have not understood the "real" difference between import and from ... import (or also from......
1
2238
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse some of these master complex and simple types. This I believe will assist me in transforming between the master schema and the other smaller schemas that contain a subset of the elements in the master schema. I understand that I can import an...
8
4804
by: Ferdi Smit | last post by:
I've never understood the rationale of allowing partial, but not explicit specialization for classes at non-namespace scope. Ie.: struct A { template <typename T1, typename T2> struct B {}; // this is not allowed: template <> struct B<int, float> {};
2
2476
by: Jeff S | last post by:
I have the following three lines at the very top of a class file (prior to the namespace declaration line). using System; using System.Data; using System.Data.SqlClient; Then, in a subsequent function in the same file I want to create a connection by entering the following line: SqlClient.SqlConnection cn = new
29
4251
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Caching;
5
10360
by: Christoffer | last post by:
Hi, I'm having trouble with namespaces when importing nodes. I'd like to get this output: <exampleRoot xmlns="http://mynamespace"> <row Lsm_Info="ABC123" /> <row Lsm_Info="DEF456" /> </exampleRoot> But instead I'm getting:
6
9009
by: John Kotuby | last post by:
Hi all, I am simply trying to include the Option Explicit declaration at the top of an ASP page and am getting an error: Error Type: Microsoft VBScript compilation (0x800A0400) Expected statement /transferkey.asp, line 2
1
1522
pbmods
by: pbmods | last post by:
Today marks the 85% mark of about a week of trying to learn SOAP, while the client is furious and demanding to know when his site will be done. I finally figured out why the server kept throwing NullReferenceExceptions in my face. The SOAP client I was using formatted its requests using explicit namespaces. E.g., <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://mynamespace.tld"> . .
1
4197
by: ARC | last post by:
Ok, this is strange. I created a new database and imported all objects from the old program file. Form some reason, the option explicit statement is no longer showing in my code modules (and I would assume any form modules as well). However, even though in the vb code window, under options,, the option "Require variable declaration" IS checked. Any ideas how to restore the Option Explicit option to all my modules? I never used to have...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.