Share python script which uses gsutil
to download a file from google cloud storage bucket. I am facing an issue while using gsutil
Python scripts throws
Syntax error : Invalid Syntax
Share python script which uses gsutil
to download a file from google cloud storage bucket. I am facing an issue while using gsutil
Python scripts throws
Syntax error : Invalid Syntax
That syntax error occurs because that command is supposed to be run from the command line and not the Python interpreter itself.
If you search for cmd
or PowerShell
and try it in that shell instead, it should work - I am guessing you are on Windows from the direction of slashes, but it will be called terminal
on Linux and Mac.
If you want to execute it from a Python script you could use subprocess
or os.system()
.
With os.system()
:
os.system('gsutil cp gs:\\somepath C:\\Users\\sensekar\\Desktop\\Python\\')
With subprocess
:
subprocess.Popen('gsutil cp gs:\\somepath C:\\Users\\sensekar\\Desktop\\Python\\', shell=True, stdout=subprocess.PIPE)
Note that using subprocess
is better practice.
Remeber also to use \\
and not escape character \
.