The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by vespaman]

Hi everyone,

I am trying to filter a Squid Proxy Server Access Log based on the username in
a record.

This code appears to work ok on Win2K (Allowing for the word wrap here the
last two lines beginning at "userlist=" is actually a single line):-

everything=logfilehandle.readlines()
userlist=[x for x in everything if string.upper(string.split(x)[7]) ==
string.upper(username)]

But on Red Hat Linux 7.3 I get (Again allowing for the word wrap here):-

[root@linuxfish bin]# python filter-by-department.py /var/log/squid/access.log.1
File "filter-by-department.py", line 21
userlist=[x for x in everything if string.upper(string.split(x)[7]) ==
String.
upper(username)]
^
SyntaxError: invalid syntax
[root@linuxfish bin]#

I have only used the Tab key not the space key for indenting.
Any ideas why it should be OK on Win2K and not Linux?
Cheers, John