如何附加到txt文件

时间:2016-12-08 20:21:15

标签: python python-3.x

你好,所以我的文字名为 students.txt ,里面有名字。

Buddy Mike Freshman 3.00
Allen Hood Sophmore 3.45
Dave Beck Freshman 3.00
Jose Sanford Sophmore 3.45
Juan Castro Freshman 3.00

我想将用户输入的信息添加到现有文件 学生 中,并将其打印出新内容。

def add_Student():
    myNames = []
    Name = input("Enter First and Last Name of Sudent: ")
    Status = input("Enter Status of Stdent: ")
    GPA = input("Enter Students GPA: ")
    newStudent = Student.Student(Name, Status, GPA )

    print("Student' Name: ",newStudent.getName())
    print("Student' Status: ",newStudent.getStatus())
    print("Student' GPA: ",newStudent.getGPA())

1 个答案:

答案 0 :(得分:0)

要将数据附加到文件,请使用选项" a":

打开它
QUERY = "SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)"