I've bought quite a few e-courses - not in vain I've learned a lot - but none of them has come even close to explain main like you; rather confused me! As another one wrote, this is pure gold. Now I not only understand the main function I even see how, and why, it will be quite an implement - a great tool - in my current ongoing projects. Thank you so much!
Masterfully explained. I loved that you reviewed the learning objectives at the end, but with a more in-depth explanation. Fantastic, easy to understand. Thanks.
That was an excellent explanation! I've always wondered whether to put my main code in the conditional or actually use a separate "main" function. Thanks for explaining it!
dude, these are practices that aren't really spoken about, new programmers are just expected just to do them without any real explanation. Awesome content man
There seem to be some variants of this, what is the difference between the following? if __name__ == '__main__': sys.exit(main()); if __name__ == '__main__': exit(main()); if __name__ == '__main__': main()
Very nice! :-) For beginners, this should be a video to watch as mandatory. Can you extend this and have a best practices, if you want to have a bigger project of, for example, 2-3 files? One with functions, one main. And how to integrate "logging" into them or loading "config" from a xxx.conf file, for example with ConfigParser or ConfigObj?
Agreed. It seems to me funny, though, to call this four best practices. It is only one, and suggestions 2, 3 and 4 are simply how to actually do #1, aren't they?
great leasson... pretty balance between deep and short material :) I suggest videos on good practices in different software architectures, as well as an analysis of pros and cons on which to choose given a real case ...
Have you done this a different way ? def number_of_countries(): def main(): print(number_of_countries) if__name__== “__main__ main() This is how the teacher wants our lab setup for tuples
If you have no specific plan to use a part of the functionality by importing the file as a module, is this practice really useful? The length of the script inflated a lot. If you know that you're going to use the functionality, why don't you separate the reusable part into a module and write a small script main.py which imports the module and calls the functions?
I have used without if __name==__main() from time import sleep print("This is my file to demostrate") def process_data(data): print("Beginn of data process") modified_data=data + "that has been modified" sleep(3) print("data processing finished") return modified_data data="My data read from web" process_data(data) modified_data=process_data(data) print(modified_data) What is the difference, if I do not use __name==__main() and did as above? COuld you please explain
"data="My data read from web" process_data(data) modified_data=process_data(data) print(modified_data)" this code is outside of a function so it is ran automatically.
I have the following questions (FYI: I run pycharm with Python 3 on Windows 10): the 'python3' command did not work in the pycharm terminal. Instead I had to use 'py' when I use the 'import' statement, I get the following error: 'import' is not recognized as an internal or external command, operable program or batch file. when I add and run: if __name__ == "__main__": main() I get: Traceback (most recent call last): File "C:\Users\*\PycharmProjects\Exercises\best_practices.py", line 20, in main() NameError: name 'main' is not defined Could someone explain to me why all these functions do not work as in the video? Thanks in advance
What is __name__ and '__main__'? They are not specified anywhere in the script so why are they evaluated as True or False? Can someone explain this please as I am very confused by this concept
When you import from the module (i.e. from time import sleep) you can just use sleep(number_of_seconds) in your code. If you import the whole module (i.e. import time), you have to use time.sleep(number_of_seconds). That's the only difference. 😊
You miss one good practice point... You may have to name your main file "__main__. py" to be able to have a package to be run from named parent directory and that way no confusion about the first main file to run.
We are creating a variable called data, assign a string to it and then print it. We then create a variable called data, assign a string to it and then print it. Repetition helps with learning I guess lol
Best explanation I've ever seen on TH-cam about Python.
It's impossible to explain it more clear than that.
Congrats!
I've bought quite a few e-courses - not in vain I've learned a lot - but none of them has come even close to explain main like you; rather confused me! As another one wrote, this is pure gold. Now I not only understand the main function I even see how, and why, it will be quite an implement - a great tool - in my current ongoing projects. Thank you so much!
Masterfully explained. I loved that you reviewed the learning objectives at the end, but with a more in-depth explanation. Fantastic, easy to understand. Thanks.
That was an excellent explanation! I've always wondered whether to put my main code in the conditional or actually use a separate "main" function. Thanks for explaining it!
Best explanation for this I've seen for a long time
dude, these are practices that aren't really spoken about, new programmers are just expected just to do them without any real explanation. Awesome content man
Very well constructed and delivered! Bravo!
Wow, this was explained very well.
That was the best explanation for __name__ I have ever heard.
There seem to be some variants of this, what is the difference between the following? if __name__ == '__main__': sys.exit(main()); if __name__ == '__main__': exit(main()); if __name__ == '__main__': main()
Very nice! :-) For beginners, this should be a video to watch as mandatory. Can you extend this and have a best practices, if you want to have a bigger project of, for example, 2-3 files? One with functions, one main. And how to integrate "logging" into them or loading "config" from a xxx.conf file, for example with ConfigParser or ConfigObj?
Agreed.
It seems to me funny, though, to call this four best practices. It is only one, and suggestions 2, 3 and 4 are simply how to actually do #1, aren't they?
Thank you, you helped me a lot. It was simple, straightforward, concise.
Concise, clear, Commendable!!
Your explanation was very useful for me. Thank u very much!!
Under rated channel
wow the quality of this video is really good. but i have to watch this video a couple of times to fully understand everything.
Great video for python newcomers.
Divide and conquer.
Nice video!
great leasson... pretty balance between deep and short material :) I suggest videos on good practices in different software architectures, as well as an analysis of pros and cons on which to choose given a real case ...
This is exactly what I was looking for. Thank you !
Thank you. Very helpful.
Have you done this a different way ?
def number_of_countries():
def main():
print(number_of_countries)
if__name__== “__main__
main()
This is how the teacher wants our lab setup for tuples
If you have no specific plan to use a part of the functionality by importing the file as a module, is this practice really useful? The length of the script inflated a lot. If you know that you're going to use the functionality, why don't you separate the reusable part into a module and write a small script main.py which imports the module and calls the functions?
This is what I've been doing as well. I use the __name__ block in the modules as a sort of quick unit test
That's what I do too
What is this text editor?
This is neat and tidy. Good work
I have used without if __name==__main()
from time import sleep
print("This is my file to demostrate")
def process_data(data):
print("Beginn of data process")
modified_data=data + "that has been modified"
sleep(3)
print("data processing finished")
return modified_data
data="My data read from web"
process_data(data)
modified_data=process_data(data)
print(modified_data)
What is the difference, if I do not use __name==__main() and did as above?
COuld you please explain
"data="My data read from web"
process_data(data)
modified_data=process_data(data)
print(modified_data)"
this code is outside of a function so it is ran automatically.
This just blew my mind.
Does everything you showed here work the same in python 3?
yes I think they were using python 3 already lol
You did not show the example of the first rule: put into the class
I have the following questions (FYI: I run pycharm with Python 3 on Windows 10):
the 'python3' command did not work in the pycharm terminal. Instead I had to use 'py'
when I use the 'import' statement, I get the following error:
'import' is not recognized as an internal or external command,
operable program or batch file.
when I add and run:
if __name__ == "__main__":
main()
I get:
Traceback (most recent call last):
File "C:\Users\*\PycharmProjects\Exercises\best_practices.py", line 20, in
main()
NameError: name 'main' is not defined
Could someone explain to me why all these functions do not work as in the video?
Thanks in advance
Thank you, very useful!
How will this code look like with a lass statement?
Great you are awesome!
Thanks, bro!
What is __name__ and '__main__'? They are not specified anywhere in the script so why are they evaluated as True or False? Can someone explain this please as I am very confused by this concept
why do you have to import from the module? (from time import sleep) why cant you just simply import the module? (import time)
When you import from the module (i.e. from time import sleep) you can just use sleep(number_of_seconds) in your code.
If you import the whole module (i.e. import time), you have to use time.sleep(number_of_seconds).
That's the only difference. 😊
You miss one good practice point...
You may have to name your main file "__main__. py" to be able to have a package to be run from named parent directory and that way no confusion about the first main file to run.
This was so helpful!
Doesn't work that way for a full POO project
Thank you man.
perfect explanation
Nice Job. Thanks for doing.
Remind me again, what are we creating in lines 13 and 14?
We are creating a variable called data, assign a string to it and then print it. We then create a variable called data, assign a string to it and then print it.
Repetition helps with learning I guess lol
A glitch in the Matrix @ 4:35 & 4:43 ;)
Awesome explanation m8
Thanks
Lines 13 and 14 were discussed twice. AI right?
I wish my teachers had taught me Python this way..
Hi can yu teach me Python from scratch
Nice.
Hi
Can anyone teach me Python from scratch.
I clicked on this video just because I was entertained by the claim that Python even has "main functions".
Spanish subtitles, plis :(
English is must-have in programming :/
Try learning english if you want to learn a programming language you can learn an english language easy as that
making bot code for free fire game eaisly tell me more
Can someone NOT stretch a video these days
öc,åc