Python is painful. But use

I've been writing Python for a little over a year because of various reasons. (Not WEB system)

Let's list some of the advantages and pains of Python that I have come to see (Sabori). It's a memo for myself, so it's a good idea ... Please point out.

To Google Sensei, please stop posting this article at the top of the search results as it only pollutes the search. I will do anything (I'm not saying anything).

TL;DR

Python has a lot of painful specifications (for me).

However, even if we accept the disadvantages, there are advantages that we would like to use, so I think we have no choice but to continue using Python ....

Python is hard

The block specifications are painful

As you know, Python indentation makes sense. The block is composed of indentation.

In other words, this

if True:
   print("hoge")
else:
   print("piyo")
print("fuga")
# =>hoge and fuga are displayed

And this

if True:
   print("hoge")
else:
   print("piyo")
   print("fuga")
# =>hoge is displayed

The displayed contents are different.

……I know. I know that it is taken for granted. But think about it. this

if xxx:
   lorem
   if yyy:
      ipsum
      dolar
else:
   sit

And this

if xxx:
   lorem
   if yyy:
      ipsum
      dolar
   else:
      sit

The only difference is indentation, and if you use an automatic indentation function such as Emacs, the structure changes depending on the editor. Does anyone think this is rather painful?

what? Are you all writing the correct code in one shot? I can't do that. I write a function in a certain amount, but this is a class, right? You can indent the whole thing After that, various internal indents are corrected. Of course, if you just want to relocate, you only need to add the required number of spaces at the beginning of the line, so it is possible. However, if it is C etc., one unnecessary process is sandwiched and thinking stops. I think it's a ridiculous disadvantage.

Apart from that, I'm not always trying to force you to enclose it in curly braces, but it could be done as an option.

Import specifications are painful

In Python, imports are often arranged at the beginning of a line, but the search path at this time is difficult.

Since there is no default structure for the project (well, it's a scripting language, this can't be helped), it may be difficult to decide. However, it is NG that the search path changes depending on how it is called.

After all, for peace of mind, it is necessary to edit sys.path and add under the current directory.

This is my responsibility, but every time I forget about this task and search for how to imoprt.

The existence of map and filter is painful

Python has maps and filters derived from functional languages. It is adaptable to classes that implement iterable and works as the name implies.

lst: list = [1, 2, 3, 4, 5, 6]
lst2 = list(map(lambda x: x*2, lst))
lst3 = list(filter(lambda x: x % 2 == 0, lst))
print(lst2) # => [2, 4, 6, 8, 10, 12]
print(lst3) # => [2, 4, 6]

Did you notice? I purposely convert the output such as map to list. Well, this isn't painful, but it feels subtle. After all, the only condition is that lambda x: iterable-> iterable, so it is the output type of the map that is iterable, so it is unavoidable that conversion is necessary.

However, in reality, it has a convenient function called comprehension. Same thing as above

lst: list = [1, 2, 3, 4, 5, 6]
lst2 = [x * 2 for x in lst]
lst3 = [x for x in lst if x % 2 == 0]
print(lst2) # => [2, 4, 6, 8, 10, 12]
print(lst3) # => [2, 4, 6]

Can be written.

disk is spicy

It seems that Python is not used by cutting the virtual environment for each project. Therefore, I use Pyenv to switch versions, and pipenv to switch libraries for each environment.

The problem is that if you do this, the disk will be eaten more and more, such as having a library for each virtual environment.

I use M.2 SSD with priority on speed, and even if it is cheap, it is sober in an environment of about 250GB.

Regarding this, it is not a problem for those who are always withdrawn in the environment such as Anaconda and Miniconda and Jupyter.

Python is good

Extensive library

Find out what you want to do-> There are many patterns where you can find a library. To be honest, I think most things have a library.

Since I live in a natural language system, I sometimes use MeCab, Human ++, etc., but since there are wrappers for them, It can be used as a Python object without thinking about anything. Convenient.

If it's a morphological analyzer, you can still implement it yourself, but it's very helpful because you don't want to use a wrapper for a parser such as KNP.

Also, is there a demand for full-width and half-width conversion? It also corresponds to that, so I can solve it by calling various libraries made by my predecessors.

The machine learning library is particularly rich, so if you want to do it, Python is a good idea.

Numpy,Pandas

A library that can be a reason to use Python by itself. Matrix operation is too strong ... It's too easy to graph ...

Environment can be isolated

Since it can be executed in a virtual environment, you do not have to worry about the version of Glibc when you run the created program. good. good.

I'm using Arch Linux personally now, so it's even better.

Still we use Python

I've complained a lot above, but in the end the benefits are so big that we can't leave Python. I think if Numpy is also in other languages ... but I don't feel like Ruby or Perl, so Python is also a good candidate for a convenient scripting language.

I wonder if there is no choice but to use it while solving the problems solved by design ...

reference

-Advantages and disadvantages of Python that I felt after using it

Recommended Posts

Python is painful. But use
Use fabric as is in python (fabric3)
Python is easy
What is python
Python is instance
How to use is and == in Python
What is Python
python int is infinite
Use thingsspeak from python
Use config.ini in Python
[Python] Use JSON with Python
Use fluentd from python
Use dates in Python
[Python] What is Pipeline ...
Use Valgrind in Python
Use MySQL from Python
Use mecab with Python3
Use LiquidTap Python Client ③
Use DynamoDB with Python
Use Python 3.8 with Anaconda
[Python] format methodical use
Use python with docker
Use MySQL from Python
Use LiquidTap Python Client ②
Use BigQuery from python.
Use profiler in Python
[Python] What is virtualenv
Use mecab-ipadic-neologd from python
Use LiquidTap Python Client ①
Re: Python lambda is useless ^ H ^ H ^ H ^ H ^ H Difficult to use
Let's use def in python
Let's use python janome easily
Python round is not strictly round
[Python] Debugging is more efficient!
Use Trello API with python
Use matplotlib on Ubuntu 12 & Python
Use let expression in Python
Use Measurement Protocol in Python
python3: How to use bottle (2)
How Python __dict__ is used
Use callback function in Python
Use Twitter API with Python
Use parameter store in Python
[Python] Use a string sequence
[Python] How to use list 1
Use HTTP cache in Python
Use TUN / TAP with Python
Use MySQL from Anaconda (python)
Python is an adult language
Use MongoDB ODM in Python
Use list-keyed dict in Python
How to use Python argparse
Use Random Forest in Python
Use regular expressions in Python
Python list is not a list
Use Spyder in Python IDE
Python: How to use pydub
[Python] How to use checkio
[Python] Python and security-① What is Python?
Python release cycle is faster!
[Python] Is the zero but non-empty object Truthy or Fallsy?