• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: File doesnt exist error before user inputs file name

Resolved: File doesnt exist error before user inputs file name

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am working with streamlit in python to produce a tool that takes a user’s input of a csv filename, and then carries out cleaning/tabulating of the data within the file.
I have encountered an issue where before the user has entered their filename, my streamlit site shows a “FileNotFoundError: [Errno 2] No such file or directory:”
This is expected because the user has not entered their filename yet – however once filename is entered the code runs smoothly. I am hoping to overcome this issue but as a relative newcomer to Python I am quite unsure how!
Please see code snippet below
The exact error I get before any user input has been taken is:
Thanks in advance to anyone who can offer a suggestion!

Answer:

The general pattern for both Streamlit and Python in general is to test for the value existing:
When the Streamlit app runs before a user inputs something, the value of autocall_gbp_file is None. By writing if autocall_gbp_file:, you’re only running the pandas read_csv after someone has entered a value.
Separately, you’re better off developing this with st.file_uploader than using text_input, as the Streamlit app doesn’t necessarily have access to the user filesystem and same drive mapping as the machine you are developing on. By using st.file_uploader, you’re literally providing the actual file, not a reference to where it might be located.

If you have better answer, please add a comment about this, thank you!

pycharm python streamlit
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.