Python Forum
embedding data in a script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
embedding data in a script
i have gotten AWS instances to run a Python script to do the instance initialization instead of bash. but this often needs to carry along chunks of data being used to create files on the instance. everything is in this one script and another script will be used to put it together and submit it. my first thought on bulk embedded data is triple quoted multiple lines of some kind of encoded data. what do others typically do in a case where a script will be creating some file (maybe binary, maybe text). can i do r""" to store raw binary such as compression output?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
You can use lexical strings concatenation to avoid triple quoted strings. Here is an example with data created by calling binascii.hexlify().decode() on raw binary data. I cut the hexlified string in chunks of 60 characters and write their Python representation on each line, with no comma between them, which concatenates them at lexical level.
data = binascii.unhexlify((
Skaperen likes this post

Possibly Related Threads…
Thread Author Replies Views Last Post
  embedding python Skaperen 0 594 Apr-22-2020, 03:19 AM
Last Post: Skaperen
  embedding Python script in shell scripts Skaperen 5 4,527 Mar-23-2018, 01:07 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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