I'm currently playing around with making a file duplicator in Python. It currently works on its own when I customise the number of duplications in the actual program, but I am working on making a separate and basic setup file. This will allow you to specify the number of duplicates you want.
At the moment, this number is saved onto a plain text document in list form. So the document can look like [0, 1, 2, 3] to [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] depending on what you put in.
The problem is that when the actual duplicator program tries to get the list from the plain text file, it interprets it as a string, so it looks like
count = ['[0, 1, 2, 3, 4, 5]']
I have searched the internet far and wide for a solution to this, but the only solution I can find is to use str.split(). From my knowledge, this was removed in Python 3. Are there any alternatives that I can employ in this situation?
Here is the code for the actual duplicator:
#!/usr/bin/env python
import shutil
import getpass
data = open("/Volumes/USB/Data.txt", "r")
username = getpass.getuser()
count = data.readlines(1)
print(str(count))
for x in count:
shutil.copy2('/Volumes/USB/img.jpg', 'img{0}.jpg'.format(x))
print(str(count))
And here is the code for the setup file:
import time
import fileinput
with open("/Volumes/USB/Data,txt", "r") as f:
# Precount is where the original list will go to let them know how many have previously been selected. I will convert this to the number of entries in the list eventually.
precount = list(f.readlines(1))
print('Enter the desired amount of images. Your current amount is {0}.'.format(precount))
countbase = input()
count = [0]
n = 1
while int(n) < int(countbase):
list.append(count, n)
n += 1
with open("/Volumes/USB/Data.txt", "w") as f:
f.write(str((count)))
print('Configuration complete!')
time.sleep(1)
quit()
Thanks for any help!