Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > interactive window vs. script: inconsistent behavior

Reply
Thread Tools

interactive window vs. script: inconsistent behavior

 
 
Bell, Kevin
Guest
Posts: n/a
 
      10-06-2005
The following works in the interactive window of PythonWin, but fails in
a script. TypeError: Objects of type 'slice' can not be converted to a
COM VARIANT

I just need to parse out these dates, but it's making me crazy.
Shouldn't it work in both the interactive window and a script?


>>> d = "5-18-05 to 5-31-05"
>>> print d[0:d.find("to")-1]

5-18-05
>>> print d[d.find("to")+3:]

5-31-05
>>>





Kev


 
Reply With Quote
 
 
 
 
Duncan Booth
Guest
Posts: n/a
 
      10-06-2005
Bell, Kevin wrote:

> The following works in the interactive window of PythonWin, but fails in
> a script. TypeError: Objects of type 'slice' can not be converted to a
> COM VARIANT
>
> I just need to parse out these dates, but it's making me crazy.
> Shouldn't it work in both the interactive window and a script?
>
>
>>>> d = "5-18-05 to 5-31-05"
>>>> print d[0:d.find("to")-1]

> 5-18-05
>>>> print d[d.find("to")+3:]

> 5-31-05
>>>>

>


Not surprisingly, the above three lines work perfectly well in a script:

d = "5-18-05 to 5-31-05"
print d[0:d.find("to")-1]
print d[d.find("to")+3:]

and the output is:
C:\temp>t.py
5-18-05
5-31-05

Perhaps if you were to post an actual script which doesn't work and the
actual error it generates, it might be possible to help you.
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      10-06-2005
This also works and IMHO reads better:

d="5-18-05 to 5-31-05"
f,t=d.split(' to '))

Larry Bates

Bell, Kevin wrote:
> The following works in the interactive window of PythonWin, but fails in
> a script. TypeError: Objects of type 'slice' can not be converted to a
> COM VARIANT
>
> I just need to parse out these dates, but it's making me crazy.
> Shouldn't it work in both the interactive window and a script?
>
>
>
>>>>d = "5-18-05 to 5-31-05"
>>>>print d[0:d.find("to")-1]

>
> 5-18-05
>
>>>>print d[d.find("to")+3:]

>
> 5-31-05
>
>
>
>
>
> Kev
>
>

 
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
Inconsistent window.print behavior in Netscape and IE6 Prasoon Javascript 1 03-20-2007 12:49 PM
DataSet inconsistent in behavior in different session state manage =?Utf-8?B?Q3phciBFY2xhcmluYWw=?= ASP .Net 0 08-30-2005 03:56 AM
Interactive/Non-interactive ASPX ? WJ ASP .Net 2 02-26-2005 02:54 AM
non Interactive and Interactive AAH Computer Support 0 01-09-2005 04:09 PM
Interactive and non interactive AAH Computer Support 1 01-09-2005 04:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57