V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
uuair
V2EX  ›  Python

Python 的问题,在 Pythonista 上跟电脑上的结果为什么不同?

  •  
  •   uuair · 2018-12-27 23:09:55 +08:00 · 2254 次点击
    这是一个创建于 1918 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个特别简单的例子:

    D={'a':1,'b':2,'c':3}
    for key in sorted(D):
    	print(key, '=>', D[key])
    

    在 Pythonista 上的结果是:

    ('a', '=>', 1)
    ('b', '=>', 2)
    ('c', '=>', 3)
    

    电脑上的结果是:

    a => 1
    b => 2
    c => 3
    

    为什么 Pythonista 上是这个结果?会不会我在学习 python 的过程中,使用 Pythonista 不靠谱啊?

    7 条回复    2018-12-29 01:26:26 +08:00
    westoy
        1
    westoy  
       2018-12-27 23:13:18 +08:00   ❤️ 1
    前一个 python2 默认的,print 是作为语法, 后面带括号的被识别成元组

    python2 导入 print_function 的 future, 或者 python3 的环境下, 带括号的 print 是作为函数
    Qzier
        2
    Qzier  
       2018-12-27 23:16:48 +08:00 via iPhone   ❤️ 1
    python 版本问题
    uuair
        3
    uuair  
    OP
       2018-12-27 23:42:04 +08:00
    @westoy
    @Qzier 感谢二位,明白了。可惜 Pythonista 上的 Stash 不支持 python3,所以很多例子,没法跟书上一致了。
    LokiSharp
        4
    LokiSharp  
       2018-12-27 23:46:37 +08:00
    @uuair #3 其实是支持 Python3 的,只是不能用 pip git 之类的东西了
    uuair
        5
    uuair  
    OP
       2018-12-27 23:51:26 +08:00
    @LokiSharp #4 不能吧。。。StaSh 这里如果选 python 运行的话,会出现错误提示:`'ascii' codec can't decode`什么什么的,而如果在 python2 中运行 StaSh,进入后输入 python3,得到`You are running StaSh in python2. Running python3 from python 2 is not (yet) supported.`
    LokiSharp
        6
    LokiSharp  
       2018-12-27 23:57:14 +08:00   ❤️ 1
    @uuair #5 更新 dev 版本就行了 只是第三方的工具不支持 Python3
    Holmes96
        7
    Holmes96  
       2018-12-29 01:26:26 +08:00 via iPhone
    pythonista 支持 py3.6 的,stash 也支持 py3
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1053 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:10 · PVG 03:10 · LAX 12:10 · JFK 15:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.