Python Forum
NameError: name 'self' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: name 'self' is not defined
#21
Self is not defined anywhere in your code
Reply
#22
(Jan-20-2021, 02:18 PM)pitterbrayn Wrote: Self is not defined anywhere in your code


Which code do you mean?

Or did you just want to leave a comment?
Reply
#23
In which lines of this code:

https://github.com/Axel-Erfurt/OrthoView...iewLite.py

do you fix the x,y coordinates? I am trying to change it in order to print real geographic x,y coordinates, meaning latitude and longitude gathered from the .tif file. Thanks...
Reply
#24
I just cut the code down to what I needed and used f-string.

I think the values ​​come from matplotlib

The original code is at line 109 (class MyToolBar)

https://github.com/kklmn/OrthoView/blob/...thoView.py
hobbyist likes this post
Reply
#25
In this part of code:

class MyToolBar(mpl_qt.NavigationToolbar2QT):
    def set_message(self, s):
        try:
            sstr = s.split()

            while len(sstr) > 5:
                del sstr[0]
            x, y = float(sstr[0][2:]), float(sstr[1][2:])
            s = f'x = {x:.2f}\ny = {y:.2f}'
        except Exception:
            pass

        if self.coordinates:
            self.locLabel.setText(s)
what is the purpose of sstr? What does it do?
Also what is the s? And why do we split it?
Reply
#26
Print s and print sstr and maybe you can figure it out by yourself
hobbyist likes this post
Reply
#27
s = coordinates

x=0.7338 y=0.952484

sstr splits into

['x=0.7338', 'y=0.952484']


x, y = float(sstr[0][2:]), float(sstr[1][2:])
result is what you see on the toolbar label

Output:
x = 0.73 y = 0.95
hobbyist likes this post
Reply
#28
Thanks!! And what is the purpose of this command?

while len(sstr) > 5:
Reply
#29
If you actually looked at what is stored in sstr you might have a clue about why some of the manipulations need to occur. If you keep asking question after question you are never going to learn how to analyze code yourself and it is going to grind your development to a halt.
Reply
#30
Ok...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Kivy] NameError: name 'App' is not defined nengkya 4 13,630 Apr-02-2017, 07:15 PM
Last Post: metulburr
  [WxPython] NameError: global name 'PyAssertionError' is not defined merlem 5 6,254 Jan-28-2017, 01:59 PM
Last Post: merlem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020