开发者

Reading a file via open().read() vs storing it in a variable

I've written this small app in Python that will generate paragraphs of dummy text, kind of like this site, except it'll work offline. Right now you're supposed to provide a reasonably long text file (I'm currently using books from Project Gutenberg), which it will call open() and then read() on to开发者_如何转开发 get the initial string for the operation, but what's to stop me from just including the whole text file in the program, as a variable? i.e

lorem_ipsum = """
***full text of De finibus bonorum et malorum***
***no seriously***
***yeah...***
"""

Are there any disadvantages to doing this versus reading it in from a separate text file?


There's a few problems:

  • Your program becomes really hard to read.
  • You run the risk of """ appearing in the text and blowing everything up
  • You break the whole concept of content existing in the format in which it belongs. The book in question is a text file, it should live in a text file and if Python needs it, it should pull it from there. Otherwise newcomers to the app have to look everywhere for every type of data. not fun.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