Python Forum
invalid syntax near break - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: invalid syntax near break (/thread-16287.html)



invalid syntax near break - synthex - Feb-21-2019

I write code

test='C:\Users\Admin\Desktop\test.lst' # folder where must be my test.lst

test='C:/Users/Admin/Desktop/test.lst'
DataSet='C:/Users/Admin/Downloads/mypic/'

data_iter = mx.image.ImageIter(
batch_size=4,
data_shape=(3,816, 1232),
label_width=4,
path_imglist='C:/Users/Admin/Desktop/test.lst',
path_root='DataSet')

for data in data_iter: d = data.data[0]
break
then i get
# error
Error:
for data in data_iter: d = data.data[0] ... break File "", line 2 break ^ SyntaxError: invalid syntax
what's wrong


RE: invalid syntax near break - buran - Feb-21-2019

what's the intended purpose of the break there - it doesn't make sense to have break there (nor it is correct syntax as the error states). break is intended to be in the body of a loop, in order to break out of it before it 'normal' end.

something like this would work:

for data in data_iter:
    d = data.data[0]
    if some_condition_is_True:
        break



RE: invalid syntax near break - synthex - Feb-23-2019

Yes, it works, thank you