Dec-27-2019, 07:19 AM
(This post was last modified: Dec-27-2019, 07:40 AM by JackMack118.)
Hello yes because I set it as a proxy for requests. I've been doing all the strip methods, string strip methods and keep getting all the errors I mentioned in the OP.
I think it's because it's not turning into a list because of the double [[]], that's why the stripping is bringing errors.
OK, I have a working example but I open file 3 times which is probably not a good idea for speed. What I need to do is get 200 lines from a text file into a list, and delete those 200 lines simultaneously.
Anyway this works, but I think it's not best:
Ok, keep answering my own post, I've slimmed down, this works best.
I think it's because it's not turning into a list because of the double [[]], that's why the stripping is bringing errors.
OK, I have a working example but I open file 3 times which is probably not a good idea for speed. What I need to do is get 200 lines from a text file into a list, and delete those 200 lines simultaneously.
Anyway this works, but I think it's not best:
with open("sample.txt") as myfile: res = [next(myfile).strip() for x in range(200)] with open('sample.txt', 'r') as fin: data = fin.read().splitlines(True) with open('sample.txt', 'w') as fout: fout.writelines(data[200:]) print(res)
Ok, keep answering my own post, I've slimmed down, this works best.
with open('sample.txt', 'r') as fin: res = [next(fin).strip() for x in range(200)] data = fin.read().splitlines(True) with open('sample.txt', 'w') as fout: fout.writelines(data[200:]) print(res)