Invalid argument: 'last10.txt' Glitch or what? file exists

Viewed 30

https://pastebin.com/raw/UdvURFRc

# -*- coding: UTF-8 -*-
import arabic_reshaper
import random
import os
import time
import mmap

# Open the file.txt
with open("file.txt", "r", encoding = "utf-8") as fileBig:
    lines = fileBig.readlines()
    #Print and choose a random line
    myline =random.choice(lines)


print(len(myline))


print(os.path.getsize("last10.txt"))

if os.path.getsize("last10.txt")>0 :
    with open('last10.txt') as f:
        lines = len(f.readlines())
        s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
        if s.find(myline.encode()) != -1:
            #Found
            print('true')
            myline =random.choice(lines)

        if s.find(myline.encode()) != -1:
            #Found
            print('true')
            myline =random.choice(lines)      
        
#Write last 10 quotes to avoid dublicateion
with open("last10.txt", "a", encoding="utf-8") as a_file:
    print('2nd open')
    a_file.write(myline)
    

print('2nd Closed')
if os.path.getsize("last10.txt")>750 :
    with open("last10.txt", "w", encoding="utf-8") as a_file:
        print('3nd open')
        a_file.write("")

here is my error:

Traceback (most recent call last):
  File "finder.py", line 43, in <module>
    with open("last10.txt", "w", encoding="utf-8") as a_file:
OSError: [Errno 22] Invalid argument: 'last10.txt'

Notes:

  • File exists
  • There is no protection UAC or whatever since it is in Drive D
  • It looks like your post is mostly code; please add some more details.
0 Answers
Related