For Python developers around. From Python 2.5 doc:
The list of base classes in a class definition can now be empty. As an
example, this is now legal:
class C():
pass
nice but why this syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
Old-style class are somewhat deprecated and could be almost always be
replaced by new-style class, so this syntax could be a nice shortcut to
create them.
Am I wrong or is there something that I've missed ? 38 2048
looping wrote: For Python developers around.
From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass
nice but why this syntax return old-style class, same as "class C:", and not the new style "class C(object):" ? Old-style class are somewhat deprecated and could be almost always be replaced by new-style class, so this syntax could be a nice shortcut to create them.
Am I wrong or is there something that I've missed ?
class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
Georg
Georg Brandl wrote: class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone
is bothering with a change that involves a part of the language that is
effectively deprecated. In other words, class(): never used to be
valid, so why make it valid now?
-Peter
Peter Hansen wrote: Georg Brandl wrote: class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone is bothering with a change that involves a part of the language that is effectively deprecated. In other words, class(): never used to be valid, so why make it valid now?
I don't recall that, you'll have to search the python-dev archives.
Georg
Peter Hansen wrote: Georg Brandl wrote: class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone is bothering with a change that involves a part of the language that is effectively deprecated. In other words, class(): never used to be valid, so why make it valid now?
-Peter
Exact.
But I think that if we make "class C():" a synonym of "class
C(object):", it will save lot of keystrokes ;-)
So I think the idea is great but the result is not actually very
usefull.
Delphi (Pascal?) use almost the same concept:
TTest = class
is a synonym of
TTest = class(TObject)
looping wrote: Peter Hansen wrote:
Georg Brandl wrote:
class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone is bothering with a change that involves a part of the language that is effectively deprecated. In other words, class(): never used to be valid, so why make it valid now?
-Peter
Exact. But I think that if we make "class C():" a synonym of "class C(object):", it will save lot of keystrokes ;-)
Since the class statement without superclass actually creates an
old-style class, I'd expect the "class MyClass():" variant to behave
the same. Sacrifying readability and expliciteness just to save half a
dozen keystrokes is not pythonic IMHO.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
bruno at modulix>Since the class statement without superclass actually
creates an old-style class, I'd expect the "class MyClass():" variant
to behave the same.<
In Python 3.0 I really hope the
class C: pass
class C(): pass
class C(object): pass
will mean the same thing. (So in Python 2.5 the second version can be
made to mean the same thing of the third).
Bye,
bearophile
bruno at modulix wrote: looping wrote: Peter Hansen wrote:
Georg Brandl wrote:
class C():
is meant to be synonymous with
class C:
and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone is bothering with a change that involves a part of the language that is effectively deprecated. In other words, class(): never used to be valid, so why make it valid now?
-Peter
Exact. But I think that if we make "class C():" a synonym of "class C(object):", it will save lot of keystrokes ;-)
Since the class statement without superclass actually creates an old-style class, I'd expect the "class MyClass():" variant to behave the same. Sacrifying readability and expliciteness just to save half a dozen keystrokes is not pythonic IMHO.
I don't think readability suffer and expliciteness could sometimes be
sacrified to simplify the life of developer: ex "abcd"[0:3] ->
"abcd"[:3].
And for newbies, the somewhat magic behavior of the "object" superclass
is not so clear even that it is very explicit.
When I write script I don't use new-style class cause is bother me to
type "(object)" when I don't need their features. But in an other hand,
I believe that new-style class are faster to instanciate (maybe I'm
wrong...).
So this new syntax is a good way to boost their uses without bother
with compatibility of existing code IMHO.
Well I stop to argue now and let Python Dev make their (very good) job.
looping wrote: Peter Hansen wrote: Georg Brandl wrote: > class C(): > > is meant to be synonymous with > > class C: > > and therefore cannot create a new-style class.
I think "looping" understands that, but is basically asking why anyone is bothering with a change that involves a part of the language that is effectively deprecated. In other words, class(): never used to be valid, so why make it valid now?
-Peter
Exact. But I think that if we make "class C():" a synonym of "class C(object):", it will save lot of keystrokes ;-)
If you have many classes in a module, putting
__metaclass__ = type
at the top can save you these keystrokes.
Georg
Em Ter, 2006-04-11 Ã*s 06:49 -0700, looping escreveu: But in an other hand, I believe that new-style class are faster to instanciate (maybe I'm wrong...).
$ python2.4 -m timeit -s 'class x: pass' 'x()'
1000000 loops, best of 3: 0.435 usec per loop
$ python2.4 -m timeit -s 'class x(object): pass' 'x()'
1000000 loops, best of 3: 0.316 usec per loop
--
Felipe. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: beliavsky |
last post by:
Ideally, one can use someone's C++ code by just looking at the header
files
(which should contain comments describing the functions in addition to
function definitions), without access to the full source code. Can
analogs of C++ header files be created for Python code?
Python "header" files could list only the 'def' statements and
docstrings of Python functions and classes, but that does not tell you
what the functions return. One could...
|
by: Alex Stapleton |
last post by:
Whenever I run python I get
"Warning! you are running an untested version of Python."
prepended to the start of any output on stdout.
This is with Debian and python 2.3 (running the debian 2.1 and 2.2 binaries
doesn't have this effect)
Does anyone have any idea how to stop this or have even seen it before?
|
by: Jordan Rastrick |
last post by:
First, a disclaimer. I am a second year Maths and Computer Science
undergraduate, and this is my first time ever on Usenet (I guess I'm
part of the http generation). On top of that, I have been using Python
for a grand total of about a fortnight now. Hence, I apologise if what
follows is a stupid suggestion, or if its already been made somewhere
else, or if this is not the appropriate place to make it, etc. But I
did honestly do some...
|
by: jeffbernstein |
last post by:
Greetings.
I'm reading "How to think like a computer scientist: Learning with
Python" and there's a question regarding string operations. The
question is, "Can you think of a property that addition and
multiplication have that string concatenation and repetition do not?"
I thought it was the commutative property but "<string>"*3 is
equivalent to 3*"<string>". Any ideas?
|
by: Mike Meng |
last post by:
Hi all,
I just finished reading Learning Python 3rd ed, and am doing my
first Python application, which retrieves and process text and XML
documents from Web. Python helped me to write the application in a few
hours, I'm very happy with its productivity. But the performance is not
satisfactory. I decide to optimized it in Python before trying C/C++
extensions. But I don't know Python much and have no clu to tune my
program. Also, I...
| |
by: John Nagle |
last post by:
This bug, " robotparser interactively prompts for username and
password", has been open since 2003. It killed a big batch job of ours
last night.
Module "robotparser" naively uses "urlopen" to read "robots.txt" URLs.
If the server asks for basic authentication on that file, "robotparser"
prompts for the password on standard input. Which is rarely what you
want. You can demonstrate this with:
import robotparser
|
by: Ivan Voras |
last post by:
Hi,
I'm looking for a construct that's similar to (Turbo) Pascal's "with"
statement. I read about the Python's new "with" statement, but I was
dissapointed to learn that it does something different (I still don't
see how it's better than try..except..finally, but that's not my question).
Is there something similar to what I want that's Pythonic enough?
(If you're not familiar with Pascal, here's how it works:
|
by: none |
last post by:
Hello,
IIRC, I once saw an explanation how Python doesn't have "variables" in
the sense that, say, C does, and instead has bindings from names to
objects. Does anyone have a link?
Thanks,
Ami
|
by: ureuffyrtu955 |
last post by:
Python is a good programming language, but "Python" is not a good
name.
First, python also means snake, Monty Python. If we search "python" in
google, emule, many results are not programming resource. If we search
PHP, all results are programming resource.
Second, python also means snake, snake is not a good thing in western
culture. Many people dislike any things relevant to snake. We must
have high regard for the custom.
|
by: Astan Chee |
last post by:
Hi,
Thanks for all the help from the previous problem. Turns out I didnt
have to use wxSizers, just change the size of my wxWidgets everytime a
EVT_SIZE is called.
Anyway, Im trying to find a python module (im not sure if it exists)
that takes two words and compares if they sound the same. So 'right' and
'write' sounds the same or 'u' and 'you' . Also I know this takes into
account the use of language and accent but is there any out there...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |