Fwd: Timezone for datetime.date objects
Forwarding to the list.. -- Forwarded message - From: Morten W. Petersen Date: Tue, Mar 1, 2022 at 12:52 PM Subject: Re: Timezone for datetime.date objects To: Chris Angelico On Mon, Feb 28, 2022 at 11:57 PM Chris Angelico wrote: > On Tue, 1 Mar 2022 at 09:28, Morten W. Petersen wrote: > > > > Hi Chris, Cameron. > > > > Well, let's say I specify the datetime 2022-02-22 02:02 (AM). I think > everyone could agree that it also means 2022-02-22 02:02:00:00, to > 2022-02-22 02:02:59:59. > > > > Not sure how many :59s you want there :) I'm going to assume you mean > "02:02:00" to "02:02:59". > > > And I think the same applies for a date. If the pipes are clogged and I > can't take (give) a shit, a shower or do anything else involving fluids, I > can just leave the keys under the doormat, and agree a date with the > plumber, and go off to a friend of relatives' place for a couple of days > while waiting for the plumber to do the necessary work. > > > > That is one of the fundamental differences between humans and > computers. Humans are very VERY sloppy with time descriptions. With > computers, it's much better to be clear about time ranges; a time does > not imply a specific window size. (And autistic humans are more like > computers.) > > Yep. Well, as I said, I could create some range objects myself, and even create a little module and put it up on pypi, if I couldn't find any existing module I could use. As we're discussing this, it is clear that different points can be made, and as for the Python standard library, it is what it is today, and part of the reason I was posting this email was to see if it should be changed, amended/appended to include range. I've worked a bit with dates, date searches and so on, and having existing range classes and objects to work with, defined in the standard library, seems like a natural and useful thing. Time, as humans have defined it with timezones, leap years, leap seconds, Denmark not following the atomic clock etc. is a bit messy, and it is easy to make mistakes creating custom code dealing with it. Regards, Morten -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ -- I am https://leavingnorway.info Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Timezone for datetime.date objects
On Tue, 1 Mar 2022 at 22:52, Morten W. Petersen wrote: > Yep. Well, as I said, I could create some range objects myself, and even > create a little module and put it up on pypi, if I couldn't find any existing > module I could use. > > As we're discussing this, it is clear that different points can be made, and > as for the Python standard library, it is what it is today, and part of the > reason I was posting this email was to see if it should be changed, > amended/appended to include range. > > I've worked a bit with dates, date searches and so on, and having existing > range classes and objects to work with, defined in the standard library, > seems like a natural and useful thing. Time, as humans have defined it with > timezones, leap years, leap seconds, Denmark not following the atomic clock > etc. is a bit messy, and it is easy to make mistakes creating custom code > dealing with it. > I think a range object wouldn't be a bad thing, but it would absolutely have to be a datetime range, NOT a date range with timezone. For dates with timezones, the obvious interpretation to one person is equally obviously wrong to another, and vice versa. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data
Cameron Simpson writes: > On 28Feb2022 10:11, Loris Bennett wrote: >>I have an SQLAlchemy class for an event: >> >> class UserEvent(Base): >> __tablename__ = "user_events" >> >> id = Column('id', Integer, primary_key=True) >> date = Column('date', Date, nullable=False) >> uid = Column('gid', String(64), ForeignKey('users.uid'), nullable=False) >> info = ?? >> >>The event may have arbitrary, but dict-like data associated with it, >>which I want to add in the field 'info'. This data never needs to be >>modified, once the event has been inserted into the DB. >> >>What type should the info field have? JSON, PickleType, String, or >>something else? > > I would use JSON, it expresses dicts well provided the dicts contain > only basic types (strings, numbers, other dicts/lists of basic types > recursively). > > I have personal problems with pickle because nonPython code can't read > it. > > Cheers, > Cameron Simpson Thanks for the various suggestions. The data I need to store is just a dict with maybe 3 or 4 keys and short string values probably of less than 32 characters each per event. The traffic on the DB is going to be very low, creating maybe a dozen events a day, mainly triggered via a command-line interface, although I will probably set up one or two cron jobs, each of which might generate another 0 to maybe 5 records a day. I could go for JSON (or rather LONGSTRING, as JSON is just an alias for LONGSTRING, but JSON is not available on the version of MariaDB I am using). However, that seems like overkill, since I am never going to have to store anything near 4 GB in the field. So I should probably in fact just use say VARCHAR(255). WDYT? Cheers, Loris -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data
Loris Bennett wrote: > Thanks for the various suggestions. The data I need to store is just a > dict with maybe 3 or 4 keys and short string values probably of less > than 32 characters each per event. The traffic on the DB is going to be > very low, creating maybe a dozen events a day, mainly triggered via a > command-line interface, although I will probably set up one or two cron > jobs, each of which might generate another 0 to maybe 5 records a day. > > I could go for JSON (or rather LONGSTRING, as JSON is just an alias for > LONGSTRING, but JSON is not available on the version of MariaDB I am > using). However, that seems like overkill, since I am never going to > have to store anything near 4 GB in the field. So I should probably in > fact just use say VARCHAR(255). > > WDYT? Using TypeDecorator to transparently convert between a dict and its JSON string representation and MutableDict to track changes, you will get a completely transparent attribute that works just like a dict. Make sure to check that the generated JSON fits into your column width. I once got bitten by the fact that VARCHAR(x) can hold only x/4 characters in utf8mb4 character set. -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data
Robert Latest writes: > Loris Bennett wrote: >> Thanks for the various suggestions. The data I need to store is just a >> dict with maybe 3 or 4 keys and short string values probably of less >> than 32 characters each per event. The traffic on the DB is going to be >> very low, creating maybe a dozen events a day, mainly triggered via a >> command-line interface, although I will probably set up one or two cron >> jobs, each of which might generate another 0 to maybe 5 records a day. >> >> I could go for JSON (or rather LONGSTRING, as JSON is just an alias for >> LONGSTRING, but JSON is not available on the version of MariaDB I am >> using). However, that seems like overkill, since I am never going to >> have to store anything near 4 GB in the field. So I should probably in >> fact just use say VARCHAR(255). >> >> WDYT? > > Using TypeDecorator to transparently convert between a dict and its JSON > string > representation and MutableDict to track changes, you will get a completely > transparent attribute that works just like a dict. Make sure to check that the > generated JSON fits into your column width. I once got bitten by the fact that > VARCHAR(x) can hold only x/4 characters in utf8mb4 character set. Thanks for pointing out TypeDecorator - I wasn't aware of that. I won't need to track changes in the JSON data, because the events I am recording form an audit trail and so are written and read, but never modified. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to solve the given problem?
On Thu, 17 Feb 2022 02:20:53 -0800 (PST), NArshad declaimed the following: >I have completed the homework or what so ever it used to be its only I am >telling the solution which looks to me as better as compared to what others >have given like the one that Christian has given. At the risk of irritating the other regulars... If you've completed it, why not show us your Python code so we may review it? I presume you did do it in Python. I'm not going to show my code -- mainly as I just spent today writing a solution in REXX. But I will show the results of running said code. My solution is GENERAL in that it handles 1 variable number of periods in the plan 2 variable number of periods in the actual (partial day) 3 the case where the mis-feed is not the last item in actual 4 the case where the actual matches the plan (no mis-feed) 5 the case where the mis-feed is a shortage (underfed) 6 the case where the mis-feed is an overage (overfed) 7 the case where multiple mis-feeds cancel out (not shown below) -=-=- Your example schedule and feed amounts C:\Users\Wulfraed\Documents\_Hg-Repositories\REXX>rexx feedme.rex Enter planned feeding schedule (feed units for each time period, space separated) 150 100 30 30 30 20 20 10 5 5 Enter actual feeding schedule up to current feed period 150 60 PLAN: 10 time periods 400 total feed units ACTUAL : 2 time periods 210 total feed units dispensed MIS-FEED: 40 underfed SCHEDULE: 150 60 39 38 38 25 25 13 6 6 -=-=- Same, but the mis-feed was not discovered until after the 3rd period C:\Users\Wulfraed\Documents\_Hg-Repositories\REXX>rexx feedme.rex Enter planned feeding schedule (feed units for each time period, space separated) 150 100 30 30 30 20 20 10 5 5 Enter actual feeding schedule up to current feed period 150 60 30 PLAN: 10 time periods 400 total feed units ACTUAL : 3 time periods 240 total feed units dispensed MIS-FEED: 40 underfed SCHEDULE: 150 60 30 40 40 27 27 13 7 6 -=-=- An example were the mis-feed was in the other direction C:\Users\Wulfraed\Documents\_Hg-Repositories\REXX>rexx feedme.rex Enter planned feeding schedule (feed units for each time period, space separated) 150 100 30 30 30 20 20 10 5 5 Enter actual feeding schedule up to current feed period 150 120 PLAN: 10 time periods 400 total feed units ACTUAL : 2 time periods 270 total feed units dispensed MIS-FEED: 20 overfed SCHEDULE: 150 120 27 26 26 17 17 9 4 4 -=-=- Finally, an example where there was no mis-feed C:\Users\Wulfraed\Documents\_Hg-Repositories\REXX>rexx feedme.rex Enter planned feeding schedule (feed units for each time period, space separated) 150 100 30 30 30 20 20 10 5 5 Enter actual feeding schedule up to current feed period 150 100 PLAN: 10 time periods 400 total feed units ACTUAL : 2 time periods 250 total feed units dispensed MIS-FEED: 0 on schedule C:\Users\Wulfraed\Documents\_Hg-Repositories\REXX> -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list
All permutations from 2 lists
If I have 2 lists, e.g.: os = ["Linux","Windows"] region = ["us-east-1", "us-east-2"] How can I get a list of tuples with all possible permutations? So for this example I'd want: [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", "us-east-1"), "Windows", "us-east-2')] The lists can be different lengths or can be 0 length. Tried a few different things with itertools but have not got just what I need. TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On 2022-03-01 at 19:12:10 -0500, Larry Martell wrote: > If I have 2 lists, e.g.: > > os = ["Linux","Windows"] > region = ["us-east-1", "us-east-2"] > > How can I get a list of tuples with all possible permutations? > > So for this example I'd want: > > [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > "us-east-1"), "Windows", "us-east-2')] > > The lists can be different lengths or can be 0 length. Tried a few > different things with itertools but have not got just what I need. [(o, r) for o in os for r in region] Feel free to import itertools, but it's not really necessary. ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
I would not use `os` as an identifier, as it is the name of an important built-in module. I think itertools.product is what you need. Example program: import itertools opsys = ["Linux","Windows"] region = ["us-east-1", "us-east-2"] print(list(itertools.product(opsys, region))) Output: [('Linux', 'us-east-1'), ('Linux', 'us-east-2'), ('Windows', 'us-east-1'), ('Windows', 'us-east-2')] itertools.product returns an iterator (or iterable, I'm not sure of the correct technical term). If you only want to use the result once you can write e.g. for ops, reg in itertools.product(opsys, region): etc. If you need it more than once, you can convert it to a list (or tuple), as above. Best wishes Rob Cliffe On 02/03/2022 00:12, Larry Martell wrote: If I have 2 lists, e.g.: os = ["Linux","Windows"] region = ["us-east-1", "us-east-2"] How can I get a list of tuples with all possible permutations? So for this example I'd want: [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", "us-east-1"), "Windows", "us-east-2')] The lists can be different lengths or can be 0 length. Tried a few different things with itertools but have not got just what I need. TIA! -- https://mail.python.org/mailman/listinfo/python-list