Why won\'t this work :
with open(\'file.pdf\', \'w\') as outfile:
outfile.write(\"Hello\")
The code works fine, but the .pdf file cann
What's the difference between a normal text file and pdf?
A PDF file has a specific format. You can read more here. A text is a much simpler file, thus when you attempt to open a file that you think it's a PDF, but doesn't have this format, the file cannot be opened.
What to do if I want to create and write to a pdf file in python?
You need to use a module, like PyPDF2, Reportlab or FPDF. Moreover read Python PDF library.