How to parse the text file in python and read the lines which contains URLs of git repos without using any libraries?
Note: The text file contains 10 URLs of git repositories.
Format of text file:
repo_name https://www.github.com/path/to/repo
repo_name https://www.github.com/path/to/repo
repo_name https://www.github.com/path/to/repo
Edit: Got it sorted.
def main():
# reading txt file
opFile = open("testrepo/textfile.txt", "r")
lines = opFile.readlines()
opFile.close()
for line in lines:
line = line.strip()
parts = line.split()
repo_name = parts[0]
branch = parts[1]
git_url = parts[2]
print("Repository name: {} \n Branch name: {} \n Git clone url: {}".format(repo_name, branch, git_url))
if __name__ == "__main__":
main()
Output:
Repository name: repo_name
Branch name: master
Git clone url: https://gitlab.com/path/to/repo.git