# Porting guide for changes in IDAPython-on-Python-3 APIs

Intended audience: IDAPython developers

### Scope of this guide

IDA 7.4 [comes with the possibility of using Python 3](https://hex-rays.com/products/ida/support/ida74_idapython_python3).

Using Python 3 means that some code, which used to work, might require porting:

* `print()` becoming a function, not a statement
* `xrange` becoming `range`
* `__builtin__` becoming `builtins`
* strings being unicode and not sets of bytes
* integer division uses `//` and not `/`
* `map()` returning a map object, not a list
* `{}.iteritems()` (and similar) are gone
* some changes in the `import` mechanism
* …

Those are all well-documented Python 3 specifics, are [thoroughly documented](https://python-future.org/compatible_idioms.html), and Python even provides [tools](https://docs.python.org/2/library/2to3.html) to help with the transition.

This guide is not about those, but about IDAPython-specific changes to the API, but many of those being “ripples” of those Python 3 changes.

### The guide

Note: that all qualified names below use their originating IDAPython module’s name (e.g., `ida_kernwin`) instead of the ‘umbrella’ `idaapi` module.

| `ida_bytes.data_format_t.printf`                                  |                               | The `value` parameter used to be a `str`, now is `bytes`                                             |
| ----------------------------------------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------- |
| `ida_bytes.get_bytes, ida_bytes.get_bytes_and_mask`               |                               | Used to return a `str`, now returns `bytes`                                                          |
| `ida_bytes.get_strlit_contents`                                   |                               | Used to return a `str`, now returns `bytes`                                                          |
| `ida_hexrays.mbl_array_t.serialize`                               |                               | Used to return a `str`, now returns `bytes`                                                          |
| `ida_idp.IDP_Hooks.ev_assemble`                                   |                               | Used to return a `str`, now must return `bytes`                                                      |
| `ida_netnode.netnode.getblob`                                     |                               | Used to return a `str`, now returns `bytes`                                                          |
| `ida_registry.reg_read_binary`                                    |                               | Used to return a `str`, now returns `bytes`                                                          |
| `ida_typeinf.tinfo_t.serialize`                                   |                               | Used to return `str` instances for the ‘type’ and ‘fields’ parts of the tuple, now those are `bytes` |
| `ida_typeinf.get_numbered_type`                                   |                               | Used to return `str` instances for the ‘type’ and ‘fields’ parts of the tuple, now those are `bytes` |
| `ida_ua.insn_t.insnpref`                                          |                               | Used to return a `str`, now returns an `int`                                                         |
| `ida_ua.insn_t.segpref`                                           |                               | Used to return a `str`, now returns an `int`                                                         |
| `idautils._cpu.<large vector registers, such as xmm0, ymm0, ...>` |                               | Used to return a `str`, now returns `bytes`                                                          |
| `idautils.Functions.next`                                         | `idautils.Functions.__next__` | Required to turn the type into a proper iterator in Python 3                                         |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hex-rays.com/9.1/archive/porting-guide-for-changes-in-idapython-on-python-3-apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
