-1

I am trying to create a python def to unzip a few .gz files within a folder. I know that the main script works if it is not in the def. The script I have created is similar to others I have done but this one give me the error

File "unzip.py", line 24, in decompressed_files(input_folder) NameError: name 'input_folder' is not defined

I copied the script below so someone can help me to see where the error is. I haven't done any BioInformatics for the last couple of years and I am a bit rusty.

import glob
import sys
import os
import argparse
import subprocess
import gzip

def decompressed_files(input_folder):
    print ('starting decompressed_files')

    output_folder=input_folder + '/fasta_files'
    if os.path.exists(output_folder):
        print ('folder already exists')
    else:
        os.makedirs(output_folder)

    for f in input_folder:
        fastqs=glob.glob(input_folder + '/*.fastq.gz')
        cmd =[gunzip, -k, fastqs, output_folder]
        my_file=subprocess.Popen(cmd)
        my_file.wait

print ('The programme has finished doing its job')
decompressed_files(input_folder)

This is done for python 2.7, I know that is old but it is the one that it is installed in my work server.

GabbeHags
  • 101
  • 1
  • 2
  • 8
Ana
  • 131
  • 1
  • 14
  • 1
    When you call `decompressed_files(input_folder)`, there is no variable `input_folder` defined. Where do you expect that to get a value? – larsks Jan 26 '20 at 22:28
  • https://stackoverflow.com/q/14804084/11301900 – AMC Jan 26 '20 at 22:57

1 Answers1

1

That's why when you call decompressed_files(input_folder) in the last line, you didn't define input_folder before. you should do it like this :

input_folder = 'C:/Some Address/'
decompressed_files(input_folder)
Mohsen_Fatemi
  • 2,183
  • 2
  • 16
  • 25