#πŸ”’ Error message doesnt show up

16 messages Β· Page 1 of 1 (latest)

wanton crow
#

Hey, guys i have a problem, im building a simple notes program that creates text files which should function as notes. My current problem is that when I try to create a note with the same name as already existing note the error message wont show up for some reason.
Any ideas why ?


running = True

def mainMenu():
   print('1. Create a new note.')
   print('2. Delete a note.')
   print('3. Exit a program.')
   print()
   choice = input('Enter a number of your choice: ')
   handleMainMenu(choice)



def handleMainMenu(choice):
    global running
    if choice == '1':
        note_name = input('Enter a name of your new note: ')
        createNote(note_name)
    elif choice == '3':
        running = False

def createNote(note_name):
    note_name = f"{note_name}.txt"
    new_note_path = os.path.join(notes_path, note_name)
    if not os.path.exists(new_note_path):
        with open(new_note_path, 'w') as file:
            file.write('')
        print(f"Note '{note_name}' created successfully.")
    else:
        print('ERROR: Note with this name already exists!')
    
    

folder_path = 'C:/Users/maxov/Desktop/projects/python'
folder_name = 'notes'
notes_path = os.path.join(folder_path, folder_name)

if(not os.path.exists(notes_path)):
   os.mkdir(notes_path)

while running:
    mainMenu()


spark lionBOT
#

@wanton crow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

flint glade
#

!code

spark lionBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

flint glade
#

pls share ur code properly

wanton crow
#

first time

flint glade
#

ur code is working perfectly

wanton crow
#

ur right

#

it works for me too

#

idk why it didnt before lol

flint glade
#

lmao

wanton crow
#

should i close this somehow ?

flint glade
#

if there is no further problem u can close the post with !close

wanton crow
#

!close

spark lionBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.