简体   繁体   中英

Syntax error when trying to open a file through Python 3 Command Shell

So I am learning Python through Udemy tutorials and now I need to open a file through CMD(CMD is opened on folder I need) and when I am typing function for opening file it says syntax error, but I have made everything good what a guy on tutorials says, I really don't know what what should I do, I checked all of the forums and still cant find the answer.

Here are some screenshots:

在此处输入图像描述

在此处输入图像描述

You have to use parenthesss () not <>

file = open("example.txt","r")

check https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

Couple of issues:

1.Your text file is called "example.txt.txt" instead of "example.txt"

2.The "example.txt","r" should be surrounded with brackets () instead of <>. These symbols look similar in cmd and are easy to confuse.

    #instead of
    file = open<"example.txt","r">
    #use
    file = open("example.txt","r")

This should fix your problem; let me know if it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM