Python Forum
Coding error. Can't open directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding error. Can't open directory
#1
IDLE can not open/ file directory even when the file existed on the directory.
Disk Location: C:\Users\hp\Desktop\Pythoncodes
Word text download from GitHub.

Result:

Output:
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. = RESTART: C:/Users/hp/Desktop/Pythoncodes/random word finder.py >>>>>>>>>>Random Word Finder<<<<<<<<<<
Using a 466K english word text file I can pick any words at random.


How many words shall I choose?20
Error:
Traceback (most recent call last): File "C:/Users/hp/Desktop/Pythoncodes/random word finder.py", line 8, in <module> with open('C:/Users/hp/Desktop/Pythoncodes/word.text', "rt") as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/hp/Desktop/Pythoncodes/word.text'
code:

import random

print(">>>>>>>>>>Random Word Finder<<<<<<<<<<")
print("\nUsing a 466K english word text file I can pick any words at random.\n")

wds=int(input("\nHow many words shall I choose?"))

with open('C:/Users/hp/Desktop/Pythoncodes/word.text', "rt") as f:
    words = f.readlines()
    words = [w.rstrip() for w in words]

print("--------------------")

for w in random.sample(words, wds):
    print (w)
print("--------------------")
Larz60+ write Jul-13-2023, 09:48 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fiixed this time. Please use BBCode tags on future posts.
Reply


Messages In This Thread
Coding error. Can't open directory - by EddieG - Jul-12-2023, 01:34 PM
RE: Coding error. Can't open directory - by EddieG - Jul-12-2023, 01:52 PM
RE: Coding error. Can't open directory - by EddieG - Jul-13-2023, 08:39 AM
RE: Coding error. Can't open directory - by buran - Jul-13-2023, 08:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. xflyerwdavis 2 552 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding Error EddieG 2 565 Jul-09-2023, 02:59 AM
Last Post: EddieG
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,522 Jun-27-2023, 01:17 PM
Last Post: diver999
  Error when using Watchdog and Qt to keep open a Queue before and after sending first pyhill00 0 1,621 Oct-28-2021, 09:10 AM
Last Post: pyhill00
  Error about missing directory Led_Zeppelin 3 2,775 Aug-31-2021, 01:37 PM
Last Post: snippsat
  Error on open of file created with tempfile.TemporaryDirectory() Brian177 4 6,381 Apr-05-2021, 07:12 PM
Last Post: Brian177
  List of error codes to find (and count) in all files in a directory tester_V 8 3,784 Dec-11-2020, 07:07 PM
Last Post: tester_V
  python coding error isntitzee 1 2,231 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,761 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 2,124 Sep-27-2020, 04:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020