Embedded Python Programming with Claude Code
Since I started using Claude Code, my motivation to create things has skyrocketed.
Previously, even if I wanted to build something, actually doing the coding felt like a hassle, so unless there was a very strong need, I rarely went as far as programming. But now, if I just jot down the specifications, Claude Code handles the rest automatically, resulting in a dramatic improvement in productivity.
I come from a generation native to ObjectScript, so I used to feel some hesitation when it came to switching to Python. However, since Claude Code excels at Python, there are now very few reasons to choose ObjectScript for new development.
That said, I was initially a bit concerned about how well Claude Code understands the quirks of Embedded Python, but I’ve come to realize that this was largely unnecessary worry.
It seems to properly understand most of what is written in the IRIS documentation.
And it produces concise and polished code that I could never write on my own.
One task I had always thought would be nice to have, but rarely implemented due to the hassle, is table import/export functionality.
In the management portal, it’s easy to export query results to CSV. However, when editing or reviewing CSV files, Excel is more convenient. On macOS, CSV files are normally output in UTF-8.
The problem is that Excel on Mac assumes CSV files are in Shift-JIS, so when Japanese text is included, the result is severe character corruption.
Therefore, being able to read and write directly in XLSX format would solve the issue, so I asked for code to export and import Excel files.
The request looked like this:
# Export and Import of Expense Item Data
## Program Name
expenseitem.py
## How to Run
### Import Data
python3 expenseitem.py import expense.xlsx
### Export Data
python3 expenseitem.py export expense.xlsx
## Processing Details
### Import Data
Delete all instances of the YNC.ExpenseItem class in InterSystems IRIS
(using the %KillExtent method of YNC.ExpenseItem)
The first row of the specified Excel file contains the column names of YNC.ExpenseItem.
Read the specified Excel file row by row, and insert records into YNC.ExpenseItem instances
in the order of the header columns, using the SQL interface of IRIS Embedded Python.
### Export Data
Write all instance data of the YNC.ExpenseItem class to the specified Excel file row by row.
Determine the column order based on the header information in the Excel file.
The response from Claude Code was as follows:
First, I will check the file contents. Executed commands, displayed filesExecuted commands,
displayed filesI have understood the structure.
An important point is that Description is used as the IdKey (primary key), so it must be handled accordingly rather than using a simple INSERT.
Created files, read filesCreated files,
read files
Here are the key implementation points:
Import processing
After deleting all data with %KillExtent(), read the Excel file row by row and perform INSERT operations
Since the header row column names are used directly in the SQL statements, it works even if the column order in Excel changes
The ID column is excluded from insertion because it is automatically managed by IRIS
Since Description is the IdKey, duplicate values would cause errors, but this is avoided by deleting all data beforehand with %KillExtent()
Export processing
If the output file already exists, SELECT and output are performed according to the header order in that file (flexible column handling)
If the file does not exist, a default order (same as expenseitem.xlsx) is used
Retrieve the internal IRIS ID by selecting %ID as ID
As you can see, it produces code with a solid understanding of IRIS-specific characteristics.