Append error in python

1.3k views Asked by At

I am using JuliaBox to run python code in python 2.

My code is as follows:

l=[]

l.append(5)

And the following is the error I got:

type Array has no field append

But I have used append as given in the python documentation. https://docs.python.org/2.6/tutorial/datastructures.html

Where did I go wrong?

enter image description here

3

There are 3 answers

4
thodic On

You are using Julia not Python:

enter image description here

0
dlask On

Your Python code is perfectly valid. Try another interpreter.

0
J Richard Snape On

I don't think you are obviously doing anything wrong. I can reproduce your problem by clicking New on the JuliaBox.org landing page and selecting Python 2 in the Notebooks subsection of the menu. This creates a new notebook which you would expect to be running against the python kernel and gives you some visual indications that it is running python.

However

In fact, it is not running Python, it is running Julia. You can test this by, for instance simply typing sin(0.3). This would fail in Python, but gives you a result in Julia. Similarly println("Hello world!")

I'm not familiar with IJulia or Juliabox, so can't state categorically whether this is a bug, but it certainly feels like one and is unexpected and counter intuitive behaviour at best.

My final comment is to try a different interpreter - if you want something with a similar look and feel, you could always use iPython directly. As a bonus, you'll be able to use Python 3 instead of being stuck with 2.6!

EDIT

As highlighted by Matt B. in comments, this is a known bug in IJulia