Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Title: Processing a Iocale file with Python In this assignment, you will write a Python program vaguely inspired by Unix command locale. Your Python program
Title: Processing a "Iocale" file with Python In this assignment, you will write a Python program vaguely inspired by Unix command locale. Your Python program will parse a file containing information about language "locales" and "charmaps" and will generate output depending on the command line. These are the specifications for your Python program: It must be named locale.py It should be invoked as: python locale.py option argumentfile In the command line above, option means one of the options described below, and argumentfile means the chosen argument file, which can have any arbitrary name. The program must check that argument argument file exists, is a file and is readable. If not, it must print an error message to the standard output and exit. The specifications for the argumentfile and option arguments are given below. File argument file can have any arbitrary name. It must be a file of text with the following format: a The file consists of an arbitrary number of lines including possibly, zero lines b Each line must contain three fields separated by commas. c The three fields are: type, language, filename. d The type field can only have as value the literal strings locale or charmap. e The language and filename fields are each a string of characters of arbitrary yet reasonably limited length. Acceptable characters include: lower and upper case letters, digits, underscore, dot. Fundamental note: your program is not expected to verify that file argument file complies with the above specifications. It will only be tested with compliant files. The following example should be regarded as the reference specification for the format of file argumentfile: Your program can be invoked with option: a In this case, it must print the filenames of all the available locales, in this format:Example with the example argument file given above:Command line:python locale.py a argumentfileExpected output:In the case in which file argument file is empty or no available locales exist, your program must instead only print: No locales available Your program can be invoked with option: m In this case, it must print the filenames of all the available charmaps, in this format:Example with the example argument file given above:Command line:python locale.py m argumentfileExpected output:Available charmaps:ENGBK In the case in which file argumentfile is empty or no available charmaps exist, your program must instead only print: No charmaps available Your program can be invoked with option: I language. The language argument has the same format as the language field in the argument file. In this case, your program must search for the language in the argument file, and if it finds it print the following information:Example with the example argument file given above:Command line:python locale.py l English argumentfileExpected output:Language English:Total number of locales: Total number of charmaps: Another example with the example argument file given above:Command line:python locale.py Chinese argumentfileExpected output:Language Chinese:Total number of locales: Total number of charmaps: In the case in which language language is not present at all in argumentfile, your program must print: No locales or charmaps in this language Example with file argumentfile given above: Command line: python locale.py German argumentfile Expected output: No locales or charmaps in this language Your program can be invoked with option: v In this case, it must only print your name, surname, student ID and date of completion of your assignment, in a format of your choice. Please note that argument arqument file is still required. No options can be used simultaneously. This means that your program can only be invoked with one of the options at a time. If your program is invoked with any other syntax than those specified above, it must print a message of your choice to the standard output and exit. Examples of incorrect syntax: python locale.py z argumentfile this option doesn't exist python locale.py a it misses the argument file python locale.py l argumentfile it misses the language argument
Title: Processing a "Iocale" file with Python
In this assignment, you will write a Python program vaguely inspired by Unix command locale. Your Python program will parse a file containing information about language "locales" and "charmaps" and will generate output depending on the command line.
These are the specifications for your Python program:
It must be named
locale.py
It should be invoked as:
python
locale.py option argumentfile
In the command line above, option means one of the options described below, and argumentfile means the chosen argument file, which can have any arbitrary name.
The program must check that argument argument file exists, is a file and is readable. If not, it must print an error message to the standard output and exit. The specifications for the argumentfile and option arguments are given below.
File argument file can have any arbitrary name. It must be a file of text with the following format:
a The file consists of an arbitrary number of lines including possibly, zero lines
b Each line must contain three fields separated by commas.
c The three fields are: type, language, filename.
d The type field can only have as value the literal strings locale or charmap.
e The language and filename fields are each a string of characters of arbitrary yet reasonably limited length. Acceptable characters include: lower and upper case letters, digits, underscore, dot.
Fundamental note: your program is not expected to verify that file argument file complies with the above specifications. It will only be tested with compliant files.
The following example should be regarded as the reference specification for the format of file argumentfile:
Your program can be invoked with option: a In this case, it must print the filenames of all the available locales, in this format:Example with the example argument file given above:Command line:python locale.py a argumentfileExpected output:In the case in which file argument file is empty or no available locales exist, your program must instead only print:
No locales available
Your program can be invoked with option: m In this case, it must print the filenames of all the available charmaps, in this format:Example with the example argument file given above:Command line:python locale.py m argumentfileExpected output:Available charmaps:ENGBK
In the case in which file argumentfile is empty or no available charmaps exist, your program must instead only print:
No charmaps available
Your program can be invoked with option: I language. The language argument has the same format as the language field in the argument file. In this case, your program must search for the language in the argument file, and if it finds it print the following information:Example with the example argument file given above:Command line:python locale.py l English argumentfileExpected output:Language English:Total number of locales: Total number of charmaps: Another example with the example argument file given above:Command line:python locale.py Chinese argumentfileExpected output:Language Chinese:Total number of locales: Total number of charmaps: In the case in which language language is not present at all in argumentfile, your program must print:
No locales or charmaps in this language
Example with file argumentfile given above:
Command line:
python
locale.py German argumentfile
Expected output:
No locales or charmaps in this language
Your program can be invoked with option: v In this case, it must only print your name, surname, student ID and date of completion of your assignment, in a format of your choice. Please note that argument arqument file is still required.
No options can be used simultaneously. This means that your program can only be invoked with one of the options at a time.
If your program is invoked with any other syntax than those specified above, it must print a message of your choice to the standard output and exit.
Examples of incorrect syntax:
python
locale.py z argumentfile this option doesn't exist
python
locale.py a it misses the argument file
python
locale.py l argumentfile it misses the language argument
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started