Python programming-a collection of problems encountered when using pycharm2018

1. Function methods are marked yellow like crazy, but it does not affect the running of the code, and it is difficult to extricate yourself from obsessive-compulsive disorder.

The reason why the function is marked yellow: The python interpreter version is incompatible with the IDE version. The above function is a simple pushbutton event binding. The IDE used is pycharm2018, the interpreter is Anaconda3, which corresponds to the python3.7 version. The connect function written like this can be used. .

Solution to the yellow mark: 1. Simply and crudely select the small light bulb on the left and choose to ignore it automatically. 2. The IDE is adapted to the interpreter version. You need to ask the experts for help.

 

2. File path str="" path writing problem

After testing, the relative paths of three different locations are written as follows:

1. In the same directory, it can be written directly as: filename = "1.jpg"

2. In the lower-level directory, write: filename = "123/1.jpg"

3. In the same level (upper level) directory, write: filename = "../image/1.jpg"

Basically covers all relative path writing methods. Absolute paths can be written without writing them, unless the local file that needs to be called is too large and should not be moved.

ps:

./ represents the path of the current project

../ represents the parent directory path of the current directory

\\name\\file or /name/file represents the absolute physical path

 

3. Guide package---import problem

Why should we write from xxx import xxx as much as possible when importing packages? ? ?

from tkinter import messagebox


import tkinter as tk

In the process of writing code and compiling and running, the difference between from import and direct import * is almost invisible.

But in the final process of encapsulating it into EXE, import * is fatal. The original 10MB gadget may be expanded to several hundred MB due to a certain package.

Therefore, write down the specific categories you use, guide the package roughly, and consider the consequences yourself.

 

4.Return value problem

This is a small detail issue with little impact.

Normally there is a return value, just return xxx and that's it.

When a function is only responsible for the execution process and does not need to return a value, you can bring a return NONE (there is no NULL in python) to mark the end of the function.

Standard code~

    def plotImage(self, pngdata):
        self.axes.imshow(pngdata, cmap='gray')
        self.draw()
        return None

 

5. Involves debugging BUG methods with interactive interfaces

Due to project needs, pyqt is used to design the user interaction interface of the software.

If you want to test a certain functional issue in the interface:

In normal DEBUG mode, when the interface is displayed normally, it would be great if the button can be clicked to jump to a certain question statement in the function. If any other situation makes DEBUG uncomfortable to use, try adding a few more prints between different paragraphs. ("666"), simple and efficient.

 

6.Python Console is a good thing

In the lower left corner of the interface, it is simple and practical, helping to test anything while writing code.

e.g

1.help(print)

2. Check the data storage format

3. Just output anything

4. Test all functions, but remember to import first.

 

7. Most commonly used shortcut keys

People with obsessive-compulsive disorder must learn to use "ctrl+alt+L" to organize code and automatically wrap lines.

"ctrl+shift+-", "ctrl+shift+=", fold the code and retract it freely.

Everything else is routine. Then there is the ignorance.

 

8.To be continued...

Guess you like

Origin blog.csdn.net/qq_32301683/article/details/100915371