Jump to content

Python script runs into invalid syntax but works on Google colab

Mr.Stork
Go to solution Solved by Kilrah,

Well check what version you get when running python. It might be python 2 which doesn't support that syntax, and needing to use python3 instead.

The script is to delete a ftp folder and anything in it, and remake it.

The error I get it when I run the same script on my Rasperry Pi is:

  File "/home/Remake.py", line 6
    ftp.delete(f"{path}/{name}")
                              ^
SyntaxError: invalid syntax

But when I run it on Google Colab it works fine, the script is this:

from ftplib import FTP
def remove_ftp_dir(ftp, path):
    for (name, properties) in ftp.mlsd(path=path):
        if name in ['.', '..']: continue
        elif properties['type'] == 'file':
            ftp.delete(f"{path}/{name}")
        elif properties['type'] == 'dir':
            remove_ftp_dir(ftp, f"{path}/{name}")
    ftp.rmd(path)
ftp = FTP('s2.seedboxws.com', 'my_username', 'my_password'); remove_ftp_dir(ftp, 'torrents/Finished'); ftp.cwd('/torrents/'); ftp.mkd('Finished')

The only thing I can think of is maybe the python version on my raspi is old? 

Link to comment
Share on other sites

Link to post
Share on other sites

Well check what version you get when running python. It might be python 2 which doesn't support that syntax, and needing to use python3 instead.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Kilrah said:

Well check what version you get when running python. It might be python 2 which doesn't support that syntax, and needing to use python3 instead.

I checked, its Python 2.7.16.

Do I need to uninstall py v2 and install v3 seperately or just install python 3?

Link to comment
Share on other sites

Link to post
Share on other sites

Python3 is almost certainly already installed, you just have to run your thing with `python3 yourfile` instead of `python yourfile`. Most likely a bunch of stuff on the pi still needs python2 so don't uninstall that.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

Just to add, the error specifically comes from the use of f-strings here. This type of formatting was introduced in Python 3.6.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×