The following doesn't work, probably because packages is a list of strings. Is there any way to have such a loop in python?      packages=['numpy','scipy']     for p in packages:         import p
848
I'm writing a Python application that takes as a command as an argument, for example:  $ python myapp.py command1   I want the application to be extensible, that is, to be able to add new modules that implement new commands without having to change the main application source. The tree looks something like:  myapp/     __init__.py     commands/         __init__.py         command1.py         command2.py     foo.py     bar.py   So I want the application to find the available command modules at runtime and execute the appropriate one.  Python defines an __import__ function, which takes a string for a module name:     __import__(name, globals=None, locals=None, fromlist=(), level=0)      The function imports the module name, potentially using the given globals and locals to determine how to interpret the name in a package context. The fromlist gives the names of objects or submodules that should be imported from the module given by name.       Source:    So currently I have something like:  command = sys.argv[1] try:     command_module = __import__("myapp.commands.%s" % command, fromlist=["myapp.commands"]) except ImportError:     # Display error message  command_module.run()   This works just fine, I'm just wondering if there is possibly a more idiomatic way to accomplish what we are doing with this code.  Note that I specifically don't want to get in to using eggs or extension points. This is not an open-source project and I don't expect there to be "plugins". The point is to simplify the main application code and remove the need to modify it each time a new command module is added.
109556
In terminal, after I start Python, how will I know what are the modules present in python? Suppose I need to learn the modules NumPy and SciPy.   How will I install it if it is not installed?  How will I know if it is already installed?
112773
I need to be able to take a string like:  '''foo, bar, "one, two", three four'''   into:  ['foo', 'bar', 'one, two', 'three four']   I have an feeling (with hints from #python) that the solution is going to involve the shlex module.
90618
What is the best way to install Python packages in Ubuntu 11? I am a recent convert to Ubuntu and want to learn best practices.  For context, I am looking to install the tweeststream package, but I did not see it in my Synaptic package manager. Also, I am very new to programming, but I usually can follow along with code samples.
44787
If you are creating a 1d array, you can implement it as a List, or else use the 'array' module in the standard library.  I have always used Lists for 1d arrays.  What is the reason or circumstance where I would want to use the array module instead?  Is it for performance and memory optimization, or am I missing something obvious?
14648
Is it possible to find all classes or interfaces in a given package? (Quickly looking at e.g. , it would seem like no.)
117094
I'd like to be able to create a package that doesnt contain any code or programs itself, but instead installs other packages that exist in the repositories onto a computer, sort of how the ubuntu-restricted-extras package does?
2312
I want to downgrade some packages. I search and find  and this  and this .  But i just want to do it with dpkg.  Could i just run dpkg -i package-name? If yes then what will be done with the highest already insatlled version?!
27093
I occasionally see the list slice syntax used in Python code like this:  newList = oldList[:]   Surely this is just the same as:  newList = oldList   Or am I missing something?
23941
I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files.  Can someone explain what this does?
47634
I need to reinstall my Ubuntu 18.04 and I want to backup and restore all installed snap packages including all installation settings.   With snap list I get the list of installed packages. However, the list is not in a suitable format for reinstalling all the packages. I need something like apt-clone that would work for snap packages the same way it works for apt installed packages.
11039
Imagine this directory structure:  app/    __init__.py    sub1/       __init__.py       mod1.py    sub2/       __init__.py       mod2.py   I'm coding mod1, and I need to import something from mod2. How should I do it?    I tried from ..sub2 import mod2 but I'm getting an "Attempted relative import in non-package".  I googled around but found only "sys.path manipulation" hacks. Isn't there a clean way?      Edit: all my __init__.py's are currently empty    Edit2: I'm trying to do this because sub2 contains classes that are shared across sub packages (sub1, subX, etc.).  Edit3: The behaviour I'm looking for is the same as described in  (thanks John B)
90785
What would happen when you load a package more than once, say via \usepackage{&lt;package&gt;} or \RequirePackage{&lt;package&gt;}.  For example:  \documentclass{book}  \usepackage{geometry} \usepackage{geometry}  \begin{document} test \end{document}   Will LaTeX ignore the double loading of geometry, or are there some problems and repercussions?
15363
If you are creating a 1d array in Python is there any benefit to using the NumPy package?
23064
I am writing a program, and I want it to do different things depending on which LaTeX packages have been installed.  My current solution is to automatically generate simple .tex files that \usepackage the packages I care about and then automatically check if pdflatex can compile them or not.  This solution seems slow and fragile.  What is a better solution?  Edit: The program I am writing is in Python.
2368
It seems like there should be a simpler way than:  import string s = "string. With. Punctuation?" # Sample string  out = s.translate(string.maketrans("",""), string.punctuation)   Is there?
13558
I'd like to output a list of all installed packages into a text file so that I can review it and bulk-install on another system.  How would I do this?