解决qpython默认根目录的问题
qpython吧
全部回复
仅看楼主
level 8
清净出尘 楼主
2016年04月03日 02点04分 1
level 8
清净出尘 楼主
很多人都不知道,qpython运行脚本时,默认是在根目录,而不是像python那样,哪里运行,目录就在哪里
2016年04月03日 02点04分 2
level 8
清净出尘 楼主
这样就导致了新人常见的一些问题,在电脑上可以os.mkdir(test)建文件夹的,在手机上却不行。在电脑上可以sqlite3.connect('123.db')新建数据库的,在手机却不行
2016年04月03日 02点04分 3
level 8
清净出尘 楼主
前些日子看到说,print __file__可以打印出当前脚本的绝对路径,而这条命令在qpython上适用!可以获取到文件名绝对路径,那我们再获取目录的绝对路径,最后进入目录,就是当前脚本所在目录了,以后在脚本里加上下面这行就ok了
2016年04月03日 02点04分 4
level 8
清净出尘 楼主
os.chdir(os.path.dirname(__file__))
2016年04月03日 02点04分 5
level 8
清净出尘 楼主
2016年04月03日 02点04分 6
level 8
清净出尘 楼主
2016年04月03日 02点04分 7
level 8
清净出尘 楼主
说得有点乱,希望大家谅解[哈哈]
2016年04月03日 02点04分 8
帮了我大忙,正愁数据库的问题
2022年07月25日 10点07分
@bluuu1 哈哈,来qq群一起耍呀540717901
2022年07月25日 10点07分
level 6
贴吧真是一个神奇的地方!楼主一则贴就解决了困扰我好久的问题。[真棒]
2016年04月04日 05点04分 9
哈哈
2016年04月04日 05点04分
Qpthon交流群欢迎你,QQ搜索qpython交流,第一出现的就是我们哦!
2016年05月25日 06点05分
level 1
[大拇指]
2016年04月15日 03点04分 10
level 13
未定义[黑线][黑线][黑线]
2016年04月21日 03点04分 11
level 1
楼主能不能帮我看看
QPython 怎么进行文件读写下面这段代码运行完提示ioerror [error2] no such file or directory as 'names.txt
import os
print('current dir')
os.chdir(os.path.dirname(__file__))
print(os.getcwd())
data=open('names.txt')
print(data)
data.close()
2016年05月25日 08点05分 12
他不是说没有这个文件吗
2016年06月01日 06点06分
level 7
感谢中
2016年05月26日 07点05分 13
level 5
解决了问题!
2018年02月27日 11点02分 14
level 7
最新版的默认执行目录指向了/sdcard/qpython 或者/storage/emulated/0/qpython
2018年02月27日 15点02分 15
1 2 尾页