Skip to content Skip to sidebar Skip to footer

Python 3.2: Ioerror: [errno 22] Invalid Argument: '/home/pi/data/temp/file1\n.txt'

I am a newbie to python programming. I have a counter.txt file from which i am reading the counter value . Using this counter value, i have to create new files into some other fold

Solution 1:

You need to remove the trailing newline from the line variable. This can be done by just calling .strip() on it. You can see the file path is coming out as

/home/pi/data/temp/file1\n.txt

when you are probably expecting it to be

/home/pi/data/temp/file1.txt

This is because your counter.txt file uses \n as the newline character, so each line also ends with it. When you use readline, it gets the full line including the newline character, so you need to strip it out. Try replacing that line with

line = counter_file.readline().strip()

Solution 2:

The process cannot write to a file in that directory. Either make it such that the process can, or write somewhere else instead.

Post a Comment for "Python 3.2: Ioerror: [errno 22] Invalid Argument: '/home/pi/data/temp/file1\n.txt'"