2016-11-08 3 views
3

私は、Microsoft Windows 7でIDLE 2.7.6のpython 2.7.6を使用しています。IDLE変数の登録に失敗しました。そんなことがあるものか?

IDLEは、下の画像のように変数(名前はx5)を登録できませんでした。そんなことがあるものか?問題をトリガーするために取ら

enter image description here


アクション:

  1. 次は私のIDLEコンソール履歴にすでにある:

    >>> x1 = np.arange(9.0).reshape((3, 3))
    >>> x5 = 4

  2. 私はは、このコピーは、次の

  3. を入力してEnterキーを押しx5 = 4

  4. 上のどこかにカーソルを置きます。コピーした後

    >>> x1 = np.arange(9.0).reshape((3, 3))
    >>> x5 = 4

  5. 、カーソルが自動的に配置されます末尾はx5 = 4です。私はx5が値4

  6. 私はx5の値をチェックするx5を型を取ることを期待して、は再びをEnterキーを押します。私はBlckknghtの回答やコメントをもとに

    >>> x5

    Traceback (most recent call last):
    File "<pyshell#118>", line 1, in <module>
    x5
    NameError: name 'x5' is not defined


を取得し、それが見えます私はコピー最初の場所でIDLEコンソールで(>>>含む)一度に次の2行を貼り付けていたのと同様に:結果

x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 4 

IDLEだけを気にするので、ライン>>> x5 = 4は単に、無視されました最初に表示されるpython文です。


全体IDLEログ:

Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32 
Type "copyright", "credits" or "license()" for more information. 
>>> '#' *3 
'###' 
>>> import numpy as np 
>>> a=np.random.random((3, 3)) 
>>> b=np.random.random((3, 3)) 
>>> a 
array([[ 0.92731349, 0.48377097, 0.32175387], 
     [ 0.65061308, 0.72905101, 0.65499733], 
     [ 0.1334612 , 0.4023123 , 0.50179231]]) 
>>> b 
array([[ 0.35232561, 0.77837691, 0.70645223], 
     [ 0.51114669, 0.83303289, 0.78842767], 
     [ 0.51179183, 0.25109079, 0.91229917]]) 
>>> a*b 
array([[ 0.32671629, 0.37655615, 0.22730374], 
     [ 0.33255872, 0.60732347, 0.51641802], 
     [ 0.06830435, 0.10101691, 0.45778471]]) 
>>> a = [[1, 0], [0, 1]] 

>>> b = [[4, 1], [2, 2]] 

>>> a = [[3, 4], [2, 1]] 
>>> a 
[[3, 4], [2, 1]] 
>>> b 
[[4, 1], [2, 2]] 
>>> np.dot(a, b) 

    File "<pyshell#12>", line 1 
    np.dot(a, b) 
^
IndentationError: unexpected indent 
>>> np.dot(a, b) 
array([[20, 11], 
     [10, 4]]) 
>>> a = [[1, 2]] 
>>> a.dot(b) 

Traceback (most recent call last): 
    File "<pyshell#15>", line 1, in <module> 
    a.dot(b) 
AttributeError: 'list' object has no attribute 'dot' 
>>> a = np.array([[1, 2]]) 
>>> a.dot(b) 
array([[8, 5]]) 
>>> a = np.array([[3,4]]) 
>>> b= = np.array([[3,4]]) 
SyntaxError: invalid syntax 
>>> b= np.dot(a, b) 
np.array([[3,4]]) 

>>> a*b 
array([[60, 44]]) 
>>> a 
array([[3, 4]]) 
>>> b 
array([[20, 11]]) 
>>> np.dot(a, b) 

Traceback (most recent call last): 
    File "<pyshell#24>", line 1, in <module> 
    np.dot(a, b) 
ValueError: objects are not aligned 
>>> 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(3.0) 

>>> np.multiply(x1, x2) 

array([[ 0., 1., 4.], 
     [ 0., 4., 10.], 
     [ 0., 7., 16.]]) 
>>> x1 
array([[ 0., 1., 2.], 
     [ 3., 4., 5.], 
     [ 6., 7., 8.]]) 
>>> z2 

Traceback (most recent call last): 
    File "<pyshell#30>", line 1, in <module> 
    z2 
NameError: name 'z2' is not defined 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0).reshape((3, 3)) 
>>> np.multiply(x1, x2) 
array([[ 0., 1., 4.], 
     [ 0., 4., 10.], 
     [ 0., 7., 16.]]) 
