What's in that variable (when running a Python script)

A quick way to understand Python scripts is to run a sample program.

Even if you don't immediately know what the function arguments and return values mean, Python's integrated environment Spyder allows you to quickly see variables, data types, and their values.

if __name__ == '__main__': The variables that appear in the block of are still on the Python interpreter even after this block has been executed.

Therefore, if you print the variable on the interpreter, you can refer to the value.

On the contrary, in the Spyder integrated environment, when you display Variable Explorer, the type, size, and value of all variables in the interpreter's memory are displayed. It is also displayed in a data structure such as a list consisting of arrays.

import pylab After pylab.imshow(img) Alternatively, do the following: import matplotlib.pyplot as plt plt.imshow(img)

(For example, when you get a parallax image from a stereo image, some algorithms have parallax values that are integers, others have floating point numbers. Some algorithms work well with just the right initial values, but others. The value doesn't work. You can see that by trying it.)

And by typing into Spyder's IPython console You can also display the post-operation variable as an image if it is an image, without modifying the original script.

In python Output = function (input argument) So, along with the fact that the data dependencies are easy to understand Good for understanding algorithms. Since it is a script language, there is no discrepancy between the executed script and the execution result. Good for understanding algorithms.

Rather than trying to run an OpenCV C ++ sample program First of all, it is recommended to run the sample of OpenCV in Python. And when you understand the input and output of the module's functions, I would like to read the C ++ source code of the module.

Summary -Variable type, size, and value can be confirmed in Variable Explorer of Spyder integrated environment. -When variables remain on the interpreter after executing the script On the IPython console  import matplotlib.pyplot as plt  plt.imshow(img) You can check the value as.

Recommended Posts

What's in that variable (when running a Python script)
When writing a program in Python
Let's create a script that registers with Ideone.com in Python.
A set of script files that do wordcloud in Python3
A Python script that lists execution history in an environment running many AWS Glue Jobs
Precautions when pickling a function in python
Run the Python interpreter in a script
Determine if standard output is piped when running a Python script
What's new in datetime that is a bit more useful in Python 3
I made a Discord bot in Python that translates when it reacts
A memo that I wrote a quicksort in Python
How to embed a variable in a python string
A program that removes duplicate statements in Python
"Python Kit" that calls a Python script from Swift
Call a Python script from Embedded Python in C ++ / C ++
Launch a shell while a Python script is running
Trap trapped when running a Python Windows executable
What's new in Python 3.5
What's new in Python 3.6
[Grasshopper] When creating a data tree on Python script
I want to embed a variable in a Python string
A memorandum to run a python script in a bat file
In Python, create a decorator that dynamically accepts arguments Create a decorator
Use communicate () when receiving output in a Python subprocess
MALSS, a tool that supports machine learning in Python
A template that I often use when making Discord BOT in Python (memorial note)
Take a screenshot in Python
Create a dictionary in Python
What's new in Python 3.10 (Summary)
Specify options when running python
Make a bookmarklet in Python
Attention when os.mkdir in Python
What's new in Python 3.4.0 (2) --enum
Draw a heart in Python
What's new in Python 3.9 (Summary)
Wrapper running Hadoop in Python
Try running python in a Django environment created with pipenv
A Python program in "A book that gently teaches difficult programming"
A general-purpose program that formats Linux command strings in python
A function that divides iterable into N pieces in Python
Published a library that hides character data in Python images
A Python script that saves a clipboard (GTK) image to a file.
Loop through a generator that returns a date iterator in Python
Creating a Python script that supports the e-Stat API (ver.2)
A story that stumbled when using pip in a proxy environment
A memo when creating a directed graph using Graphviz in Python
[GCP] A memorandum when running a Python program on Cloud Functions
Create code that outputs "A and pretending B" in python
[MQTT / Python] Implemented a class that does MQTT Pub / Sub in Python
Scripts that can be used when using bottle in Python
Precautions that must be understood when building a PYTHON environment
Try running a function written in Python using Fn Project
A story about trying to implement a private variable in Python.
A script that displays the running CloudFormation stack like a mannequin
A python script that converts Oracle Database data to csv
A Python script that compares the contents of two directories
I wrote a script that splits the image in two
Summary of points to keep in mind when writing a program that runs on Python 2.5
A story that went missing when I specified a path starting with a tilde (~) in python open
A Python script that stores 15 years of MLB game data in MySQL in 10 minutes (Baseball Hack!)
Run a multi-line script in a PDB