5 Replies - 486 Views - Last Post: 02 October 2012 - 07:04 PM Rate Topic: -----

#1 CPP%  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 10

Non-ASCII Symbols causing run error

Posted 02 October 2012 - 06:22 PM

So I got the following code from someone else, but have been trying to figure out whats wrong with it. The thing that is causing the problem is the "©" symbol apparently used to pick up the enter key (hex 0D0A or something). I've searched around a bit but everything is about how to to unicode in a string. The error also told me I could put the line "# -*- coding: utf-8 -*-" in my code to fix it, but it didnt. I am not really that good in python so I am sort of clueless on how to fix something like this. Any ideas?

	def getString(self):
		data = ''
		keypress = []
		c = self.request.recv(1024)		while c == '\b':
			self.request.send(' ')				
			c = self.request.recv(1024)
		if len(©) <= 1:
			keypress.append(©)
			while c != endl:
				c = self.request.recv(1024)
				if c == endl:
					break
				elif c == '\b':
					self.request.send(' \b')
					if (len(keypress) > 0):
						keypress.pop()
					else:
						while c == '\b':
							self.request.send(' ')
							c = self.request.recv(1024)
						keypress.append(©)
				else:
					keypress.append(©)
			for key in keypress:
				data += key
		else:
			data = c
		if endl in data:
			data = data.strip(endl)
		return data 


Is This A Good Question/Topic? 0
  • +

Replies To: Non-ASCII Symbols causing run error

#2 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Non-ASCII Symbols causing run error

Posted 02 October 2012 - 06:29 PM

Add apostrophe's? (')

>>> '©'
'\xb8'



Yep, most definitely do that. Cake is 0:
>>> if cake == 0:
...     print 'Jenny' + '©'
... else:
...     print 'I haz cake'
...
Jenny©


Was This Post Helpful? 0
  • +
  • -

#3 CPP%  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 10

Re: Non-ASCII Symbols causing run error

Posted 02 October 2012 - 06:29 PM

View PostfromTheSprawl, on 02 October 2012 - 04:27 PM, said:

Add apostrophe's? (')

>>> '©'
'\xb8'


Thats interesting I tried adding the apostrophes and it just broke it. I'll try that again.
Was This Post Helpful? 0
  • +
  • -

#4 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Non-ASCII Symbols causing run error

Posted 02 October 2012 - 06:32 PM

Wait, what did you want to do with that symbol, get the enter key press?
Was This Post Helpful? 0
  • +
  • -

#5 CPP%  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 10

Re: Non-ASCII Symbols causing run error

Posted 02 October 2012 - 06:45 PM

View PostfromTheSprawl, on 02 October 2012 - 04:32 PM, said:

Wait, what did you want to do with that symbol, get the enter key press?

Its some really stupid complicated way of getting data, the previous version of this only captured 1 letter at a time, the enter thing was someones revision so it wouldnt do that, but I think its just overly complicated, but thanks it did work.
Was This Post Helpful? 0
  • +
  • -

#6 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Non-ASCII Symbols causing run error

Posted 02 October 2012 - 07:04 PM

Whoa that's neat, glad to know it worked. ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1