当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Make a variable from what's in a text file

问题描述:

So I want to make a variable from the contents of a text file.

E.g

The text file contains the sentence "Ask not what your country can do for you ask what you can do for your country"

Now I want the variable to be like

Sentence = ("Ask not what your country can do for you ask what you can do for your country")

But from the text file, if that makes any sense?

网友答案:

The file contains.

[email protected] ~/Projects/Stackoverflow $ cat abc.txt 
hai am here

Here is the python code.It's very simple logic.

fo = open("abc.txt", "r+")
a = fo.read()
分享给朋友:
您可能感兴趣的文章:
随机阅读: