当前位置:网站首页>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 !“
边栏推荐
猜你喜欢
随机推荐
勤于奋聊聊现在还有哪些副业可以做
HCIA static routing basic simulation experiment
Web框架介绍
【无标题】按照一定的条件,对 i 进行循环累加。条件通常为循环数组的长度,当超过长度就停止循环。因为对象无法判断长度,所以通常搭配 Object.keys() 使用。\nforEach 一般认为是 普
Affine transformation module and conditional batch Standardization (CBN) of detailed text generated images
R-score reproduction R-Precision evaluation index quantitative text generation image r-score quantitative experiment whole process reproduction (R-Precision) quantitative evaluation experiment step on
Standard dialog qmessagebox
C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)
如何将Photoshop图层复制到其他文档
【牛客讨论区】第七章:构建安全高效的企业服务
不需手动安装cuda和cudnn,通过一行程序即可安装tensorflow-gpu,以tensorflow-gpu2.0.0,cuda10.0,cudnn7.6.5为例
CDH集群集成外部Flink(改进版-与时俱进)
Solution: read the files with different names in the two folders and deal with the files with different mappings
【报错】:Cannot read properties of undefined (reading ‘prototype‘)
深入 Qt5 信号槽新语法
一道数学题,让芯片巨头亏了5亿美金
[search] connectivity model of DFS + search order
Photoshop裁剪工具隐藏技巧
智慧展厅设计的优势及适用行业分析
When using Photoshop, the prompt "script error -50 general Photoshop error appears“









