Chris Mathews 1 Posted August 4 I've had success running python scripts and returning class properties to Delphi. I'm struggling with where to start to return a python tuple (containing an OrderedDict and a string to a Delphi collections. The module is usaddress and I'm using as follows: script from collections import OrderedDict import usaddress od = OrderedDict() od = usaddress.tag('5757 Woodway Ave APT 150 WEST PALM BEACH FL 37205 ') print(od) print(type(od)) first = od[0] print(first) print(type(first)) second = od[1] print(second) print(type(second)) and the output is this: (OrderedDict({'AddressNumber': '5757', 'StreetName': 'Woodway', 'StreetNamePostType': 'Ave', 'OccupancyType': 'APT', 'OccupancyIdentifier': '150', 'PlaceName': 'WEST PALM BEACH', 'StateName': 'FL', 'ZipCode': '37205'}), 'Street Address') <class 'tuple'> OrderedDict({'AddressNumber': '5757', 'StreetName': 'Woodway', 'StreetNamePostType': 'Ave', 'OccupancyType': 'APT', 'OccupancyIdentifier': '150', 'PlaceName': 'WEST PALM BEACH', 'StateName': 'FL', 'ZipCode': '37205'}) <class 'collections.OrderedDict'> Street Address <class 'str'> Guiding me to a starting point would be appreciated. Share this post Link to post
pyscripter 689 Posted August 4 (edited) I am not exactly sure what you are trying to do, Also the 4th line in your script is doing nothing since you are assigning a new value in the next statement. However, if you want to access these values in Delphi and store them say in a Delphi data structure, the easiest way is using VarPyth. For instance to access the AddressNumber, after running the above script, you use something like: var AddressNumber := MainModule.od[0]['AddressNumber']; Edited August 4 by pyscripter Share this post Link to post
Chris Mathews 1 Posted August 4 Thanks. PS I'd love for you to write a book on P4D. I'll pre-order. Share this post Link to post
Chris Mathews 1 Posted August 4 Followup Question: Why am I getting an Incompatible type error integer and string on var AddressNumber := MainModule.od[0]['AddressNumber']; Share this post Link to post
pyscripter 689 Posted August 4 (edited) As you can see from your output AddressNumber is a string (as well as the other fields). You need to convert it to an integer. Edited August 4 by pyscripter Share this post Link to post