Guest User

Untitled

a guest
Sep 10th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. How do I search a string for an ASCII character in Jython?
  2. import sys
  3. sys.path.append('C:\IBM\UniDK\uojsdk\lib\asjava.jar')
  4. import os.path
  5.  
  6. from asjava.uniclientlibs import UniDynArray, UniDataSet
  7. from asjava.uniobjects import UniSession, UniFile
  8. from asjava.uniobjects import UniSubroutineException
  9. from asjava.uniobjects.UniObjectsTokens import AT_FM
  10.  
  11. class u2py :
  12.  
  13. def __init__ (self):
  14. self.conn = UniSession()
  15.  
  16. def get_db(self):
  17. """ establish a connection to Unidata """
  18. username = 'dbuser'
  19. password = 'SuperSecretPassword'
  20. return self.conn.connect("host", username, password, "ACCOUNT")
  21.  
  22. def close_db(self):
  23. """ drop connection to Unidata """
  24. if self.conn.isActive():
  25. self.conn.disconnect()
  26.  
  27. def open_file(self,file_name,rec):
  28. """ open a U2 file read a record and return it """
  29. uvfile = self.conn.open(file_name)
  30. uvrec = uvfile.read(rec)
  31. dataset = uvrec
  32. uvfile.close()
  33. return dataset
  34.  
  35. def open_field(self,file_name,rec,field):
  36. """ open a U2 file read a record and return it """
  37. uvfile = self.conn.open(file_name)
  38. uvrec = uvfile.readField(rec,field)
  39. dataset = uvrec
  40. uvfile.close()
  41. return dataset
  42.  
  43. from u2py import *
  44.  
  45. u2 = u2py()
  46. c = u2.get_db() #creates the connection to the DB
  47. c #actually makes the connection
  48. rec = u2.open_file('SOFILE','SO133700')
  49. print rec
  50.  
  51. ZZZAA■XN3■CEL■931819501■20020215■BWI/PP■■
  52.  
  53. >>>rec = u2.open_file('SOFILE','SO133699').split(chr(254))
  54.  
  55. Traceback (most recent call last):
  56. File "<stdin>", line 1, in <module>
  57. AttributeError: 'asjava.uniclientlibs.UniString' object has no attribute 'split'
  58.  
  59. rec.toString().split(chr(254))
  60.  
  61. >>> "fooxFEbarxFEbaz".split(chr(254))
  62. ['foo', 'bar', 'baz']
  63.  
  64. if 'xFE' in db_string:
  65. # 254 char was in the string
  66.  
  67. delimiter_pos = db_string.find('xFE') # will be -1 if delimiter not found
Add Comment
Please, Sign In to add comment