python-simple.ecl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. IMPORT Python;
  2. /*
  3. This example illustrates and tests the use of embedded Python
  4. */
  5. // Scalar parameters and resuls
  6. integer add1(integer val) := EMBED(Python)
  7. val+1
  8. ENDEMBED;
  9. string add2(string val) := EMBED(Python)
  10. val+'1'
  11. ENDEMBED;
  12. string add3(varstring val) := EMBED(Python)
  13. val+'1'
  14. ENDEMBED;
  15. utf8 add4(utf8 val) := EMBED(Python)
  16. val+'1'
  17. ENDEMBED;
  18. unicode add5(unicode val) := EMBED(Python)
  19. val+'1'
  20. ENDEMBED;
  21. utf8 add6(utf8 val) := EMBED(Python)
  22. return val+'1'
  23. ENDEMBED;
  24. unicode add7(unicode val) := EMBED(Python)
  25. return val+'1'
  26. ENDEMBED;
  27. data testData(data val) := EMBED(Python)
  28. val[0] = val[0] + 1
  29. return val
  30. ENDEMBED;
  31. // Sets in ECL map to Python lists
  32. set of integer testSet(set of integer val) := EMBED(Python)
  33. return sorted(val)
  34. ENDEMBED;
  35. set of string testSet2(set of string val) := EMBED(Python)
  36. return sorted(val)
  37. ENDEMBED;
  38. set of string testSet3(set of string8 val) := EMBED(Python)
  39. return sorted(val)
  40. ENDEMBED;
  41. set of utf8 testSet4(set of utf8 val) := EMBED(Python)
  42. return sorted(val)
  43. ENDEMBED;
  44. set of varstring testSet5(set of varstring val) := EMBED(Python)
  45. return sorted(val)
  46. ENDEMBED;
  47. set of varstring8 testSet6(set of varstring8 val) := EMBED(Python)
  48. return sorted(val)
  49. ENDEMBED;
  50. set of unicode testSet7(set of unicode val) := EMBED(Python)
  51. return sorted(val)
  52. ENDEMBED;
  53. set of unicode8 testSet8(set of unicode8 val) := EMBED(Python)
  54. return sorted(val)
  55. ENDEMBED;
  56. set of data testSet9(set of data val) := EMBED(Python)
  57. return val
  58. ENDEMBED;
  59. // Now run the tests
  60. add1(10);
  61. add2('Hello');
  62. add3('World');
  63. add4(U'Oh là là Straße');
  64. add5(U'Стоял');
  65. add6(U'Oh là là Straße');
  66. add7(U'Стоял');
  67. add2('Oh là là Straße'); // Passing latin chars - should be untranslated
  68. testData(D'aa');
  69. testSet([1,3,2]);
  70. testSet2(['red','green','yellow']);
  71. testSet3(['one','two','three']);
  72. testSet4([U'Oh', U'là', U'Straße']);
  73. testSet5(['Un','Deux','Trois']);
  74. testSet6(['Uno','Dos','Tre']);
  75. testSet7([U'On', U'der', U'Straße']);
  76. testSet8([U'Aus', U'zum', U'Straße']);
  77. testSet9([D'Aus', D'zum', D'Strade']);