Python Forum
Facing Problem while opening a file through command prompt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Facing Problem while opening a file through command prompt
#1
Hi Everyone,

Here is the code that I have written for reading a file through command prompt.
from sys import argv

 script, filename = argv

 txt = open(filename)

 print(f"Here's your file {filename}:")
 print(txt.read())

 print("Type the filename again:")
 file_again = input("> ")

 txt_again = open(file_again)

 print(txt_again.read())
but while executing this program I am facing this error
Error:
txt = open(file.txt) AttributeError: 'str' object has no attribute 'txt'
please guide me through this problem
Reply


Messages In This Thread
Facing Problem while opening a file through command prompt - by vlearner - Jan-29-2022, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,023 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  problem with print command in super() akbarza 5 647 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  Facing issue in python regex newline match Shr 6 1,364 Oct-25-2023, 09:42 AM
Last Post: Shr
  problem in using input command akbarza 4 1,191 Oct-19-2023, 03:27 PM
Last Post: popejose
  What is the difference between Command Prompt and Sublimes yaoyao22 1 660 Jul-09-2023, 02:56 PM
Last Post: snippsat
  Facing problem with Pycharm - Not getting the expected output amortal03 1 871 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 6,087 Jan-07-2022, 04:55 PM
Last Post: bowlofred
  Subprocesses not opening File Select Dialog teut 2 2,436 Feb-22-2021, 08:07 PM
Last Post: teut
  Facing error while executing below Python code ramu4651 1 5,773 Jan-26-2021, 06:40 PM
Last Post: ibreeden
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,364 Dec-20-2020, 04:23 AM
Last Post: adifrank

Forum Jump:

User Panel Messages

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