在ubuntu上学习python 3.0

发布于 2024-07-16 11:16:53 字数 1549 浏览 2 评论 0原文

[已解决]

我调整了科莫多编辑中的首选项,最终得到:

不要自动缩进

不允许文件内容覆盖制表符设置

更喜欢制表符而不是空格 每个缩进

4 个空格

每个制表符的 4 个宽度

我还将科莫多设置为显示空白和制表符,最终露出了搞砸的部分。

是的——有点挑剔。 :)

[/resolved]

我已经在 ubuntu 8.10 上安装了 python 3.0 以及 komodo-edit ide。

我刚刚开始学习 python,正在阅读可视化快速入门指南 python 第二版。 (下面的例子来自那本书)。 我遇到了一些非常令人沮丧的错误,非常感谢您的想法。

我已经多次重新输入和检查选项卡。

我开始认为安装或设置中出现了问题。

我在 komodo-edit 中输入了以下内容:

#!/usr/bin/python3.0
for row in range(1, 10):
    for col in range(1, 10):
        p = row * col
        if p < 10:
            print(' ', end = '')
        print(row * col, ' ', end = '')
    print()

我无法用 python 3 测试这是 IDLE - 似乎无法安装该版本的 IDLE。 现在,我正在尝试从 shell 中运行。

首先,只是使用“python”来调用程序...

PYTHON [1] $  python ktest.py 
      File "ktest.py", line 6
        print(' ', end = '')
                       ^
    SyntaxError: invalid syntax

现在尝试调用python编译器的不同方法...

PYTHON [1] $  python ktest.py 
          File "ktest.py", line 6
            print(' ', end = '')
                           ^
        SyntaxError: invalid syntax


PYTHON [1] $  python3 ktest.py 
      File "ktest.py", line 4
        p = row * col
                    ^
    TabError: inconsistent use of tabs and spaces in indentation


PYTHON [1] $  python3.0 ktest.py 
      File "ktest.py", line 4
        p = row * col
                    ^
    TabError: inconsistent use of tabs and spaces in indentation

[resolved]

I tweaked the preferences in komodo edit and ended up with:

don't auto indent

don't allow file contents to override tab settings

prefer tab characters over spaces

4 spaces per indent

4 width of each tab char

I also set komodo to show whitespace and tabs, which eneded up revealing the screwed up sections.

yeah - it's a little picky. :)

[/resolved]

I have installed python 3.0 on ubuntu 8.10 along with komodo-edit ide.

I'm just getting into python, and I'm reading through visual quickstart guide python 2nd ed. (the example below is from that book). I'm getting some really frustrating errors and would really appreciate your thoughts.

I've re-typed and checked tabs many times over.

I'm starting to think that something in the install or setup has gone wrong.

I typed the following into komodo-edit:

#!/usr/bin/python3.0
for row in range(1, 10):
    for col in range(1, 10):
        p = row * col
        if p < 10:
            print(' ', end = '')
        print(row * col, ' ', end = '')
    print()

I can't test this is IDLE with python 3 - can't seem to get that version of IDLE installed. for now, I'm trying to run from the shell.

first, just using "python" to call the program...

PYTHON [1] $  python ktest.py 
      File "ktest.py", line 6
        print(' ', end = '')
                       ^
    SyntaxError: invalid syntax

now trying different ways of calling the python compiler...

PYTHON [1] $  python ktest.py 
          File "ktest.py", line 6
            print(' ', end = '')
                           ^
        SyntaxError: invalid syntax


PYTHON [1] $  python3 ktest.py 
      File "ktest.py", line 4
        p = row * col
                    ^
    TabError: inconsistent use of tabs and spaces in indentation


PYTHON [1] $  python3.0 ktest.py 
      File "ktest.py", line 4
        p = row * col
                    ^
    TabError: inconsistent use of tabs and spaces in indentation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-07-23 11:16:53

该示例使用 python 2.x ,因为 python 显然引用了 python2.x (对于某些 x),而不是 python3.0 (这很好,因为大多数程序都是针对 2.x 的)。

后两个示例使用 python 3.0 。 您在源代码中混合了制表符和空格,并且应该删除制表符(不要重新输入 - 使用正则表达式替换)。 Python 3.0 对此比 2.x 更敏感——您可以使用 2.x 的 python -tt 获得相同的行为。

The example used python 2.x , since python apparently referred to python2.x (for some x), not python3.0 (which is good, since most programs are for 2.x).

The second two examples used python 3.0 . You mixed tabs and spaces in your source, and should get rid of the tab characters (don't retype-- use regular-expression replacement). Python 3.0 is more sensitive about this than 2.x-- you can get the same behavior using python -tt for 2.x .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文