# tf.compat.v1.data.make_one_shot_iterator

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4242-L4272) |

Creates an iterator for elements of `dataset`.

    tf.compat.v1.data.make_one_shot_iterator(
        dataset
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

This is a legacy API for consuming dataset elements and should only be used
during transition from TF 1 to TF 2. Note that using this API should be
a transient state of your code base as there are in general no guarantees
about the interoperability of TF 1 and TF 2 code.

In TF 2 datasets are Python iterables which means you can consume their
elements using `for elem in dataset: ...` or by explicitly creating iterator
via `iterator = iter(dataset)` and fetching its elements via
`values = next(iterator)`.

<br />

<br />

## Description

> [!NOTE]
> **Note:** The returned iterator will be initialized automatically. A "one-shot" iterator does not support re-initialization.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dataset` | A [`tf.data.Dataset`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/data/Dataset). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tf.data.Iterator`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/data/Iterator) for elements of `dataset`. ||

<br />