2

to-dos.py

import streamlit as st
import get_todos

todos = get_todos.getTodos()

def add_todos():
    todo1 = st.session_state["new_todo"] + "\n"
    todos.append(todo1)
    get_todos.writeTodos(todos)


st.title("My TO-DO App")
...

get_todos.py

def getTodos():
    with open("docs.txt", "r") as file:
        data = file.readlines()
    return data


def writeTodos(adder):
    with open("docs.txt", "w") as file:
        file.writelines(adder)


I built a TO-DO App in Python using streamlit While performing this task in terminal, it's continuously showing 'FileNotFoundError' meanwhile the file actually exist.

What could be the problem ? Any syntax error? or Logical Error?

Error Traceback: enter image description here

My project structure is shown below: enter image description here

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
  • In which directory is the file located?. If it is in same directory you can try this `./docs.txt` – Jamiu S. Dec 02 '22 at 08:14
  • @JamiuShaibu No it's not working. I could also be wrong! Please mention clearly what to change and not. Moreover, it's in lib folder – Samik Pandit Dec 02 '22 at 11:57
  • I am sorry I can't help and neither will any one can if we don't know the structure of your directories. I think you should rather make your question more clear my providing the structure of your directories.. – Jamiu S. Dec 02 '22 at 12:12
  • @JamiuShaibu I am providing the screenshot of the structure of my directories [link](https://drive.google.com/file/d/1PyLLF8EIYN7DX0QhV2om4ZvfNpNhwlnT/view?usp=share_link) Please check – Samik Pandit Dec 02 '22 at 12:29
  • 1
    Your files are not in lib folder, they are in venv and venv shouldn't contain any of the files I saw in your screeshot. Your structure is not appropriate. I will recommend you [visit pycharm project structure](https://www.jetbrains.com/help/pycharm/configuring-project-structure.html) to restructure your project. It might feel like a pain on the neck but I bet it worth it. Those files should rather be in `samik` folder. – Jamiu S. Dec 02 '22 at 12:45
  • 1
    @JamiuShaibu Thanks a lot for helping. As soon as I placed the files in the Samik folder, it worked. – Samik Pandit Dec 02 '22 at 14:49
  • I am glad it worked, I edited the question to make it more specific and reusable so it could be beneficial to someone who happened to face same or similar issue.. – Jamiu S. Dec 02 '22 at 16:51

1 Answers1

1

The main purpose of virtual environments or venv is to manage settings and dependencies of a particular project regardless of other Python projects. virtualenv tool comes bundled with PyCharm, so the user doesn't need to install it. It is always found in the project directory named venv which should be a unique folder design to fulfil a specific purpose.

Note: No external file(s) should be added to the venv folder.

This clearly indicates that your structure is not appropriate. I will recommend you visit pycharm project structure to read more about configuration of virtual environments. You should restructure your project properly. It might feel like a pain on the neck but I bet it worth it.

Attention:
All the external files you added to venv should rather be in your samik folder which is your project main folder.

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34