Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phantom Errors
#11
The plot thickens......

It seems to me that the spook errors occur when I paste in code taken from files I have previously made using UltraEdit-32 9.10

I'm presently using v 26 10.0.30


I have submitted a tech query to IDM Big Grin
Reply
#12
I would check the line endings and tabs carefully.

I gotta say, I used to be a huge UltraEdit fan. But I tried out the latest version a few months ago, and after a few weeks I went right back to Sublime Text.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#13
I copied this function from another file. It causes not errors in it's original location.
(It's part of a class)

	def IsValidEnemy (self, entity):
		me=Bladex.GetEntity(self.Name)
		if not entity.Person: 
			return FALSE
		if entity.Kind=="LookoutMan": 
			return FALSE
		if not entity.Life > 0:
			return FALSE
		if entity.Name == self.Name:
			return FALSE
		if entity.Kind==me.Kind:
			return FALSE
		if IsHoldingBow(entity.Name):
			return FALSE
		if  CheckIfEnemy(entity.Name): 
			return TRUE
     if entity.Name == "Player1":
         return TRUE
     return FALSE
But it doesn't like it. Sad

Traceback (innermost last):
  File "Cfg.py", line 98, in ?
    execfile("DefFuncs.py")
  File "DefFuncs.py", line 21, in ?
    import EnemyNPCTypes
SyntaxError: 'return' outside function (line 1061)
** I am now using Notepad++
Reply
#14
It gets worse...... Cry

I am now getting bogus errors on anything I try to edit.

I desperation I copied an entire file from my old computer and pasted it in place of the file I was editing.

It all works fine now. I will have to somehow try to migrate my old UltraEdit onto my new PC. Dodgy


I've been writing Python for the best part of 20 years and never had a this before. It's tricky enough keeping
everything working when you can see the code, but when it looks (and is) correct as it appears in the editor but
has some invisible errors it's a bit harder.

Sorry to rant..... Going for a kip now. Wink
Reply
#15
That sort of sounds like spaces are being converted to tabs (or the other way around), but I think the error you get would be indentation errors or "inconsistent use of whitespace". It also kind of looks like the error you'd get if the line previous was missing a closing parenthasis, but that shouldn't happen just from copy/paste.

How are you running it? Is it possible that there's multiple versions of python involved, like it works in 2.x but the other program is using 3.x?
Reply
#16
I've always been very particular in my coding style and always use a single tab for indentation.
Tidy code is easy-to-read code is my motto. Big Grin

It's Python 2 all the way I'm afraid as the game I am modding comes with it built in. Rolleyes

I seem to remember years ago when I started editing Python files I used Notepad which is fine. Then when
the files got too big I used Wordpad, which exhibited similar symptoms - perfectly sound code as written but
wouldn't run.

That's when I got UltraEdit and the rest is history...... Cool
Reply
#17
(Nov-02-2019, 02:23 AM)prospero Wrote: I've always been very particular in my coding style and always use a single tab for indentation.
[ ... ]
It's Python 2 all the way [ ... ]

Hi!

I'm just a newbie, so I'm not sure if this could help you.

I saw this in PEP8:

Tabs or Spaces?
Spaces are the preferred indentation method.
Tabs should be used solely to remain consistent with code that is already indented with tabs.
Python 3 disallows mixing the use of tabs and spaces for indentation.
Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.
When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!


Source:

https://www.python.org/dev/peps/pep-0008...-or-spaces

Depending on your version of Python, maybe you could import and use the module tabnanny and the following function to detect ambiguous indentation in a file:

tabnanny.check(file_or_dir)

https://docs.python.org/2/library/tabnan...e-tabnanny

https://docs.python.org/3.3/library/tabn...e-tabnanny

for instance, for both Python 2.7.17 and Python 3.3.7. (Changing the version on the top of the page, you can look for your specific version). The tabnanny.check() function checks the file or directory that you pass to as an argument, and detects ambiguous indentation.

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#18
That's very interesting. Thanks for posting. Big Grin

The problem does seem to be with the indentation. What I can't get my head around is you can't see an error
when the code is displayed in the editor. And why after coding for many years without any problem of this nature does
it manifest itself now? Huh
Reply
#19
Look at this code.......


	def MyGetEnemyName (self):
		me=Bladex.GetEntity(self.Name)
		char=Bladex.GetEntity("Player1")
		if not self.AttackOnSight:
    	return None
	  if not self.NameOfEnemy or Bladex.GetEntity(self.NameOfEnemy).Life <=0:
      pjp = me.Position
			enemyList=[]
		  pj_dir=me.Rel2AbsVector(0.0,-1.0,0.0)
			
			for ename in Bladex.GetEnemiesVisibleFrom(pjp,30000,pj_dir,0.0):
				ene=Bladex.GetEntity(ename)
				if ene.Person:
					if self.IsValidEnemy(ene):
            enemyList.append(ene.Name)
          if me.CanISee(char):	
            enemyList.append("Player1")
        if len(enemyList) == 0:
          return None
        enemyList.sort(self.ChooseCanISeeNearest)
        self.NameOfEnemy=enemyList[0]
                   	
		enemy=Bladex.GetEntity(self.NameOfEnemy)
    me.SetEnemy(enemy)
    self.ChaseCount=0
		return self.NameOfEnemy			
					
It's all over the place. Cry Trouble is, in the editor it appears correct. Huh

This is how it should look......


	def MyGetEnemyName (self):
		me=Bladex.GetEntity(self.Name)
		char=Bladex.GetEntity("Player1")
		if not self.AttackOnSight:
			return None
		if not self.NameOfEnemy or Bladex.GetEntity(self.NameOfEnemy).Life <=0:
			pjp = me.Position
			enemyList=[]
			pj_dir=me.Rel2AbsVector(0.0,-1.0,0.0)
			
			for ename in Bladex.GetEnemiesVisibleFrom(pjp,30000,pj_dir,0.0):
				ene=Bladex.GetEntity(ename)
				if ene.Person:
					if self.IsValidEnemy(ene):
						enemyList.append(ene.Name)
					if me.CanISee(char):	
						enemyList.append("Player1")
				if len(enemyList) == 0:
					return None
				enemyList.sort(self.ChooseCanISeeNearest)
				self.NameOfEnemy=enemyList[0]
		enemy=Bladex.GetEntity(self.NameOfEnemy)           
		me.SetEnemy(enemy)
		self.ChaseCount=0
		return self.NameOfEnemy			
I cut each line in turn and set the cursor to the left margin. Did the required number of tabs and pasted
it back in. It works fine now. This process could get a wee bit tedious though. Sick

And I might write code and it may be that it raises no errors, but how can I be sure it hasn't shifted a
clause sideways and upset my logic???????? I can't keep checking it on this page.
Reply
#20
This really sounds like a tabs vs spaces problem. Ultraedit has settings for making the white space characters visible, so you can tell where there are spaces and where there are tabs. Have you turned that on and looked at the code that is giving you errors?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? GaryKuipers 4 3,173 Aug-28-2018, 02:32 PM
Last Post: GaryKuipers

Forum Jump:

User Panel Messages

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