i am currently undergoing my A2 studies in Computer Science and i am having difficulties with random access file processing.
I am trying to have a list UsersArray
which stores some record data types UsersArray = [lion,soso,Sxia]
and loop through the list and store each record in the File TEST.DAT
at a specific offset calculated like this Address = hash(UsersArray[i].Password)
. The problem occurs when i try to do File.seek(Address)
. It gives me an error and tells me the argument in seek()
function is not correct, and i don't understand why this error occurs.
import Users,pickle
File = open("TEST.DAT","rb+")
lion = Users.Users()
lion.Password = "ilovefood"
soso = Users.Users()
soso.Password = "cats123"
Sxia = Users.Users()
Sxia.Password = "luca<3"
UsersArray = [lion,soso,Sxia]
for i in range(3):
Address = hash(UsersArray[i].Password)
File.seek(Address)
pickle.dump(UsersArray[i],File)
File.close()
Error Message:
Traceback (most recent call last):
File "C:\Users\Vaio\Desktop\PythonA2\File Processing\RandomAccessWrite.py", line 17, in <module>
File.seek(Address)
OSError: [Errno 22] Invalid argument
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "C:\Users\Vaio\Desktop\PythonA2\File Processing\RandomAccessWrite.py"]
[dir: C:\Users\Vaio\Desktop\PythonA2\File Processing]
[path: C:\MinGW\bin;C:\Users\Vaio\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Vaio\AppData\Local\Programs\Python\Python36-32\]
Thank you for the help in advance!