Kindly I have error

please can anyone help me because I face issue:
when I run my code the python program does not read my directory ( the place where I save my file) I use abspath code and exists also. but the python program return the value is not correct

1 Like

please provide the error message and the link to your repl, as we (most likely) cannot help you without the code for your discord chatbot.

They are referring to one of the first two repls of this account: https://replit.com/@aymanhwa

2 Likes

hello @aymanhwa, I assume that you are talking about the following code:

import os

if os.path.abspath("D:\\Python learning\\test.txt"):
  print("That location exists!")
else:
  print("That location does not exist!")

Replit uses linux, not windows, so their directory structure is slightly different. Upload your test.txt file to your repl’s Files and then use os.path.relpath(“test.txt”) to automatically find “test.txt” in your repl.
EDIT: use os.path.realpath(“test.txt”) instead

me is stoopid use:

os.path.exists("test.txt")

Sorry for my stupidity

If this answer helped, please mark as solution.

4 Likes

thank you for reply, yes this code that is I mean it
let me talk also about the other code , appriximitly same as the code written ,

import os
if os.path.exists("D:\\Python learning\\test.txt"):
  print("That location exists!")
else:
  print("That location does not exist!")

when I execute or run the program the python program run result always the second print even the path wrong or correct.

1 Like

still the result fix even true or false

1 Like

I apologize for my earlier typoes. You should use os.path.exist, and inside it use os.path.exists("test.txt"). I didn’t mean to use relpath, i got confused in the process.

thank you for that answer, it is work brilliant, but you have to upload the file or folder then replit - python can read the file, that mean the replit- python dos not read the file from roots ( the real path of file or saved place path on the hard drive)

1 Like

Well yeah, Replit can’t read files on your computer.

if it could, then that would be scary :cold_face:

1 Like

I hope that replit develop their environment to read the files direct from root on hard drive

I’d hope they don’t, as then a malicious Repl could do whatever it wanted with all your files.

2 Likes

That would be possible using the new web API which allows select filesystem access, but it probably wouldn’t be too high of a priority with the new deployments changes.

2 Likes

Thank you so much for your explanation . I understand now why they do not deploy that.

Shukran = many thanks

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.