Welcome to the Treehouse Community
Looking to learn something new?
igsm '10,440 Points
CTRL+D handicap in cmd?
Hey. When I test my program in cmd, I cannot pass the stage when I need to hit CTRL+D as this hotkey is not perceived in the command prompt. How can I fool it?
Sorry, I think you also need to hit Enter after you press Ctrl+Z and it prints the ^Z. You're actually inputting an End-of-file character.
Martin Cornejo Saavedra18,132 Points
I couldn't get it work either, but I did an alternative way to close the reader, I write quit to finish the entry.
def add_entry(): '''Add an entry''' print("Enter your entry. Write <quit> when finished.") final_data = '' while(True): data = sys.stdin.readline().strip() if data == 'quit': if input('Save entry? [Yn] ').lower() != 'n': Entry.create(content=final_data) print("Saved successfully!") break else: final_data += data+'\n'
By using "quit", you've made a word which can't be used in you diary entry for content: quit your job, quit a terrible program, quit working because the work day ended. If you use "QUIT" instead (loud, but effective), this is less likely to be a problem. It is also a technique used in previous example programs. Other possibilities include embedded caps, embedded special characters ("qu!t"), or nonsense strings ("mzwp") to name a few.
If by 'cmd' you mean you're running the Windows Command Prompt, then you'll need to use Ctrl+Z instead of Ctrl+D.
Igor, you're probably way beyond this by now (I hope). I'm taking the course, apparently, almost a month later. Just in case, though:
I'm on a mac, and I had this same problem for a moment. I'm guessing you're also on a mac, even though you didn't specify, because your experience mirrors mine. As a mac user, I'm used to all sorts of commands to be labeled "control", but I actually use "command", because they're intended for windows users. When I do that, I get the same results you do, printing ^D. However, when I actually push 'control' and 'd' -- yeah, that button that you almost never use on your mac -- rather than 'command' and 'd', it seems to work.
Sometimes I have to push it twice? Not quite sure what's up with that, but ultimately it does recognize the end-of-file key sequence.