Python Forum
empty lines in source code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
empty lines in source code
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
As far as I know it is perfectly safe.
Reply
#3
(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.
Skaperen likes this post
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
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.
Reply
#6
why would i use # coding: latin-1?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  visual studio code python how to get source code of import module definitian umen 2 1,182 Jun-13-2020, 06:20 PM
Last Post: umen
  Looking for editor with drag & drop interface vs entering in individual lines of code yeto 1 737 Jul-17-2019, 05:24 PM
Last Post: Yoriz
  Where can I get information about internal logic of source code Python? AlekseyPython 1 1,154 Dec-17-2018, 05:27 AM
Last Post: siripriya
  How do I properly release my code open-source? Brennan 1 1,449 Jun-30-2018, 12:33 PM
Last Post: snippsat
  Recovering lost source code when the code is running in memory micseydel 13 5,608 Apr-14-2017, 02:35 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020