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 'ofstream.py', which I placed inside "C:\Program Files\GIMP-2.0\lib\gimp\2.0\python" (next to pygimp.py).

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

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

[code]
import math
import ofstream
from gimpfu import *

def testFile():
ofstream.fout()

register(
"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",
"2010",
None,
None,
[],
[],
testFile
)

main()
[/code]

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 gimpfu.py just fine, so by rights I should be able to use fout() contained within ofstream.py 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?"