+ 4

How can I zip my python file(.py) with a text file(.txt)?

I used a text file in a python project. I wish to combine both so that I won't have to be sending them separately to 3rd parties that wish to run the code

28th Apr 2020, 4:03 PM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar
3 ответов
+ 4
from zipfile import ZipFile with ZipFile("Name1.zip", "w") as any: any.write("Name2.py") any.write("Name3.txt") any. write("Name4.md") #Name 1 refers to the name of the zip you're trying to make #Name 2,3,4, etc refers to the different types of file you wish to 'zip together'(i.e put in a zip file) #The condition is that Name2,3,4, etc must all be in the same directory/folder
8th May 2020, 9:55 AM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar
+ 7
If the file is not too big, you could store it inside your program as a multiline string, like text = """ This is your text file. """
28th Apr 2020, 7:05 PM
Tibor Santa
Tibor Santa - avatar
+ 4
Tibor Santa , thanks for your feedback
8th May 2020, 9:56 AM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar