Comments on: Python: Open the Most Recent Log File http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Ross http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-21358 Tue, 07 Feb 2012 18:34:10 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-21358

This is great, but where you make the dict, instead of doing simple string concatenation (with the plus), you should:
os.stat(os.path.join(directory,x)).st_mtime)

Reply  |  Quote
]]>
By: Luke Maciak http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15597 Tue, 18 May 2010 20:38:12 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15597

@ usecide:

Yes. That would be easier. :)

Although if you do use a perl or python script you can extract the data you need and do stuff with it. Like send an email. You can do this with shell scripts as well, but the more complex the “stuff” is the more difficult it becomes to create and maintain that shell script.

@ jambarama:

LOL. Geobytes seems to be a tiny little bit off the target. :P Just a bit!

Reply  |  Quote
]]>
By: jambarama http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15594 Tue, 18 May 2010 19:25:36 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15594

Ah, smart enough to put me in the US. Geobytes IP locator put me in hong kong.

Reply  |  Quote
]]>
By: jambarama http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15593 Tue, 18 May 2010 19:24:45 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15593

I think these posts are very interesting, but this comment is really just to see where your country locator puts my IP address. I’m in a plane over the Southeast US.

Reply  |  Quote
]]>
By: usecide http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15590 Tue, 18 May 2010 17:42:35 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15590

Is not easier to use one line bash script?
I think that:
$ tail -f `ls -c *.log | head -n 1` -n 10
should do the trick :)

Reply  |  Quote
]]>
By: Luke Maciak http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15570 Tue, 18 May 2010 01:05:51 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15570

@ Zel:

No, that’s just me cleaning up the code the last second inside wordpress. I think originally the arguments were dir and pnam, files was fl and the dictionary was just fdi.

I do that sometimes. I copy and paste code into wordpress and then next day I’m like – hey, I can clean this up before I post it. That’s where the typos come from.

@ road:

I don’t think Perl is better or worse. It’s different – and since I haven’t used it for a while, I got a bit rusty. My main problem was my own use of:

a) long and cryptic regexes which I had to actually work out on paper because I did not remember what they were supposed to do

b) Use of the default variables ($_ and @_) all over the place which made the code harder to read than if it had explicit and appropriately named arguments.

Not really a problem with the language itself – just with me. You can write perfectly readable code in Perl. Python just lends itself to a slightly cleaner and more explicit code. On the other hand it has that white space rule that a lot of people hate.

I think I mainly wanted an excuse to mess around with Python some more.

Reply  |  Quote
]]>
By: road http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15569 Tue, 18 May 2010 00:16:21 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15569

I’m a biologist and I do a lot of bioinformatics. Perl is the only language I know intimately. Lately I’ve been engaged in a debate with a co-worker about whether there’s value to learning Python. It sounds like a swell language, but I already know Perl. Your points about perl-golf and spaghetti code are well-taken, but you didn’t go-on to describe if/why you thought Python was superior. Perhaps you don’t actually think it’s superior… but — and I don’t intend to start an argument here, this is an honest question — can you explain to someone who only knows perl if/why they should be interested in Python? I mean, you could also just write *better* Perl code, no?

Reply  |  Quote
]]>
By: Zel http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15566 Mon, 17 May 2010 18:48:33 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15566

name_n_timestamp = dict([(x, os.stat(diexctory+x).st_mtime) for x in files])

Shouldn’t it be directory and not diexctory ? I think this is the second or third time I notice an obvious typo in the code you post, is it intentional ? You know, so that it won’t work if you don’t actually read, understand and fix it ?

Reply  |  Quote
]]>
By: Sam Weston http://www.terminally-incoherent.com/blog/2010/05/17/python-open-the-most-recent-log-file/#comment-15564 Mon, 17 May 2010 16:55:57 +0000 http://www.terminally-incoherent.com/blog/?p=5731#comment-15564

Everyone’s coding style changes over time. If I look at code I wrote a year ago I cringe and facepalm :P I really need to get around to learning python; it looks like such a versatile language.

Reply  |  Quote
]]>