Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument Parsing 3/3 #30

Open
dpshelio opened this issue Nov 18, 2024 · 0 comments
Open

Argument Parsing 3/3 #30

dpshelio opened this issue Nov 18, 2024 · 0 comments
Labels
week07 Creating packages

Comments

@dpshelio
Copy link
Contributor

dpshelio commented Nov 18, 2024

Carrying on from the previous exercise (#29), now we will change the options so instead of reading the numbers from the command line, they are read from text files (one number per line), and keeping the optional parameter to accept weights also as a file.

Reading data from files

  1. Choose who in your team is writing now! (pull the code from the previous exercise into your local repository)
    Hint: You need to add a new remote from your team member and pull their branch

  2. Create a new branch from the branch used in the previous exercise.

  3. Open the file squares.py. Make sure you can run it from a terminal with some input values!

  4. Look at the part of the file that is using argparse

  5. Modify the arguments so the data is read from a text file. Where the weights are still optional. The file should be runnable as:

    python squares.py <file_numbers> --weights <file_weights>

    where <...> should be replaced by the file of your choice.
    The <file_numbers> and <file_weights> could be as simple as a txt file with a single row of numbers.

    • Look at the working with data section to refresh how we read files in Python.
    • Modify the argparser arguments to receive file names instead of numbers.
    • Check the auto-generated help: python squares.py --help.
    • Check that you can run the file with the new form, whether you pass a weights file or not.
  6. Share your solution as a pull request to the average_squares repository mentioning this issue (by including the text Addresses UCL-COMP0233-24-25/RSE-Classwork#30 in the pull request description), remember to mention your team members too! (with @github_username)


Sample solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
week07 Creating packages
Projects
None yet
Development

No branches or pull requests

1 participant