Python Forum
Can read files in command prompt but not IDE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can read files in command prompt but not IDE
#1
Why does writing files work in both the command prompt and PyCharm (IDE)...

a = open("workfile.txt", "w")

a.close()
but reading them only works in the command prompt?

a = open("workfile.txt", "r")

a.read()

a.close()
Reply
#2
(Sep-12-2019, 11:39 PM)Exsul Wrote: but reading them only works in the command prompt?
Are you sure that a.read() does not work? Try print(a.read()). Is workfile.txt empty?
Reply
#3
Do you have the correct path to locate the file? If have an incorrect path and it will try to open the file in the default path. If your data file is not in this directory, the file cannot be opened.

default path in idle
C:\Users\yourname\AppData\Local\Programs\Python\Python37>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the difference between Command Prompt and Sublimes yaoyao22 1 594 Jul-09-2023, 02:56 PM
Last Post: snippsat
  How to read in mulitple files efficiently garynewport 3 848 Jan-27-2023, 10:44 AM
Last Post: DeaD_EyE
  Read directory listing of files and parse out the highest number? cubangt 5 2,254 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,353 Feb-13-2022, 07:13 PM
Last Post: menator01
  Facing Problem while opening a file through command prompt vlearner 4 1,857 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Open and read multiple text files and match words kozaizsvemira 3 6,676 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,232 Dec-20-2020, 04:23 AM
Last Post: adifrank
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,835 Dec-06-2020, 04:14 PM
Last Post: Divya577
  Running Python in Command Prompt Anwar 3 3,003 Nov-15-2020, 03:15 PM
Last Post: snippsat
  How to read csv files parallay Mekala 2 1,948 Oct-24-2020, 07:33 AM
Last Post: Mekala

Forum Jump:

User Panel Messages

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