Python Forum

Full Version: empty lines in source code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
is it safe to discard empty lines in Python source code other than a multi-line triple quote? i need to keep source code for EC2 instance userdata as small as possible so i want to have the processing throw out empty lines.
As far as I know it is perfectly safe.
(Jun-01-2021, 12:48 AM)Skaperen Wrote: [ -> ]i need to keep source code for EC2 instance userdata as small as possible so i want to have the processing throw out empty lines.

User-Data is saved in Python-Code?!

Then just compile them and use the compiled pyc. They are much smaller than source code.
normally AWS userdata is done in bash. if the AMI expects something different it can do anything. the default is to check the #! and if the command is recognized, run it. unfortunately, python is not recognized. so i am embedding it,, compressed, in a bash script. doing this pre-compiled will be even better.

it turns out i will have the script in memory. is there a way to pre-compile it memory with some python calls? there will be 3 files:

1. the userdata script with places to insert certain data.
2. the user config file with level 2 settings (level 1 are hard coded default in the submit script and level 3 is the command line).
3. the submit script. it merges settings. sets up userdata, submits the instance (spot request if a price is in the settings).
Back to the original question, if your file starts with two blank lines then a comment such as
# coding: latin-1
python will assume that the file is encoded in utf8, but if you remove the blank lines, it will assume that the file is encoded in latin-1.
why would i use # coding: latin-1?
Well some people encode their files in latin-1 encoding and it is still valid Python source code. The question didn't imply it was only your code and that you never encode in latin-1.