#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    How can I write a file to a shared folder?


    Hello,

    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:
    Code:
      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')
    
      outputFile.close()
    So for this specific example, lets say that I have mounted a directory /mnt/My_Network_Drive to the server pi at //hostname/Folder.

    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.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,961
    Rep Power
    481
    unix paths look all alike, even if the virtual file system spans many real file systems.

    Had you tried

    open('/mnt/My_Network_Drive/lights.csv', 'w')


    and as a unix command you should be able to create a file

    echo hi world > /mnt/My_Network_Drive/a.file
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo