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