473,750 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with slices.

I'm for the moment writing two classes.

A table, which is like a list, but can start at any integer.

A tree which is like a dictionary, but will iterate over the
keys in sorted order.

The problem is that I would like to implemet slices but, that
seems to be impossible with how slices are implemented now.

I wrote the following class to test things out.

class Tst:
def __getitem__(sel f, key):
print key

then I called the interpreter and got this:
from tst import Tst
t=Tst()
t[:] slice(0, 2147483647, None) t[:9] slice(0, 9, None) t[:'ok'] slice(None, 'ok', None) t['ok':] slice('ok', None, None) t[6:] slice(6, 2147483647, None) t[1,2] (1, 2) t[1,2:] (1, slice(2, None, None)) t[(1,2):]

slice((1, 2), None, None)
Now suppose tab is a table with indexes from -5 to 12.

tab[:4] would have to make a table ranging from -5 to 4
tab[0:4] would have to make a table ranging from 0 to 4.

But each time I would be given the same argument, being
slice(0, 4, None). So I would be unable to distinghuish
between the two.

I don't think it very likely but I could have a table
with indexes from 2147483647 to 2147483700, so having
2147483647 as value that indicated till the end of
the sequence is a bit awkward.

The same problems occur when I have a tree with integer
key values. But even if I don't use integers as keys
I have a problem with what is returned since None is
a valid key and thus it shouldn't be used this way.

--
Antoon Pardon
Oct 3 '05 #1
1 1315
Antoon Pardon wrote:
I'm for the moment writing two classes.

A table, which is like a list, but can start at any integer.

A tree which is like a dictionary, but will iterate over the
keys in sorted order.

The problem is that I would like to implemet slices but, that
seems to be impossible with how slices are implemented now.

I wrote the following class to test things out.

class Tst:
def __getitem__(sel f, key):
print key

then I called the interpreter and got this:
from tst import Tst
t=Tst()
t[:] slice(0, 2147483647, None) t[:9] slice(0, 9, None) t[:'ok'] slice(None, 'ok', None) t['ok':] slice('ok', None, None) t[6:] slice(6, 2147483647, None) t[1,2] (1, 2) t[1,2:] (1, slice(2, None, None)) t[(1,2):] slice((1, 2), None, None)
Now suppose tab is a table with indexes from -5 to 12.

tab[:4] would have to make a table ranging from -5 to 4
tab[0:4] would have to make a table ranging from 0 to 4.

But each time I would be given the same argument, being
slice(0, 4, None). So I would be unable to distinghuish
between the two.

I don't think it very likely but I could have a table
with indexes from 2147483647 to 2147483700, so having
2147483647 as value that indicated till the end of
the sequence is a bit awkward.

The same problems occur when I have a tree with integer
key values. But even if I don't use integers as keys
I have a problem with what is returned since None is
a valid key and thus it shouldn't be used this way.

Consider new-style classes:
class T(object): .... def __getitem__(sel f, key):
.... return key
.... t = T()
t[:4] slice(None, 4, None) t[0:4] slice(0, 4, None) t[0:]

slice(0, None, None)

Peter
Oct 3 '05 #2

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

Similar topics

4
1429
by: Microsoft | last post by:
I used photoshop to slice up some images. PS, creates the tables and differant images. You are supposed to simple upload the photos and copy and past the table codes taht was generated from the HTML PS creates. When I launche the created html file everything looks good, but when I put the table code into VS...there are spaces between the images were the slice was at, the image is broken up and you can see the idfferant images which is the...
3
2417
slightlybefuddled
by: slightlybefuddled | last post by:
(Exporting ImageReady slices as CSS rather than tables) apparently means it'll work just fine in Firefox, but do wacky stuff in IE? Can anyone help me figure out why on earth the slices are not showing up in their proper places in IE(7)? The button bar I created is perfectly set up in Firefox, but when I preview in IE, not so much. The slices have weird spaces in between. Why.....? Any help greatly appreciated. Thx.
31
1724
by: Antoon Pardon | last post by:
The following is part of the explanation on slices in the tutorial: The best way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the first character numbered 0. Then the right edge of the last character of a string of n characters has index n, for example: +---+---+---+---+---+ | H | e | l | p | A |
3
1168
by: David | last post by:
That xpairs() generator is nice, but it's not the best possible code What do you mean by best possible? Most efficient? Most readable? And why don't you use islice? eg: def xpairs(seq): len_seq = len(seq) for i, e1 in enumerate(seq):
0
9396
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
9342
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
9256
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...
1
6808
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
6081
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();...
0
4888
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3323
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
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
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.