在requirements.txt中包含python版本?

时间:2017-04-18 13:22:44

标签: python python-3.x github repository

我是python的新手,但编写了一个小型控制台应用程序来帮助我分析文本文件中保存的一些数据。我没有使用任何外部依赖项,程序是使用python 3.6编写的。遵循最佳实践,我应该在我的存储库中包含requirements.txt文件吗?

虽然这是供个人使用,但我希望将其作为github上的存储库包含在内。目前我的存储库看起来像:

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class DataMaker {
    public static void main(final String args[]) throws IOException {
        DataMaker dm = new DataMaker();
        String file = "D:\\input.txt";
        int roll = 1;
        String rollnum = null;
        String outputfilename = null;

        boolean shouldContinue = false;

        try (BufferedReader br = new BufferedReader(new FileReader(file))) {

            do {

                rollnum = "file-00" + roll;
                outputfilename = "D:\\output\\" + rollnum + ".txt";
                shouldContinue = dm.fillFile(outputfilename, br, 200);
                roll++;
            } while (shouldContinue);

        } catch (FileNotFoundException e) {
            System.out.println("File not found");
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private boolean fillFile(final String outputfilename, final BufferedReader reader, final int limit)
            throws IOException {

        boolean result = false;
        String line = null;
        BufferedWriter fbw = null;
        int temp = 0;
        try {
            OutputStreamWriter writer = new OutputStreamWriter(
                    new FileOutputStream(outputfilename, true), "UTF-8");
            fbw = new BufferedWriter(writer);

            while (temp < limit && ((line = reader.readLine()) != null)) {

                temp++;
                fbw.write(line);
                fbw.newLine();

            }

            // abort if we didn't manage to read the "limit" number of lines
            result = (temp == limit);

        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());
        } finally {
            fbw.close();
        }

        return result;

    }

}

对于小型单模块控制台应用程序,此目录结构是否可接受?

1 个答案:

答案 0 :(得分:2)

这就是为什么我们使用readme.txt权利?您可以在那里包含所需的版本。 Here是对“好的自述文件”的一个很好的解释。希望这会有所帮助。