File operations with open — "../"

I didn't understand the file structure and operation of with open

Location of sample.py  Python → robot → hello → sample.py

Location of hello.txt  Python → robot → templates → hello.txt

sample.py


#Include some code for the class
 def hello(self):
        with open("../templates/hello.txt", encoding="utf-8") as f:
            t = string.Template(f.read())
            contents = t.substitute(robot_name = self.name)
            print(contents)
            user_name = input()

You can do it if you use "../" well

Recommended Posts

File operations with open — "../"
File operations
Open the file with the default app
Scripting with Paver-File Operations
File operations in Python
[Python] File / directory operations
File operations in Python
File upload with django
[Python] Summary of S3 file operations with boto3
Open a file dialog with a python GUI (tkinter.filedialog)
Folder creation / file move / compress / delete operations with python
Draw netCDF file with python
Fast file transfer with fabric
Perform logical operations with Perceptron
Bidirectional file transfer with Pythonista 3
File upload with Flask + jQuery
Basic commands for file operations
Download csv file with python
Create xlsx file with XlsxWriter
Extract the xz file with python
Get video file information with ffmpeg-python
[Python] Write to csv file with Python
[Automation with python! ] Part 1: Setting file
Implemented file download with Python + Bottle
Package filer for simple file operations
Follow the file hierarchy with fts
Build a deb file with Docker
Output to csv file with Python
Serve static files with X-Send File
Open UTF-8 with BOM in Python
Create an Excel file with Python3
Let's develop something close to embedded with TDD ~ file open edition ~
Output cell to file with Colaboratory
Download the file deployed with appcfg.py
Automation of remote operations with Fabric
Use camera calibration file with OpenCvSharp4
Python memo ① Folder and file operations
ORC, Parquet file operations in Python
[Automation with python! ] Part 2: File operation
Create a file uploader with Django
Creating a simple PowerPoint file with Python
Exclusive control with lock file in Python
Read CSV file with python (Download & parse CSV file)
Check the existence of the file with python
Quickly create an excel file with Python #python
Let's read the RINEX file with Python ①
Create a large text file with shellscript
Create a VM with a YAML file (KVM)
Create Excel file with Python + similarity matrix
Record with Python → Save file (sounddevice + wave)
Try rewriting the file with the less command
Check the file size with du -sh *
Read a character data file with numpy
Download the file with PHP [Under construction]
[Go] Use Open ID Connect with go-oidc
I made a configuration file with Python
Create an upgradeable msi file with cx_Freeze
[Automation] Read mail (msg file) with Python
Summary of operations often performed with asyncpg
[Python3] Understand the basics of file operations
How to deal with the inability to open the lock file / var / lib / dpkg / lock-frontend