Jump to content

Python Error

Wictorian
while(true):
    for f in range(i-1):
        try:
            dList1[h].append(columnLists[f][20-i+f])
    if state == 1:
        i+=1
        if i == 20:
            state = 2
    elif state == 2:
        i -= 1
        if i == 0:
            state = 3
    elif state == 3:
        i += 1
        if i == 5:
            break
    h += 1

gives error 

if state == 1:                                                                                                            

    ^                                                                                                                         

IndentationError: unexpected unindent          

Link to comment
Share on other sites

Link to post
Share on other sites

Fighting my need to say "this is why I dislike Python!" and why we just need curly brackets

 

Indent means "a space created by pressing Tab", basically. Unindent is the opposite, the lack of such an indent.

Anything in the Try needs to be indented one Tab further. I think except is also needed.

 

I'm not a Python expert, so that may not all be 100% correct

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, minibois said:

Fighting my need to say "this is why I dislike Python!" and why we just need curly brackets

 

Indent means "a space created by pressing Tab", basically. Unindent is the opposite, the lack of such an indent.

Anything in the Try needs to be indented one Tab further. I think except is also needed.

 

I'm not a Python expert, so that may not all be 100% correct

@shadow_ray

 

wait, I just wanna continue the loop in case of expect.

 

if I write continue would it be ok?

Link to comment
Share on other sites

Link to post
Share on other sites

Except block is missing, the boolean value should be capitalized as True, and if this is your entire code then the variables (state, i, dList1, columnList, h) all need to be defined

 

7 minutes ago, minibois said:

Anything in the Try needs to be indented one Tab further. I think except is also needed.

The code inside Try is already indented, he is just missing the Except and it thinks that the if statement should be intended when it doesn't have to be because it's continuing processing code in the same indentation as the Try.

Quote or Tag people so they know that you've replied.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Wictorian said:

@shadow_ray

 

wait, I just wanna continue the loop in case of expect.

 

if I write continue would it be ok?

try:   
	dList1[h].append(columnLists[f][20-i+f])
except: 
	pass

or just simply this without the try and except

dList1[h].append(columnLists[f][20-i+f])

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, Wictorian said:

@shadow_ray

 

wait, I just wanna continue the loop in case of expect.

 

if I write continue would it be ok?

Yes you can use "continue" inside the except block, but it isn't recommended if you're doing so to ignore errors, only if you expect a type of error to occur then you should specify which error to catch, though you can still do a continue statement without that if you want.

 

for f in range(i-1):
	try:
		dList1[h].append(columnLists[f][20-i+f])
	except:
		continue

 

Continue statements can only be valid if the "try" is inside a loop, which this one is, so it works

Quote or Tag people so they know that you've replied.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, .Apex. said:

Yes you can use "continue" inside the except block, but it isn't recommended if you're doing so to ignore errors, only if you expect a type of error to occur then you should specific which error to catch, though you can still do a continue statement without that if you want.

 


for f in range(i-1):
	try:
		dList1[h].append(columnLists[f][20-i+f])
	except:
		continue

 

Continue statements can only be valid if the "try" is inside a loop, which this one is, so it works

I wanted to ignore an error but I dont know if its true. Can you please check my latest thread?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×