[Python-ideas] Re: Add symlinks option at shutil.move parameters
Well, I suppose it wants simlink=False. Anyway, why not change the signature of move to def move(src, dst, **kwargs): and change the call of copytree to copytree(src, real_dst, **kwargs) ? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ALEUCO7GE2RIFJ3CT2PQEYLO4F7BLZIK/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Segmentation of string
import itertools as itools def segment(it, n=1): try: len_it = len(it) it_true = it except TypeError: it_true = tuple(it) len_it = len(it_true) size, rest = divmod(len_it, n) sizes = [size] * n for i in range(rest): sizes[-i] += 1 all_sizes = frozenset(itools.permutations(sizes)) res = [] for sizes in all_sizes: elem = [] i = 0 for size in sizes: elem.append(it[i:i+size]) i += size res.append(elem) return res ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7O64PBAIPITLTO32ZCIGPL2STKEGNQW4/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Segmentation of string
Excuse me, ignore my previous post, this is the correct implementation. It works for every iterable: import itertools as itools def segment(it, n=1): if n < 1: raise ValueError(f"Number of segment must be > 0") try: len_it = len(it) it[0:0] it_true = it except TypeError: it_true = tuple(it) len_it = len(it_true) if len_it < n: raise ValueError(f"Iterable length {len_it} must be greater than number of segments {n}") size, rest = divmod(len_it, n) sizes = [size] * n orig_sizes = sizes.copy() all_sizes = [] for i in range(1, rest+1): for j in range(1, rest-i+2): sizes[-j] += i all_sizes.append(frozenset(itools.permutations(sizes))) sizes = orig_sizes.copy() if not all_sizes: all_sizes.append((sizes, )) res = [] for perm_sizes in all_sizes: for sizes in perm_sizes: elem = [] i = 0 for size in sizes: elem.append(it_true[i:i+size]) i += size res.append(elem) return res ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/E452LQGA3XKU5ADPTG54XP36ENXDZN2B/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"
There's already: for i in range(j): if i > 5: ... else: ... else: ... ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/3HHT4L3A4PMAABPIWG6JJMGQCJFPACGC/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Segmentation of string
See my implementation, is generic and not only for strings. It could be added to more-itertools, I suppose: https://mail.python.org/archives/list/python-ideas@python.org/message/E452LQGA3XKU5ADPTG54XP36ENXDZN2B/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TOCNFSPMUZSCFZCUEXMAOYEDYS65UDQH/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Segmentation of string
Excuse me again, I just relized that my algorithm was flawed. I just inserted in my function the brilliant algorithm of Mark Dickinson and now it works: import itertools as itools def segment(it, n=1): if n < 1: raise ValueError(f"Number of segment must be > 0, {n} found") try: len_it = len(it) it[0:0] it_true = it except TypeError: it_true = tuple(it) len_it = len(it_true) if len_it < n: err = f"Iterable length {len_it} must be greater than number of segments {n}" raise ValueError(err) return ( [it_true[i:j] for i, j in zip((0, ) + startends, startends + (len_it, ))] for startends in itools.combinations(range(1, len_it), n-1) ) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KYMYVYHLILBWOSQ4LSVBWON723HJKH3D/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)
If I can spend my two cents, I think the fact the most of you prefer | is because is already how sets works. And IMHO it's a bit illogical, since sets also support -. So I do not understand why | was chosen instead of +. Furthermore, sets supports < operator, that gives you the false hope that sets can be sorted. But it's not. So I don't think sets are *not* a good example. On the contrary, I feel so **natural** to see dict1 + dict2. Furthermore, the problem is: what is better for generic functions? Maybe I need a generic function that, in its code, do also a sum of input objects. Maybe I want to support also dict. In this way writing such function is much more hard. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/GAXPZEUWV2R6LTOD4GKDOIKQRIGNSJWN/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Renaming json.load()
Well, `json` and the other modules could add another standard: `serialize` and `deserialize` As an example, this is how I deserialize from a custom class: def __init__(self, source): path = None try: # most common case: JSON string self._data_raw = json.loads(source) except TypeError: try: # check if it's a dict-like object source.items self._data_raw = copy.deepcopy(source) except AttributeError: try: # maybe a file object? self._data_raw = json.load(f) except AttributeError: # maybe a PathLike? path = source except JSONDecodeError: # maybe a path string? path = source if path: with open(path) as f: self._data_raw = json.load(f) Apart the `dict` check, this logic could be applied to a `json.deserialize()` function. Python let you function overloading more simple, so why not use it? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6KZ54WSNMPB3PQELLDZAQ27SLSJPEVNS/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)
Andrew Barnert wrote: > On Dec 25, 2019, at 14:57, python-ideas--- via Python-ideas > python-ideas@python.org wrote: > > If I can spend my two cents, I think the fact the > > most of you prefer | is because is already how sets works. And IMHO it's a > > bit illogical, > > since sets also support -. So I do not understand why | was chosen instead > > of +. > First, what does it matter that sets support -? You could just as well argue > that > + for list and str is illogical because int supports - and they don’t. Subtracting two lists or two strings has no sense, so the comparison is unfair. On the contrary, on sets you can apply union *and* difference. And since union seems the exact contrary of difference, it's illogical that | is used instead of +. That said, the set API at this point is consolidated. My only hope is Python does not make the same errors with `dict` or any other type. > (Although really, I think “illogical” is a strange claim to make for any > option here. It’s > logical to spell the union of two dicts the same way you spell the union of > two sets See above... > Of course you have to be careful because it’s only a partial order, and > sorting sets > that aren’t comparable is usually meaningless Indeed, what a coder really need is a isstrictsubset() method, not <. Since set1 < set2 has sense, but sorted(sets) have not. So it was better to have set1.isstrictsubset(set2) and **no** <. But, as I said, the ship was sailed for sets. > What kind of code needs to “sum” generic things that might be dicts and might > be > lists, when they mean such different things? Now I can't think about any practical example. Anyway, generally speaking, Python is full of functions that can be applied to completely different objects, just because the API is identical. If it quacks... > And why doesn’t this code also need to sum sets? Who said it does not need? It will be simply more convoluted. So I hope, again, this does not happen to `dict` too. > What’s special and common to numbers, timediffs, sequences, and dicts. but > not sets, tries, and datetimes? Well, because summing 2 datetimes has no sense? About tries, I don't remember tries in the stdlib. If so, it's OT. > Also, the PEP explicitly says that it’s not ruling out adding all of the set > operators, > just deferring it to a separate PEP to be written (and accepted or rejected) > in the > future. ...I'm not asking to support other operators and I don't really know why you think so. > you seem to have configured your python-ideas-posting address > with the name “python-ideas” rather than with a name that can be used to > distinguish you > from other people. This will make conversations confusing. it's python-ideas@***marco.sulla.e4ward.com ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/3MR4NMJO6SBG3JMGDE4PN74AAKIRAJKW/ Code of Conduct: http://python.org/psf/codeofconduct/