w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
ImportError when calling python script via a shell script
I had a similar problem. It turned out that in my bash script I was running the Python script with a different version of Python than I was on the command line (my env was set up with virtualenv on Python 2.7 but I was calling the script with Python3 from the bash script). There is nothing in your snippets indicating this is the case but it is worth checking to make sure that the Python versions match up.

Categories : Python

Invoke python script from another python script and set execution directory of the executed script
You could use cwd parameter, to run scriptB in its directory: import os from subprocess import check_call check_call([scriptB], cwd=os.path.dirname(scriptB))

Categories : Python

calling python script from another script
you need to give it the full path to the script that you are trying to call, if you want to do this dynamically (and you're in the same directory), you can do: import os full_path = os.path.abspath('kvadrat.py')

Categories : Python

Capture value from shell script and use it in Python without using subprocess
Try commands module for py2.3.4, note that this module has been deprecated since py2.6: Use commands.getoutput: import commands answer = commands.getoutput('./a.sh')

Categories : Python

how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

On Mac, how to create a drag & drop app for a python script where the script name rather than Python shows in the MenuBar (etc.)?
I have an answer to my question, but I am hoping that someone can come up with something less complex. The solution I came up with was a Python script to create an AppleScript (ugh!), compile it into a bundle and then modify the bundle to change the allowed file extension(s), the icon and so on. I did not find a way to get drag-and-drop working when starting a wxpython script, without an AppleScript (or using py2app) and I could not get the AppleScript to work in a bundle I created, I had to use osacompile to create the bundle for me. I like better the approach here or here, where one creates the plist file "by hand" rather than than modify an externally created one as I do here, but the script below does do the job. #!/usr/bin/env python '''This script creates an AppleScript app to

Categories : Python

duplicate HTTP POST from python script with Lua
Make sure your Lua script is sending the same HTTP headers. The important part for PHP is that the form with attached file upload is sent as "multipart/form-data", and the file must be properly embedded in the POST body of the HTTP request as a multipart mime message. I cannot see if your Lua script actually does this, but I think no. Otherwise PHP would be happy.

Categories : PHP

Jenkins runs imported python script before main python script
The child process flushes its output buffers on exit but the prints from the parent are still in the parent's buffer. The solution is to flush the parent buffers before running the child: print("Starting script...") sys.stdout.flush() build.run()

Categories : Python

Python: calling another python script
The way your script is written, there is no way to import it and not have the plots made. To make it so that import stumpff will work, and your script will understand C(z) and S(z), you'll need to make the plotting code such that it will only run if you are running as a script. One way to do this is to put all of it in a main() function, and then use if __name__ == '__main__': main() Alternatively, simply have all of it underneath that condition, like this: #!/usr/bin/env ipython # This program plots the Stumpff functions C(z) and S(z) import numpy as np import pylab from matplotlib.ticker import MaxNLocator def C(z): if z > 0: return (1 - np.cos(z ** 0.5)) / z elif z < 0: return (np.cosh(np.sqrt(-z)) - 1) / -z return 0.5 def S(z): if z

Categories : Python

Calling an IDL script in Python
Try pyIDL. Google for it, I'm not sure where the most recent version lives. It seems to be fairly old, you might have to do some work to convert from numarray to NumPy.

Categories : Python

Calling a python script in Cakephp
Try moving ob_start() above $tmp=passthru("python serverscript1.py $query");. It appears nothing is being output after the output buffer is started. <?php class SearchCategorizationService { function searcher($query) { ob_start(); $tmp=passthru("python serverscript1.py $query"); $out=ob_get_contents(); echo print_r($out,true); } } ?>

Categories : PHP

Calling c++ function, from Python script, on a Mac OSX
How to compile my project so it can be used from python? I've read that I should create a *.so file but how to do so? That depends on your compiler. By example with g++: g++ -shared -o myLib.so myObject.o Should it work like a lib, so python calls some specific functions, chosen in python level? Yes it is, in my opinion. It seems do be the "obvious" way, since it's great for the modularity and the evolution of the C++ code.

Categories : C++

Calling python script from C++ and using its output
Here is a solution to embed the execution of your python module from within your C++ application. It's not better or worst than forking/executing your python script through a system call, it just is a different way to do it. Whether it is best or not depend on your context and usage. Some time ago I have coded a way to load python modules as plugins to a C++ application, here's the interesting part. Basically, you need to #include <Python.h>, then Py_Initialize() to start your python interpreter. Then you do import sys, using : PyRun_SimpleString("import sys");, and you can load your plugin by doing PyRun_SimpleString('sys.path.append("path/to/my/module/")'). To exchange values between C++ and Python, things get harder, you have to to transform all your C++ objects into python o

Categories : C++

Calling to a Sikuli script from Python (Selenium)
For calling Sikuli code from Selenium, my first choice would be TestAutomationEngr's suggestion of using Java, since Selenium and Sikuli both have native Java bindings. Since you want to use Python, you should try running Selenium under Jython. It's important to remember that Sikuli is Jython, which is probably why you're not able to import it. (The other reason would be that you don't have it in Jython's module path.) I have not tried this myself, but there was a bug fixed last year in Selenium which indicates that it should be fine under Jython. Note that if you call your Sikuli code directly from Jython, you need to add from sikuli.Sikuli import * to the top. This is because the Sikuli IDE implicitly adds that to all Sikuli code. Finally, your last resort is to call Sikuli fr

Categories : Python

how to call a python script inside another python script where both in the same directory?
In script1.py place this: def main(): do something if __name__ == "__main__": main() In script2.py: import script1 if condition: script1.main()

Categories : Python

Hudson server running app engine, duplicate shell script executions result in duplicate property errors
It might be the case that the dev_appserver is already running and then you run it again with hudson job. The best way will be to stop the dev_appserver instance first and then pump it up again.

Categories : Python

Python Script not running in crontab calling pysaunter
What you've said makes no sense. You say shell_env = sys.path. sys.path is a list of folders for python to look for modules, not an environment variable mapping! You then use that in subprocess.call. Perhaps you meant to write env=my_env. That's the next problem. First, PATH should be a list of folder separated by ':'. You just tack shell_path onto the last folder. Finally, python uses PYTHONPATH as a list to locate python modules (which seems to be what problem you're having.)

Categories : Python

print result to cell SPSS python script
Not sure exactly how the SPSS interface works but I suspect it's not working because nearly every line in your code is invalid Python syntax. Try converting to the the following: import spss, spssaux spssaux.OpenDataFile('C:UsersšoťaDesktopdatacssd.sav') dlist = ['PARLAMENTCSSD2010'] ilist = ['KRAJCSSD2012'] vlist = ['VYSLEDKY'] ddim = len(dlist) idim = len(ilist) for i in range(ddim): if dlist[x] < ilist[x]: print ('the ilist is higher in cases: + .') spss.Submit("vlist[1]=vlist[1]+1")

Categories : Python

python send commands to interpreter from script and get result
Well, you can invoke python in the same way as you do a shell script and pass python code to it using the -c option. See http://docs.python.org/2/using/cmdline.html However, this is unbelievably insecure and I would not recommend doing it in a web app! If you are set on this, read up on restricted execution in Python http://docs.python.org/2/library/restricted.html

Categories : Python

calling a java program in a python script : Classpath Error
The problem is that you are putting the .. dots in the wrong place. clldsystem.esa.ESAAnalyzer is the Java class that contains the main() method which is to be executed by java. java tries to find clldsystem.esa.ESAAnalyzer by looking through the classes which it loads from the jars specified in the classpath by -cp. So try replacing java -cp "../lib/*:esalib.jar" ../clldsystem.esa.ESAAnalyzer with the following: java -cp "../lib/*:../esalib.jar" clldsystem.esa.ESAAnalyzer

Categories : Java

How to show result of python script in a console when running from ST editor?
SublimeREPL for is a plugin for SublimeText It does not open a cmd instance but can provide you a REPL, where You can provide input, which you usually cannot give on default console. Installation Install Package Control. http://wbond.net/sublime_packages/package_control Install SublimeREPL Preferences | Package Control | Package Control: Install Package Choose SublimeREPL Restart SublimeText2 Configure SublimeREPL (default settings in Preferences | Package Settings | SublimeREPL | Settings - Default should be modified in Preferences | Package Settings |SublimeREPL | Settings - User, this way they will survive package upgrades! Note from the documentation: ctrl+, , f means: press Ctrl and Comma, release all, press F. The keybinding above is used to Evaluate in REPL If Sublim

Categories : Python

sys module giving different output when running Python script through IDLE and by double-clicking the script
print os.path.dirname(sys.executable) is what you should use. When you click it it is probably running through python.exe so you are removing the extra char from the w.

Categories : Python

How do scan a script for return values from a upper script in python?
Don't invoke a Python script from a Python script by using system, which spawns a whole other interpreter. Just import it. Like this: import ToBuildOrNot needsBuild = ToBuildOrNot.run() # or whatever you call your top-level function Since ToBuildOrNot.py is a script now, make sure the "main" function is protected so it doesn't execute automatically on import. Most people do it this way in Python: What does <if __name__=="__main__":> do?

Categories : Python

Cron not running Python script is script not in home folder
cron is running crontab(5) entries from the home directory of the user. You need to change appropriately the directory i.e. to call the chdir(2) syscall (either thru the cd shell builtin, or inside your python script using os.chdir). You should query the current directory (using getcwd(3), or the pwd command, or the os.getcwd in Python) in your script. Also check your PATH if running commands.

Categories : Python

dump files from bash script in different directory from where python script ran it
You should change directory within the same command: cmd = "/path/to/executable/executable" outputdir = "/path/to/output/" subprocess.call("cd {} && {}".format(outputdir, cmd), shell=True)

Categories : Python

Redirect output of a .bat file run by a python script to GUI, and making that script into EXE
You could use the subprocess module to call your script Example calling the 'ls' command on Linux: >>> from subprocess import call >>> call(['ls', '-l']) total 0 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file1 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file2 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file3 0

Categories : Python

How run a Python script from another script and get resulting global dict?
Importing a module executes the code at the top level, and that module's "global" namespace gets imported as the name of the module james@bodacious:~$cat test.py def func(): pass myname = "michael caine" print "hello, %s" % myname james@bodacious:~$python Python 2.7.5 (default, Jul 12 2013, 18:42:21) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import test hello, michael caine >>> dir(test) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'func', 'myname'] >>> if the code you want to be run is at the top level of the file, just importing the module will execute the code and give you access to its "global" namespace all in one convenient package.

Categories : Python

error with global name when running a script from another script - python
This is a pretty interesting problem. First a quick workaround, you can provide dictionaries to use as the local and global namespace when calling execfile(), using an empty dictionary for globals works fine: # test_fun1.py a = 1 def test1(): print a execfile('test_fun2.py', {}) test1() Alternatively, if you want the code to execute within the global scope of your module you can use globals() instead of {}. Now on to why this isn't working... from the documentation on execfile(): If both dictionaries are omitted, the expression is executed in the environment where execfile() is called. Here "both dictionaries" is referring to the optional globals and locals arguments to execfile(). In this case "the environment where execfile() is called" is the local scope of the fun

Categories : Python

How to capture the exit code of a shell script in a perl script?
You can check the exit code of another process with the child error variable $?. For example: system("perl foo.pl"); my $exit_val = $? >> 8; # now contains the exit value of the perl script Read the documentation for more info.

Categories : Perl

How to get a python script to listen for inputs from another script
I would use a socket connection. Essentially you are writing a very simple server that only takes one connection at a time import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 9988)) s.listen(1) while True: conn, addr = s.accept() data = conn.recv(1024) conn.close() my_function_that_handles_data(data) s.accept() is a blocking call. It waits for a connection. Then you do a read on the connection. In this case we are assuming the length of the parameters are only 1024 bytes. Then we do something with the data we received from the socket and wait for another connection. The client could look like this: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("localhost", 9988)) s.sendall('My parameters that I wan

Categories : Python

Conversion of shell script to python script
It looks like you're after a templating engine, but if you wanted a straight forward, no thrills, built into the standard library, here's an example using string.Template: from string import Template with open('a.html') as fin: template = Template(fin.read()) print template.substitute(name='Bob') # <head>Bob</head> I thoroughly recommend you read the docs especially regarding escaping identifier names and using safe_substitute and such...

Categories : Python

When running Python's pdb as a script, how do I autostart the script?
that's probably not the way to do to it. you should modify/extend the existing pdb.py. the code looks like this: while True: try: pdb._runscript(mainpyfile) if pdb._user_requested_quit: break print "The program finished and will be restarted" except: traceback.print_exc() print "Uncaught exception. Entering post mortem debugging" print "Running 'cont' or 'step' will restart the program" t = sys.exc_info()[2] pdb.interaction(None, t) print "Post mortem debugger finished. The "+mainpyfile+" will be restarted" it looks like you could replace `pdb._runscript(mainpyfile)' with something like runpy.run_module(sys.argv[0], run_name="__main__", alter_sys=True) (from PEP 338). not a complete solutio

Categories : Python

How to return a value from a shell script in a python script
use Subprocess.check_output instead of Subprocess.call. Subprocess.call returns return code of that script. Subprocess.check_output returns byte stream of script output. Subprocess.check_output on python 3.3 doc site

Categories : Python

How can I call a python script from a python script
1: why I don't see any prints out from 'b.py' and when I do 'ps -efW' I don't see a process named 'b.py'? Change run_b lines: p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr) You will not see a process named "b.py" but something like "python b.py" which is little different. You should use pid instead of name to find it (in your code "p.pid" has the pid). 2: Why when I kill a process like above, I see 'permission declined'? os.kill is supported under Windows only 2.7+ and acts a little bit different than posix version. However you can use "p.pid". Best way to kill a process in a cross platform way is: if platform.system() == "Windows" : subprocess.Popen("taskkill /F /T /PID %i" % p.pid , shell=True) else : os.killpg( p.

Categories : Python

python doesn't run script with 'python