Append error in python - python

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?

You are using Julia not Python:

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

Your Python code is perfectly valid. Try another interpreter.

Related

Python VS code detect incorrect argument name

How can I make VS code detect incorrect argument names?
def test_function(name1, name2, name3):
print(name1)
print(name3)
print(name2)
test_function(name1=1, name2=2, name4=4)
Currently, VS code doesn't flag this as an error. Detecting this would be very useful since argument names change. Otherwise you get an error at run time which is far too late.
VS code is a text editor that one can use to write code in multiple languages but is not a Python interpreter. What you can do is install an extension to do that. For example: Python from Microsoft, has a linter that shows you what problems your code has, including the kind of problem you're describing. Make sure you read the docs to configure it correctly.

Jupyter Notebook not handling properly .js elements in VS Code

Some data/value representations are working as expected when using Jupyter Notebook "native" support in VSC, but it seems that JavaScripts elements are not properly represented or previewed.
When I try to get Map (gmaps) as a figure, in VS Code, as a result, I get Figure(layout=FigureLayout(height='420px')) whereas when I execute the same code block in Jupyter Notebook/Lab server inside of Chrome browser, I get the wanted output which tells me that my external setup should be Ok. I'm using jupyter-js-widgets and jupyter-gmaps extensions.
I have a feeling that I'm missing some additional configuration(s) in VS Code regarding JavaScripts.
My VS Code About:
My Jupyter Version
Thank you
#MatejZ. Currently most widget based Jupyter extensions won't work in VSCode Notebook Editor and Interactive Window. However we are looking at add more support for this as it's a highly requested feature. If you want you can track our GitHub issue for this support (that we've already started to look into) here:
https://github.com/microsoft/vscode-python/issues/3429
Temporary solution was to add something like this:
# create html
from ipywidgets.embed import embed_minimal_html
embed_minimal_html('export.html', views=[fig], title = 'Gmap output')
which will take object "fig" and make it accessible through "export.html" page.
Thank you #Ian Huff for pointing to the issue :) Webview was mentioned in the issue, which could be coupled with the temp solution. But, I'm satisfied for now.

PyCharm: Storing variables in memory to be able to run code from a "checkpoint"

I've been searching everywhere for an answer to this but to no avail. I want to be able to run my code and have the variables stored in memory so that I can perhaps set a "checkpoint" which I can run from in the future. The reason is that I have a fairly expensive function that takes some time to compute (as well as user input) and it would be nice if I didn't have to wait for it to finish every time I run after I change something downstream.
I'm sure a feature like this exists in PyCharm but I have no idea what it's called and the documentation isn't very clear to me at my level of experience. It would save me a lot of time if someone could point me in the right direction.
Turns out this is (more or less) possible by using the PyCharm console. I guess I should have realized this earlier because it seems so simple now (though I've never used a console in my life so I guess I should learn).
Anyway, the console lets you run blocks of your code presuming the required variables, functions, libraries, etc... have been specified beforehand. You can actually highlight a block of your code in the PyCharm editor, right click and select "Run in console" to execute it.
This feature is not implement in Pycharm (see pycharm forum) but seems implemented in Spyder.

Python: Executing selected statements

I am new to python programming... Just wanted to know does IDLE has a concept of 'executing selected statements'??
F5 runs the whole program... Is there any way to do this?
No, not now. Since you are at least the second person to ask this, I added the idea to my personal list of possible enhancements. However, while running a selection would not be a problem, producing accurate tracebacks for exception would be. Doing so is an essential part of Python's operation.
Currently, one can disable code that you need to not run by commenting it out (Alt-F3) or by making it a string. One can stop execution after a particular statement by adding 1/0. Or you can copy code to a new editor window.
Do you have a specific use case in mind, or are you just wondering?
Install Spyder, with its dependecies, and you will have wonderful FREE IDE !
You will have another solution, is to use IPython Notebook, where you will be able to use your Internet Browser to run python codes!:

Is there a way to Pre-Analyze a Python program for naming conflicts?

One of the most frustrating things about programming in Python thus far has been the lack of some kind of "pre-analysis". In Java, for example, a pre-analysis is performed before the actual compilation of a program, in which things like name usage is checked. In other words, if I have called a variable list_one in one area, and say I mispell it as list_on in another area, Java will say "Hey you cant do that, I dont know what list_on is."
Python does not seem to do this, and it is terribly frustrating! I have a program that takes about 15 minutes to run, and the last thing I was to see at 14.5 minutes into it is something like
NameError: name 'list_on' is not defined
Are their any tools available out there can can perform this kind of check before the interpreter actually runs the program? If not, what are some ways to work around this issue?
Have you considered checking your code with something like pyflakes or pylint?
UPDATE
I found a fantastic solution to this problem for those that happen to be emacs users. You can install PyFlakes-Flymake. This is a great tool! It will perform a static analysis of your code on the fly, and highlight trouble areas in red. I suggest using PIP instead of the suggested easy_install. Other than that, it is pretty simple to get it up and running. And well worth the effort!

Categories

Resources