Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I search a string for an ASCII character in Jython?
    primarykey
    data
    text
    <p>I am pulling data from a database that uses the ASCII character 254 as the delimiter. I'm stumped as to how to search the string returned for the 254 and then create dictionary based on that? </p> <p>My python class</p> <pre><code>import sys sys.path.append('C:\\IBM\\UniDK\\uojsdk\\lib\\asjava.jar') import os.path from asjava.uniclientlibs import UniDynArray, UniDataSet from asjava.uniobjects import UniSession, UniFile from asjava.uniobjects import UniSubroutineException from asjava.uniobjects.UniObjectsTokens import AT_FM class u2py : def __init__ (self): self.conn = UniSession() def get_db(self): """ establish a connection to Unidata """ username = 'dbuser' password = 'SuperSecretPassword' return self.conn.connect("host", username, password, "ACCOUNT") def close_db(self): """ drop connection to Unidata """ if self.conn.isActive(): self.conn.disconnect() def open_file(self,file_name,rec): """ open a U2 file read a record and return it """ uvfile = self.conn.open(file_name) uvrec = uvfile.read(rec) dataset = uvrec uvfile.close() return dataset def open_field(self,file_name,rec,field): """ open a U2 file read a record and return it """ uvfile = self.conn.open(file_name) uvrec = uvfile.readField(rec,field) dataset = uvrec uvfile.close() return dataset </code></pre> <p>Here is my code in the console:</p> <pre><code>from u2py import * u2 = u2py() c = u2.get_db() #creates the connection to the DB c #actually makes the connection rec = u2.open_file('SOFILE','SO133700') print rec </code></pre> <p>Which then prints this to the screen:</p> <pre><code>ZZZAA■XN3■CEL■931819501■20020215■BWI/PP■■ </code></pre> <p>"■" is actually a field mark chr(254) </p> <p>EDIT:</p> <p>When I use this:</p> <pre><code> &gt;&gt;&gt;rec = u2.open_file('SOFILE','SO133699').split(chr(254)) </code></pre> <p>I get this error</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'asjava.uniclientlibs.UniString' object has no attribute 'split' </code></pre> <p>EDIT and FINAL answer:</p> <p>Using UniObjects Java</p> <pre><code>rec.toString().split(chr(254)) </code></pre> <p>SUCCESS!!!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload