[Solved] Reading log files in python

Try this way. but you have to confirm that each row list length must equal to 6. list1 = [] list2 = [] with open(‘example.log’) as f: for i in f.readlines(): if (len(i.split(‘,’)) == 6): list1.append(i.split(‘,’)[4]) list2.append(i.split(‘,’)[5]) print(list1) print(list2) 1 solved Reading log files in python

[Solved] Written Equation To Python Code [closed]

You need to group the both the expression under the division bar in parentheses: >>> ( … (.310 * .290) / .260 … / … ( … (.310 * .290) / .260 … + … ((1 – .310) * (1 – .290) / (1 – .260)) … ) … ) 0.3430943785456421 This ensures that the … Read more

[Solved] Python miminum length/max value in dictionary of lists

def get_smallest_length(x): return [k for k in x.keys() if len(x.get(k))==min([len(n) for n in x.values()])] def get_largest_sum(x): return [k for k in x.keys() if sum(x.get(k))==max([sum(n) for n in x.values()])] x = {‘a’: [4, 2], ‘c’: [4, 3], ‘b’: [3, 4], ‘e’: [4], ‘d’: [4, 3], ‘g’: [4], ‘f’: [4]} print get_smallest_length(x) print get_largest_sum(x) Returns: [‘e’, ‘g’, … Read more

[Solved] Open a file in python from 2 directory back

Opening files in python is relative to the current working directory. This means you would have to change cd to the directory where this python file is located. If you want a more robust solution: To be able to run this from any directory, there is a simple trick: import os PATH = os.path.join(os.path.dirname(__file__), ‘../../test.txt’) … Read more

[Solved] Check If Port is Open in Python3?

This is a Python3 example I got from https://www.kite.com/python/answers/how-to-check-if-a-network-port-is-open-in-python import socket a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = 8080 location = (“127.0.0.1”, port) check = a_socket.connect_ex(location) if check == 0: print(“Port is open”) else: print(“Port is not open”) 1 solved Check If Port is Open in Python3?

[Solved] Why is my code displaying the wrong output?

Sorry for the confusion regarding my previous answer. The problem was that you were appending n instead of i in myList.append(n). Moreover, you could simply use sum to sum your list. Your output was wrong because you were appending the number n and hence when you do sum=sum+myList[i], you were just adding n to the … Read more

[Solved] Return the list is empty python [closed]

As is, your code shoud do nothing. I guess you are calling Main() in some way. But the function doObjects is never called. Moreover, you may have forgotten to add self.list1 = list1 in your function definition The good way to do this could be first to add to your script at the end: M … Read more

[Solved] 3d image visualisation with numpy/vtk

I finally find out what was wrong here’s my new code import vtk import numpy as np import os import matplotlib.pyplot as plt import PIL import Image DEBUG =False directory=”splitted_mri/” l = [] k=0 #add the next picture in a differente level of depth/z-positions for file in os.listdir(directory): img = directory + file if DEBUG … Read more