Aisha's Greetings

I recently posted my completed code for the Intermediate Python3 Course for AISHA’S GREETINGS project. After I completed the project I saved my work as a Github GIST (link above).
Then I copied and pasted it into my Atom Directory for my python projects.
When I ran it It did nothing.
Then I realized I needed the other files:
thankyou_card.txt
happy_bday.txt
and now there are additional .txt files: (The result of calling the context manager and class approach methods):
Mwenda_generic.txt
john_personalized.txt
Josiah_personalized.txt
Josiah_generic.txt

My question and area where I would like clarification:
I recently completed (and posted as a gist - see link above) the final project in the ‘Intermediate Python3’ course, Aisha’s Greetings working in the codecademy environment. And herein lies my problem. The project (directory) utilizes two .txt files that are provided.
Note: after creating the gist I added the other .txt files later.

So my problem is two-fold:
HOW DO I INCLUDE THE ‘HAPPY_BDAY.TXT’ AND ‘THANKYOU_CARD.TXT’ FILES IN BOTH MY GIST AND ATOM SO THE PROGRAM WILL RUN SUCCESSFULLY?

I also saved my work in Atom (I also work with Visual Studio code, but this time I chose Atom)
When I went to run the program I received the following error:
FileNotFoundError: [Errno 2] No such file or directory: ‘thankyou_card.txt’

So, of course I realized, I need the two provided text files ‘thankyou_card.txt’, and ‘bday_card.txt’ but I don’t know how to include them in Atom. I’ve been reading some documentation for Atom but an still confused. Can someone explain to me how to proceed?

I have other Atom saved projects that involve

importing modules but these .txt files are not modules that already exist elsewhere.
As I read the Atom documentation it seems I can create a project folder and add other directories to the primary folder but don’t seem to be able to add ‘files’. So I’m not sure. Do I save the two .txt files as directories so that Aisha’s Greetings application has access to them or is there another way?
It seems Visual Studio Code would have been a better format to use, but since I am working in Atom I would like to understand and learn what to do.
Can someone explain this to me? Thanks.

PS - i added the 'thankyou_card.txt in Atom as a string as follows:
thankyou_card = “There are not enough thanks That I can give to you Not enough flowers I can lay at your feet”
and it ran successfully for the ‘decorator’ based context manager method

However, when I attempted to ■■■ the ‘happy_bday.txt’ as a string for the ‘class’ based context manager I received and error when I attempted to run the program:
Traceback (most recent call last):
File “Aishas_greetings.py”, line 69, in
with generic(“happy_bday.txt”,“Josiah”,“Remy” ) as generic_card, personalized(“Josiah”, “Esther”) as personal2:
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py”, line 112, in enter
return next(self.gen)
File “Aishas_greetings.py”, line 9, in generic
card_file = open(card_type, ‘r’)
FileNotFoundError: [Errno 2] No such file or directory: ‘happy_bday.txt’
So, why does the decorator based context manager work but not the class based context manager?

As far as gists go you can share them with multiple files. Not sure of cc’s stance on publicly sharing that sort of project specific data though, probably fine but it might be worth double-checking with them.

As for your project in Atom all you’d really want is the text files to be accessible from the python module, which is more to do with Python than anything to do with Atom.

Probably the easiest route for this is simply including them in the same directory as the Python module (since this how they’re set up on the cc side). You could do this in your preferred file explorer, using the shell or using something like save as in Atom or any equivalent text editor.

If they were saved elsewhere you need to tell Python where those files are, which would involve altering your open function to use a path to wherever those files are actually located.

Please have a look at How do I format code in my posts? for posting any code to the forums, even short snippets like you’ve used. It’s very hard to read unformatted code, especially for something as reliant on indentation as Python is.

Thanks for the feedback.

II didn’t expect my Atom text editor to be so simply compliant. After creating a file for:
Aisha’s Greetings.py all I had to do was create two additional files in the same directory:
1). thankyou_card.txt
2) happy_bday.txt
These two text files are immediately available to access. Since they are not modules, they do not need to be
imported. They contain the same content as the codecademy course page.
So I went back to my bash terminal
At the command line I entered:
python3 which is Aishas_greetings.py
and everything ran succesafully.
Very satisfying.

1 Like