(curses) issue about inch()
steve at holdenweb.com
Sun Sep 16 20:25:42 CEST 2007
> On Sep 17, 12:07 am, Steve Holden <st... at holdenweb.com> wrote:
>> Jimmy wrote:
>>> hi, all
>>> I attempt to use the function inch() to get the character at the
>>> current position, and compare it with a particular character like :
>>> if screen.inch(x,y) == 'F'
>>> but this method doesn't seem work, can anyone tell me the reason and
>>> how to corrent it
>> The reason is because something is wrong, and yo fix it by correcting
>> that issue.
>> In other words, if you could be a bit more specific about *how* it
>> doesn't work (like, show us the code you are running,a nd any error
>> messages or evidence of incorrect results) you will be able to get some
>> help that actually helps you.
>> Would you go to a car repair shop with faulty brakes and just tell them
>> "my car isn't working"?
>> Steve Holden +1 571 484 6266 +1 800 494 3119
>> Holden Web LLC/Ltd http://www.holdenweb.com
>> Skype: holdenweb http://del.icio.us/steve.holden
>> Sorry, the dog ate my .sigline
> actually i'm writing a game like mine,the pertainign code is:
> def mark():
> """mark the bomb"""
> (row, col) = gb.scrn.getyx()
> x = gb.scrn.inch(row,col)
> if x == 'F':
> gb.scrn.addch(row,col, 'X',curses.color_pair(3))
> gb.scrn.addch(row,col, 'F',curses.color_pair(3))
> the situation is x never equals 'F', even when it really is!
> I checked the mannual and found the return value of inch() consists
> the actual character(low 8bits)
> and the attributes, so I tried the following: (x<<24)>>24,cause I
> guess the int is 32bits long.
> but it still doesn't work :(
Well first of all, thanks for reading the manual.
Let's suppose the value you are receiving is 1234 (clearly more than 8
bits). Unfortunately for you, recent versions of Python don't just use
32-bit integers, but extend the values into Python's long values where
What you really need is a logical and with 255:
>>> 1234 & 255
Hope this helps.
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Sorry, the dog ate my .sigline
More information about the Python-list