Hi I was asked to write a program which launch an external program test the program. I wrote a python method in one file and imported it into another file and wrote test cases for it.  But I need to launch an external program.  Could someone please help me with what that is and how to do that?
2579
How do you call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
42444
How can I call an external program with a python script and retrieve the output and return code?
22283
Before I add more detail to my question, I have to say something very important: Yes, my script has &quot;Allow executing file as program&quot; turned on. The question itself: For programming reasons (shared libraries), I can't execute my program just from the executable, because I need to access LD_LIBRARY_PATH before executing the program. I created this script to do this (baring in mind this is my first time ever writing a script): #!/bin/bash #Get the current directory and append the SO's location currentDir=$(pwd)'/libs/'  #Change the library path export LD_LIBRARY_PATH=$currentDir  #Run the program ./program  After running this from the terminal I thought that it has worked, there were no errors and the program didn't complain about shared libraries. But unfortunately, if I try to double-click the .sh file from Nautilus, nothing happens. The worst part as well, is that since I'm running it from the GUI, I have no idea what error it is getting. I'm running Ubuntu 14.04 and the executable is a C++ program using the SFML libraries (Yes I could just have the dependencies, but SFML isn't commonly installed on Linux computers, and this is besides the point).
51670
Is there a way to step through a .bat script? The thing is, I have a build script , which calls a lot of other scripts, and I would like to see what is the order in which they are called, so that I may know where exactly I have to go about and add my modifications.
12284
Trying to learn how to run my scripts through Ubuntu's terminal regularly.  That being said I am familiar with bash, wget, and awk being called but how do I call python files to run in the terminal?  I would like to learn this but I am unsure on where to research it.  I have a .pyw file that references several .py files in a folder.
19675
and other coding contests often have a maximum time to run or people boast of how fast their particular solution runs. With Python, sometimes the approaches are somewhat kludgey - i.e., adding timing code to __main__.  What is a good way to profile how long a Python program takes to run?
31639
I have an entire folder dedicated to python scripts.  I'm tired of doing chmod on every new python script that I write.  Is there a way to make every file inside my folder executable if it is a python script?  It would be nice to have a script that checks whenever a new .py script is created and if there is a new .py script make it executable right there on the spot.   I use Vim.
31376
I've discovered a new pattern.  Is this pattern well known or what is the opinion about it?  Basically, I have a hard time scrubbing up and down source files to figure out what module imports are available and so forth, so now, instead of  import foo from bar.baz import quux  def myFunction():     foo.this.that(quux)   I move all my imports into the function where they're actually used., like this:  def myFunction():     import foo     from bar.baz import quux      foo.this.that(quux)   This does a few things.  First, I rarely accidentally pollute my modules with the contents of other modules.  I could set the __all__ variable for the module, but then I'd have to update it as the module evolves, and that doesn't help the namespace pollution for code that actually lives in the module.  Second, I rarely end up with a litany of imports at the top of my modules, half or more of which I no longer need because I've refactored it.  Finally, I find this pattern MUCH easier to read, since every referenced name is right there in the function body.
109255
I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon.  Some questions to get us going in the right direction:   Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's finished?   Have you already started or plan on starting soon?  Or do you plan on waiting until the final version comes out to get into full swing?
110498
That's it. If you want to document a function or a class, you put a string just after the definition. For instance:  def foo():     """This function does nothing."""     pass   But what about a module? How can I document what a file.py does?
27458
I've got a utility that outputs a list of files required by a game.  How can I run that utility within a C program and grab its output so I can act on it within the same program? UPDATE: Good call on the lack of information.  The utility spits out a series of strings, and this is supposed to be portable across Mac/Windows/Linux.  Please note, I'm looking for a programmatic way to execute the utility and retain its output (which goes to stdout).
89893
The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?  The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set foo before importing other modules and then they would see the same value for it.
13296
I don't want to use /Application.../blender -P my_script.py but I want to tell a running Blender process to execute a script.   Is there an existing method to tell a running Blender process to execute a python script?  For example using http://localhost:123/run_script=myscript.py
22784
What is the best way to unit test a method that calls into multiple methods, for example:  modify(string value) {     if(value.Length &gt; 5)  replaceit(value);      else changeit(value); }   This pseudo code has a modify method that (currently) calls either replaceit() or changeit(). I have already wrote tests for replaceit and changeit, so writing a new test for modify will be 99% the same set of code.  I need to test it thought because it may change in the future.    So do I copy paste the existing test code?  Move the test code to a common function?  Any other ideas?  I'm not sure of the best practice here.
38789
What version of Python does Blender use and are other languages available? Also, does Python work the same in Blender as when you write console applications or when working with Pygame or are there any differences? If so, what are the main differences?
73556
How do I launch an app and capture the output via stdout and maybe stderr?  I am writing an automated build system and I need to capture the output to analyze. I'd like to update the svn repo and grab the revision number so I can move the files in autobuild/revNumber/ if successful. I also would like to build using make and upload the compile text to my server for everyone to see the warnings and errors on a failed build.  I can't find the system() function, but I found the CreateProcess() function on MSDN. I am able to launch what I need but I have no idea how to capture the stderr and stdout.  I notice the process launches separately unless I set a breakpoint and keep my app exiting which it then will keep all the text in my app console window. I would also want to wait until all processes are finished and then scan the data it produced to do any additional operations I need. How do I do any of this?
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.