Page 1 of 1

Suppress output when loading hoc file using h(xopen(''))

Posted: Fri Aug 27, 2021 6:52 pm
by landoskape
I'm running an optimization that requires me to reload cells frequently. Everytime I do so it outputs a "1" to the screen (I'm working in jupyter lab). How do I suppress this?

I'm loading a .hoc file by using the following line:

Code: Select all

h('xopen("./filename.hoc")');
Thanks for your assistance

Re: Suppress output when loading hoc file using h(xopen(''))

Posted: Tue Aug 31, 2021 9:12 am
by landoskape
For anyone bothered by this: here's a python specific solution:

Code: Select all

from contextlib import contextmanager
import sys, os

@contextmanager
def suppress_stdout():
    with open(os.devnull, "w") as devnull:
        old_stdout = sys.stdout
        sys.stdout = devnull
        try:  
            yield
        finally:
            sys.stdout = old_stdout

with suppress_stdout():
	h('xopen("./filename.hoc")');