当前位置:网站首页>写代码涉及到的斜杠/和反斜杠\
写代码涉及到的斜杠/和反斜杠\
2022-07-27 04:42:00 【理不尽的神之手】
写代码涉及到的斜杠/和反斜杠\
记得我上大学的时候最讨厌遇见的就是斜杠(/)和反斜杠(\),经常傻傻分不清,这超级打击人的编码积极性啊。
1.
不过随着读一些代码的书籍,就是《Python从入门到实践》,我倒是明白了,写代码就是不断试错的过程,你写代码遇见错误是百分百的哈,现在我也不管斜杠和反斜杠是啥区别了,反正写进去(IDE),集成开发环境(像是PyCharm)会报错,执行也能快速看到结果。
不过还是要分清一下的哈,我们经常使用的Windows系统中的路径就是用的反斜杠(\),而Linux系统则是斜杠(/)。
2.
那么我们来看下代码(Python下的代码):
相对路径(Windows操作系统):
with open("text_file\digits_1.txt") as file_object:
contents = file_object.read()
print(contents)
相对路径(Linux操作系统):
with open('text_files/filename.txt') as file_object:
绝对路径路径(Windows操作系统):
path = "F:\python_project\other_text_file\other_digits_1.txt"
with open(path) as file_object:
contents = file_object.read()
print(contents)
绝对路径路径(Linux操作系统):
file_path ='/home/ehmatthes/other_files/text_files/filename.txt'
with open(file_path) as file_object:
注意 Windows系统有时能够正确地解读文件路径中的斜杠。如果你使用的是Windows系统,且结果不符合预期,请确保在文件路径中使用的是反斜杠。
相对路径(Windows操作系统):
with open("text_file/digits_1.txt") as file_object:
contents=file_object.read()
print(contents)
反正斜杆和反斜杠,你自己试着用,这个不行就换那个。
3.
不过我明白了一点道理:
任何程序员都会遇见问题,这是无法避免的
程序出现错误,仔细阅读日志信息,报错信息
离开计算机,休息一会儿,再尝试。
反正你是写代码的,写出来先运行吧!对了,Python很优雅啊,代码结构很清晰哈,学一学吧,你就明白了,比较”优雅永不过时!“
边栏推荐
- Knowledge about hash index and b+ tree
- Customize the viewport height, and use scrolling for extra parts
- Basic configuration of static routing to achieve network wide accessibility
- Chapter 4 scope and life cycle of bean object
- 【Acwing】第61场周赛 题解
- 网络协议详解:IP
- Approval of meeting OA
- Easy to use mobile app automation testing framework where to find? Just collect this list!
- Structural mode - decorator mode
- CDH集群集成外部Flink(改进版-与时俱进)
猜你喜欢

The execution process of a select statement in MySQL

The digital China Construction Summit ended with a list of massive pictures on site!

MySQL download and installation & perfect uninstall

小程序项目如何创建
![[search] - multi source BFS + minimum step model](/img/42/11b5b89153ab48d837707988752268.png)
[search] - multi source BFS + minimum step model

Digital integrated circuit: MOS tube device chapter (II)

C language - two dimensional array, pointer

Comprehensive experiment of static routing

【Acwing】第61场周赛 题解

js小技巧
随机推荐
The price reduction of iphone13 is just a show. Consumers are waiting for iphone14
Digital integrated circuit: MOS tube device chapter (II)
STM32_ HAL_ SUMMARY_ NOTE
static和final关键字 学习 demo练习
HCIA dynamic routing OSPF experiment
Basic configuration of static routing to achieve network wide accessibility
Ref Hook
2022 T2i text generated image Chinese Journal Paper quick view-1 (ecagan: text generated image method based on channel attention mechanism +cae-gan: text generated image technology based on transforme
TCP's three handshakes and four waves
[error reporting]: cannot read properties of undefined (reading 'prototype')
Vscode opens a new chapter in the visualization of pull request update code branches
ceph操作
Easily download data in power Bi reports with power auto
日落红暖色调调色滤镜luts预设Sunset LUTs 1
Hiding skills of Photoshop clipping tool
关于gorm的BeforeDelete钩子方法不生效的问题
消防安全培训资料汇总
[search] - multi source BFS + minimum step model
会议OA之我的审批
使用mq消息队列来进行下单流程的高并发设计,消息挤压,消息丢失,消息重复的产生场景和解决方案