Hack Forums
[Python] Undefined syntax and indent error - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Undefined syntax and indent error (/showthread.php?tid=6165103)



Undefined syntax and indent error - simmer - Jul 25, 2021

Does anyone have advice on how to string blocks of code together?

What I have now all works when blocks of code are isolated.

But what I define in those blocks are coming up as undefined


RE: Undefined syntax and indent error - Flash7475 - Jul 25, 2021

Would you be able to post your code so far so we can help you better and to get better context to what you mean?


RE: Undefined syntax and indent error - 3phase - Jul 26, 2021

First of all, I hope you use proper IDE such as PyCharm/Visual Code/Atom or whatever,
don't use notepad or notepad++ to write python, it will get you a hard time if you don't know what you are doing.

If you want us to help you, you gotta share your code.

Your errors related to basically not understanding the fundamentals of Python,
you can define your indentation, but once you define it you gotta keep using it for the whole code.

and yes, there is a difference between a 'space' indentation and a 'Tab' indentation, even if the code looks aligned


RE: Undefined syntax and indent error - simmer - Jul 27, 2021

Incorrect usage of scope?

Here’s a snippet of code from my program
Code
n = set()
N = set()
k = [n]
for n in N:
    a = set((k[n]) == k[n] in set(0, 1))
print(a)

I’m wondering how to print a
At least that’s what I’m saying on here
(Damn firewall)


RE: Undefined syntax and indent error - 3phase - Jul 28, 2021

(Jul 27, 2021 09:23 AM)simmer Wrote:  Incorrect usage of scope?

Here’s a snippet of code from my program
Code
n = set()
N = set()
k = [n]
for n in N:
    a = set((k[n]) == k[n] in set(0, 1))
print(a)

I’m wondering how to print a
At least that’s what I’m saying on here
(Damn firewall)

It's quite hard to understand you, that snippet is a 100% mess.
I don't even know where to start, what's the obsession with set()?

You can't iterate over an empty collection, N is empty -> 'for' loop will not happen -> a is not defined.
You can't iterate over N with n, I'm not sure what you tried to do here, but that param you define for the iteration should be a completely new param,
so saying " for n in N" make no sense here, I mean the param will be n, it will get each value
in N, but it will not be related to the first "n = set()" you defined at the beginning.

also, set() is a function, the base idea of that function is to take a list and return a set,
so far so good, but if you look into set() function you will see it get at most 1 argument,
which means set(0,1) make no sense, the correct way will be set([0,1]), but why even use set here? just type "[0,1]" it 100% percent the same effect here
and even in a more efficient way.

That's an achievement for sure, that 6 lines of code is like having 10 typos in a word that only have 2 chars.
Go back to basics, learn Python from the very beginning.

Also, I have no clue what "firewall" is related to here?
I'm so confused


RE: Undefined syntax and indent error - simmer - Jul 28, 2021

Ok so I shouldn’t have taken a single line directly from my code (it caused a lot of confusion)

This:
Code
for x in range(10):
    x

print x

is similar


RE: Undefined syntax and indent error - Pernat1y - Jul 30, 2021

(Jul 28, 2021 02:39 PM)simmer Wrote:  Ok so I shouldn’t have taken a single line directly from my code (it caused a lot of confusion)

This:
Code
for x in range(10):
    x

print x

is similar

Again, get decent IDE, as suggested above. At least it will show syntax and some of logical errors.
Also, no idea what you trying to do with this loop. It will always print last value.


RE: Undefined syntax and indent error - simmer - Jul 30, 2021

That’s what I intended

I guess the problem is something else