Hi,
With Python 3.9.2 I get
$ import datetime
$ s = "1-00:01:01"
$ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
$ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute,
seconds=t.second)
$ d.days
1
$ d.seconds
61
$ d.minutes
AttributeError: 'datetime.timedelta
"Loris Bennett" writes:
> Hi,
>
> With Python 3.9.2 I get
>
> $ import datetime
> $ s = "1-00:01:01"
> $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute,
> seconds=t.second)
> $ d.days
> 1
> $ d.seconds
> 61
>
I think because minutes and hours can easily be composed by multiplying
seconds. days is separate because you cannot compose days from seconds;
leap seconds are applied to days at various times, due to
irregularities in the Earth's rotation.
On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:
Additionally, which datatype would you expect them to be returned in?
One could argument for int or float (Decimal?), both could be valid
datatypes, depending on how exact you might want them, while the second
is the time base of SI units.
Cheers
Lars
--
Lars Liedtke
Software Entwickler
In C when you declare a variable static in a function, the variable
retains its value between function calls.
The first time the function is called it has the default value (0 for
an int).
But when the function changes the value in a call (for example to 43),
the next time the function is called th
On 2022-04-14, Paul Bryan wrote:
> I think because minutes and hours can easily be composed by multiplying
> seconds. days is separate because you cannot compose days from seconds;
> leap seconds are applied to days at various times, due to
> irregularities in the Earth's rotation.
That's an argu
> On 14 Apr 2022, at 16:28, Cecil Westerhof via Python-list
> wrote:
>
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function c
Am 14.04.2022 um 17:02 schrieb Cecil Westerhof via Python-list:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the va
On 2022-04-14 16:22, Jon Ribbens via Python-list wrote:
On 2022-04-14, Paul Bryan wrote:
I think because minutes and hours can easily be composed by multiplying
seconds. days is separate because you cannot compose days from seconds;
leap seconds are applied to days at various times, due to
irre
On Wed, 13 Apr 2022 at 20:05, Peter J. Holzer wrote:
>
> On 2022-04-12 21:03:00 +0200, Marco Sulla wrote:
> > On Tue, 29 Mar 2022 at 00:10, Peter J. Holzer wrote:
> > > They are are about a year apart, so they will usually contain different
> > > versions of most packages right from the start. So
On Thu, 14 Apr 2022 at 19:16, MRAB wrote:
>
> When you're working only with dates, timedelta not having a 'days'
> attribute would be annoying, especially when you consider that a day is
> usually 24 hours, but sometimes 23 or 25 hours (DST).
I agree. Furthermore, timedelta is, well, a time delta
I've seen people use function attributes for this.
```
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def function():
... print(function.variable)
... function.variable += 1
...
>>> function.variab
Cecil Westerhof writes:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the value in a call (for example to 43),
> t
On Fri, 15 Apr 2022 at 03:45, Marco Sulla wrote:
>
> On Thu, 14 Apr 2022 at 19:16, MRAB wrote:
> >
> > When you're working only with dates, timedelta not having a 'days'
> > attribute would be annoying, especially when you consider that a day is
> > usually 24 hours, but sometimes 23 or 25 hours
Cecil Westerhof wrote at 2022-4-14 17:02 +0200:
>In C when you declare a variable static in a function, the variable
>retains its value between function calls.
>The first time the function is called it has the default value (0 for
>an int).
>But when the function changes the value in a call (for ex
On Fri, 15 Apr 2022 at 00:54, Loris Bennett wrote:
>
> Hi,
>
> With Python 3.9.2 I get
>
> $ import datetime
> $ s = "1-00:01:01"
> $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute,
> seconds=t.second)
> $ d.days
>
On Fri, 15 Apr 2022 at 03:53, Sam Ezeh wrote:
>
> I've seen people use function attributes for this.
> ```
> Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def function():
> ... print(function.var
Yes, python has something like that. In fact, two things.
1) Generator. Use a "yield" statement. Every call "yields" a new value.
The state of the function (local variables) is remembered from each previous
call to the next.
2) In a file, declare a variable to be global. In the funct
On 2022-04-14, MRAB wrote:
> On 2022-04-14 16:22, Jon Ribbens via Python-list wrote:
>> On 2022-04-14, Paul Bryan wrote:
>>> I think because minutes and hours can easily be composed by multiplying
>>> seconds. days is separate because you cannot compose days from seconds;
>>> leap seconds are app
Am 13.04.2022 um 20:39 schrieb Dennis Lee Bieber:
> On Thu, 14 Apr 2022 03:38:11 +1000, Tim Deke declaimed
> the following:
>
>> Dear Sir,
>>
>> I have successfully downloaded Python into my laptop but the shortcut icon
>> is not appearing on the desktop. I am using Windows 10 with the PC
>> spec
On 2022-04-14, Mirko via Python-list wrote:
>> Python normally does not create "shortcut icon"s -- one downloads an
>
> The Python Windows installer *absolutely* should.
Agreed. I'm not much of a Windows user, but I do maintain a few
Windows applications with installers. They all create des
that is not an error, its simply the python console intrepeter
--
https://mail.python.org/mailman/listinfo/python-list
On 4/14/22 2:42 PM, Mirko via Python-list wrote:
Am 13.04.2022 um 20:39 schrieb Dennis Lee Bieber:
On Thu, 14 Apr 2022 03:38:11 +1000, Tim Deke declaimed
the following:
Dear Sir,
I have successfully downloaded Python into my laptop but the shortcut icon
is not appearing on the desktop. I am
On 4/14/22 17:08, Richard Damon wrote:
> I think the issue is that the 'python' interpreter/compiler isn't the
> sort of program that makes sense to make a desktop icon for, as it is a
> command line utility.
>
> Perhaps making an icon for IDLE, if it has also been installed, but then
> the issue
On 2022-04-14, Richard Damon wrote:
> I think the issue is that the 'python' interpreter/compiler isn't the
> sort of program that makes sense to make a desktop icon for, as it is a
> command line utility.
Yes, it is a command line utility. Why does that mean you shouldn't
have a desktop short
On 4/14/22 18:06, Grant Edwards wrote:
> On 2022-04-14, Richard Damon wrote:
>
>> I think the issue is that the 'python' interpreter/compiler isn't the
>> sort of program that makes sense to make a desktop icon for, as it is a
>> command line utility.
>
> Yes, it is a command line utility. Why
26 matches
Mail list logo