Skip to content

Commit fc7000e

Browse files
committed
update following solutions
1 parent ad7a7f4 commit fc7000e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

_episodes/07-command_line.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,17 @@ if __name__ == "__main__":
483483
>> {: .language-python}
484484
>>
485485
> {: .solution}
486+
>
486487
>> ## Solution - Mac and Linux
487-
>> For this solution, you would have to find the option `nargs` which would be added to `add_argument` which tells argparse that it may receive more than one value for the argument. T
488+
>> This solution will work for Mac and Linux operating systems. For this solution, you would use the script without the quotes (below).
489+
>> Note that the solution given above will work for any operating system.
490+
>>
491+
>> ~~~
492+
>> $ python analyze_mdout.py data/*.mdout
493+
>> ~~~
494+
>> {: .language-bash}
495+
>>
496+
>> For this solution, you would have to find the option `nargs` which would be added to `add_argument` which tells argparse that it may receive more than one value for the argument. This works on Mac and Linux because these operating systems will automatically create a list of files when you use the wildcard character (`*`).
488497
>>
489498
>> ~~~
490499
>> import os
@@ -498,6 +507,7 @@ if __name__ == "__main__":
498507
>>
499508
>> args = parser.parse_args()
500509
>>
510+
>> # This will already be a list, so we don't need to use glob.
501511
>> filenames = args.path
502512
>>
503513
>> for filename in filenames:
@@ -548,17 +558,20 @@ if __name__ == "__main__":
548558
>> ~~~
549559
>> import os
550560
>> import argparse
561+
>> import glob
551562
>>
552563
>> # Get filename from argparse
553564
>>
554565
>> parser = argparse.ArgumentParser("This script parses amber mdout file to extract the total energy.")
555566
>>
556567
>> parser.add_argument("path", help="The filepath of the file to be analyzed.", nargs='*')
568+
>>
569+
>> # store_true makes this True by default
557570
>> parser.add_argument("-make_plots", help="Flag to create plots", action='store_true')
558571
>>
559572
>> args = parser.parse_args()
560573
>>
561-
>> filenames = args.path
574+
>> filenames = glob.glob(args.path)
562575
>>
563576
>> for filename in filenames:
564577
>>

0 commit comments

Comments
 (0)