Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concatenate str
#1
I have a main class that returns the result of a secondary class. The problem is defined in the following message in the terminal:

TypeError: can only concatenate str (not "CompletedProcess") to str

This is due to the sub-process that I need to concatenate within the body of the html, below is an excerpt from the primary class and the secondary class:

Primary Class

def do_GET(self): self.do_HEAD() from index import Index o_html = Index().view() self.wfile.write(bytes(o_html, "utf8")) return
Secondary Class

#! /usr/local/bin/python3.9 import subprocess # Class name : Index -> Structure html page : class Index: # Class method : Constructor -> Object Build : def __init__(self): pass # Class method : build -> : Render code html : def view(self): self.v_shell = subprocess.run("ls") # Variable : v_html5 -> Code Html self.v_html5 = """ <!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Webstrucs Action</title> </head> <body> <h1>Action</h1> Python Web Server For Asynchronous Requests<br> """ + self.v_shell + """ <p> </p> </body> </html> """ return self.v_html5
How can I get around this TypeError?
Reply
#2
You expect subprocess.run("ls") returns a string, but in "Subprocess management" I read:
... Wait for command to complete, then return a CompletedProcess instance
A CompletedProcess instance contains: args, returncode, stdout and stderr.

Therefore I believe you should do: subprocess.run("ls").stdout.
Reply
#3
This is how it works :

subprocess.getoutput("ls")
ibreeden likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Concatenate array for 3D plotting armanditod 1 1,868 Mar-21-2024, 08:08 PM
Last Post: deanhystad
  How to concatenate filepath with variable? Mark17 2 11,630 Jan-31-2022, 09:13 PM
Last Post: Mark17
  Concatenate two dataframes moralear27 2 3,161 Sep-15-2020, 08:04 AM
Last Post: moralear27
  concatenate a request to the endpoint of OSM-API?! - how to? apollo 0 2,061 Aug-18-2020, 03:21 PM
Last Post: apollo
  can only concatenate str (not "int") to str gr3yali3n 6 8,851 May-28-2020, 07:20 AM
Last Post: pyzyx3qwerty
  How to concatenate multiple dataframes rajeshE 1 3,018 Mar-02-2020, 06:37 AM
Last Post: scidam
  Concatenate two dictionaries harish 3 3,858 Oct-12-2019, 04:52 PM
Last Post: strngr12
  Python split and concatenate saravanatn 5 5,473 Jul-31-2018, 08:29 AM
Last Post: Axel_Erfurt

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.