在python中打开Type文件的文件

时间:2017-03-02 06:24:41

标签: python

我很少<?php if (isset($_POST['Btn'])) { echo "<p>".$_POST['Btn']."</p>"; } ?> <form action="somefile.php" method="POST"> <div class="form-group col-md-4"> <label>Sold Out</label> <div> <button data-toggle="collapse" name="btn" value="YES">YES </button> <button data-toggle="collapse" name="btn" value="NO">NO</button> </div> </div> </form> 存储没有任何扩展程序:

{{3}}

如何打开它们?

3 个答案:

答案 0 :(得分:4)

with open('1', 'r') as fp:
    content = fp.read()

这样,文件将一直关闭。

答案 1 :(得分:3)

要添加@ math2001的答案,你可以这样做:

numOfFiles = #int
data = []

for files in range(1, numOfFiles+1):
    with open(str(files), 'r') as f:
        // do whatever data processing you need to do
        fileData = f.read()
        data.append(fileData)

答案 2 :(得分:2)

另一种方式:

import os
import glob
files = filter(os.path.isfile, glob.glob("./[0-9]*"))
for name in files:
    with open(name) as fh:
        contents = fh.read()
        # do something with contents (parse email format)