# Python String Parse

**URL:** <https://forum.inductiveautomation.com/t/python-string-parse/11840>\
**Category:** Ignition\
**Created:** [June 21, 2016, 4:10pm UTC](https://forum.inductiveautomation.com/t/python-string-parse/11840 "2016-06-21T16:10:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jreynolds](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jreynolds](https://forum.inductiveautomation.com/u/jreynolds)\
**Post date:** [June 21, 2016, 4:10pm UTC](https://forum.inductiveautomation.com/t/python-string-parse/11840/1 "2016-06-21T16:10:38Z")

</div>

I’m wanting to parse the first 4 character from the string.

I’m getting this error when I run the following code:  
Code:

`scanEntry = event.source.parent.getComponent('txtJobNum').text
entry = scanEntry.split[:4]
event.source.parent.getComponent('t1').text = entry`

Error:

[code]Traceback (most recent call last):  
File “event:actionPerformed”, line 2, in   
TypeError: ‘builtin\_function\_or\_method’ object is unsubscriptable

```
at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject. __finditem__ (PyObject.java:585)
at org.python.core.PyObject. __getitem__ (PyObject.java:653)
at org.python.core.PyObject. __getslice__ (PyObject.java:740)
at org.python.pycode._pyx25.f$0(<event:actionPerformed>:3)
at org.python.pycode._pyx25.call_function(<event:actionPerformed>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:623)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at com.sun.proxy.$Proxy33.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

```

Ignition v7.8.2 (b2016030813)  
Java: Oracle Corporation 1.8.0\_60  
[/code]

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [June 21, 2016, 4:45pm UTC](https://forum.inductiveautomation.com/t/python-string-parse/11840/2 "2016-06-21T16:45:43Z")

</div>

Line 2 should probably look like this:

```auto
entry = scanEntry.split()[:4]
```

---

<div class="post-metadata">

**Author:** ![markdobtech](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@markdobtech](https://forum.inductiveautomation.com/u/markdobtech)\
**Post date:** [June 21, 2016, 7:10pm UTC](https://forum.inductiveautomation.com/t/python-string-parse/11840/3 "2016-06-21T19:10:52Z")

</div>

Why the split?  
scanEntry = event.source.parent.getComponent(‘txtJobNum’).text[:4]
