srinivasan srinivas wrote:
Hi,
I am getting an error while executing the following snippet. If i comment out method __repr__ , it works fine.
class fs(frozenset):
def __new__(cls, *data):
data = sorted(data)
self = frozenset.__new __(cls, data)
self.__data = data
return self
def __repr__(self):
return "%s(%r)" % (self.__class__ .__name__, self.__data)
a1 = fs(1,2,3)
a2 = fs(3,4,5)
print a1.difference(a 2)
Error:
return "%s(%r)" % (self.__class__ .__name__, self.__data)
AttributeError: 'fs' object has no attribute '_fs__data'
Please help me in fixing this.
When posting problems like this, please include the Python version.
If you ran this with 2.6, please run the following:
x = frozenset('abc' )
y = frozenset('bcd' )
z = x.difference(y)
print(id(x) != id(z))
This should print (True), but if 2.6 has a bug for frozenset similar one
it has for bytearrays, it will print (False) and that would explain your
error.
tjr 0 1250 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: chris |
last post by:
hi,
i am tinkering with properties of new style classes:
class Base(object):
def m(self):
return 'p of Base'
p = property(m)
class Sub(Base):
|
by: Jim Newton |
last post by:
hi all, does anyone know what print does if there is no __str__ method?
i'm trying ot override the __repr__. If anyone can give me some advice
it would be great to have.
I have defined a lisp-like linked list class as a subclass of list.
The __iter__ seems to work as i'd like, by traversing the links,
and the __repr__ seems to work properly for somethings but not others.
The basic idea is that a list such as is converted to
]],...
|
by: Stefan Behnel |
last post by:
Hi!
frozenset() doesn't behave as the other immutable empty data types in 2.4:
..>>> '' is ''
True
..>>> () is ()
True
..>>> frozenset() is frozenset()
False
|
by: Bill Davy |
last post by:
I am working with MSVC6 on Windows XP.
I have created an MSVC project called SHIP
I have a file SHIP.i with "%module SHIP" as the first line (file is below).
I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the
latter contains the line "import _SHIP".
I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
|
by: Will McGugan |
last post by:
Hi,
Are there any benefits in using a frozenset over a set, other than it
being immutable?
Will McGugan
--
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in
| |
by: Jacob Page |
last post by:
I have released interval-0.2.1 at
http://members.cox.net/apoco/interval/. IntervalSet and
FrozenIntervalSet objects are now (as far as I can tell) functionality
equivalent to set and frozenset objects, except they can contain
intervals as well as discrete values.
Though I have my own unit tests for verifying this claim, I'd like to
run my code through actual set and frozenset unit tests. Does any such
code exist? Is it in pure...
|
by: Mark E. Fenner |
last post by:
Hello all,
I was migrating some code from sets.ImmutableSet to frozenset and noticed
the following:
******code********
#!/usr/bin/env python
from sets import ImmutableSet
|
by: Roc Zhou |
last post by:
Now I have to design a class that overload __getattr__, but after
that, I found the __repr__ have been affected. This is a simple
example model:
#!/usr/bin/env python
class test:
def __init__(self):
self.x = 1
def __getattr__(self, attr_name):
try:
|
by: srinivasan srinivas |
last post by:
Hi,
I am getting an error while executing the following snippet. If i comment out method __repr__ , it works fine.
class fs(frozenset):
def __new__(cls, *data):
data = sorted(data)
self = frozenset.__new__(cls, data)
self.__data = data
return self
|
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: 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...
| |
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: 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: 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
| |
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...
| |