You are here

using imported functions fail within plugin, but works fine in the console?

Hey everyone. I've run into a bit of trouble trying to use an imported function in one of my PyGimp plugins, and I was hoping someone on the forum might be able to give me a heads up as to why this is happening. Here is the contents of a module that I wrote, called '', which I placed inside "C:\Program Files\GIMP-2.0\lib\gimp\2.0\python" (next to

def fout():
f = open('C:/testData.dat', 'w')
f.write("Hello World")

I'm trying to call the function 'fout' from within a plugin, which contains:

import math
import ofstream
from gimpfu import *

def testFile():

"shows how to open a file and read / write from it using PyGimp",
"takes no arguments. Has no return values",
"jason sultana",
"jason sultana 2010",


Note that if i import ofstream in the PyGimp console and run ofstream.fout(), it works fine. It only plays up if I try to call the function from within my testFile plugin. I get:

"Traceback (most recent call last):
File "", line 1, in
RuntimeError: execution error"

Any ideas as to why this is happening? I'm able to use register() and main() contained within just fine, so by rights I should be able to use fout() contained within also.

Please disregard the lack of whitespace, the forum won't let me indent properly, but the code is properly indented.

Thanks heaps every1 4 any replies

I use neither Python nor Windows, but shouldn't the 'open' statement need backslashes as the directory separator (better still, use Python's 'os.path.join')?

Yeah, I needed to use "\\" just like with C-style languages.

Dunno why I didn't, I guess python reminds me of BASIC lol.

Thanks m8

Subscribe to Comments for "using imported functions fail within plugin, but works fine in the console?"