0

What should be the variable type of a _io.TextIOWrapper object as argument for a function in Cython?

e.g.

f = open("myfile.txt","r")

cpdef int myFunction(f):
    ...
    return 0 

Something like this?:

cpdef int myFunction(FILE* f):
    ...
    return 0

Thank you.

aerijman
  • 2,522
  • 1
  • 22
  • 32
  • 1
    I haven't studied the `cython` docs recently, but I wonder if it has any special OS code. It may just take open files as generic Python objects, and call their own methods. In that case, variable type isn't needed nor useful. – hpaulj Aug 26 '20 at 18:57
  • 1
    It'd always be possible to use the C standard library file handling functions instead, but you'd need to switch to them completely. You then couldn't use a `cpdef` function because there's no Python equivalent. Personally I'd just leave it as an untyped Python object as hpaulj suggests – DavidW Aug 26 '20 at 21:19

0 Answers0