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.
(1) I create a module in gedit and import to run. I want to know if there is a command I can use to re-run the same module without having to quit() and restart Python and re-import it again to run it a second time.
(2) Just mean how to exit a Python module based on a condition.. ie prematurely..
1. reimport is quite simple, just type import module again. But it won't rerun anything else just the initialisation of that module
2. I do not think you can exit a module - by the way what does it mean at all?
When you import a module it will be available. And when you execute del module, it won't be available any more, but it won't work in case of from module import something.
You don't need p if it's just to store the length of the list. And the Pythonic way to do this would be with a list comprehension. Note the use of enumerate to iterate over the list and get both the index and the value at that index.
Code:
>>> values = [150, 320, 120, 550, 630]
>>> values = [[value, index] for index, value in enumerate(values)]
>>> values
[[150, 0], [320, 1], [120, 2], [550, 3], [630, 4]]
I'm also having trouble understanding what you mean by "re-import". Python 2 had a "reload" keyword, which I think may be what you're thinking of. It's changed in Python 3. Here's a link about that:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.