0

Suppose I have a Python script working on my windows computer. It reads a file at path 'E:/.../input' and gives output at path 'E:/.../output'. Is it possible to upload it on github, such that with appropriate shell commands other people just need to run the same script on their linux machine?

The question is motivated by

https://github.com/InsightDataScience/prediction-validation

However I do not have a Linux machine I can use to test my script. Hence the question.

1 Answer 1

1

It can be.

But since format of file path and structure of file system is OS-specific, you should modify your code to support cross-platform feature.

You can choose to do one of these:

1) If you use relative path for read from input or write to output, you can use code like os.path.join("input", "folder", "input.txt") to get the path of input file from the place of your source code. Since implementations of os.path.join in different operating systems are different with each other. So you don't need care about the different format of file path any more.

2) If you use absolute path for read and write, you can use program arguments to let user to specify the absolute path of the input/output file path. Like, in simplest case,

import sys
input = sys.argv[1]
output = sys.argv[2]
print(input, output)

When you run the code (if named with script.py) with:

python3 script.py E:\data\input.txt E:\data\output.txt

Then you will get the output

E:\data\input.txt E:\data\output.txt

So in this way, you give the freedom to users to choose the input and output path, no matter what operating system they are using.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot. I am about to finish my script. Thanks for the help.
@Newlearner if you feel that I really help you or give you some useful hints, please vote for me. I'd appreciate that.
@pfctgeorge: Unfortunately I do not have enough reputation to upvote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.