小编Eri*_*a E的帖子

.gitignore 否定不起作用

我正在使用 msysgit 1.9.4。

我的 .gitignore 文件位于 repo 的根目录,如下所示:

build/
a/b/
!a/c/d/e/**/build/
Run Code Online (Sandbox Code Playgroud)

我的意图是,所有 build/ 目录都将被忽略,除非它们是 a/c/d/e/ 的子目录(任何深度)。但是 a/c/d/e/f/build/ 仍然被 Git 忽略。

我在这里缺少什么?

git msysgit gitignore

6
推荐指数
1
解决办法
2604
查看次数

如何捕获 NoSuchElementException?

我的课堂作业是编写一个程序,让用户输入一组数值。如果用户输入的值不是数字,程序应该给用户 2 秒的机会正确输入一个数字,在这两次机会之后,停止要求输入并打印到目前为止正确输入的所有值的总和.

照原样,我的代码不能正常工作。当输入第一个非数字时,程序执行一次 catch 块中的代码,在 try 块的开头打印“gimme input”行,然后立即再次执行 catch 块中的代码,无需等待用户输入另一个号码。

在仔细阅读我的教科书以寻找线索时,我注意到这一行:“任何 catch 子句都不会捕获NoSuchElementException 。异常一直抛出,直到它被另一个 try 块捕获或 main 方法终止。”

这很好,因为现在至少我知道发生这种情况是有充分理由的,但是我的教科书没有包含有关此怪癖的任何进一步信息,而且我无法通过 StackOverflow 或 Google 找到任何可以理解的答案。所以我的问题是两部分:

a) 为了这个任务的目的,我应该如何解决这个问题?

b) 异常没有被 catch 子句捕获到底是什么意思?那不是catch 子句存在的目的吗?我确实想要我的任务的解决方案,但我也想了解为什么会这样,如果可能的话。

谢谢你的帮助!

import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.util.Scanner;

public class NotANumber {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("This program computes the sum of any number of real numbers. When you are done entering values, enter something …
Run Code Online (Sandbox Code Playgroud)

java exception-handling

5
推荐指数
1
解决办法
3万
查看次数

如何让tkinter使用Ubuntu的默认Python 2.7安装?

我正在使用预装了Python 2.7.3的Ubuntu 11.10.

我通过apt-get install安装了python3软件包和python3-tk软件包,他们一起"开箱即用".

但是虽然我已经安装了python-tk包,但我无法弄清楚如何让Python2.7看到它.我尝试导入时收到以下错误消息.

import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
Run Code Online (Sandbox Code Playgroud)

编辑:我还运行了以下基于Python-tk包,在Python 2.7.3中无法识别,并获得:

$ file /usr/lib/libtk8.5.so.0
/usr/lib/libtk8.5.so.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped

$ uname -a
Linux bugbot 3.0.0-23-generic-pae #39-Ubuntu SMP Thu Jul 19 19:39:19 UTC 2012 i686 …
Run Code Online (Sandbox Code Playgroud)

python ubuntu tkinter

3
推荐指数
1
解决办法
2万
查看次数

为什么我在Python中遇到此属性错误?

在此先感谢任何帮助,我知道这可能是一个新问题,但我找不到任何通过搜索似乎回答我的问题.这是追溯的相关部分:

  File "war.py", line 183, in __battle
    if (card1 > card2):
  File "war.py", line 24, in __lt__
    return self.int_id % 13 < other.int_id % 13
AttributeError: 'function' object has no attribute 'int_id'
Run Code Online (Sandbox Code Playgroud)

我对这意味着什么感到困惑....什么是'功能'对象?另外,为什么从一个比比较大的行调用lt?为什么现在这是一个问题,因为我单元测试了我的Card类(其中card1和card2是其实例),包括所有丰富的比较运算符,并且它通过了?

这些是我的Card类中丰富的比较方法的定义(int_id,正如您可能猜到的,只是一个实例变量int):

(对不起下面的缩进搞砸了)

class Card():

    def __init__(self, int_id):
        self.int_id = int_id

    def __lt__(self, other):
        return self.int_id % 13 < other.int_id % 13

    def __le__(self, other):
        return self.int_id % 13 <= other.int_id % 13

    def __eq__(self, other):
        return self.int_id % 13 == other.int_id % 13

    def __ne__(self, …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
212
查看次数

标签 统计

python ×2

exception-handling ×1

git ×1

gitignore ×1

java ×1

msysgit ×1

tkinter ×1

ubuntu ×1