File tree 4 files changed +36
-0
lines changed
4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ to create it. There is some material not covered in the presentation as well.
28
28
configuration files.
29
29
1 . ` data-formats ` : illustrates how to deal with data formats such as CSV
30
30
files, binary data and XML.
31
+ 1 . ` directory-entrypoint ` : illustrates how to define an application entry point in
32
+ a directory.
31
33
1 . ` enviroment-variables ` : illustrates how to use environment variables to set paths
32
34
in a script.
33
35
1 . ` hydra ` : Facebook Hydra application framework illustration.
Original file line number Diff line number Diff line change
1
+ # Directory entry point
2
+
3
+ Using ` __main__.py ` as an entry point, the Python interpreter can run a
4
+ directory.
5
+
6
+ ## What is it?
7
+
8
+ 1 . ` messenger ` : directory containing the application.
9
+ 1 . ` messenger/__main__.py ` : Python application entry point.
10
+ 1 . ` messenger/messenger.py ` : Python module defining some functions for the
11
+ application.
Original file line number Diff line number Diff line change
1
+ import argparse
2
+ import messenger
3
+ import sys
4
+
5
+
6
+ arg_parser = argparse .ArgumentParser (description = 'say something to the user' )
7
+ arg_parser .add_argument ('--hello' , action = 'store_true' , help = 'say hello' )
8
+ arg_parser .add_argument ('--bye' , action = 'store_true' , help = 'say bye' )
9
+ arg_parser .add_argument ('name' , help = 'name to talk to' )
10
+ options = arg_parser .parse_args ()
11
+
12
+ if options .hello :
13
+ messenger .say_hello (options .name )
14
+ if options .bye :
15
+ messenger .say_bye (options .name )
16
+ if not (options .hello or options .bye ):
17
+ print (f"don't know what to say to { options .name } " , file = sys .stderr )
18
+ sys .exit (1 )
Original file line number Diff line number Diff line change
1
+ def say_hello (name ):
2
+ print (f'hello { name } ' )
3
+
4
+ def say_bye (name ):
5
+ print (f'bye { name } ' )
You can’t perform that action at this time.
0 commit comments