Issue
I am having trouble why I am getting an invalid syntax error when I declare what my variable is inside my function. The function works when I step through it in python, but not when I try to run the program from the command line.
command line code:
python filename.py
python code:
import pandas as pd
def my_func(df:pd.DataFrame,name:str):
print("Hello world")
def main():
my_func(df=pd.DataFrame(),name='name')
if __name__ == "__main__":
main()
Solution
Your code is perfectly valid. Check your Python version – you’re probably using a version that doesn’t support type hints, such as Python 2.
(Perhaps python
resolves to python2
?)
Answered By – richardec
Answer Checked By – David Marino (BugsFixing Volunteer)