Re: wordcount.py provided exercise solution not working?

Matthew Borkenhagen <[email protected]>
Newsgroups gmane.comp.python.tutor
Message-ID <CA+to6D2xMJQCeO2bcJSrb+_usCnVcFiV7fmmEOEMA=bEiauijQ@mail.gmail.com>
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 <[email protected]> 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  -  [email protected]
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.