当前位置:网站首页>Slashes / and backslashes involved in writing code\
Slashes / and backslashes involved in writing code\
2022-07-27 05:03:00 【Inexhaustible hand of God】
Writing code involves slashes / And the backslash \
I remember when I was in college, what I hated most was the slash (/) And the backslash (\), Often foolishness can't tell , This super attacks people's coding enthusiasm .
1.
But with reading some code books , Namely 《Python From introduction to practice 》, I see , Writing code is a process of trial and error , When you write code, it's 100% wrong , Now I don't care about the difference between slash and backslash , Anyway, write it in (IDE), Integrated development environment ( Like PyCharm) Will report a mistake , Execution can also quickly see the results .
But we still have to distinguish it , We use it a lot Windows The path in the system is the backslash (\), and Linux The system is a slash (/).
2.
So let's look at the code (Python Under the code ):
Relative paths (Windows operating system ):
with open("text_file\digits_1.txt") as file_object:
contents = file_object.read()
print(contents)
Relative paths (Linux operating system ):
with open('text_files/filename.txt') as file_object:
Absolute path path (Windows operating system ):
path = "F:\python_project\other_text_file\other_digits_1.txt"
with open(path) as file_object:
contents = file_object.read()
print(contents)
Absolute path path (Linux operating system ):
file_path ='/home/ehmatthes/other_files/text_files/filename.txt'
with open(file_path) as file_object:
Be careful Windows Sometimes the system can correctly interpret the slash in the file path . If you're using Windows System , And the results do not meet expectations , Make sure you use a backslash in the file path .
Relative paths (Windows operating system ):
with open("text_file/digits_1.txt") as file_object:
contents=file_object.read()
print(contents)
Reverse diagonal and backslash , Try it yourself , If this doesn't work, change that .
3.
But I understand a little bit :
Any programmer will encounter problems , This is inevitable
Program error , Read the log information carefully , Error message
Leave the computer , Let's take a rest , Try again .
Anyway, you write code , Write it out and run it first ! by the way ,Python Very elegant! , The code structure is very clear , Learn it , You'll see , Compare ” Elegance never goes out of style !“
边栏推荐
- MySQL下载安装 & 完美卸载
- Plato Farm有望通过Elephant Swap,进一步向外拓展生态
- TypeScript 详解
- Final Cut Pro Chinese tutorial (2) understanding of material window
- 【C语言】动态内存管理
- Why is select not recommended*
- feign调用丢失请求头问题解决及原理分析
- 会议OA之我的审批
- Digital integrated circuit: MOS tube device chapter (I)
- Advantages of smart exhibition hall design and applicable industry analysis
猜你喜欢

JS tips

如何做数据平滑迁移:双写方案

HCIA static routing comprehensive experiment

树莓派输出PWM波驱动舵机

Final Cut Pro中文教程 (1) 基础认识Final Cut Pro

"Photoshop2021 tutorial" align and distribute to make dot patterns

日落红暖色调调色滤镜luts预设Sunset LUTs 1

Summary of fire safety training materials

一道数学题,让芯片巨头亏了5亿美金

「Photoshop2021入门教程」“拉平”带有透视感的图像
随机推荐
TCP three handshakes and four disconnects
再一个技巧,每月稳赚3万+
小程序项目如何创建
When using Photoshop, the prompt "script error -50 general Photoshop error appears“
Unit test Chapter6
报错:cannot read poperties of undefined(reading ‘then‘)
MySQL下载安装 & 完美卸载
如何重置Photoshop首选项?ps重置首选项的方法
利用Power Automate,轻松下载Power BI报告中的数据
二、MySQL高级
「Photoshop2021入门教程」调整图片到不同的长宽比
"Photoshop2021 tutorial" align and distribute to make dot patterns
网络协议详解:IP
Dialog introduction
MySQL download and installation & perfect uninstall
C language - two dimensional array, pointer
Photoshop裁剪工具隐藏技巧
Reproduce ssa-gan using the nine day deep learning platform
[search] flood fill and shortest path model
Three paradigms, constraints, some keyword differences,