Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access file in external hard drive using python on mac

Tags:

python

io

macos

I have a Python file in /Users/homedir/... and I want it to access a csv file on an external hard drive.

Does anyone know how to do this? I only need reading permission.

like image 840
Neal Bayya Avatar asked Mar 10 '18 23:03

Neal Bayya


People also ask

How do I view files on my external hard drive Mac?

First, connect the drive by USB. Double-click the USB hard drive icon to open up a Finder window and browse its contents. Click Finder > Devices to see a small icon of the external hard drive when plugged in. Click to select it and show its contents in Finder.

How do I open a drive in Python?

Have you ever wondered that you can open your drives by just typing C, D or E and then that drives are open. This can be possible by using Python. So, for performing this task this we are using os. startfile() method of OS library.


2 Answers

External drives can be found under /Volumes on macOS. If you provide the full path and have read access you should be able to read in your csv.

like image 116
Patrick Duncan Avatar answered Sep 26 '22 21:09

Patrick Duncan


I have USB connected WD 4 TB hard drive that appears as "My Passport for Mac" in finder. I have created a folder called model on this drive and stored a file called model.json

Here is code to read the file.

import os
import sys
 # load json and create model

json_file = open('/Volumes/My Passport for Mac/model/model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()

My Mac Mini has 121 GB SSD which I find limiting when I work with huge data for ML exercises. I used to keep getting messages such as "low volume. clean up your disk " often and then I had to clean the files. To work around I bough 4 TB external HD from WD and attached it to MAC mini via USD. I put all my data files and models onto this drive now and it works fine.

like image 40
Evergreen Technologies Avatar answered Sep 23 '22 21:09

Evergreen Technologies