Python Forum
Need Help with Simple Text Reformatting Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help with Simple Text Reformatting Problem
#4
Sweet... so... new problem... related to this...

I now have two files of different formats:
1.)"LinesfromDialogs.txt"
2.)"ShakespearsDialogs.txt"

In #1 the format is as follows-

"no no it is my fault we did not have a proper introduction
cameron

cameron
the thing is cameron i am at the mercy of a particularly hideous breed of loser my sister i cannot date until she does

the thing is cameron i am at the mercy of a particularly hideous breed of loser my sister i cannot date until she does
seems like she could get a date easy enough"

In #2, we have the following format:
"Nay, but this dotage of our general's O'erflows the measure: those his goodly eyes, That o'er the files and musters of the war Have glow'd like plated Mars, now bend, now turn, The office and devotion of their view Upon a tawny front: his captain's heart, Which in the scuffles of great fights hath burst The buckles on his breast, reneges all temper, And is become the bellows and the fan To cool a gipsy's lust. Look, where they come: Take but good note, and you shall see in him. The triple pillar of the world transform'd Into a strumpet's fool: behold and see.
If it be love indeed, tell me how much."

I am now trying to get them into the same .txt and using the same format as #2:

f = open("/Users/Tuck/Documents/PyCharm_PythonPrograms/ChatBot_Test/srcs/trainingdata.txt", 'w')
f2 = open("/Users/Tuck/Documents/PyCharm_PythonPrograms/ChatBot_Test/corpus/cornell movie-dialogs corpus/"
          "LinesfromDialogs.txt", 'r')
f3 = open("/Users/Tuck/Documents/PyCharm_PythonPrograms/ChatBot_Test/corpus/shakespeare/ShakespearsDialogs.txt", 'r')

for line in f3:
    f.write(line)
for i, line in f2:
    if (i % 3 == 1):
        f.write(line)
BUT! I keep getting the following error:

Error:
Traceback (most recent call last): File "/Users/Tuck/Documents/PyCharm_PythonPrograms/ChatBot_Test/CleanUpCorpras.py", line 19, in <module> for i, line in f2: ValueError: too many values to unpack
How can I fix this...?
Reply


Messages In This Thread
RE: Need Help with Simple Text Reformatting Problem - by MattTuck - Aug-14-2017, 09:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple flask rest api problem cancerboi 4 2,914 Jan-29-2020, 03:10 PM
Last Post: brighteningeyes
  Help on parsing simple text on HTML amaumox 5 3,593 Jan-03-2020, 05:50 PM
Last Post: amaumox
  html to text problem Kyle 4 5,710 Apr-27-2018, 09:02 PM
Last Post: snippsat
  Problem With Simple Multiprocessing Script digitalmatic7 11 9,429 Apr-16-2018, 07:18 PM
Last Post: digitalmatic7
  Problem formatting output text aj347 5 4,245 Sep-10-2017, 04:54 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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