>>> x1 
array([[ 0., 1., 2.], 
     [ 3., 4., 5.], 
     [ 6., 7., 8.]]) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0).reshape((3, 3)) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 
array([[ 0., 1., 2.], 
     [ 3., 4., 5.], 
     [ 6., 7., 8.]]) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0).reshape((3, 3)) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0) 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = 3 
>>> x2 
array([ 0., 1., 2.]) 
>>> x1=1 
>>> x1 
1 
>>> x2 = 3 
>>> x2 
3 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0) 
>>> x2 
3 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0) 
>>> x2 
3 
>>> x1 
array([[ 0., 1., 2.], 
     [ 3., 4., 5.], 
     [ 6., 7., 8.]]) 
>>> x1x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x2 = np.arange(9.0) 
>>> x1 = np.arange(9.0).reshape((3, 3)) 

>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x3 = np.arange(9.0) 
>>> x3 

Traceback (most recent call last): 
    File "<pyshell#60>", line 1, in <module> 
    x3 
NameError: name 'x3' is not defined 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x3 = 4 
>>> x3 

Traceback (most recent call last): 
    File "<pyshell#62>", line 1, in <module> 
    x3 
NameError: name 'x3' is not defined 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x4 = 4 
>>> x4 

Traceback (most recent call last): 
    File "<pyshell#64>", line 1, in <module> 
    x4 
NameError: name 'x4' is not defined 
>>> 
>>> 


>>> 



>>> 

>>> 


>>> 

>>> 

>>> 

>>> 

>>> 

>>> 

>>> 

>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x4 = 4 
>>> x4 

Traceback (most recent call last): 
    File "<pyshell#78>", line 1, in <module> 
    x4 
NameError: name 'x4' is not defined 
>>> x4 = 4 
>>> x4 
4 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x4 = 4 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 5 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 4 
>>> x5 

Traceback (most recent call last): 
    File "<pyshell#84>", line 1, in <module> 
    x5 
NameError: name 'x5' is not defined 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 4 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 4 
>>> x1 = np.arange(9.0).reshape((3, 3)) 
>>> x5 = 4 
>>> x5 

Traceback (most recent call last): 
    File "<pyshell#104>", line 1, in <module> 
    x5 
NameError: name 'x5' is not defined 
>>> 
+0

あなたのコードを実行するIDLEではなく、Pythonであり、エラーメッセージを生成しています。インストールに何か問題があるようです。 IDLEのないインタラクティブなPythonで同じことをするとどうなりますか?インタラクションをコピーして質問に貼り付けてください。不安定なビデオで何かをすることは不可能です。 2.7.12にアップグレードすることを強くお勧めします。 –

+0

@TerryJanReedy問題は、ENTERキーボードショートカットを使用して前のコードをコピーした場合にのみ表示されます。私が 'x5 = 4'と入力すると、動作します。だから私はIDLEが何かを台無しにしていると思う。私は質問にIDLEログ全体を出しました。 –

+0

あなたの 'x5'の名前の1つに、目に見えない制御文字がありますか?時間のうちの1つの名前をコピーして貼り付けていて、他のものを貼り付けていない場合、これが問題を説明することができます。 – Blckknght

答えて

5

は、一度に複数の行をコピーしています。これがPython 2.7のIDLEバージョンで起こると、最初の文の後のすべての文が無視されます。したがって、あなたのx5行は決して実行されず、名前は何にも束縛されません。

x5行の先頭にあるアニメーション内の>>>文字の色が、他の行と異なることがわかります。コピーされると、他の入力テキストと同様に黒色になります。彼らが実際のプロンプトであるとき、彼らは赤色です(少なくともデフォルトの配色で)。

この問題を回避するには、1行のコードを強調表示し、入力されたエントリ全体ではなく、Enterキーを押してコピーします。

Python 3では、IDLEコンソールで複数の文を同時に提供するのはエラーです(SyntaxError: multiple statements found while compiling a single statementと表示されます)。

+0

ありがとう、それは理にかなっています(なぜ私はIDLEが最初の行だけを実行するかを理解していませんが)。ちなみに、1行をクリックしてEnterキーを押すと、一度に複数の行がコピーされます。 –

+1

私が言うことができる限り、以前のバージョンの行も一度にすべて貼り付けられている場合(おそらく他の場所からのCTRL + Vを使用して)、ENTER-to-copyメソッドでのみ行います。 – Blckknght

+0

ありがとうございます、すべてが明確です、私は今質問に表示されていた動作を完全に再現できます。 –

関連する問題