interactive window vs. script: inconsistent behavior

B

Bell, Kevin

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
 
D

Duncan Booth

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.
 
L

Larry Bates

This also works and IMHO reads better:

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

Larry Bates

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top