Calculating timespan
I've been looking at the date/time classes and I'm at a loss as to how to do this (probably too used to other platforms). I have two date/time values. One represents 'now' and the other the last modified time of a file on disk (from stat). I need to calculate the difference in time (i.e., a 'timespan') between the two so I can tell if the file has been modified in the past X minutes and do something to it. Thanks =) -- http://mail.python.org/mailman/listinfo/python-list
Re: Calculating timespan
[EMAIL PROTECTED] wrote: from datetime import datetime, timedelta span = datetime.now() - datetime(year=2008,month=8,day=27,hour=12,minute=34,second=56) if span < timedelta(minutes=37): # do something timedelta! Yes, it's obvious that's what I was looking for. I was stuck with 'timespan' in my head and couldn't find anything like it in the docs. Thank you very much! -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 and stronger typing (note: probably a newbie question)
On Thu, Jul 12, 2007 at 11:26:22AM -0700, Paul Rubin wrote: > > Guy Steele used to describe functional programming -- the evaluation > of lambda-calculus without side effects -- as "separation of Church > and state", a highly desirable situation ;-). > > (For non-FP nerds, the above is a pun referring to Alonzo Church, who > invented lambda calculus in the 1920's or so). Wow, I didn't realize I was an FP nerd :) On proving programs correct... from my CS study days I distinctly remember thinking "sure, you can prove it correct, but you cannot do actual useful stuff with it". We might have come a long way since then (late 80s :P), but I don't hold out much hope (especially since the halting problem does exist, and forever will). Bye, J -- http://mail.python.org/mailman/listinfo/python-list
Auto execute python in USB flash disk
I am still fairly new to python and wanted to attempt a home made password protection program. There are files that I carry on a USB flash drive that I would like to password protect. Essentially, I would like to password protect an entire directory of files. Is there a way to auto execute a python script after a user double clicks to open a folder on the USB drive? How can you capture that double click event on a specific folder? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Event: First meeting of Karlsruhe User Group (tentatively named "KaPy"), 2010-04-16, 19:00:00 CEST
A new user group is being set up by some interested pythoneers from (around) Karlsruhe. The first meeting will be on Friday, 2010-04-16 (April 16th, 2010) at 19:00 (7pm) in the rooms of Entropia eV (the local affiliate of the CCC). See http://entropia.de/wiki/Anfahrt on how to get there. Or reply to me if you need instructions in English; there's a map on that page, but the devil's in the details, as always. Bye, J -- http://mail.python.org/mailman/listinfo/python-list
KaPy -- Karlsruhe Python User Group meeting, 2010-05-21, 19:00
The Karlsruhe Python User Group (KaPy) meets again. Friday, 2010-04-16 (May 21st) at 19:00 (7pm) in the rooms of Entropia eV (the local affiliate of the CCC). See http://entropia.de/wiki/Anfahrt on how to get there. For your calendars: meetings are held monthly, on the 3rd Friday. Bye, J PS: Sorry for the late announcement. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Error
On Sun, Jul 29, 2012 at 01:08:57PM +0200, Peter Otten wrote: > [email protected] wrote: > > > Dear Group, > > > > I was trying to convert the list to a set, with the following code: > > > > set1=set(list1) > > > > the code was running fine, but all on a sudden started to give the > > following error, > > > > set1=set(list1) > > TypeError: unhashable type: 'list' > > > > Add a print statement before the offending line: > > print list1 > set1 = set(list1) > > You will see that list1 contains another list, e. g. this works... > Peter's right, but instead of a print before the line, put a try/except around it, like try: set1 = set(list1) except TypeError: print list1 raise This way, only the *actual* error triggers any output. With a general print before, you can get a lot of unnecessary output. Grits, J -- http://mail.python.org/mailman/listinfo/python-list
Re: Linux shell to python
On Mon, Jul 30, 2012 at 12:35:38PM +0200, Philipp Hagemeister wrote:
> On 07/30/2012 09:05 AM, Vikas Kumar Choudhary wrote:
> > `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" | cut -c1-7'
>
> The rough Python equivalent would be
>
> import subprocess
> [ l.partition(' ')[0] # or l[:7], if you want to copy it verbatim
> for l in subprocess.check_output(['lspci']).splitlines()
> if 'Q' in l and isp_str1 in l and isp_str2 in l
> ]
Ouch. A list comprehension spanning more than one line is bad code
pretty much every time.
But you did qualify it as "rough" :D
Grits, J
--
http://mail.python.org/mailman/listinfo/python-list
Re: On-topic: alternate Python implementations
On Sat, Aug 04, 2012 at 08:40:16AM +0200, Stefan Behnel wrote: > Steven D'Aprano, 04.08.2012 08:15: > > Most people are aware, if only vaguely, of the big Four Python > > implementations: > > > > And not to forget Cython, which is the only static Python compiler that is > widely used. Compiles and optimises Python to C code that uses the CPython > runtime and allows for easy manual optimisations to get C-like performance > out of it. Cython is certainly *not* a Python *implementation*, since it always uses the CPython runtime (and compiling Cython C files requires Python.h). None of the other implementations require Python for actually compiling or running Python source. Oh, yes, you can create a stand-alone... wait, a "stand-alone" app. By embedding the Python runtime (dynamic linking with libpythonX.Y... maybe static too? Didn't test, because it's irrelevant for making the point). Grits, J -- http://mail.python.org/mailman/listinfo/python-list
Re: On-topic: alternate Python implementations
On Sun, Aug 05, 2012 at 07:46:59AM +0200, Stefan Behnel wrote: > Jürgen A. Erhard, 05.08.2012 01:25: > > On Sat, Aug 04, 2012 at 08:40:16AM +0200, Stefan Behnel wrote: > >> Steven D'Aprano, 04.08.2012 08:15: > >>> Most people are aware, if only vaguely, of the big Four Python > >>> implementations: > >> > >> And not to forget Cython, which is the only static Python compiler that is > >> widely used. Compiles and optimises Python to C code that uses the CPython > >> runtime and allows for easy manual optimisations to get C-like performance > >> out of it. > > > > Cython is certainly *not* a Python *implementation*, since it always > > uses the CPython runtime (and compiling Cython C files requires > > Python.h). > > Yes, it avoids an unnecessary duplication of effort as well as a > substantial loss of compatibility that all non-CPython based > implementations suffer from. But it's not an Python *implementation*, "just" an extension. Mind you, this is not intended as a slight of Cython as such. I really like it, though I haven't had need for it yet, but I sure prefer it to writing extensions in pure C. *b* > > None of the other implementations require Python for actually > > compiling or running Python source. > > Nuitka was on the list as well. True, which I realized only after my missive. But doesn't change much, only that the list is wrong. > > Oh, yes, you can create a stand-alone... wait, a "stand-alone" app. > > By embedding the Python runtime (dynamic linking with libpythonX.Y... > > maybe static too? > > Sure, that works. My definition, to also answer your following post, is "does not rely on any executable part of the CPython source (which includes .c files and executable code in header files if any, but of course can exclude the stdlib)". Not sure that's precise enough, but... if it can't run/work on a system that has no shred of CPython installed, it's not an alternative *implementation*. The big three don't need CPython (except PyPy for building, and even it can use a precompile PyPy I think). Grits, J -- http://mail.python.org/mailman/listinfo/python-list
