Converting zipfile extracting code from ruby to python

Viewed 43

I am converting a code from ruby to python that extracts the contents of a zipfile.

I am new to python and not sure how to exactly convert the below code.

ruby code:

def extract_from_zipfile(inzipfile)

  txtfile=""
  Zip::File.open(inzipfile) { |zipfile|
    zipfile.each { |file|
      txtfile=file.name
      zipfile.extract(file,file.name) { true }
    }
  }

  return txtfile
end

this is my python code:

def extract_from_zipfile(inzipfile):

 txtfile=""
 with zipfile.ZipFile(inzipfile,"r") as z:
  z.extractall(txtfile)
 return txtfile

it returns the value as none.

1 Answers
Related