[Solved] How to execute a function inside a python script on a string [closed]

First, it is not a good idea to do so from security viewpoint. But, if you want to do it, you can do it this way: import os script = “”” print(“Executed!”) “”” with open(‘script.py’,’w’) as fhand: fhand.write(script) os.system(‘python script.py’) You can write the string in script to another *.py file and then run that … Read more

[Solved] Process each element in a list for each line from a text file [closed]

You need to split each string into each port, then print each one. And you can use enumerate() to get the line number. # Example data port_strings = [ ‘443, 9993’, ‘443, 3389, 445’, ‘443, 22, 3389, 23’, ‘3389, 445, 443’, ‘443, 3389, 445’] for i, port_string in enumerate(port_strings, 1): print(‘line’, i) for port in … Read more

[Solved] Problem with can only concatenate str (not “NoneType”) to str

The problem is, sizes doesn’t return anything. print does not return values, it just prints. You’d need to do something like: acc = “” for span in Size: acc += span.text.replace(‘EU:’,”).strip() # Concatenate the strings together return acc There are also more efficient ways of doing this using a list comprehension/generator expression and join: return … Read more

[Solved] How to scrape simple image from webpage

In your code, the image_url gives the directory of the image where it stored on the hosting service. You need to append the domain name to the image_url variable and use the requests library to download it. Use the following code and it will work. import bs4 import requests url = “https://parts.bmwmonterey.com/a/BMW_2004_330i-Sedan/_52014_5798240/Cooling-System-Water-Hoses/17_0215.html” resp = requests.get(url) … Read more

[Solved] File upload testing using unit test python [closed]

Start by rewriting the method to take an iterable as an argument: def scene_upload(self, scene): csv_reader = csv.reader(scene, delimiter=”,”, quotechar=”|”) next(csv_reader) # Skip the header for line_count, row in enumerate(csv_reader, 1): self.time_stamp.append(int(row[0])) self.active_func.append(int(row[1])) self.active_func_output.append(row[2]) self.dstream_func.append(int(row[3])) self.dstream_func_aspect.append(row[4]) self.time_tolerance.append(row[5]) In production use, you make the caller responsible for opening the file: filename_scene = filedialog.askopenfilename(initialdir=”https://stackoverflow.com/”, title=”Select file”) print(filename_scene) … Read more

[Solved] How draw bounding box on Specfic Area using Opencv python? [closed]

Here is my Python/OpenCV code. I can get the region by a judicious choice of area thresholding. But this is not likely going to be robust for other images. Input: import cv2 import numpy as np # read image img = cv2.imread(“younas.jpg”) # convert img to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # median filter gray … Read more

[Solved] Getting a none type error python 3?

In insertEnd, you’re guaranteeing you always have None for actualnode at the end of the loop: def insertEnd(self, data): self.size += 1 newnode = Node(data) actualnode = self.head # Keep going until actualnode is None while actualnode is not None: actualnode = actualnode.nextnode # Here actualnode will always be None actualnode.nextnode = newnode To fix … Read more