How to upload a Python script on github
How to upload a Python script on github
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
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:datainput.txt E:dataoutput.txt
Then you will get the output
E:datainput.txt E:dataoutput.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.
@Newlearner stackoverflow.com/help/someone-answers
– tehhowch
Aug 28 at 4:19
@Newlearner if you feel that I really help you or give you some useful hints, please vote for me. I'd appreciate that.
– pfctgeorge
Aug 28 at 6:03
@pfctgeorge: Unfortunately I do not have enough reputation to upvote.
– New learner
Aug 28 at 23:47
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks a lot. I am about to finish my script. Thanks for the help.
– New learner
Aug 28 at 3:27