July 10th, 2013, 10:47 AM
How can I write a file to a shared folder?
I have 2 linux machines (raspberry pis), one set up as a NAS server, and another one which will run a script for me.
The goal: I would like to have the one raspberry pi use python to write a .csv file to an already mounted directory. That way, after the script is completed and the file is written to the shared folder, I will then be able to access the .csv file from my windows computer on the same network.
As it stands now, I can see the Samba share from my windows computer, but I can not figure out how to make python write the file to that shared location instead of the pi's desktop.
This is the code I have that writes it to the desktop:
So for this specific example, lets say that I have mounted a directory /mnt/My_Network_Drive to the server pi at //hostname/Folder.
outputFile = open('lights.csv', 'w')
for i in range(len(button_array)):
#Convert the button's time_on variable to a string and append a comma and newline.
outputFile.write(str(button_array[i].total_time_on) + ',\n')
Does anyone know how to fix my code? And if there is something else I am missing, I would appreciate hearing that too. I am still very new to linux, networking, and python, and I would appreciate any input.
July 10th, 2013, 07:51 PM
unix paths look all alike, even if the virtual file system spans many real file systems.
Had you tried
and as a unix command you should be able to create a file
echo hi world > /mnt/My_Network_Drive/a.file
[/code] are essential for python code and Makefiles!