Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Gettin' CRUD-y With It View and Search Entries

bryonlarrance
bryonlarrance
16,414 Points

Using Pycharm and getting a EOFError

Here is my code:

import datetime from collections import OrderedDict import sys

from peewee import *

db = SqliteDatabase('diary.db')

class Entry(Model): content = TextField() timestamp = DateTimeField(default=datetime.datetime.now)

class Meta:
    database = db

def initialize(): db.connect() db.create_tables([Entry], safe=True)

def menu_loop(): """Show the menu""" choice = None while choice != 'q': print("Enter 'q' to quit.") for key, value in menu.items(): print('{}) {}'.format(key, value.doc)) choice = input('Action: ').lower().strip()

    if choice in menu:
        menu[choice]()

def add_entry(): """Add an entry.""" print('Enter your entry. Press ctrl+d when finished.') data = sys.stdin.read().strip()

if data:
    if input('Save entry? [Y,n] ').lower() !='n':
        Entry.create(content=data)
        print("Saved successfully!")

def view_entries(): """View previous entries."""

def delete_entry(entry): """Delete an entry"""

menu = OrderedDict([ ('a', add_entry), ('v', view_entries), ])

if name == 'main': initialize() menu_loop()


Here is the error message.

Enter 'q' to quit. a) Add an entry. v) View previous entries. Action: a Enter you entry. Press ctrl+d when finished. New code. . . New entry. . .^D Enter 'q' to quit. Traceback (most recent call last): a) Add an entry. v) View previous entries. File "/Users/bryonlarrance/PycharmProjects/Diary/diary.py", line 66, in <module> Action: menu_loop() File "/Users/bryonlarrance/PycharmProjects/Diary/diary.py", line 34, in menu_loop choice = input('Action: ').lower().strip() EOFError: EOF when reading a line

Any ideas on what might be causing this. Thanks!!!

1 Answer

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

I had EOF error because Pycharm does not work with ctrl+d command. It should work with ctrl+z and enter afterwards. But you have to use the terminal and do it manually.