Python Forum
How do I put a variable inside a String in Python?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I put a variable inside a String in Python?
#1
hello all ...

im trying to add a variable inside a String ...
this is my code :

import os 
import sys

cmd2 = """powershell -command "Get-Process | where {$_.Description -like 'VMware Tools Core Service'} | select -expand id""" # the commnad run the powerashell and search for a proccess with Description then get her pid number 
tmp = os.popen(cmd2).read()

cmd3 = "wmic process where processId="+tmp+"get name | findstr /v Name"  # this commnad show the name of the pid number thet getting from first command 

tmp2 = os.popen(cmd3).read()
#print("hey " + tmp ) 
print tmp2
the problem here : wmic process where processId="+tmp+"get name | findstr /v Name" ,,,, my script ignore this section of command ( get name | findstr /v Name ) it's add new line and just run the commnad until here : wmic process where processId="+tmp

how i can solve this issue ?

i think the problem is here :
[Image: Untitled.png]

the powershell add a new empty line !! when i try to use len() it gives me 5 while they are just 4 !!
how i can remove the empty line ?
Reply


Messages In This Thread
How do I put a variable inside a String in Python? - by evilcode1 - Sep-24-2018, 09:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable being erased inside of if statement deusablutum 8 561 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Variable definitions inside loop / could be better? gugarciap 2 598 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 2,476 Nov-07-2023, 09:49 AM
Last Post: buran
  Replacing String Variable with a new String Name kevv11 2 926 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 2,432 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 3,306 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 1,072 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,627 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 1,992 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,451 Jul-11-2022, 08:52 AM
Last Post: japo85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020