Alex
Alex

Reputation: 1031

How to output to custom file descriptor?

C code:

write(3, "str", sizeof("str") - 1);

Usage: ./a.out 3>/dev/stdout

How to achieve the same functionality in Python? From documentation I should call open function and use given file descriptor. But what if I already have it?

Upvotes: 1

Views: 486

Answers (1)

Damon Snyder
Damon Snyder

Reputation: 1372

You should be able to do something similar in python. See this SO answer for a more detailed description.

It'll look something like:

yourfd = open(3, "w")
yourfd.write("str")
yourfd.close()

Upvotes: 1

Related Questions