Python Forum
i need to change the code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need to change the code
#1
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 ;(
Reply
#2
Do not double post the same question.

You have not provided enough information to help you.  Additionally, if you "don't know python" and aren't willing to learn, this isn't the right place.  We help people solve their problems who show effort to learn.  We do not do your work for you.
Reply
#3
On top of Mekire's comments - you haven't said what change you actually need in the code.
Reply
#4
(Nov-22-2017, 09:07 PM)woiwoi Wrote: i have to do this on tomorrow

Probably should have started earlier, tbh, especially if you don't know anything about what it is you need to do.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected change to a list in a small amount of self-contained code Johno 5 2,847 Mar-15-2020, 05:06 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020