python – Count *.plot files in certain directories on network filesystems

It’s generally a very bad idea to put credentials in a program. That’s
a bigger topic, and the best approach will vary depending on your situation.
But you should address this problem.

When naming things, let ordinary English usage guide you: plural for
collections (lists, tuples, dicts, etc) and singular for individual values. For
example, use files and file (or even just f if the context is clear), not
files and Files.

Let your code breathe by putting spaces around operators and related items
(equal signs, commas, etc). It helps with readability and often editability
(latter can depend on the editor). Search for PEP8 if you want more details on
recommended naming and layout practices (PEP8 is not gospel, but it is a good
starting point).

It’s often a good idea to group similar data into collections: for example,
a tuple/list/dict of shares rather than sharename, sharename2, sharename3.

When you see repetition in your code, get rid of it. It’s as simple as that.
Usually, you can do this by writing a function to generalize the behavior: for
example, a function taking a share and returning a count. In your specific,
case the grouping of the shares in a collection provides a more direct route:
kill the repetition via a loop over that collection. And since the logic inside
the loop is just counting, you can stick the whole thing in a single sum()
expression (this works because bool is a subclass of int).

shares = (

ext = '.plot'

totalfiles = sum(
    for share in shares
    for _, _, files in os.walk(share)
    for f in files

You asked about making the script less hardcoded. The most natural
way to do that is via command-line arguments and the argparse module.
That’s a bigger topic, but the basic idea is that the share paths and the extension
(.plot) should be variable parameters with default values. Run the script
without arguments, and it will do the default thing. Run it with arguments
and/or options, and it will use different parameters. That’s the time-tested
way to go with scripts like this, and the internet is full of examples
illustrating how to set up argparse.

Finally, if you intend to write more scripts as you build
your Chia Empire,
just adopt the practice of putting all code inside of functions.
It might seem like an unnecessary hassle at first, but this
is another one of those time-tested ideas. The benefits are
numerous. Here’s the basic structure:

import sys

def main(args):
    # Program starts here.

if __name__ == '__main__':