Opening and appending to file in Python3

Joined
Mar 29, 2023
Messages
10
Reaction score
1
I am really enjoying myself learning Python3. But now i seem to have hit a brick wall and cannot find a way around it.
I have been practicing the little i know of python3 with a simple little script called "practice.py" as follows:

Code:
    #!/usr/bin/env python3
    #
    practice = ["Billy", "John", "Peter", "Simon", "Kevin"]
    print(*practice, sep='\n')

Which returned the following:

Billy
John
Peter
Simon
Kevin

Flushed with success i decided to add another name to the list "a":

Code:
    f = open("lpthw/practice.py", "a") 
    When i try to go to the second line i recieve an error of "Invalid syntax"

Could some one help me out here please.
 
Joined
Dec 10, 2022
Messages
72
Reaction score
22
This f = open("lpthw/practice.py", "a") doesn't do anything by itself.
I recommend reading about working with files.
 
Joined
Mar 29, 2023
Messages
10
Reaction score
1
I have now got around the error and can't wait to learn all i can regarding the Python programming Language.
I have to agree with VBService that using With Open is a better option. Big thanks for the replies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,717
Messages
2,569,382
Members
44,701
Latest member
OurCBDLifeSupplement

Latest Threads

Top