-1

I have some basic code that I am running:

import random 
import string 


def generate_id(): 
    return "".join(random.choices(string.ascii_uppercase,k=12)) #generates random 12 character string 


class Person: 
    def __init__(self,name,address): 
        self.name = name
        self.address = address 

    def __str__(self): 
        return f"{self.name}, {self.address}"


def main(): 
    person = Person("John","123 Main St")
    print(person)



if __name__ == "__main__": 
    main()

When I run this code in my Pycharm IDE, I get:

John, 123 Main St

As expected.

However, when I run it from my terminal, I get a syntax error for line 14 (return f"{self.name}, {self.address}")!

Any idea what could be causing this?

Patrick_Chong
  • 302
  • 1
  • 8
  • 3
    Different Python versions? f-strings were introduced in Python 3.6. Add a line `print(sys.version)` and run again in both environments – Tomerikoo May 26 '22 at 09:01
  • 1
    Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly as a [mre]. You can get more [formatting help here](https://stackoverflow.com/help/formatting). You can also read about [why you shouldn't post images/links of code](//meta.stackoverflow.com/q/285551). – Tomerikoo May 26 '22 at 09:03
  • Thanks Tomerikoo, you're right! I didn't think about the versions. I've also changed the image to code. – Patrick_Chong May 26 '22 at 09:14
  • And thanks for the heads up regarding the image, I had no idea until now! :) – Patrick_Chong May 26 '22 at 09:15

0 Answers0