473,586 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine an object is "scriptable "

I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable " or "unscriptab le"?

Mar 30 '06 #1
10 13034

"abcd" <co*******@gmai l.com> wrote in message
news:11******** **************@ j33g2000cwa.goo glegroups.com.. .
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable " or "unscriptab le"?


subscriptable: supports an indexing operator, like a list does.

Mar 30 '06 #2
Richard Brodie wrote:
subscriptable: supports an indexing operator, like a list does.


doesn't seem to be a builtin function or module...or is that just your
definition of subscriptable?

Mar 30 '06 #3
abcd wrote:
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable " or "unscriptab le"?

Simplest answer is to use isinstance to see if it is a string, list,
or tuple:

if isinstance(vari able, (str, list, tuple)):
..
..
..

Now the problem is that this answer doesn't address the problem.
Your code is attempting to do something to the wrong type of
object/variable which is a logic problem.

-Larry Bates
Mar 30 '06 #4
Richard Brodie wrote:
subscriptable: supports an indexing operator, like a list does.


Right. You can check this e.g. with

hasattr(x, "__getitem_ _")

because the __getitem__ method is used for indexing.

Daniel
Mar 30 '06 #5
Daniel Evers wrote:
Right. You can check this e.g. with

hasattr(x, "__getitem_ _")

because the __getitem__ method is used for indexing.


Thanks...that is what I was looking for!

Mar 30 '06 #6
Larry Bates wrote:
abcd wrote:
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable " or "unscriptab le"?

Simplest answer is to use isinstance to see if it is a string, list,
or tuple:

if isinstance(vari able, (str, list, tuple)):


Which will fail for a whole lot of objects that are scriptable...
Better use Daniel's solution or a try/except.

Now the problem is that this answer doesn't address the problem.
Your code is attempting to do something to the wrong type of
object/variable which is a logic problem.


Of course !-)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Mar 30 '06 #7

"abcd" <co*******@gmai l.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
doesn't seem to be a builtin function or module...or is that just your
definition of subscriptable?


Yes, I figured you were just confused. You were using the wrong words,
after all.

Mar 30 '06 #8
abcd wrote:
Richard Brodie wrote:
subscriptable : supports an indexing operator, like a list does.
doesn't seem to be a builtin function or module...


It's not. Look no further.
or is that just your
definition of subscriptable?


It's a correct definition of 'subscriptable' in the context of the
Python programming language - as well as a good exemple of an implied
interface.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Mar 30 '06 #9
abcd wrote:
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable " or "unscriptab le"?


By trying to apply the subscript operator ('[<index>]'). If it raises a
TypeError, then it's not subscriptable.

But, as Larry Bates already pointed out, your real problem is a logic
error: you get an unsubscriptable object where you assumed you had a
subscriptable one.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Mar 30 '06 #10

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

Similar topics

2
8506
by: Simon Wigzell | last post by:
What is the call? Better yet is there a link to a page that describes all the possible javascript calls to the various browser menu items and explains compatibility across different browsers? Thanks!
1
1371
by: Zack Sessions | last post by:
Running VB.NET 2003. I have an application that is a "client/server" type application. The VB.NET code depends on a set of stored procedures to do some of the more complex SQL stuff. I have a script that installs all the stored procs and related tables. Can I have this script run automatically during the installation of the VB.NET app? I do...
12
3060
by: Paul Tillotson | last post by:
At my company we are looking at deploying clients for our client/server app outside our firewall, which will then require our postgres box to be internet-accessible. Does anyone out there have experience with this or recommended best practices? We have been looking at either (a) tunnelling everything over ssh, or (b) just making sure that...
4
4641
by: ajschuster | last post by:
I cannot get my Javascript to work in Firefox. I am just trying to access the .name property of a DIV tag but it keeps coming back as "undefined". The same code works in IE and it works in Safari.... and if I change it to .id instead of .name it can read that so why wouldn't it be able to read the .name? I need urgent help!! Here's my...
10
2168
by: petermichaux | last post by:
Hi, I'm picking apart the Yahoo! UI event.js library and stripping it down to just what I need. I'm also trying to make the parts I use better. I'm stumped on how to fix the code for the getPageX() method. This method is supposed to give the same value in IE as other browsers for the event position relative to the left of the page. This...
11
3567
by: Jon Davis | last post by:
Can a solution built in C# utilize MSMQ and/or MTS? If so, does this make the training material I already have on MSMQ and MTS in the context of VB6 an appropriate prerequisite foundation before learning how to build C# solutions on MSMQ / MTS, if I already know VB6 as well as C#? Jon
11
2432
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css"> ..historylinks {
26
3875
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are almost no posts from the last 3 years: ...
14
75469
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post" enctype="multipart/form-data" name="form1"> <select onchange="this.form.submit();" name="prod"> <option value="">Select product</option> <option value="12">abc</option>
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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...
1
7959
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...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.