Question
01/project_name.py (50 points, group admin) Write a Python program that tries to guess project name when executed. The program will look for a file named
01/project_name.py (50 points, group admin)
Write a Python program that tries to guess project name when executed.
The program will look for a file named README.md (in current directory) and it will print its first non-empty line. We assume that project name would be on the first line of the read-me file.
If all lines are empty or the file does not exist, the program will try to look for readme.md, README and readme in this order (stopping the search when title is found). That is, if readme.md contains non-empty line, it will not even try to look for README.
If no file from the above list contains non-empty line, the program will print name of the current directory (os.path.basename(os.getcwd())).
We consider line empty if line.strip().lstrip('# ') == ''. Printing the project title should also strip it of blank spaces and leading # (i.e. the above code). This ensures that trailing whitespace is ignored and for Markdown titles we remove extra formatting.
name the file project_name.py.
For this task, we have created a simple skeleton that you should use as a starting point.
Important: the first line in the skeleton code from us starting with #! is there for a reason and you have to keep it there. Also keep the usage of main() and the condition with __name__ as that represents a proper module-ready code.
here is the skeleton code:
#!/usr/bin/env python3 def main(): print('project-name') if __name__ == '__main__': main()
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