Oct-14-2019, 03:28 PM
you still don't get it. let's break the code in post 12
lines 1-2: here you import necessary modules. you want this part to be executed always (i.e. when import module or when execute as standalone script)
lines 4-27: this is the function definition. you want this part to be executed always (i.e. when import module or when execute as standalone script)
line 29: you executed
line 31-32: the if __name__ == '__main__': part, the body (line 32 and others if there were others) will be executed only when you execute the script as standalone. Line 32 will not be executed if you import module.
To sum up - remove line 29
lines 1-2: here you import necessary modules. you want this part to be executed always (i.e. when import module or when execute as standalone script)
lines 4-27: this is the function definition. you want this part to be executed always (i.e. when import module or when execute as standalone script)
line 29: you executed
listCWD()
function. Again, this part to be executed always (i.e. when import module or when execute as standalone script), however is it what you want? Do you want to execute listCWD() AT THE TIME WHEN YOU IMPORT THE MODULE?line 31-32: the if __name__ == '__main__': part, the body (line 32 and others if there were others) will be executed only when you execute the script as standalone. Line 32 will not be executed if you import module.
To sum up - remove line 29
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs