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.





Thanks a lot. I am about to finish my script. Thanks for the help.
– New learner
Aug 28 at 3:27





@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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)