Q:

Newbie issue with python, script works fine on other os

I am using a bot with python to create accounts on a website. When I use it on my windows machine with python installed, it works fine. I bought a linux VPS yesterday (Ubuntu 16.04) and my script apparently isn't working anymore. This is the error I get on my linux machine:
Traceback (most recent call last):
  File "roblox.py", line 2, in <module>
    from utils import *
  File "/home/py/newbot/utils.py", line 18
    key, *values = line.split(" ")
         ^
SyntaxError: invalid syntax

The line in the script its referring to is this
def string_to_dict(headers):
headers_dict = {}
for line in headers.split("\n"):
    if not line: continue
    line = line.strip()
    key, *values = line.split(" ")
    key = key[:-1]
    if not (key and values): continue
    headers_dict[key] = " ".join(values)
return headers_dict

Any ideas what could have gone wrong? 

A:

As mentioned in other answers, you need to run this in Python3. The shortest answer is:

Install python3, which may not already be on your machine: $ sudo apt-get update; sudo apt-get install python3
Get in the habit of using a shebang in your script files. Add #!/usr/bin/env python3 to the first line of your script to direct the shell to invoke python3 instead of python2 -- most systems come with /usr/bin/python aliased to python2 installations.

You can find out more about sourcing files in the Bash shell (default shell for Ubuntu 16.04) here.
The longer answer -- if you're wondering why the code doesn't work in Python2 but does work in Python3 -- is that Python3 introduced extended iterable unpacking in PEP 3132, but this feature was not implemented in Python2.

