How to Save Python Files in the Same Directory in VS Code (Update)

In a recent post I gave a programmatic solution to how to get Python to write files in the same folder as the Python file itself when working in VS Code. By default, Python programs in VS Code write files in the root folder of the project, not in the folder where the Python file is saved.

My solution involved the use of a built-in variable named “__file__“, which together with some fancy path concatenation, achieved what I was hoping for.

Continue reading “How to Save Python Files in the Same Directory in VS Code (Update)”

How to Save Python Files in the Same Directory in VS Code

Introduction

Have you ever been frustrated because your Python programs in VS Code always save in the root folder of your GitHub project, even if the program is in a subfolder? You’re not alone. I’ve encountered this problem too, and I couldn’t find a solution within VS Code’s settings.

Solution

The solution is within Python itself.

Python has a built-in variable called __file__ that refers to the path of the current Python file. By using this with os.path.join(), you can ensure that your file will be saved in the same directory as your program, not in the root folder.

The os.path.join() function in Python is a smart way to stick together pieces of a file path. It knows how to correctly use the right kind of slash (/ or \) depending on your computer’s operating system. So, if you have a folder named “folder” and a file named “file.txt”, os.path.join("folder", "file.txt") will give you the correct full path: “folder/file.txt”. It’s a handy tool for dealing with file paths in Python.

Continue reading “How to Save Python Files in the Same Directory in VS Code”

The Donkey and the Tiger

The image is a colorful, detailed illustration depicting a whimsical scene. A donkey, anthropomorphized and dressed in green traditional Indian attire, appears to be in an intense conversation with a lion, who is roaring back. A tiger, wearing a turban and blue attire, sits nearby, observing the exchange. The setting is outdoors, with lush green grass and a green curtain hanging from above. In the background, there’s a silhouette of an elaborate building structure resembling Indian architecture. The sky is bright with scattered clouds, suggesting it’s either dawn or dusk.

I’m not sure what the original source is of fable this, but in light of the political bickering that seems to be pervasive nowadays, I thought it was worth sharing here. Thanks to my friend Doug for making me aware of it on Facebook, and thanks of course to the original author.!


The donkey told the tiger, “The grass is blue.”

The tiger replied, “No, the grass is green .”

The discussion became heated, and the two decided to submit the issue to arbitration, so they approached the lion.

Continue reading “The Donkey and the Tiger”

Tech Ed AQ and ABQ Courses – Winter 2024

Course: Construction Technology: Grades 9 & 10 (Brock)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/construction-technology-grades-9-10-abq-brock-winter-online/

Course: Technological Design, Grades 9 & 10 (Brock)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/technological-design-grades-9-10-abq-brock-winter-online/

Course: Communications Technology Grades 11/12 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/communications-technology-grades-1112-abq-queens-winter-online/

Course: Communications Technology Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/communications-technology-grades-910-abq-queens-winter-online/

Course: Computer Technology Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/computer-technology-grades-910-abq-queens-winter-online/

Course: Green Industries Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/green-industries-grades-910-abq-queens-winter-online/

Course: Green Industries, Grades 11 & 12 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/green-industries-grades-11-and-12-abq-queens-winter-online/

