need quick python help.

2Tartu

Head Admin
Head Admin
Joined
Jun 21, 2011
Messages
4,798
f = open("alice.txt")
x = 0
def if20(file):
z = 0
for line in file:
z += 1
return z

o = if20(f)
print(o)
if o == 20:
for line in f:
print(str.strip(line))

if o != 20:
for line in f:
print(str.strip(line))
x += 1
if x == 20:
input("----- to continue click ENTER -----")
x=0

wtf am I doing wrong the indents are there, the tbg text editor is having a blast.

I need to print lines in blocks of 20, if file only has 20 lines, not ask for ENTER.
 
Ok. So you want it to not ask for enter as it should print lines in blocks of 20 if the file only contains 20 lines? What data files are you using?
 
@2Tartu I know nothing about Python, but my good friend does. He says: the python code is unreadable. It needs the indentations or else it can't tell where a function starts or stops. Can you post it on pastebin?
 
the text editor here screwed it up, I managed to fix it. The problem was that running the first function read all the way to the end of the file, causing other functions to simply attempt to read nothingness. Fixing that would have been a nightmare so I simply went for an easier route.

Apparently this worked fine(you can still see a remnant of my batshit plan in there....) The key was to have the addition to the helper-variable in the end of the for loop.
lolcontrol.png
 
Back
Top