Nov-22-2017, 09:07 PM
import random nazwaPlikuZDanymi = open('123.txt') content = nazwaPlikuZDanymi.read() allObjects = content.splitlines() sizeTST = len(allObjects)/5 tst = random.sample(allObjects, k=int(sizeTST)) for x in range(len(tst)): allObjects.remove(tst[x]) theFile = open('tst1.txt', 'w') for item in tst: theFile.write("%s\n" % item) theFile.close() theFile = open('trn1.txt', 'w') for item in allObjects: theFile.write("%s\n" % item) theFile.close() tmp = tst tst = random.sample(allObjects, k=int(sizeTST)) for x in range(len(tst)): allObjects.remove(tst[x]) theFile = open('tst2.txt', 'w') for item in tst: theFile.write("%s\n" % item) theFile.close() theFile = open('trn2.txt', 'w') for item in allObjects: theFile.write("%s\n" % item) for item in tmp: theFile.write("%s\n" % item) theFile.close() tmp = tst tst = random.sample(allObjects, k=int(sizeTST)) for x in range(len(tst)): allObjects.remove(tst[x]) theFile = open('tst3.txt', 'w') for item in tst: theFile.write("%s\n" % item) theFile.close() theFile = open('trn3.txt', 'w') for item in allObjects: theFile.write("%s\n" % item) for item in tmp: theFile.write("%s\n" % item) theFile.close() tmp = tst tst = random.sample(allObjects, k=int(sizeTST)) for x in range(len(tst)): allObjects.remove(tst[x]) theFile = open('tst4.txt', 'w') for item in tst: theFile.write("%s\n" % item) theFile.close() theFile = open('trn4.txt', 'w') for item in allObjects: theFile.write("%s\n" % item) for item in tmp: theFile.write("%s\n" % item) theFile.close() tmp = tst tst = random.sample(allObjects, k=int(sizeTST)) for x in range(len(tst)): allObjects.remove(tst[x]) theFile = open('tst5.txt', 'w') for item in tst: theFile.write("%s\n" % item) theFile.close() theFile = open('trn5.txt', 'w') for item in allObjects: theFile.write("%s\n" % item) for item in tmp: theFile.write("%s\n" % item) theFile.close()can u help me guys? i need to change this code but have to work like this. I mean diffrent function or something
i dont know python and i have to do this on tomorrow ;(