Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python can't find 'main' module

When I run the code using the command python filename.py, I am getting the following error,

/Library/anaconda/bin/python: can't find '__main__' module in filename.py

I am not sure what exactly is going wrong here. I need help correcting this. How can I correct this?

SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
            1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}

def approximate_size(size, a_kilobyte_is_1024_bytes=True):
    '''Convert a file size to human-readable form.

    Keyword arguments:
    size -- file size in bytes
    a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024
                                if False, use multiples of 1000

    Returns: string

    '''
    if size < 0:
        raise ValueError('number must be non-negative')

    multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
    for suffix in SUFFIXES[multiple]:
        size /= multiple
        if size < multiple:
            return '{0:.1f} {1}'.format(size, suffix)

    raise ValueError('number too large')

if __name__ == “__main__”:
    print(“Hello World”)
    print(approximate_size(1000000000000, False))
    print(approximate_size(1000000000000))
like image 712
sheetal_158 Avatar asked Mar 08 '17 20:03

sheetal_158


People also ask

What is __ main __ module in Python?

__main__ is the name of the environment where top-level code is run. “Top-level code” is the first user-specified Python module that starts running. It's “top-level” because it imports all other modules that the program needs. Sometimes “top-level code” is called an entry point to the application.

What is if name == Main in Python?

if __name__ == “main”: is used to execute some code only if the file was run directly, and not imported.


1 Answers

It's because of the quote marks you are using. Change the s to "s

like image 162
crookedleaf Avatar answered Nov 14 '22 21:11

crookedleaf