Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the interpreter automatically save the code without BUG before executing any Python code

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to let the interpreter automatically save the code without BUG before executing any Python code". In the daily operation, it is believed that many people have doubts about how to let the interpreter save the code automatically before executing any Python code without BUG problems. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the question of "how to let the interpreter automatically save the code without BUG before executing any Python code"! Next, please follow the editor to study!

Thank you for your blessing, Everything is ok,No bugs in the code.

You must really want to know how this is achieved?

If you are familiar with Linux, you will know when you are using SSH to remotely log in to the Linux server. The .bash _ profile file is read to load some environment variables.

Bash _ profile you can think of it as a shell script, where you can write some shell code to meet your customized requirements.

In Python, there is also a file like .bash _ profile, which generally does not exist.

We need to create a new user environment directory, which is long and does not require you to memorize it. You can get it using the site module method, and then use the mkdir-p command to create it.

In this directory, create a new usercustomize.py file. Note that the name must be this, but other files will not be recognized.

The content of this usercustomize.py is as follows (Note: Buddha only bless a few main application directions of Python, after all, we are Python engineers.)

I put this file on my github, you can go and get it.

After everything is done, whether you are using python xxx.py to execute the script

If you still use python to enter Python Shell, you will read the safe Sutra first.

Continue to explore, but is there any other way?

Of course there is, but relatively speaking, it will be a little more troublesome.

Let's take a look at the effect first.

First check that there is no usercustomize.py file in the ~ / Library/Python/3.9/lib/python/site-packages directory.

However, after executing python to enter Python Shell mode, the Ping an Sutra will still be printed.

How do you do this? What the hell.

The method is actually very simple, as long as you do two things, you can achieve this effect:

First of all, in any directory you like, create a new Python script with a random name. For example, my name is startup.py, and the content is the same as above.

Second, set an environment variable PYTHONSTARTUP that points to your script path

$export PYTHONSTARTUP=/Users/MING/startup.py

That's all right.

But this approach only applies to Python Shell, not the way Python executes scripts.

If you want to achieve this effect in a script, I've come up with the roughest and clumsiest way to do this-- load and execute manually.

At this point, the study on "how to let the interpreter automatically save the code without BUG before executing any Python code" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report