# Try to print a value of list by readblocking ,found some interesting

**URL:** <https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [July 1, 2024, 2:16am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589 "2024-07-01T02:16:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelvin\_wang](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@kelvin\_wang](https://forum.inductiveautomation.com/u/kelvin_wang)\
**Post date:** [July 1, 2024, 2:16am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/1 "2024-07-01T02:16:18Z")

</div>

Can you help exlplain this ? if you already got A[0].value is Good ,then this code should print True , but I got False.

```python
path=["default]Folder/Tag_A"]

A=system.tag.readBlocking(path)
print A[0].value #this is Good
if A[0].value == 'Good':
	print True
else:
	print False

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 1, 2024, 7:00am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/2 "2024-07-01T07:00:09Z")

</div>

Try `print type(A[0].value)`.

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [July 1, 2024, 8:11am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/3 "2024-07-01T08:11:48Z")

</div>

You'll find that Ignition scripting uses a lot of strange Jython class like types, in unexpected areas.

If I'm checking something like a string I always typecast it first just in case.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 1, 2024, 8:31am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/4 "2024-07-01T08:31:34Z")

</div>

> [@Hayden\_Watson](#):
>
> If I'm checking something like a string I always typecast it first just in case.

I wouldn't do that, that's how you end up with very hard to diagnose unexpected behaviors.  
Type casting is something you should do with a purpose, when you know what type your variable is and what type you want it to be, and how casting it will affect it. Type casting "just in case" sounds like something that might come back later with a vengeance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 1, 2024, 11:32am UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/5 "2024-07-01T11:32:40Z")

</div>

Stringification is also **expensive** , computationally. Only use stringification to show things to users.

If you have a quality code, perhaps from a qualified value, check for "good" with its `.good` native property. (A boolean, no equals comparison required.)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 1, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/6 "2024-07-01T15:35:02Z")

</div>

The `print` statement asks whatever expression you give it for a string representation. Qualified values happen to string represent in ways that _look_ like they're regular strings, but they are not. Always `print someVar, type(someVar)` if you're not absolutely sure it's a string.

This _would_ work, but to Phil's point:

# Don't do this!

```python
if str(A[0].value) == 'Good':

```

Instead, you should examine the quality attribute of the Qualified Value object you receive from readBlocking.

# Do this!

```python
if A[0].quality.good:

```

In the **rare** case you actually need to compare between two explicit quality codes, you should do it with the `is` function, e.g.

```python
from com.inductiveautomation.ignition.common.model.values import QualityCode

uncertain = QualityCode.Uncertain_InitialValue

if A[0].quality.is(uncertain):

```

> **[QualifiedValue​ - Scripting Object Reference | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/scripting-object-reference#qualifiedvalue)**
>
> This page describes several common scripting objects

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 1, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/try-to-print-a-value-of-list-by-readblocking-found-some-interesting/92589/7 "2024-07-01T17:21:03Z")

</div>

To add to what Phil and Paul have said, if you were trying to compare string values then if those values matched, you would have gotten what you expected. So obviously, something was not the value you expected it to be.

```python
system.tag.writeBlocking(["[default]testString"],["Good"])
value = system.tag.readBlocking(["[default]testString"])[0].value

print value, type(value)
print value == "Good":

if value == "Good":
    print True
else:
    print False

system.tag.writeBlocking(["[default]testString"],["good"])
value = system.tag.readBlocking(["[default]testString")[0].value

print value, type(value)
print value == "good"

if value == "Good":
    print True
else:
    print False

```

Output:

```plaintext
>>> 
[Good]
Good <type 'unicode'>
True
True
[Good]
good <type 'unicode'>
True
False
>>> 

```

The good in square brackets is the Quality Code returned by `system.tag.writeBlocking()`
