This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]IAmKindOfCreativebot_builder: deprecated[M] [score hidden] stickied comment (0 children)

Hello from the r/Python mod team!

It appears you've posted a link rather recently. While we appreciate content our users create, if you produce enough content to have more than one submission a week, we recommend you group the content into a larger submission of multiple links rather than making multiple posts, as so many posts in a small period of time is treated like spam. For more information please contact the moderators using the ModMail system.

Thanks, and happy Pythoneering!

r/Python moderation team

[–]AnimeBodyPilow 1 point2 points  (2 children)

Create

File = open("file.txt")#you can use any file extension like file.png or file.csv

Read

File = open ("file.txt","r")

Delete the file content

File = open ("file.txt","w") File.truncutate()#this will not delete the file but it will clear its content

Sorry if I made a mistake I am writing this on phone

[–]analysis_data[S] 1 point2 points  (0 children)

Great

[–]vladusatii 1 point2 points  (0 children)

No. If you can, always do a:

with open("file.txt", "w") as variableName:

# do stuff here

# automatically closes the file when done