1

In Python, what is a database "cursor" most like?

  1. A method within a class

  2. A Python dictionary

  3. A function

  4. A file handle

I have searched on internet but I am not getting proper justification of this question.

0

2 Answers 2

2

According to the PEP 249 (Python Database API Specification), it is an object which is expected to have certain attributes and methods defined. Optionally, cursors can support an iteration protocol.

This is though a spec, and, your database driver of choice may not follow the API specification. But, this is a more or less general answer to the rather general question.

Sign up to request clarification or add additional context in comments.

Comments

2

Probably it is most like a file handle.

That does not mean that it is a file handle, and a cursor is actually an object - an instance of a Cursor class (depending on the actual db driver in use).

The reason that it's similar to a file handle is that you can consume data from it, but (in general) you can't go back to previously consumed data. Consumption of data is therefore unidirectional. Reading from a file handle returns characters/bytes, reading from a cursor returns rows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.