ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a need to convert PNG files to EPS format. I did some searching and found som python commands I can execute from the python interpreter and they seem to work just fine.
Distribution: KDE Neon User edition; Manjaro; OpenSUSE Leap
Posts: 298
Rep:
I've been using python for a while and seen "if __name__ == '__main__'" but what is the point of it? You could just call the function main without that line.
The advantage isn't so great in this example but the idea is that it allows making an executable script which is also usable as a module. In this case another program could "import png2eps" (where __name__ != '__main__') and it won't attempt to execute main() at load. The script could then set up sys.argv and call png2eps.main(). This is fairly pointless here but it is not uncommon to have an executable script structured so that it can be imported. The usage is varied (think code + test case) or a program+lib in one file where the other functions are useful in a modular context. In any case it's never the decision of the programmer how the code will be used and it's generally polite to make sure that the right thing happens if the module is imported regardless of whether it makes sense or not.
Distribution: KDE Neon User edition; Manjaro; OpenSUSE Leap
Posts: 298
Rep:
That's because you haven't made it as a function. It needs to start "def func_name():" otherwise return doesn't work. If you don't want it as a function you could use sys.exit() to close the script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.