Having trouble with File writing inside a class

I have a class which I want to create a write method for which at the moment looks like this:

  write {
    arg path;
    var outPath, outFile;
    outPath = PathName.new(path);
    this.traverse(this);
    outFile = File.new("~/foo.rpp".standardizePath, 'w');
    outFile.close;
  }

Eventually "~/foo.rpp" will be replaced by outPath, however, this current code calls an error when I try to run the write method.

ERROR: Primitive '_FileOpen' failed.
Wrong type.
RECEIVER:
Instance of File {    (0x7fe6aa89f5e8, gc=88, fmt=00, flg=00, set=02)
  instance variables [1]
    fileptr : nil
}

I’ve tried this on both MacOS and windows to rule out any basic errors with my build on the M1 Macbook but I get the same error on both. If I make a fairly comparable bit of code outside of the class and in the language it works. Example is here:

(
x = File.new("~/foo.rpp".standardizePath, "w"):
x.close;
)

Can anyone point me to where I am thinking about this poorly or incorrectly?

You’re doing
outFile.close
but haven’t set it to anything, it seems

Cheers,
eddi

Sorry I edited my original post with an error in my code :slight_smile: outFile is now assigned with File.new(). I also removed the close line to see if that stopped the error but it didnt.

mode needs to be a String not a Symbol

“w” not ‘w’

cheers

Ha, great catch… I’m still getting used to the difference as a Python user.