Hi guys,
I'm involved in WorkBench development written in Python.
For debug purposes I need to create a file from within the python code.
Is there a way to do it?
I've tried to call open("filename", "w"), but got "Read-only file system" exception...
If not, is there any other ways to output data beside the FreeCAD.Console.PrintMessage?
Thanks.
Create file from Python WB
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Create file from Python WB
here a sample code for writing a file to home folderproject4 wrote: ↑Thu Jul 19, 2018 5:55 pm Hi guys,
I'm involved in WorkBench development written in Python.
For debug purposes I need to create a file from within the python code.
Is there a way to do it?
I've tried to call open("filename", "w"), but got "Read-only file system" exception...
If not, is there any other ways to output data beside the FreeCAD.Console.PrintMessage?
Thanks.
Code: Select all
import FreeCAD, os, sys
from os.path import expanduser
home = expanduser("~")
out_file=os.path.join(home,'myfile.txt')
FreeCAD.Console.PrintMessage (out_file)
FreeCAD.Console.PrintMessage ('\n')
mycontent=['Hello','this is a second line','and then a third']
with open(out_file, 'w') as my_file:
for item in mycontent:
my_file.write("%s\n" % item)
And the folder must be writable