python-2.7

PyList_GetItem() returning a reference

PyList_GetItem() returning a reference Question: I am using the PyHelper class that I found HERE My python script is returning a list and in C++ I can call PyList_Size() and successfully get the size but when I try get item it returns a very large number which I assume is a address reference rather than …

Total answers: 1

Get a element from list, from pair of 3

Get a element from list, from pair of 3 Question: Hello I have a list in which elemnets are in pair of 3 list given below, labels = [”, ”, ‘5000’,”, ‘2’, ”,”, ”, ‘1000’,’mm-dd-yy’, ”, ”,”, ”, ’15’,’dd/mm/yy’, ”, ”, ”, ‘3’, ”,”, ”, ‘200’,”, ‘2’, ”,’mm-dd-yy’, ”, ”,”, ”, ”,”, ”, ”] in …

Total answers: 3

Reading netcdf time with unit of years

Reading netcdf time with unit of years Question: All, I am trying to read the time coordinate from Berkley Earth in the following temperature file. The time spans from 1850 to 2022. The time unit is in the year A.D. (1850.041667, 1850.125, 1850.208333, …, 2022.708333, 2022.791667,2022.875). The pandas.to_datetime cannot correctly interpret the time array because …

Total answers: 1

Python2 vs Python3 : Exception variable not defined

Python2 vs Python3 : Exception variable not defined Question: I wrote this small snippet in python2 (2.7.18) to catch the exception in a variable and it works >>> ex = None >>> try: … raise Exception("test") … except Exception as ex: … print(ex) … test >>> ex Exception(‘test’,) >>> >>> ex2 = None >>> try: …

Total answers: 1

error "unmatched group" when using re.sub in Python 2.7

error "unmatched group" when using re.sub in Python 2.7 Question: I have a list of strings. Each element represents a field as key value separated by space: listA = [ ‘abcd1-2 4d4e’, ‘xyz0-1 551’, ‘foo 3ea’, ‘bar1 2bd’, ‘mc-mqisd0-2 77a’ ] Behavior I need to return a dict out of this list with expanding the …

Total answers: 3

Calling a C function with a char* argument through python ctypes difference python2 and python3

Calling a C function with a char* argument through python ctypes difference python2 and python3 Question: I am converting a file from python2 to python3 that calls a C function using the ctypes module. The below minimal example works in python2, however raises the following error in python3 (3.11) OSError: exception: access violation writing 0x00000000000094E0 …

Total answers: 1

How to wait until a certain output (string) occurs while executing subprocess.check_output?

How to wait until a certain output (string) occurs while executing subprocess.check_output? Question: I am trying to write a Python script which will download my software build. So the script will wait until certain output occurs and proceed for the next task: import os import subprocess out = subprocess.check_output(["wget", "–downloadlink–"]) print(out) if "saved" in out: …

Total answers: 1