0

I am new to using terminal in Mac. When I type any python3 command it only checks the users folder on my PC, HOW can I change the directory to open a folder in the users section and check for the .py file there?

4 Answers4

1

Access the desired path using cd command

cd path/to/access

Then you can run the python command to run the scripts.

frab
  • 1,162
  • 1
  • 4
  • 14
0

If you know the name of the folder in which you want to check, you can change the current python directory using: os.chdir

https://docs.python.org/3/library/os.html#os.chdir

In that case it doesn't matter from where you're running your python script.

robbo
  • 525
  • 3
  • 11
0

You can use the OS library which comes shipped with Python. to change the current directory inside the script, you can simply write:

import os

os.chdir("newDir/")

if you should want to get all directories which are in the user's current location, you can use the method:

os.listdir()

Hope that helps you out.

Bialomazur
  • 1,122
  • 2
  • 7
  • 18
0

You have to use the command cd to your folder first.

KKCH
  • 79
  • 9