Course: Honour Specialist Technological Education (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/honour-specialist-technological-education-aq-queens-winter-online/

Course: Technological Design Grades 11/12 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/technological-design-grades-1112-abq-queens-winter-online/

Course: Technological Design Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/technological-design-grades-910-abq-queens-winter-online/

Course: ABQ Communications Technology, Grades 11 and 12 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-communications-technology-grades-11-and-12-windsor-winter-online/

Course: ABQ Communications Technology, Grades 9 and 10 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-communications-technology-grades-9-and-10-windsor-winter-online/

Course: ABQ Green Industries, Grades 11 and 12 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-green-industries-grades-11-and-12-windsor-winter-online/

Course: ABQ Green Industries, Grades 9 and 10 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-green-industries-grades-9-and-10-windsor-winter-online/

Course: AQ Honour Specialist, Technological Education (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/aq-honour-specialist-technological-studies-windsor-winter-online/

Am I missing any? If so, please let me know in the comments below or at the site formerly know as Twitter at @pbeens or Mastodon at mstdn.ca/@pbeens. Thanks!

Computer Studies AQ and ABQ Courses – Winter 2024

Course: Computer Studies Part 1 AQ (DSBN)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/computer-studies-part-1-aq-dsbn-winter-online/

Course: Honour Specialist – Computer Studies (Western)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/honour-specialist-computer-studies-aq-western-winter-online/

Course: Intermediate Division – Computer Studies (Western)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/intermediate-division-computer-studies-abq-western-winter-online/

Course: Senior Division – Computer Studies (Western)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/senior-division-computer-studies-abq-western-winter-online/

Am I missing any? If so, please let me know in the comments below or at the site formerly know as Twitter at @pbeens or Mastodon at mstdn.ca/@pbeens. Thanks!

Ten Things I Learned – December 5, 2023 Update

April Wine

I was sad to hear of Myles Goodwyn‘s death. Myles was the lead singer of April Wine, a Canadian band that had quite an influence on my musical tastes.

WordPress

Want to your open WordPress links in a new tab as the default? “External Links in New Window / New Tab” is your solution.

Speed Test

Google has a speed test webpage. (I’ve added it to my Google A-Z page.)

Continue reading “Ten Things I Learned – December 5, 2023 Update”

Tech Ed AQ and ABQ Courses – Fall 2023

Course: Communications Technology Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/communications-technology-grades-910-abq-queens-fall-online/

Course: Honour Specialist Technological Education (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/honour-specialist-technological-education-aq-queens-fall-online/

Course: Technological Design Grades 9/10 (Queen’s)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/technological-design-grades-9-10-abq-queens-fall-online/

Course: ABQ Communications Technology, Grades 11 and 12 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-communications-technology-grades-11-and-12-windsor-fall-online/

Course: ABQ Communications Technology, Grades 9 and 10 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-communications-technology-grades-9-and-10-windsor-fall-online/

Course: ABQ Green Industries, Grades 11 and 12 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-green-industries-grades-11-and-12-windsor-fall-online/

Course: ABQ Green Industries, Grades 9 and 10 (Windsor)
URL: https://www.otffeo.on.ca/en/learning/pd-calendar/events/abq-green-industries-grades-9-and-10-windsor-fall-online/

Am I missing any? If so, please let me know in the comments below or at the site formerly know as Twitter at @pbeens or Mastodon at mstdn.ca/@pbeens. Thanks!

Quick Encryption/Decryption Utility

lock on keyboard

Need a quick program to encrypt or decrypt small amounts of text, such as passwords? Here’s a quick utility I wrote in Python using Google Colab, Google’s implementation of Jupyter Notebooks. You can run the program there or copy it to your own Google Drive first. Note that you’ll need a Google account to access it.

https://bit.ly/beens-encrypt

I personally use this utility to encrypt sensitive information in Google Keep, as shown in the screenshot below. I save the URL of the utility with the encrypted text so I can decrypt it quickly.

(For longer notes, I’d honestly recommend a proper password manager that can encrypt notes. I use the Premium version of Bitwarden, which I highly recommend.)

The instructions in the program should be adequate to run it on your own.

Bookmark it in your browser for quick access! (Ctrl-D on your PC or Command-D on your Mac)

Why AI Won’t Be Replacing Teachers Anytime Soon

Read the original article here.

While AI has made significant progress in recent years, it is unlikely to replace teachers anytime soon. One reason for this is that AI lacks the ability to understand human emotions and social cues, which are essential for effective teaching. Additionally, AI is not capable of providing the same level of personalized attention that human teachers can provide.

Continue reading “Why AI Won’t Be Replacing Teachers Anytime Soon”