selfteaching / selfteaching/selfteaching-python-camp
Day09 运行main.py出现读取不了tang300.json文件错误原因
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
因为vs code打开的路径是/User/xxx/19100101/,
当main.py直接读取文件tang300.json的时候,
是默认读取/User/xxx/19100101/tang300.json路径,
而我们的tang300.json实际路径是/User/xxx/19100101/用户名/tang300.json,所以就会报错。
解决方法:vs code ==>文件==>打开(文件)找到/User/xxx/19100101/用户名/,然后打开,再运行main.py就能直接读取tang300.json了。
还有一种教练提供解决方法是:
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tang300.json')) as f :
这样可以读取到文件的绝对路径
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open main.py and inspect how it opens tang300.json; reproduce the failure when running from /User/xxx/19100101/ instead of the user subdirectory. Done means the script can locate tang300.json using the project path handling described in the issue, and the run succeeds from the stated VS Code location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100