简体   繁体   English

如何在python中传递文件路径?

[英]How do I pass a file path in python?

I'm trying to get an image to show on the screen.我正在尝试让图像显示在屏幕上。 I have the image file and code file in the same folder.我在同一个文件夹中有图像文件和代码文件。 I tried using the image file name and it said that there is no such file or directory.我尝试使用图像文件名,它说没有这样的文件或目录。 How do I do that?我怎么做?

I think you should try to write absolute path.我认为您应该尝试编写绝对路径。 you can use following code您可以使用以下代码

import os
path = os.getcwd()

abs_path = path + img_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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