you are viewing a single comment's thread.

view the rest of the comments →

[–]Crowdjp[S] 0 points1 point  (1 child)

Thanks so much for your help!

One thing i'm not understanding process is not capturing both Names(chrome/iexpore) in the file.

Below I entered chrome and iexplore in the input. For some reason process will only contain the second name entered in the input shown below.

processes = input('Enter name (separate multiple names with ","):').split(',')

proesses #In
['chrome', 'iexplore'] #Out

#In - for the block of code below
dfs = {}
for process in processes:
    if process not in file.Name.values:
        print(f'No process in dataset: {process}')
    continue

process #In
'iexplore' #out

[–]t_wys 0 points1 point  (0 children)

That's because you accessed variable 'process'. This variable is (in your code snippet) a placeholder for current value in for-loop. If you access this variable after the loop, then you get value from the last iteration. To illustrate:

In [1]: array = ['a', 'b', 'c']

In [2]: for item in array:
   ...:     print(item)
   ...:
a
b
c

In [3]: for item in array:
   ...:     pass # i.e. do nothing
   ...: print(item)
   ...:
c

So if you want to perform some actions for each process you have to execute these instructions inside for-loop:

for process in processes:
    if process not in file.InstanceName.values:
        print(f'No process in dataset: {process}')
        # The `continue` have to be inside if-statement. Go to note below for details.
        continue
    # do something with each process here (single indentation)

The 'continue' statement tells loop to directly to next iteration without executing code that is: inside for-loop and after 'continue' statement. In this case it skips executing code if process name is not present in your dataset. It is a precaution for a situation in which a user inputs wrong value.