New Posts  All Forums:Forum Nav:

Python question - Page 2

post #11 of 28
Thread Starter 
Quote:
Originally Posted by poroboszcz View Post

So it prints:
Code:
a == a?
False

?
correct
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #12 of 28
Quote:
Originally Posted by White Fire View Post

Oh, sorry redface.gif
OK, fixed it like you said.
It returns everything its supposed to, but even pressing A returns false -.-

'A' and 'a' are different.
Meh
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 3.8 Ghz GA-P55-USB3 Gigabyte GTX 460 16GB(4x4) Corsair Vengeance 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB Asus Cheapo Corsair H70 Arch Linux 
MonitorKeyboardPowerCase
LG 26LH20 HDTV Das Model S Ultimate Silent Corsair HX850 Lian Li(Lancool) PC-K62 
MouseMouse Pad
Logitech MX 518 My desk. 
  hide details  
Reply
Meh
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 3.8 Ghz GA-P55-USB3 Gigabyte GTX 460 16GB(4x4) Corsair Vengeance 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB Asus Cheapo Corsair H70 Arch Linux 
MonitorKeyboardPowerCase
LG 26LH20 HDTV Das Model S Ultimate Silent Corsair HX850 Lian Li(Lancool) PC-K62 
MouseMouse Pad
Logitech MX 518 My desk. 
  hide details  
Reply
post #13 of 28
Quote:
Originally Posted by Metmop View Post

'A' and 'a' are different.

if you want to ignore caps you should have a condition for that...

aka use key.lower() and c.lower() ???
Code:
def keyStroke():
    key = msvcrt.getch()
    c = 'a'
    print (key.lower() + "==" + c.lower() "?\n")
    print (key.lower() == c.lower())

while(True):
    keyStroke()

Edited by JQuantum - 8/2/12 at 7:15pm
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
post #14 of 28
Something like that. I'm not all that familiar with the python standard library. Whatever the equivalent tolower() function is...
Meh
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 3.8 Ghz GA-P55-USB3 Gigabyte GTX 460 16GB(4x4) Corsair Vengeance 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB Asus Cheapo Corsair H70 Arch Linux 
MonitorKeyboardPowerCase
LG 26LH20 HDTV Das Model S Ultimate Silent Corsair HX850 Lian Li(Lancool) PC-K62 
MouseMouse Pad
Logitech MX 518 My desk. 
  hide details  
Reply
Meh
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 3.8 Ghz GA-P55-USB3 Gigabyte GTX 460 16GB(4x4) Corsair Vengeance 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB Asus Cheapo Corsair H70 Arch Linux 
MonitorKeyboardPowerCase
LG 26LH20 HDTV Das Model S Ultimate Silent Corsair HX850 Lian Li(Lancool) PC-K62 
MouseMouse Pad
Logitech MX 518 My desk. 
  hide details  
Reply
post #15 of 28
Quote:
Originally Posted by Metmop View Post

Something like that. I'm not all that familiar with the python standard library. Whatever the equivalent tolower() function is...

*nod* google says for strings it's the "lower()" method... (http://www.tutorialspoint.com/python/string_lower.htm) dunno if char will be different though just try it else look it up
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
post #16 of 28
Thread Starter 
Quote:
Originally Posted by Metmop View Post

Quote:
Originally Posted by White Fire View Post

Oh, sorry redface.gif
OK, fixed it like you said.
It returns everything its supposed to, but even pressing A returns false -.-

'A' and 'a' are different.
I pressed a, i only capitalized it to differentiate between the words.
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #17 of 28
maybe mine just didn't compile right or my msvcrt is bust but whenever i'm running it, msvcrt.getch() almost always returns chr(255)... always... raw_input works though ...

EDIT: did you know you break the bb if you type the other direction of > aka shift ,

i forgot about that actually..
Edited by JQuantum - 8/3/12 at 7:33am
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
2012
(20 items)
 
Testing v2.5
(8 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7-3770k Gigabyte Z77X-UD5H MSI nVidia GTX 670 MSI nVidia GTX 670 
RAMHard DriveHard DriveHard Drive
Patriot Viper Xtreme DIV. 2 Samsung 830 OCZ Vertex 3 MAX IOPS OCZ Vertex 3 
Hard DriveOptical DriveOSOS
Seagate LG BluRay Windows 8 Professional x64 Mac OS X 10.8.1 (Pending) 
OSMonitorKeyboardPower
Fedora 17/Ubuntu 12.04 (Pending) Dell ST2220T Logitech G110 Corsair HX1050 
CaseMouseAudioOther
Corsair 600T Special Edition White Logitech G9x Unknown yet Keyboard: Corsair K90 (Pending) 
CPUMotherboardGraphicsRAM
Intel i5-3570k Asus P8Z77-i Deluxe MSI HD 7950 Samsung 
Hard DriveCoolingOSCase
OCZ Agility 3 Corsair H100i Windows 8 Professional x64 Cardboard box 
  hide details  
Reply
post #18 of 28
Erggh.
Code:
import msvcrt

def keyStroke():
    key = msvcrt.getch()
    c = 'a'
    print ("%s == %s?\n" % (key.lower(), c))
    print (key.lower() == c)

while (True):
    keyStroke()

That will work when ran from the console. It won't work if you run it from IDLE. String formatting, guys. String formatting.
post #19 of 28
Thread Starter 
Quote:
Originally Posted by Bassdoken View Post

Erggh.
Code:
import msvcrt

def keyStroke():
    key = msvcrt.getch()
    c = 'a'
    print ("%s == %s?\n" % (key.lower(), c))
    print (key.lower() == c)

while (True):
    keyStroke()

That will work when ran from the console. It won't work if you run it from IDLE. String formatting, guys. String formatting.
I never ran it through the idle. erggh
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #20 of 28
Code:
if keyValue == ("/r"):
\r is a carriage return, not /r. "/r" is a two character string. getch() returns a single character, and your if checks if that character is equal to "/r". which is never true.

Why are you using getch? You shouldn't use DLLs directly unless you have a very good reason. Use raw_input instead...
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming