0

I have a folder, say myFolder, in which there are multiple csv files and I want to bzip2 them. One option is of course to use shell:

bzip2 myFolder/file1.csv

How can I do it (same command) in jupyter notebook?

I tried:

for x in os.listdir("myFolder"):
    sourceFile = 'myFolder/'+x
    !bzip2 sourceFile

which returns

bzip2: Can't open input file sourceFile: No such file or directory.

mujjiga
  • 16,186
  • 2
  • 33
  • 51
Ala Tarighati
  • 3,507
  • 5
  • 17
  • 34

1 Answers1

1
for x in os.listdir("myFolder"):
    sourceFile = 'myFolder/'+x
    !bzip2 {sourceFile}

Passing Python variables into the shell–is possible using the {varname} syntax

mujjiga
  • 16,186
  • 2
  • 33
  • 51