The story of FileNotFound in Python open () mode ='w'

When dealing with files in Python 3.x, I mainly use open () and with, but like other languages, there is a write mode. There are also read-only and append modes, but they are omitted.

sample1.py


file_path = 'sample1.txt'
with open(file_path, mode='w') as f:
    print('Hello Py!!')

If you create files in the same hierarchy, this is usually fine, but in the case of Windows, there is a ** character limit ** [Beware of pathnames that are too long --AtFILE_Guide](https://secure01.blue.shared-server.net/www.yes-online.jp/atfile_guide/Filer_PathNameLength.html#:~:text=Windows%E3%81 % AE% E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E5% 90% 8D% E3% 81% AE,% E6% 96% 87% E5% AD% 97% E3% 81% A8% E3% 81% 84% E3% 81% 86% E5% 88% B6% E9% 99% 90% E3% 81% 8C% E3% 81% 82% E3% 82% 8A% E3% 81% BE% E3% 81% 99% E3% 80% 82) Windows10 home 64Bit path character limit lifted-Microsoft community

Some people may not work by creating folders in such a deep hierarchy, but OneDrive for bussiness creates personal folders in a fairly deep hierarchy (I feel).

C: \ Users \% username% \ OneDrive-Co., Ltd. 〇〇〇〇〇〇 \ Yeah, if the company name and user name aren't long, you won't hit them normally. .. ..

But I got a FileNotFoundError. Even if I try to google, it only mentions the reason that the folder directly above does not exist, and this was only different. (Maybe it happened, but I overlooked it)

Suddenly, I thought that Windows had a file name restriction, so I found a file name with a limited number of characters. No, I forgot because I can't always give a long file name

For example, if you add date information to the file name (exactly this time), the file name will be long, so you may need to be careful.

Log _ Co., Ltd. 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 _ 〇 〇 〇 〇 〇 〇 〇 base _ setting change _ final log _ yyyymmdd.txt I wrote a program to extract show run and show start It was what I thought. Log _ Co., Ltd. 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 _ 〇 〇 〇 〇 〇 〇 〇 base _ setting change _ final log _yyyymmdd.txt_show running-config_yyyymmdd.txt Log _ Co., Ltd. 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 〇 _ 〇 〇 〇 〇 〇 〇 〇 _ _ _ _ _ _ _ _ _ _ _

By the way, even if I tried pathlib.touch (), I got an error.

Recommended Posts

The story of FileNotFound in Python open () mode ='w'
The story of reading HSPICE data in Python
Let's use the open data of "Mamebus" in Python
The story of Python and the story of NaN
The story of participating in AtCoder
The story of the "hole" in the file
Check the behavior of destructor in Python
The story of an error in PyOCR
The story of verifying the open data of COVID-19
The story of making Python an exe
The result of installing python in Anaconda
The story of manipulating python global variables
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
The story of blackjack A processing (python)
Open an Excel file in Python and color the map of Japan
Output the number of CPU cores in Python
The story of low learning costs for Python
[Python] Sort the list of pathlib.Path in natural sort
Get the caller of a function in Python
Match the distribution of each group in Python
View the result of geometry processing in Python
Make a copy of the list in Python
Find the divisor of the value entered in python
Image processing? The story of starting Python for
The story of finding the optimal n in N fist
Find the solution of the nth-order equation in python
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Output in the form of a python array
The story of viewing media files in Django
Basic story of inheritance in Python (for beginners)
the zen of Python
The story of sys.path.append ()
Experience the good calculation efficiency of vectorization in Python
The story of Python without increment and decrement operators.
How to get the number of digits in Python
The story of building the fastest Linux environment in the world
Learn the design pattern "Chain of Responsibility" in Python
Implement the solution of Riccati algebraic equations in Python
Get the size (number of elements) of UnionFind in Python
Not being aware of the contents of the data in python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
[Python] Outputs all combinations of elements in the list
Get the URL of the HTTP redirect destination in Python
A reminder about the implementation of recommendations in Python
The story of automatic language conversion of TypeScript / JavaScript / Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Check the asymptotic nature of the probability distribution in Python
A story about trying to introduce Linter in the middle of a Python (Flask) project
The story of building Zabbix 4.4
Towards the retirement of Python2
Download the file in Python
[Apache] The story of prefork
Find the difference in Python
About the ease of Python
Equivalence of objects in Python
Implementation of quicksort in Python