Python Forum
empty lines in source code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: empty lines in source code (/thread-33840.html)



empty lines in source code - Skaperen - Jun-01-2021

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.


RE: empty lines in source code - Gribouillis - Jun-01-2021

As far as I know it is perfectly safe.


RE: empty lines in source code - DeaD_EyE - Jun-01-2021

(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.


RE: empty lines in source code - Skaperen - Jun-01-2021

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).


RE: empty lines in source code - Gribouillis - Jun-02-2021

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.


RE: empty lines in source code - Skaperen - Jun-02-2021

why would i use # coding: latin-1?


RE: empty lines in source code - Gribouillis - Jun-02-2021

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.