comprehension parsing
The two comprehensions: all((srt(n, m) in c_np) == (srt(a, b) in c_ap) for (m, b) in na) all( srt(n, m) in c_np == srt(a, b) in c_ap for (m, b) in na) parse differently but I am unclear what the second one produces since I thought it would be the same as the first. Any ideas how the second one parses? -- https://mail.python.org/mailman/listinfo/python-list
Re: comprehension parsing
On Saturday, 5 November 2022 at 16:06:52 UTC, cactus wrote: I should have quoted the full comprehensions: all((srt(m, n) in c_np) == (srt(a, b) in c_ap) for (m, a), (n, b) in combinations(na8, 2)) all( srt(m, n) in c_np == srt(a, b) in c_ap) for (m, a), (n, b) in combinations(na8, 2)) -- https://mail.python.org/mailman/listinfo/python-list
Re: Does os.path relpath produce an incorrect relative path?
On Thursday, 25 May 2023 at 17:57:21 UTC+1, MRAB wrote: > On 2023-05-25 16:53, Eryk Sun wrote: > > On 5/25/23, BlindAnagram wrote: > >> > >> vcx_path = 'C:\\build.vs22\\lib\\lib.vcxproj' > >> src_path = 'C:\\lib\\src\\' > >> rel_path = '..\\..\\..\\lib\\src' > >> > >> [snip] > >> > >> The first of these three results produces an incorrect relative path > >> because relpath does not strip off any non-directory tails before > >> comparing paths. > > > > The start path is assumed to be a directory, which defaults to the > > current working directory, and the input paths are first resolved as > > absolute paths. In order to reach src_path from vcx_path, one has to > > traverse 3 levels up to the root directory. > > > > https://docs.python.org/3/library/os.path.html#os.path.relpath > Well, it's not necessarily the optimal relative path, because it's not > always necessary to go all the way up to the root, as in the first example. Thanks to all for their comments. I was hoping that there would be an direct way in Python to find a relative path between two paths in which the convention is that all directories end with '\\' so that it is possible to distinguish the 'tail' references to files as not part of the path comparison. But I will just have to remember to strip the file tails myself. Surprisingly (for me at least) the alternative provided by the pathlib module 'relative_to' method doesn't provide for full relative path computation. I was expecting this would offer everything that os.path offers but it doesn't in this case. Brian -- https://mail.python.org/mailman/listinfo/python-list
Declaring variables from a list
Hi, If I got a list is it possible to declare a variable from the items in that list? Code Sample: Blob = ['Var1', 'Var2', 'vAR3'] i = 5 for listitems in Blob: i += 1 listitems = i print Var1 6 print Var2 7 print vAR3 8 Something like that? This doesn't work (obviously) but is there a way to do this? TIA, Cacti -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > "Cactus" wrote: > > > If I got a list is it possible to declare a variable from the items in that > > list? > > > > Code Sample: > > Blob = ['Var1', 'Var2', 'vAR3'] > > i = 5 > > for listitems in Blob: > >i += 1 > >listitems = i > > > > print Var1 > > 6 > > print Var2 > > 7 > > print vAR3 > > 8 > > > > > Something like that? This doesn't work (obviously) but is there a way to do > > this? > > why? > > if you want a dictionary, use a dictionary (see the tutorial for details). > > Thanks, I'll look in to that. Seems like that will work Cacti -- http://mail.python.org/mailman/listinfo/python-list