[Tutor] wordcount.py provided exercise solution not working?
Matthew Borkenhagen
borkenhagenmatthew at gmail.com
Wed Sep 20 19:33:52 EDT 2023
Thank you Mats, that is very helpful. Is a file provided by Google or will
I need to create one myself? (Just use a text editor like Notepad++? Save
it with a .txt extension?)
Matt Borkenhagen
On Wed, Sep 20, 2023, 5:10 PM Mats Wichmann <mats at wichmann.us> wrote:
> On 9/20/23 16:41, Matthew Borkenhagen wrote:
> > Hello,
> >
> > In working through Google's Python Class (
> > https://developers.google.com/edu/python) I just ran the provided
> solution
> > from Google for the exercise on dicts and files: wordcount.py
> > When I run this program while in the proper directory at the command
> > prompt, the program only prints *this result*:
> >
> > *usage: ./wordcount.py {--count | --topcount} file*
> >
> > My question is this--Is this provided solution ever reading a file?
> (What
> > is the filename that it should be reading called? Where would this file
> > be located? In the directory google-python-exercises\basic\solution or
> > would I need to create a file myself for it to read in order to test the
> > program?)
>
> The filename is whatever you tell it. But, apparently, you *have* to
> select one of the options too (it's not "optional").
>
> def main():
> if len(sys.argv) != 3:
> print('usage: ./wordcount.py {--count | --topcount} file')
> sys.exit(1)
>
> option = sys.argv[1]
> filename = sys.argv[2]
>
> This says: if the script is not called with three arguments, print an
> error message and quit. By convention, the name of the program you just
> ran is sys.argv[0], so you have to supply two more arguments on the
> command line. The first will be the option you selected, and the second
> will be the filename to count the words in.
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list