473,941 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrapping float

Hi all,

I'm trying to make a float-like class (preferably a subclass of
'float') that wraps around. The background: I'm modeling a
multi-dimensional space, and some of those dimensions are circular.

Here is my code so far:

class WrapFloat(float ):
def __init__(self, value, wrap = None):
float.__init__( self, value)
self.wrap = wrap

The problem is this:

Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
from engine.geometry import WrapFloat
WrapFloat(45) 45.0 WrapFloat(45, 3)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: float() takes at most 1 argument (2 given)

So my question to you is: how can I change my code so I can pass two
values to the WrapFloat constructor?

Thanks in advance,
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Sep 17 '05 #1
3 3478
On Sat, 17 Sep 2005 11:12:34 +0200, Sybren Stuvel <sy****@localho st.localdomain> wrote:
Hi all,

I'm trying to make a float-like class (preferably a subclass of
'float') that wraps around. The background: I'm modeling a
multi-dimensional space, and some of those dimensions are circular.

Here is my code so far:

class WrapFloat(float ):
def __init__(self, value, wrap = None):
float.__init__( self, value)
self.wrap = wrap

The problem is this:

Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
from engine.geometry import WrapFloat
WrapFloat(45)45.0 WrapFloat(45, 3)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: float() takes at most 1 argument (2 given)

So my question to you is: how can I change my code so I can pass two
values to the WrapFloat constructor?

Float is an immutable, so you need to override __new__

Regards,
Bengt Richter
Sep 17 '05 #2
Sybren Stuvel wrote:
Hi all,

I'm trying to make a float-like class (preferably a subclass of
'float') that wraps around. The background: I'm modeling a
multi-dimensional space, and some of those dimensions are circular.

Here is my code so far:

class WrapFloat(float ):
def __init__(self, value, wrap = None):
float.__init__( self, value)
self.wrap = wrap

The problem is this:

Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
from engine.geometry import WrapFloat
WrapFloat(4 5)
45.0
WrapFloat(4 5, 3)


Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: float() takes at most 1 argument (2 given)

So my question to you is: how can I change my code so I can pass two
values to the WrapFloat constructor?


You also have to override __new__ I think. It automatically gets passed
the arguments to __init__. C.f.
http://www.python.org/2.2/descrintro.html#__new__

In [11]: class WrapFloat(float ):
....: def __new__(cls, value, *args, **kwds):
....: return float.__new__(c ls, value)
....: def __init__(self, value, wrap=None):
....: float.__init__( self, value)
....: self.wrap = wrap
....:

In [12]: x = WrapFloat(45, 3)

In [13]: x
Out[13]: 45.0

In [14]: x.wrap
Out[14]: 3

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Sep 17 '05 #3
Bengt Richter enlightened us with:
Float is an immutable, so you need to override __new__


Thanks, that works!

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Sep 17 '05 #4

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

Similar topics

1
4174
by: joes | last post by:
Hello there ! I rendering a PDF with XSLT using Xalan and FOP. I like to place in my article an image, so that the text is floating around the image. I tried several things but it didn't work so far. I found some hints that it should work with "fo:float" but it seems not to work with apache's FOP, so has anybody out there any solution and experience ? example:
2
13947
by: Suzanne Boyle | last post by:
I have the following code in a webpage: <p><img src="images/clydesdale.gif" width="100" height="41" style="float: left;" /> <strong>Test</strong><br /> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <br /> visit website
2
3264
by: Andrew Poulos | last post by:
I have a DIV with a nested DIV. The nested DIV is to sit in the bottom right corner of the outer DIV. I tried using absolute positioning but that means that the text the outer DIV contains goes behind the nested DIV. Is there a way I can have the nested DIV in the bottom right corner but still allow text to wrap around it? Andrew Poulos
4
2612
by: Shark | last post by:
Hi, I have the following code: <div id="navAlpha"><div id="mainImage"><img src="/All/10001/main.jpg"></div> <div id="mainInfo"> // a list apart's mountain top <dl id="red"><dt>nick: astronomer</dt><dd> R: 800</dd><dd> P: 875</dd></dl></div> <div style='clear: both;'>&nbsp;</div></div>
8
13887
by: Nathan | last post by:
I am trying to prevent a horizontal list from wrapping. Each list item is floated with "float: left". Currently I use an ugly hack. I set the width of the list to a large number which is guananteed greater than the total width of all items. Is there a way to accomplish this without my hack? It would be handy because I would like to read the total width of all items in javascript. I looked into white-space: nowrap, but it doesn't work...
10
14914
by: hendedav | last post by:
Gang, I am not quite sure if this has been posted before. I have searched google groups and couldn't find anything. I am trying to setup a container div that contains columns of divs (to generate a "spreadsheet". Each "cell" can contain either text or an object. My problem is that when I generate columns that run outside of the width of the container div, the following div's wrap. I have tried using <nobrtags, "white-space: nowrap"...
4
2462
by: Huseyin | last post by:
Dear alls I am trying to put an image with text wrapped all around it except the top part. Is it possible to do that without using invinsible tables? Any advice will be immencely appreciated. Thanking you in advance for the foregoing information. Regards Huseyin
0
1938
by: Christian Ulrich | last post by:
Hi, I have a "funny" problem that does not make sense to me. I have a SELECT statement that manipulate a datetime : SELECT COUNT(ID) AS Amount, CAST(ROUND(CAST(DischargeEventTime AS float), 0, 1) AS datetime) AS TimeValue FROM tblItemData WHERE DischargeEventTime between '2007-02-02' and '2007-10-02' GROUP BY CAST(ROUND(CAST(DischargeEventTime AS float), 0, 1) AS datetime)
5
1653
by: Big Moxy | last post by:
Please check this link - http://projects.zanalysts.com/hearing/work.htm. The graphic is part of the page template. How can I get the text to wrap around it? The style sheet is at http://projects.zanalysts.com/hearing/css/hearing.css. Thank you, - Tim
0
10134
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
9964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11296
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,...
0
10659
tracyyun
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...
0
6299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
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
4487
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3507
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.