The -S option to python is defined by the documentation as "Disable the import of the module site and the site-dependent manipulations of sys.path that it entails." I've found that python startup on my machine is more than twice as fast, sometimes much more, when I use this option. For example, on one (slow) machine:
$ time python -c 'print "hello"'
hello
python -c 'print "hello"' 0.14s user 0.03s system 85% cpu 0.204 total
$ time python -Sc 'print "hello"'
hello
python -Sc 'print "hello"' 0.02s user 0.01s system 73% cpu 0.038 total
That's a 5.3x speedup. And it seems to work fine, at least with the scripts I've tried. What are the disadvantages to using it?
Yes, Python is safe for your computer. If you use a Mac, Python is already installed on your computer, in fact. Installing Python won't expose you to any security issues - it won't allow attackers to do anything extra you couldn't already do from the shell/terminal.
Python is Easy to Access and Use Premium privacy software goes further than looking for existing hacking methods; it also highlights any suspicious behavior that could be the result of a new cybercrime tactic. Use a high-quality antivirus to keep your system safe from all varieties of attack.
But like all programming languages, Python is not immune to security threats. Secure coding best practices must be adopted to avoid risks from attackers. In this post, we'll explore Python security best practices that should employed when building secure application.
Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems.
It's probably not a good idea. Among other things, it means that the site-packages directory won't be added to the path, so you won't be able to import anything but the standard lib modules:
python -Sc "import numpy"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy
You can look at site.py
yourself to see what it's doing. It's just a module in the regular library directory. At least on my system, it looks like it does four main things:
quit
and help
)The first one is probably the most critical, as mentioned above. The second could be important for doing string I/O depending on your system's locale settings (i.e., you may get errors if the default encoding isn't correctly set). The third is probably not that important. The last one could be important if you like to have per-user path customizations (letting users have their own personal library directories, etc.).
The -S
flag does the following:
don't imply 'import site' on initialization
This means the module site is not imported during initialization of Python. A brief description is that this module "will append site-specific paths to the module search path and add a few builtins". Not doing all this work will indeed make the startup faster.
Using the documentation as a guide, the -S
flag results in:
sys.path
. You can compare the difference by starting python
and python -S
and doing the following in both import sys; print sys.path
. Many modules won't be available so you won't be able to import them.sitecustomize
).usercustomize
).The short answer to your question is: yes, it makes Python startup faster but many modules and customization code won't be available or possible.
If you primarily import your own modules and write your own computations / code then the -S
flag is fine. But if you have a Python installation with modules installed in different places then you won't be able to use them with the -S
flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With