Skip to main content

Move a file from one directory to another in Python

You can move a file from one directory to another in Python using the shutil module.  The shutil module provides functions to perform various file operations, including moving files.  How you can move a file from one directory to another:

Using OpenAI to summarise PDF

To use OpenAI to summarise text from a PDF using Python 3.11.6, you'll first need to extract the text from the PDF and then send it to the OpenAI API for summarisation.

 

Preparation

 

Set-up

pip install python-dotenv langchain openai tiktoken pypdf pymupdf

 

Code

The current code is on my Summaries GitHub page.

How to add an environment variable in Ubuntu

To set an environment variable on Ubuntu, can be achieved via a few options.  This depends on whether you want the variable to be system-wide or specific to a user's session.  Here are a couple of more common methods for setting environment variables:

Run Python within a Lando environment

To begin, note that Lando is often used for web development and it may not be optimised for running long-running Python scripts or applications.  It's primarily designed to host web services, so if you have specific Python development requirements, you might want to consider using a dedicated Python development environment or container.  However, Lando can be useful for running Python scripts in the context of web development projects.

Managing VS Code extensions via terminal

Visual Studio Code (VS Code) allows you to manage extensions using the VS Code Command Line Interface (CLI) called code. With the code CLI, you can install, list, uninstall, and manage extensions from the command line.  

To check you have the code prompt running, run

code --version

Response you're looking for is

npm package management

A summary of Node package commands

Short cut commands

npm install <package>

npm i <package>

npm install --save <package>

npm i -S <package>

npm install --save-dev <package>

npm i -D <package>

npm install --global <package>

Could not get lock /var/lib/apt/lists/lock

Logging into the server, and there are packages to be updated.  You know the standard Ubuntu / Linux response

5 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

3 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Followed by the action

Git changing local and remote branch name

Something I haven't had to do in a while is to change the name of a Git branch both local and remote.

 

Steps to renaming a branch

Rename your local branch:

If you are on the branch you want to rename:

git branch -m new-name

Whereas, if you're on a different branch:

Subscribe to Terminal