0

I would like to run my python script from Powershell ISE. How do I do that when I also want to pass parameters to the python script. Basicly I want the user to use the script and make little changes, without the neeed to change the actual python script.

This is how the 4 variables are currently written in python:

campaign = "ABC"
dir_xml = r'd:\path\xml'
dir_pictures = r'd:\path\pictures'
dir_output = r'd:\path\output'

I want those 4 variables written in powershell script. What needs to be changed in my python script and how do I pass the variables in powershell?

Also I would like to freeze my packages I have used in the script and copy those in a directory from a different computer. How can I make it possible that the user do not have to install any packages?

2
  • Does this answer your question: Passing command line arguments from powershell script to a python script. For the other question "freeze my packages"? (See how to ask). Are you aiming for a docker container? Commented Jan 30, 2023 at 16:40
  • No that doesn't answer my question unfortunetly, I need to know what I need to change within my python script and how i write the powershell line. The link you posted only shows a powershell script, so I dont understand the link to python. Commented Jan 30, 2023 at 17:38

1 Answer 1

1

I figured it out myself, this is my current solution:

In powershell:

$campaign = "ABC"
$dir_xml = "d:\path\xml"
$dir_pictures = "d:\path\pictures"
$dir_output = "d:\path\output"

python path\file.py -c $campaign, -x $dir_xml, -p $dir_pictures, -o $dir_output

In python:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--campagne", required=True)
parser.add_argument("-x", "--xml", required=True)
parser.add_argument("-p", "--picture", required=True)
parser.add_argument("-o", "--output", required=True)
args = parser.parse_args()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.