如何在路径上下文中使用“~"(波浪号)? [英] How do I use '~' (tilde) in the context of paths?

查看:22
本文介绍了如何在路径上下文中使用“~"(波浪号)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 Web 应用程序开发新手.我有一个函数可以打开一个文件并读取它.不幸的是,测试服务器和生产服务器之间的目录结构不同.我被告知使用相对于 ~ 的路径".不过,我一直无法在~"上找到任何资源!

如何在路径上下文中使用波浪号?

这是在 Python 中.我使用 os.path.expanduser('~/path/in/home/area').

解决方案

它是你在 UNIX 中的 $HOME var,通常是 /home/username.

你的家"是指正在执行像 cd ~/MyDocuments/ 这样的命令的用户的家是 cd/home/user_executing_cd_commnd/MyDocuments

I'm a web application development noob. I have a function that opens a file and reads it. Unfortunately, the directory structures between the test and production servers differ. I was told to "use a path relative to ~". I haven't been able to find any resources on the '~', though!

How do I use the tilde character in the context of paths?

EDIT: This is in Python. I fixed the problem, using os.path.expanduser('~/path/in/home/area').

解决方案

it is your $HOME var in UNIX, which usually is /home/username.

"Your home" meaning the home of the user who's executing a command like cd ~/MyDocuments/ is cd /home/user_executing_cd_commnd/MyDocuments

这篇关于如何在路径上下文中使用“~"(波浪号)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