--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/57944e74-0ad7-4b4d-976d-6bdaccdf412co%40continuum.io.
Hi Mark,thank you for using Numba, and thank you for asking about this.It might be a bit of a longshot, but perhaps you could use an 'objmode' block: http://numba.pydata.org/numba-doc/latest/user/withobjmode.html?highlight=objmode%20block#the-objmode-context-manager - it says you can't use `with` in that block, but perhaps you can close the file manually?Best wishes,V-
On Tue, Jun 23, 2020 at 8:06 AM Mark Turiansky <mark.t...@gmail.com> wrote:
Hello,--I was wondering if it is possible with the jitclass interface to define "staticmethods", which are not compiled with nopython=True?The reason I ask is because a very common code style that I run into is for data classes that read and write to a file. For example,```class Data:def __init__(self, fname, data):self.fname = fnameself.data = data# stuff stuff stuff@staticmethoddef from_file(filename):with open(filename, 'r') as f:data = []for line in f:data.extend([float(x) for x in line.split()])return Data(filename, data)```In this case, applying @jitclass compiles the class, and I can access all of the other variables/methods. However, when I try to do "Data.from_file(filename)", I get an error associated with the "with" statement. If I replace the statement with "f = open(filename, 'r')" and "f.close()", then I get an error "Untyped global name 'open': cannot determine Numba type of <class 'builtin_function_or_method'>". It would be nice if I could specify that this specific method doesn't need to be compiled or should just be in object mode.Thanks for your help.Best,Mark
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba...@continuum.io.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/8501a0ed-4fdc-462c-8f01-7d1690bfa4c4o%40continuum.io.