'How to compress a file to tar in python [duplicate]

May I know what I need to modify or add to my import script for me to compress a csv file to .tar?

My script

export_csv(
     my_csv=my_csv,
    sheet_id=gsheet_name(worksheet_name)
)

shutil.move(my_csv, '/home/admin/processedCSV')

# If its possible my plan is after moving the CSV file to another folder that time the tar extraction will execute. 
print ('DONE')

Let me know if you need more details. TYIA



Solution 1:[1]

Take a look at the tarfile module in the standard library: https://docs.python.org/3/library/tarfile.html.

Solution 2:[2]

Use str.replace:

df["Message"] = df["Message"].str.replace('^.*?\]\s*', '')

Here is a regex demo showing the logic is working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ndc85430
Solution 2 Tim Biegeleisen