2

I defined a class in try.py

try.py

class student:
    def __init__(self, name, major, gpa, is_on_probation):
        self.name = name
        self.major = major
        self.gpa = gpa
        self.is_on_probation = is_on_probation

Now i created new file in same directory. class.py

class.py

from try import student

student1 = student("Jimmy", "Business", 3.1, False)
print(student1.name)

Output

C:\Users\User\PycharmProjects\test\venv\Scripts\python.exe C:/Users/User/PycharmProjects/test/try.py

Process finished with exit code 0

PROBLEM

The print statement does not produce any result. I'm new to both python and stack overflow. I searched and couldn't find a solution. So I'm posting this.

1
  • 1
    try and class are reserved keyword, thus it will result in a syntax error. Please rename try.py and class.py to a different name to avoid this issue. Also, running what you currently named as try.py produce no output because it only defined a class student and immediately exit. Commented Feb 4, 2019 at 1:46

1 Answer 1

2

You're not running the program that prints things. You're running try.py as a script. You need to run class.py (and you also need to pick better file names, because you've picked two names that are both keywords, preventing use of import).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.