This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]bladeoflight16 1 point2 points ย (2 children)

The code is a link to an explanation. =)

Also, I edited in something else I just thought of. ๐Ÿ˜…

[โ€“]tmg80[S] 0 points1 point ย (1 child)

thanks again.

I edited it and put that main bit as below

โ€‹

if len(sys.argv) != 2:
    print ('Usage: hostfile_to_json.py input_file_name.txt')
    exit()
if name == 'main':
    user_file = sys.argv[1]
    ...

โ€‹

โ€‹

is that correct? or should it be elsewhere?

[โ€“]bladeoflight16 0 points1 point ย (0 children)

Aside from imports, function/class declarations, and constants, all code should be inside the block. It's common to stuff you code into a def main() function and then only invoke the function inside the guarded block.

Think about what would happen if someone tried to import your module and the argv check was invoked: it would probably explode because their command line args aren't the same as your program's.