Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: list Integer indexing dies??

Reply
Thread Tools

Re: list Integer indexing dies??

 
 
Ishwor
Guest
Posts: n/a
 
      12-23-2004
On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo
<(E-Mail Removed)> wrote:
>
>
> [Ishwor]
>
> #- > What should 035[0] cough up? Be carefull it should
> #-
> #- >>>035[0]
> #- 3 # my own opinion.

why 3? The reason we get 3 and not 0 here is the *fact* that Python
knows that its an octal rep. and not decimal
035[2] could return error here. Same for hex. No idea for binary. ~;-(

> #-
> #- > cough up the same as 29[0].
> #-
> #- >>>29[0]
> #- 2 #again my own opinion

since it's decimal its fine to get 2 which is at offset 0.

[snip]

--
cheers,
Ishwor Gurung
 
Reply With Quote
 
 
 
 
Jeff Shannon
Guest
Posts: n/a
 
      12-23-2004
Ishwor wrote:

>On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo
><(E-Mail Removed)> wrote:
>
>
>>[Ishwor]
>>
>>#- > What should 035[0] cough up? Be carefull it should
>>#-
>>#- >>>035[0]
>>#- 3 # my own opinion.
>>
>>

>why 3? The reason we get 3 and not 0 here is the *fact* that Python
>knows that its an octal rep. and not decimal
>
>


Except that, at the point where the indexing takes place, Python
*doesn't* know that it's an octal rep. All integer literals, regardless
of representation, generate exactly the same bytecode.

>>> def f():

.... x = 035
.... y = 29
....
>>> dis.dis(f)

0 SET_LINENO 1

3 SET_LINENO 2
6 LOAD_CONST 1 (29)
9 STORE_FAST 1 (x)

12 SET_LINENO 3
15 LOAD_CONST 1 (29)
18 STORE_FAST 0 (y)
21 LOAD_CONST 0 (None)
24 RETURN_VALUE
>>>


Given that Python may not even have access to the .py file, only the
..pyc (which has lost all record of the source representation), there's
no way for the interpreter to do what you suggest.

Jeff Shannon
Technician/Programmer
Credit International

 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      12-23-2004
Jeff Shannon wrote:
> Ishwor wrote:
>
> >On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo
> ><(E-Mail Removed)> wrote:
> >
> >
> >>[Ishwor]
> >>
> >>#- > What should 035[0] cough up? Be carefull it should
> >>#-
> >>#- >>>035[0]
> >>#- 3 # my own opinion.
> >>
> >>

> >why 3? The reason we get 3 and not 0 here is the *fact* that Python
> >knows that its an octal rep. and not decimal
> >
> >

>
> Except that, at the point where the indexing takes place, Python
> *doesn't* know that it's an octal rep. All integer literals,

regardless
> of representation, generate exactly the same bytecode.
>
> >>> def f():

> ... x = 035
> ... y = 29
> ...
> >>> dis.dis(f)

> 0 SET_LINENO 1
>
> 3 SET_LINENO 2
> 6 LOAD_CONST 1 (29)
> 9 STORE_FAST 1 (x)
>
> 12 SET_LINENO 3
> 15 LOAD_CONST 1 (29)
> 18 STORE_FAST 0 (y)
> 21 LOAD_CONST 0 (None)
> 24 RETURN_VALUE
> >>>

>
> Given that Python may not even have access to the .py file, only the
> .pyc (which has lost all record of the source representation),

there's
> no way for the interpreter to do what you suggest.

And even if there was, what should (104 + 0x68 + 0150)[0] print?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic indexing (multi-dimensional-indexing) (probably my most important/valuable posting up to this date) Skybuck Flying C Programming 30 09-18-2011 11:29 PM
Indexing services under Windows XP SP2 - Can I disable MS Indexing Service to hasten Google's OR does Google Desktop uses this MS Indexing Service? ricardodefaria Computer Support 6 08-05-2007 04:14 AM
How much slower is dict indexing vs. list indexing? Emin Python 4 01-12-2007 02:40 PM
Indexing PDF's using MS Indexing Service C ASP General 3 10-17-2003 05:47 PM
Indexing PDF Files using MS Indexing Service C ASP .Net 0 10-17-2003 04:27 PM



Advertisments