Hello all, I found a thread similar, but it was closed... so here is the code and my question...
I am wondering how to change the code from creating files to creating variables?
this is the code from the thread on here....
and below it is the code that i am personally using....
thanks all!
a = 0
while a < 10:
a = a + 1
if a == 4 or a == 6:
# create file for instance 'output4.dat'
# only strings concatinate
output = open('output'+str(a)+'.dat', 'w')
# write the value to file (needs to be a string)
output.write('%s' % (a))
output.close()
and here is my code...
import re
f=open("c:\\textofemail.txt", "r")
fileString = f.read()
f.close()
processedString = re.sub(r"\n\s*\n*", "\n", fileString) #removes blank lines
s=processedString
a=s[s.index("Rate:"):s.index("Best,")] #parses string for desired content
finalStr = re.sub(r"\Rate:\s?","",a)
f=open("c:\\newtextofemail2.txt", "w")
f.write(finalStr) #write new file of cleaned and parsed data
f.close()
#this section will chunk the file into 130 character lengths
f = open('C:\\newtextofemail2.txt')
chunks = []
while "file is not empty":
chunk = f.read(130)
if not chunk:
break
chunks.append(chunk)
f.close()
# write each chunk to own file
for i,name in enumerate(chunks):
g = open("C:\\newchunkedmultiples"+str(i+1)+".txt","w")
g.write(name+"\n")
g.close()
print "CHUNKED! LOL" #just for fun :)
it would be better for me to have variables stored in memory instead of files written, so i can send them to twilio later in my program.
thanks