From nik at naturalnet.de Sun Apr 1 02:22:51 2018 From: nik at naturalnet.de (Dominik George) Date: Sun, 1 Apr 2018 08:22:51 +0200 Subject: GPG signatures invisible in new PyPI (was: Re: new Python Package Index is now in beta at pypi.org) In-Reply-To: <3226c38e-c423-3e95-7219-0da10e14d8cf@changeset.nyc> References: <20180326195115.32277.53743@mail.python.org> <20180331222647.GH2559@portux.lan.naturalnet.de> <3226c38e-c423-3e95-7219-0da10e14d8cf@changeset.nyc> Message-ID: <20180401062251.GA10210@portux.lan.naturalnet.de> Hi Sumana, > I've been trying to reach out to the Debian Python community via IRC, > personal connections, tickets, and mailing lists to ensure a smooth > transition; I see now that a post I tried to get onto the debian-python > list a few weeks ago did not get posted there, so I've re-sent it. I'm > sorry that this is (I infer) the first you're hearing about this change. Thank you ?! I see that the discussion there now has started. Cheers, Nik -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 902 bytes Desc: not available URL: From p.f.moore at gmail.com Sun Apr 1 06:24:16 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 1 Apr 2018 11:24:16 +0100 Subject: Beta release of pip version 10 In-Reply-To: <9ed81c44-d550-70aa-3983-27f120f910c2@mrabarnett.plus.com> References: <9ed81c44-d550-70aa-3983-27f120f910c2@mrabarnett.plus.com> Message-ID: On 1 April 2018 at 03:16, MRAB wrote: > On 2018-04-01 02:50, Mikhail V wrote: >> >> Steven D'Aprano writes: >> >>>> >>>> PS: was looking forward to PIP improvements on Windows, on 9.0.3 still >>>> some issues. E.g. trying to redirect output from 'pip search ... > >>>> a.txt' gives a wall of errors. it's on Windows 10. >>> >>> >>> >>> >>> Don't be shy, tell us what those errors are. >> >> >> >> You meant - don't be lazy to figure out how to reproduce it. >> >> UnicodeEncodeError: 'charmap' codec can't encode character >> >> when it meets a non-ascii char. >> >> e.g. tried this: >> pip search pygame > a.txt >> > Well, _I_ didn't get an error! > > One of the lines is: > > kundalini (0.4) - L?VE-like PyGame API > > So it's down to what system encoding (active code page) is in use. As noted in the announcement, please feel free to report the issue. We fixed a lot of encoding errors for pip 10, but it's quite possible that we missed this as no-one reported it. We'll need clear instructions on how to reproduce it, as it doesn't fail for me (Windows 10, pip 10.0.0b1, Python 3.6, Powershell shell): >py -m pip search kundalini kundalini (0.4) - L?VE-like PyGame API Paul From p.f.moore at gmail.com Sun Apr 1 06:26:28 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 1 Apr 2018 11:26:28 +0100 Subject: Beta release of pip version 10 In-Reply-To: References: Message-ID: On 1 April 2018 at 04:15, Mikhail V wrote: > MRAB writes: > > >> > UnicodeEncodeError: 'charmap' codec can't encode character >> > >> > when it meets a non-ascii char. >> > >> > e.g. tried this: >> > pip search pygame > a.txt >> > >> Well, _I_ didn't get an error! >> >> One of the lines is: >> >> kundalini (0.4) - L?VE-like PyGame API >> >> So it's down to what system encoding (active code page) is in use. > > Dunno, it gives me error regardless of active codepage, > my default is 866, i've set to 1252 or 65001, same error. > > The output itself is fine - I see correct glyphs, so the error > only appears when I redirect to file. > if I try some python script e.g. "a.py": > print ("???") > > and run: > py a.py > a.txt > > I get some gibberish in the file. > So it is probably a global issue. Nothing works in this life :) That actually sounds more like a redirection issue. Redirecting in the cmd shell uses the OEM codepage, I believe, and Python outputs to a pipe using the ANSI codepage, IIRC (I'd have to check to be certain). Paul From rustompmody at gmail.com Sun Apr 1 13:03:09 2018 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 1 Apr 2018 10:03:09 -0700 (PDT) Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: > On 30/03/2018 21:13, C W wrote: > > Hello all, > > > > I want to create a dictionary. > > > > The keys are 26 lowercase letters. The values are 26 uppercase letters. > > > > The output should look like: > > {'a': 'A', 'b': 'B',...,'z':'Z' } > > > I know I can use string.ascii_lowercase and string.ascii_uppercase, but how > > do I use it exactly? > > I have tried the following to create the keys: > > myDict = {} > > for e in string.ascii_lowercase: > > myDict[e]=0 > > If the input string S is "cat" and the desired output is {'c':'C', > 'a':'A', 't':'T'}, then the loop might look like this: > > D = {} > for c in S: > D[c] = c.upper() > > print (D) > > Output: > > {'c': 'C', 'a': 'A', 't': 'T'} As does? >>> {c: c.upper() for c in s} {'a': 'A', 'c': 'C', 't': 'T'} : dict [Recent pythons; not sure when dict-comprehensions appeared] From rosuav at gmail.com Sun Apr 1 13:13:15 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2018 03:13:15 +1000 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: On Mon, Apr 2, 2018 at 3:03 AM, Rustom Mody wrote: > On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: >> On 30/03/2018 21:13, C W wrote: >> > Hello all, >> > >> > I want to create a dictionary. >> > >> > The keys are 26 lowercase letters. The values are 26 uppercase letters. >> > >> > The output should look like: >> > {'a': 'A', 'b': 'B',...,'z':'Z' } >> >> > I know I can use string.ascii_lowercase and string.ascii_uppercase, but how >> > do I use it exactly? >> > I have tried the following to create the keys: >> > myDict = {} >> > for e in string.ascii_lowercase: >> > myDict[e]=0 >> >> If the input string S is "cat" and the desired output is {'c':'C', >> 'a':'A', 't':'T'}, then the loop might look like this: >> >> D = {} >> for c in S: >> D[c] = c.upper() >> >> print (D) >> >> Output: >> >> {'c': 'C', 'a': 'A', 't': 'T'} > > As does? >>>> {c: c.upper() for c in s} > {'a': 'A', 'c': 'C', 't': 'T'} : dict > > [Recent pythons; not sure when dict-comprehensions appeared] 3.0, and also backported to 2.7. So go ahead and use 'em. https://www.python.org/dev/peps/pep-0274/ ChrisA From arek.bulski at gmail.com Sun Apr 1 13:55:51 2018 From: arek.bulski at gmail.com (Arkadiusz Bulski) Date: Sun, 01 Apr 2018 17:55:51 +0000 Subject: check if bytes is all nulls Message-ID: What would be the most performance efficient way of checking if a bytes is all zeros? Currently its `key == b'\x00' * len(key)` however, because its Python 2/3 compatible: sum(key) == 0 is invalid key == bytes(len(key)) is invalid I already considered precomputing the rhs value. Length of key is unknown, could be few bytes, could be megabytes. -- ~ Arkadiusz Bulski From python at mrabarnett.plus.com Sun Apr 1 14:04:30 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 1 Apr 2018 19:04:30 +0100 Subject: Beta release of pip version 10 In-Reply-To: References: Message-ID: <045ba7ad-dcfe-cbc5-7417-fab846a7be91@mrabarnett.plus.com> On 2018-04-01 11:26, Paul Moore wrote: > On 1 April 2018 at 04:15, Mikhail V wrote: >> MRAB writes: >> >> >>> > UnicodeEncodeError: 'charmap' codec can't encode character >>> > >>> > when it meets a non-ascii char. >>> > >>> > e.g. tried this: >>> > pip search pygame > a.txt >>> > >>> Well, _I_ didn't get an error! >>> >>> One of the lines is: >>> >>> kundalini (0.4) - L?VE-like PyGame API >>> >>> So it's down to what system encoding (active code page) is in use. >> >> Dunno, it gives me error regardless of active codepage, >> my default is 866, i've set to 1252 or 65001, same error. >> >> The output itself is fine - I see correct glyphs, so the error >> only appears when I redirect to file. >> if I try some python script e.g. "a.py": >> print ("???") >> >> and run: >> py a.py > a.txt >> >> I get some gibberish in the file. >> So it is probably a global issue. Nothing works in this life :) > > That actually sounds more like a redirection issue. Redirecting in the > cmd shell uses the OEM codepage, I believe, and Python outputs to a > pipe using the ANSI codepage, IIRC (I'd have to check to be certain). > Yep, it's fine until redirected. From arek.bulski at gmail.com Sun Apr 1 14:04:40 2018 From: arek.bulski at gmail.com (Arkadiusz Bulski) Date: Sun, 01 Apr 2018 18:04:40 +0000 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: Some interesting timeits: In [7]: timeit('sum(x)==0', 'x=bytes(10)') Out[7]: 0.30194770699927176 In [11]: timeit('x==bytes(10)', 'x=bytes(10)') Out[11]: 0.2181608650007547 In [12]: timeit('x==z*10', 'x=bytes(10); z=bytes(1)') Out[12]: 0.1092393600010837 In [13]: timeit('x==x2', 'x=bytes(10); z=bytes(1); x2=bytes(10)') Out[13]: 0.05795672599924728 niedz., 1 kwi 2018 o 19:55 u?ytkownik Arkadiusz Bulski < arek.bulski at gmail.com> napisa?: > What would be the most performance efficient way of checking if a bytes is > all zeros? Currently its `key == b'\x00' * len(key)` however, because its > Python 2/3 compatible: > > sum(key) == 0 is invalid > key == bytes(len(key)) is invalid > > I already considered precomputing the rhs value. > Length of key is unknown, could be few bytes, could be megabytes. > > -- > ~ Arkadiusz Bulski > -- ~ Arkadiusz Bulski From python at mrabarnett.plus.com Sun Apr 1 14:21:25 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 1 Apr 2018 19:21:25 +0100 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: On 2018-04-01 18:55, Arkadiusz Bulski wrote: > What would be the most performance efficient way of checking if a bytes is > all zeros? Currently its `key == b'\x00' * len(key)` however, because its > Python 2/3 compatible: > > sum(key) == 0 is invalid > key == bytes(len(key)) is invalid > > I already considered precomputing the rhs value. > Length of key is unknown, could be few bytes, could be megabytes. > Have you tried: not key.lstrip(b'\x00') ? (Although the result of the lstrip could be as long as the original.) Or: set(key) == set(b'\x00') ? (The set will never have more than 256 members.) From __peter__ at web.de Sun Apr 1 14:23:18 2018 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Apr 2018 20:23:18 +0200 Subject: check if bytes is all nulls References: Message-ID: Arkadiusz Bulski wrote: > What would be the most performance efficient way of checking if a bytes is > all zeros? Currently its `key == b'\x00' * len(key)` however, because its > Python 2/3 compatible: > > sum(key) == 0 is invalid > key == bytes(len(key)) is invalid > > I already considered precomputing the rhs value. > Length of key is unknown, could be few bytes, could be megabytes. Things you might try: data = ... bytes ... (1) not data.strip(b"\x00") Worst case: creates another len(data)-1 byte string (2) # preparation search = re.compile(b"[^\0x00]").search # actual check search(data) is not None From bc at freeuk.com Sun Apr 1 14:43:45 2018 From: bc at freeuk.com (bartc) Date: Sun, 1 Apr 2018 19:43:45 +0100 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: On 01/04/2018 18:55, Arkadiusz Bulski wrote: > What would be the most performance efficient way of checking if a bytes is > all zeros? Currently its `key == b'\x00' * len(key)` however, because its > Python 2/3 compatible: That doesn't too efficient, if you first have to construct a compatible object of all zeros. > sum(key) == 0 is invalid > key == bytes(len(key)) is invalid > > I already considered precomputing the rhs value. > Length of key is unknown, (So how can you precompute the table?) could be few bytes, could be megabytes. > How likely would be a block of all zeros? Or one that is all zeros but with a sparse smattering of non-zeros? If not very, then just check the bytes one by one. If non-zero, you will know as soon as you see the first non-zero byte, possibly the first one. def allzeros(a): for x in a: if x: return 0 return 1 -- bartc From kirillbalunov at gmail.com Sun Apr 1 15:03:06 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Sun, 1 Apr 2018 22:03:06 +0300 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: 2018-04-01 20:55 GMT+03:00 Arkadiusz Bulski : > What would be the most performance efficient way of checking if a bytes is > all zeros? Try `not any(key)` ;) With kind regards, -gdg From arek.bulski at gmail.com Sun Apr 1 15:14:05 2018 From: arek.bulski at gmail.com (Arkadiusz Bulski) Date: Sun, 01 Apr 2018 19:14:05 +0000 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: Thanks, timeit gives `not any(key)` same performance as `sum(key)==0`. niedz., 1 kwi 2018 o 21:03 u?ytkownik Kirill Balunov < kirillbalunov at gmail.com> napisa?: > 2018-04-01 20:55 GMT+03:00 Arkadiusz Bulski : > >> What would be the most performance efficient way of checking if a bytes is >> all zeros? > > > Try `not any(key)` ;) > > With kind regards, > -gdg > -- ~ Arkadiusz Bulski From kirillbalunov at gmail.com Sun Apr 1 15:15:15 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Sun, 1 Apr 2018 22:15:15 +0300 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: 2018-04-01 22:03 GMT+03:00 Kirill Balunov : > > > 2018-04-01 20:55 GMT+03:00 Arkadiusz Bulski : > >> What would be the most performance efficient way of checking if a bytes is >> all zeros? > > > Try `not any(key)` ;) > > Sorry, I don't timed it before I posted. In reality, it is far from the fastest, it is 10 times slower than `==`, but I like it:) With kind regards, -gdg From rosuav at gmail.com Sun Apr 1 15:18:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2018 05:18:31 +1000 Subject: check if bytes is all nulls In-Reply-To: References: Message-ID: On Mon, Apr 2, 2018 at 5:14 AM, Arkadiusz Bulski wrote: > Thanks, > timeit gives `not any(key)` same performance as `sum(key)==0`. Are you timing these on ten-byte keys, or really large keys? For short keys, just use whatever looks most elegant, and don't worry about performance. If the key is actually megabytes long (which seems unlikely, but you did mention it), do your timing tests on megabyte-long keys. ChrisA From __peter__ at web.de Sun Apr 1 15:20:30 2018 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Apr 2018 21:20:30 +0200 Subject: check if bytes is all nulls References: Message-ID: Arkadiusz Bulski wrote: > Thanks, > timeit gives `not any(key)` same performance as `sum(key)==0`. Then you did not feed it the "right" data $ python3 -m timeit -s 'key = b"x" + bytes(10**6)' 'sum(key)' 100 loops, best of 3: 15.7 msec per loop $ python3 -m timeit -s 'key = b"x" + bytes(10**6)' 'not any(key)' 10000000 loops, best of 3: 0.168 usec per loop While sum() always has to touch every byte any() can stop at the first non- nul byte. > niedz., 1 kwi 2018 o 21:03 u?ytkownik Kirill Balunov < > kirillbalunov at gmail.com> napisa?: > >> 2018-04-01 20:55 GMT+03:00 Arkadiusz Bulski : >> >>> What would be the most performance efficient way of checking if a bytes >>> is all zeros? >> >> >> Try `not any(key)` ;) From davidfstr at gmail.com Sun Apr 1 17:24:38 2018 From: davidfstr at gmail.com (David Foster) Date: Sun, 1 Apr 2018 14:24:38 -0700 (PDT) Subject: Why is the use of an undefined name not a syntax error? Message-ID: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify which names are not valid. If broken name references were detected at compile time, it would eliminate a huge class of errors before running the program: missing imports, call of misspelled top-level function, reference to misspelled local variable. Of course running a full typechecker like mypy would eliminate more errors like misspelled method calls, type mismatch errors, etc. But if it is cheap to detect a wide variety of name errors at compile time, is there any particular reason it is not done? - David P.S. Here are some uncommon language features that interfere with identifying all valid names. In their absence, one might expect an invalid name to be a syntax error: * import * * manipulating locals() or globals() * manipulating a frame object * eval From rosuav at gmail.com Sun Apr 1 17:38:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2018 07:38:07 +1000 Subject: Why is the use of an undefined name not a syntax error? In-Reply-To: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: > My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify which names are not valid. > It's not as simple as you think. Here's a demo. Using all of the information available to the compiler, tell me which of these names are valid and which are not: import sys def search_file(fn): with open(fn) as f: for line in f: if "spam" in line and len(line) < 80: print("Mmmm delicious spam") if __name__ == "__main__": try: search_file(sys.argv[1]) except IndexError: print("Please provide a file name", file=sys.stderr) except FileNotFoundError: print("File not found", file=sys.stderr) except OSError as Exception: print("Error %d reading file: %s" % (Exception.errno, Exception.strerror)) except Exception: print("Something else went wrong:") import traceback traceback.print_exc() finally: print("Goodbye.") Okay. Reckon you got them all? Look again there's probably at least one sneaky one that you missed. List them for me, and tell me what's valid and what's not. ChrisA From jeanpierreda at gmail.com Sun Apr 1 17:40:22 2018 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 1 Apr 2018 14:40:22 -0700 Subject: Why is the use of an undefined name not a syntax error? In-Reply-To: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: > But if it is cheap to detect a wide variety of name errors at compile time, is there any particular reason it is not done? >From my perspective, it is done, but by tools that give better output than Python's parser. :) Linters (like pylint) are better than syntax errors here, because they collect all of the undefined variables, not just the first one. Maybe Python could/should be changed to give more detailed errors of this kind as well. e.g. Clang parse errors for C and C++ are much more thorough and will report all of your typos, not just the first one. > P.S. Here are some uncommon language features that interfere with identifying all valid names. In their absence, one might expect an invalid name to be a syntax error: Also, if statements, depending on what you mean by "invalid": def foo(x): if x: y = 3 return y # will raise UnboundLocalError if not x -- Devin From jeanpierreda at gmail.com Sun Apr 1 18:05:43 2018 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 1 Apr 2018 15:05:43 -0700 Subject: Why is the use of an undefined name not a syntax error? In-Reply-To: References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: On Sun, Apr 1, 2018 at 2:38 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: >> My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify which names are not valid. >> > > It's not as simple as you think. Here's a demo. Using all of the > information available to the compiler, tell me which of these names > are valid and which are not: This feels like browbeating to me. Just because a programmer finds it hard to figure out manually, doesn't mean a computer can't do it automatically. And anyway, isn't the complexity of reviewing such code an argument in favor of automatic detection, rather than against? For example, whether or not "except Exception:" raises an error depends on what kind of scope we are in and what variable declarations exist in this scope (in a global or class scope, all lookups are dynamic and go up to the builtins, whereas in a function body this would have resulted in an unbound local exception because it uses fast local lookup). What a complex thing. But easy for a computer to detect, actually -- it's right in the syntax tree (and bytecode) what kind of lookup it is, and what paths lead to defining it, and a fairly trivial control flow analysis would discover if it will always, never, or sometimes raise a NameError -- in the absence of "extreme dynamism" like mutating the builtins and so on. :( Unfortunately, the extreme dynamism can't really be eliminated as a possibility, and there's no rule that says "just because this will always raise an exception, we can fail at compile-time instead". Maybe a particular UnboundLocalError was on purpose, after all. Python doesn't know. So probably this can't ever sensibly be a compile error, even if it's a fantastically useful lint warning. -- Devin From rosuav at gmail.com Sun Apr 1 18:16:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2018 08:16:33 +1000 Subject: Why is the use of an undefined name not a syntax error? In-Reply-To: References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: On Mon, Apr 2, 2018 at 8:05 AM, Devin Jeanpierre wrote: > On Sun, Apr 1, 2018 at 2:38 PM, Chris Angelico wrote: >> On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: >>> My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify which names are not valid. >>> >> >> It's not as simple as you think. Here's a demo. Using all of the >> information available to the compiler, tell me which of these names >> are valid and which are not: > > This feels like browbeating to me. Just because a programmer finds it > hard to figure out manually, doesn't mean a computer can't do it > automatically. And anyway, isn't the complexity of reviewing such code > an argument in favor of automatic detection, rather than against? Nope, I'm pointing out that it's basically impossible. How can you know at compile time which names are going to be accessible via builtins? It can change. Now, you might say "assume the default set of builtins", and that's fine for a linter; but if you raise a compile-time SyntaxError for it, you'll break perfectly valid code. > For example, whether or not "except Exception:" raises an error > depends on what kind of scope we are in and what variable declarations > exist in this scope (in a global or class scope, all lookups are > dynamic and go up to the builtins, whereas in a function body this > would have resulted in an unbound local exception because it uses fast > local lookup). What a complex thing. But easy for a computer to > detect, actually -- it's right in the syntax tree (and bytecode) what > kind of lookup it is, and what paths lead to defining it, and a fairly > trivial control flow analysis would discover if it will always, never, > or sometimes raise a NameError -- in the absence of "extreme dynamism" > like mutating the builtins and so on. :( > > Unfortunately, the extreme dynamism can't really be eliminated as a > possibility, and there's no rule that says "just because this will > always raise an exception, we can fail at compile-time instead". Maybe > a particular UnboundLocalError was on purpose, after all. Python > doesn't know. So probably this can't ever sensibly be a compile > error, even if it's a fantastically useful lint warning. Yep, exactly. There is no way that you can codify this into an *error*. The set of builtins can change at run-time, and even if you don't actually mutate builtins directly, they can certainly be added and removed between Python versions. And *because* they can change between versions, it's perfectly plausible to have version compatibility shims injected when you're running on an older version. The job of statically recognizing misspelled variable names is best done by a linter, not the language compiler. A linter can do more than the compiler itself can, including checking the file system and saying "probable missed import" if it finds that the name corresponds to a module, or noticing "unused local variable" and "unrecognized global" and suggesting that one of them is misspelled. ChrisA From ben.usenet at bsb.me.uk Sun Apr 1 19:32:46 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 02 Apr 2018 00:32:46 +0100 Subject: Why is the use of an undefined name not a syntax error? References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: <87in9asdsx.fsf@bsb.me.uk> David Foster writes: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which > names correspond to local variables in functions. That suggests it has > enough information to identify all valid names in a .py file and in > particular to identify which names are not valid. > > If broken name references were detected at compile time, it would > eliminate a huge class of errors before running the program: missing > imports, call of misspelled top-level function, reference to > misspelled local variable. I'm not sure what you mean by "valid name" and "broken name references". The usual error is about unbound names, and binding happens at run-time. Consider this rather contrived example: def g(a): if f1(a): x = a else: y = 2*a return x+1 if f2(a) else y+1 ('a' is there only to prevent some obvious optimisations.) Are there any broken name references here? You might get an UnboundLocalError, though that depends on what f1 and f2 return. -- Ben. From tmrsg11 at gmail.com Sun Apr 1 20:52:35 2018 From: tmrsg11 at gmail.com (C W) Date: Sun, 1 Apr 2018 20:52:35 -0400 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: Thank you all for the response. What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the values are shift by one position. key: abcdefghijklmnopqrstuvwxyz value: BCDEFGHIJKLMNOPQRSTUVWXYZA Can I fill in a key and its corresponding value simultaneously on the fly? Something in the following structure. myDict = {} for i in range(26): myDict[lowercase] = uppercase Thank you! On Sun, Apr 1, 2018 at 1:13 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 3:03 AM, Rustom Mody wrote: > > On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: > >> On 30/03/2018 21:13, C W wrote: > >> > Hello all, > >> > > >> > I want to create a dictionary. > >> > > >> > The keys are 26 lowercase letters. The values are 26 uppercase > letters. > >> > > >> > The output should look like: > >> > {'a': 'A', 'b': 'B',...,'z':'Z' } > >> > >> > I know I can use string.ascii_lowercase and string.ascii_uppercase, > but how > >> > do I use it exactly? > >> > I have tried the following to create the keys: > >> > myDict = {} > >> > for e in string.ascii_lowercase: > >> > myDict[e]=0 > >> > >> If the input string S is "cat" and the desired output is {'c':'C', > >> 'a':'A', 't':'T'}, then the loop might look like this: > >> > >> D = {} > >> for c in S: > >> D[c] = c.upper() > >> > >> print (D) > >> > >> Output: > >> > >> {'c': 'C', 'a': 'A', 't': 'T'} > > > > As does? > >>>> {c: c.upper() for c in s} > > {'a': 'A', 'c': 'C', 't': 'T'} : dict > > > > [Recent pythons; not sure when dict-comprehensions appeared] > > 3.0, and also backported to 2.7. So go ahead and use 'em. > > https://www.python.org/dev/peps/pep-0274/ > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Sun Apr 1 21:13:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Apr 2018 01:13:49 +0000 (UTC) Subject: check if bytes is all nulls References: Message-ID: On Sun, 01 Apr 2018 19:14:05 +0000, Arkadiusz Bulski wrote: > Thanks, > timeit gives `not any(key)` same performance as `sum(key)==0`. Have you considered what happens when the key is *not* all zeroes? key = b'\x11'*1000000 any(key) bails out on the first byte. sum(key) has to add a million values. -- Steve From tmrsg11 at gmail.com Sun Apr 1 21:34:05 2018 From: tmrsg11 at gmail.com (C W) Date: Sun, 1 Apr 2018 21:34:05 -0400 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: A different but related question: myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, string.ascii_lowercase + string.ascii_uppercase)) >myDict {'A': 'A', 'B': 'B', 'C': 'C',...,'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z'} Why are the keys sorted from upper case to lower case? I asked for lower case first, then upper case. On Sun, Apr 1, 2018 at 8:52 PM, C W wrote: > Thank you all for the response. > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > values are shift by one position. > > key: abcdefghijklmnopqrstuvwxyz > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > Can I fill in a key and its corresponding value simultaneously on the fly? > > Something in the following structure. > > myDict = {} > for i in range(26): > myDict[lowercase] = uppercase > > Thank you! > > On Sun, Apr 1, 2018 at 1:13 PM, Chris Angelico wrote: > >> On Mon, Apr 2, 2018 at 3:03 AM, Rustom Mody >> wrote: >> > On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: >> >> On 30/03/2018 21:13, C W wrote: >> >> > Hello all, >> >> > >> >> > I want to create a dictionary. >> >> > >> >> > The keys are 26 lowercase letters. The values are 26 uppercase >> letters. >> >> > >> >> > The output should look like: >> >> > {'a': 'A', 'b': 'B',...,'z':'Z' } >> >> >> >> > I know I can use string.ascii_lowercase and string.ascii_uppercase, >> but how >> >> > do I use it exactly? >> >> > I have tried the following to create the keys: >> >> > myDict = {} >> >> > for e in string.ascii_lowercase: >> >> > myDict[e]=0 >> >> >> >> If the input string S is "cat" and the desired output is {'c':'C', >> >> 'a':'A', 't':'T'}, then the loop might look like this: >> >> >> >> D = {} >> >> for c in S: >> >> D[c] = c.upper() >> >> >> >> print (D) >> >> >> >> Output: >> >> >> >> {'c': 'C', 'a': 'A', 't': 'T'} >> > >> > As does? >> >>>> {c: c.upper() for c in s} >> > {'a': 'A', 'c': 'C', 't': 'T'} : dict >> > >> > [Recent pythons; not sure when dict-comprehensions appeared] >> >> 3.0, and also backported to 2.7. So go ahead and use 'em. >> >> https://www.python.org/dev/peps/pep-0274/ >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From rosuav at gmail.com Sun Apr 1 21:38:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Apr 2018 11:38:08 +1000 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: On Mon, Apr 2, 2018 at 11:34 AM, C W wrote: > A different but related question: > > myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, > string.ascii_lowercase + string.ascii_uppercase)) >>myDict > {'A': 'A', 'B': 'B', 'C': 'C',...,'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z'} > > Why are the keys sorted from upper case to lower case? I asked for lower > case first, then upper case. > What version of which Python interpreter are you using? Dictionaries aren't sorted by definition, but sometimes they do retain order. ChrisA From tmrsg11 at gmail.com Sun Apr 1 21:47:14 2018 From: tmrsg11 at gmail.com (C W) Date: Sun, 1 Apr 2018 21:47:14 -0400 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: I am using Python 3.6. I ran the those lines and got a sorted dictionary by keys. On Sun, Apr 1, 2018 at 9:38 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 11:34 AM, C W wrote: > > A different but related question: > > > > myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, > > string.ascii_lowercase + string.ascii_uppercase)) > >>myDict > > {'A': 'A', 'B': 'B', 'C': 'C',...,'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z'} > > > > Why are the keys sorted from upper case to lower case? I asked for lower > > case first, then upper case. > > > > What version of which Python interpreter are you using? Dictionaries > aren't sorted by definition, but sometimes they do retain order. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Sun Apr 1 22:00:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Apr 2018 02:00:10 +0000 (UTC) Subject: Why is the use of an undefined name not a syntax error? References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: On Sun, 01 Apr 2018 14:24:38 -0700, David Foster wrote: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which names > correspond to local variables in functions. That suggests it has enough > information to identify all valid names in a .py file and in particular > to identify which names are not valid. Not even close. The bottom line is, the Python core developers don't want to spent their time writing and maintaining what is effectively a linter. Python is run by a small team of volunteers with relatively little funding, and there are far more important things for them to work on than duplicating the work done by linters. If you want something to check your code ahead of time for undefined names, then run a linter: you have many to choose from. But even if they were prepared to do so, it isn't as easy or cheap as you think. This sort of analysis works for local variables because Python has decided on the rule that *any* binding operation to a local name in a function makes it a local, regardless of whether that binding operation would actually be executed or not. So: def function(): len return None if False: len = len fails with UnboundLocalError. That's the rule for functions, and it is deliberately made more restrictive than for Python code outside of functions as a speed optimization. (In Python 3, the rule is more restrictive than for Python 2: star imports inside functions and unqualified exec are forbidden too.) But it doesn't work for globals unless you make unjustifiable (for the compiler) assumptions about what code contains, or do an extremely expensive whole-application analysis. For example, here's a simple, and common, Python statement: import math Can you tell me what global names that line will add to your globals? If you said only "math", then you're guilty of making those unjustifiable assumptions. Of course, for *sensible* code, that will be the only name added, but the compiler shouldn't assume the code is sensible. Linters can, but the compiler shouldn't. The imported module is not necessarily the standard library `math` module, it could be a user-defined module shadowing it. That module could have side-effects, and those side-effects could include populating the current module (not the fake `math`) with any number of globals, or adding/deleting names from the builtins. So the instant you import a module, in principle you no longer know the state of globals. Of course, in practice we don't do that. Much. But it is intentionally allowed, and it is not appropriate for the compile to assume that we never do that. A linter can assume sensible code, and get away with more false negatives than the compiler can. So here is a partial list of things which could change the global or built-in name spaces, aside from explicit binding operations: - star imports; - importing any module could inject names into builtins or your globals as a side-effect; - calling any function could do the same; - exec; - eval, since it could call exec; - manipulating globals() or locals(); - even under another name, e.g: foo = False or globals # later foo()['surprise'] = 12345 I've probably missed many. Of course sensible code doesn't do horrible things like those (possible excluding the star imports), but the compiler would have to cope with them since they are allowed and sometimes they're useful. Unlike a linter, which can afford to be wrong sometimes, the compiler cannot be wrong or it counts as a compiler bug. Nobody will be too upset if a linter misses some obscure case in obfuscated weird code. But if the compiler wrongly flags an error when the code is actually legal, people will be justifiably annoyed. -- Steve From steve+comp.lang.python at pearwood.info Sun Apr 1 22:02:55 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Apr 2018 02:02:55 +0000 (UTC) Subject: How to fill in a dictionary with key and value from a string? References: Message-ID: On Sun, 01 Apr 2018 20:52:35 -0400, C W wrote: > Thank you all for the response. > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > values are shift by one position. > > key: abcdefghijklmnopqrstuvwxyz > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > Can I fill in a key and its corresponding value simultaneously on the > fly? Of course. myDict = dict(zip("abcdefghijklmnopqrstuvwxyz", "BCDEFGHIJKLMNOPQRSTUVWXYZA")) -- Steve From tmrsg11 at gmail.com Sun Apr 1 22:24:31 2018 From: tmrsg11 at gmail.com (C W) Date: Sun, 1 Apr 2018 22:24:31 -0400 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: Thank you Steven. I am frustrated that I can't enumerate a dictionary by position index. Maybe I want to shift by 2 positions, 5 positions... I want to know/learn how to manipulate dictionary with loop and by its position location. On Sun, Apr 1, 2018 at 10:02 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Sun, 01 Apr 2018 20:52:35 -0400, C W wrote: > > > Thank you all for the response. > > > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > > values are shift by one position. > > > > key: abcdefghijklmnopqrstuvwxyz > > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > > > Can I fill in a key and its corresponding value simultaneously on the > > fly? > > Of course. > > myDict = dict(zip("abcdefghijklmnopqrstuvwxyz", > "BCDEFGHIJKLMNOPQRSTUVWXYZA")) > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > From breamoreboy at gmail.com Sun Apr 1 23:06:14 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 2 Apr 2018 04:06:14 +0100 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: On 02/04/18 03:24, C W wrote: > Thank you Steven. I am frustrated that I can't enumerate a dictionary by > position index. > > Maybe I want to shift by 2 positions, 5 positions... > > I want to know/learn how to manipulate dictionary with loop and by its > position location. > Frankly I think you'd be much better off just using a list or a deque, although a SortedListWithKey http://www.grantjenks.com/docs/sortedcontainers/sortedlistwithkey.html is available if you really need it, although I'll admit to being very dubious about that. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sun Apr 1 23:13:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Apr 2018 03:13:04 +0000 (UTC) Subject: How to fill in a dictionary with key and value from a string? References: Message-ID: On Sun, 01 Apr 2018 22:24:31 -0400, C W wrote: > Thank you Steven. I am frustrated that I can't enumerate a dictionary by > position index. Why do you care about position index? > Maybe I want to shift by 2 positions, 5 positions... Sounds like you are trying to program the Caesar Shift cipher, am I right? You probably should be manipulating *strings*, not dicts. Do these examples help? py> import string py> letters = string.ascii_lowercase py> letters 'abcdefghijklmnopqrstuvwxyz' py> letters[1:] + letters[:1] 'bcdefghijklmnopqrstuvwxyza' py> letters[5:] + letters[:5] 'fghijklmnopqrstuvwxyzabcde' py> letters[23:] + letters[:23] 'xyzabcdefghijklmnopqrstuvw' Slice your strings into the order that you want, then put them in a dict for fast lookups by character. > I want to know/learn how to manipulate dictionary with loop and by its > position location. Dict entries don't have a position location except by accident, or in sufficiently new versions of Python, by insertion order. If you want to process dict entries in a specific order, operate on the dict in whichever order you want: ordered_keys = 'azbycxdwevfugthsirjqkplomn' for k in ordered_keys: print(mydict[k]) In Python 3.7, dicts will keep their insertion order, so long as you don't delete any keys. -- Steve From tmrsg11 at gmail.com Sun Apr 1 23:46:58 2018 From: tmrsg11 at gmail.com (C W) Date: Sun, 1 Apr 2018 23:46:58 -0400 Subject: How to fill in a dictionary with key and value from a string? In-Reply-To: References: Message-ID: Yes, you see right through me! I was able to conquer it, there's probably better ways: self.myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, string.ascii_lowercase[shift:26] + string.ascii_lowercase[:shift] + string.ascii_uppercase[shift:26] + string.ascii_uppercase[:shift])) How to debug a particular chunk of code? Everything in OOP is self.myDict, self.shift_dict. So, I must run the entire code to test. I just want to try myDict('hello', 4), shift_dict(4), like how you would do in C language. Thank you! On Sun, Apr 1, 2018 at 11:13 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Sun, 01 Apr 2018 22:24:31 -0400, C W wrote: > > > Thank you Steven. I am frustrated that I can't enumerate a dictionary by > > position index. > > Why do you care about position index? > > > Maybe I want to shift by 2 positions, 5 positions... > > Sounds like you are trying to program the Caesar Shift cipher, am I right? > > You probably should be manipulating *strings*, not dicts. Do these > examples help? > > py> import string > py> letters = string.ascii_lowercase > py> letters > 'abcdefghijklmnopqrstuvwxyz' > py> letters[1:] + letters[:1] > 'bcdefghijklmnopqrstuvwxyza' > py> letters[5:] + letters[:5] > 'fghijklmnopqrstuvwxyzabcde' > py> letters[23:] + letters[:23] > 'xyzabcdefghijklmnopqrstuvw' > > > Slice your strings into the order that you want, then put them in a dict > for fast lookups by character. > > > > I want to know/learn how to manipulate dictionary with loop and by its > > position location. > > Dict entries don't have a position location except by accident, or in > sufficiently new versions of Python, by insertion order. > > If you want to process dict entries in a specific order, operate on the > dict in whichever order you want: > > ordered_keys = 'azbycxdwevfugthsirjqkplomn' > for k in ordered_keys: > print(mydict[k]) > > > In Python 3.7, dicts will keep their insertion order, so long as you > don't delete any keys. > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Apr 2 00:08:59 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Apr 2018 00:08:59 -0400 Subject: Why is the use of an undefined name not a syntax error? In-Reply-To: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> References: <3822e044-3b19-454f-a502-89a1dcc23be5@googlegroups.com> Message-ID: On 4/1/2018 5:24 PM, David Foster wrote: > My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify which names are not valid. > > If broken name references were detected at compile time, it would eliminate a huge class of errors before running the program: missing imports, call of misspelled top-level function, reference to misspelled local variable. > > Of course running a full typechecker like mypy would eliminate more errors like misspelled method calls, type mismatch errors, etc. But if it is cheap to detect a wide variety of name errors at compile time, is there any particular reason it is not done? > > - David > > P.S. Here are some uncommon language features that interfere with identifying all valid names. In their absence, one might expect an invalid name to be a syntax error: > > * import * > * manipulating locals() or globals() > * manipulating a frame object > * eval The CPython parser and compiler are autogenerated from an LL(1) context-free grammer and other files. Context-dependent rules like the above are for linters and other whole-program analyses. A linter that makes occasional mistakes in its warning can still be useful. A compiler should be perfect. -- Terry Jan Reedy From dlt.joaquin at gmail.com Mon Apr 2 02:31:04 2018 From: dlt.joaquin at gmail.com (dlt.joaquin at gmail.com) Date: Sun, 1 Apr 2018 23:31:04 -0700 (PDT) Subject: semicolon at end of python's statements In-Reply-To: References: Message-ID: El mi?rcoles, 28 de agosto de 2013, 21:18:26 (UTC-3), Mohsen Pahlevanzadeh escribi?: > Dear all, > > I'm C++ programmer and unfortunately put semicolon at end of my > statements in python. > > Quesion: > What's really defferences between putting semicolon and don't put? > > Yours, > Mohsen Well, if you have to program in both c and python, and switch between them on intervals of time lowers than some hours I would suggest keep on with the semicolons at the end of lines... It would be very difficult to lose that habit, and while it is inoffensive on python, it may cause some troubles on c. From ian.g.kelly at gmail.com Mon Apr 2 02:55:24 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Apr 2018 00:55:24 -0600 Subject: Unified async/sync interface In-Reply-To: <1522547099.2744.15.camel@gmail.com> References: <1522547099.2744.15.camel@gmail.com> Message-ID: On Sat, Mar 31, 2018 at 7:44 PM, Demian Brecht wrote: > I might be entirely off my face, but figured I'd ask anyways given I > haven't figured out a clean solution to this problem myself yet: > > I'm trying to write a REST API client that supports both async and > synchronous HTTP transports (initially requests and aiohttp). So far, > I've tried a few approaches with `async def` but, of course, you always > run into the issue with the top level API that should either be async > or not, but can't be redefined on the fly (AFAICT). I'm also trying to > limit code duplication. I know I could write async and sync versions of > each method and then instantiate through composition based on the > transport layer but I'd like to avoid that if possible. As an > simplified example of what I'm after: > > [code snipped] > > Is this perhaps possible through asyncio.coroutine decorators > (admittedly, I haven't looked yet, I've had async/await blinders on)? > Are there any projects that anyone's aware of that does anything > similar that I could use as an example? > > The overall point of what I'm trying to achieve here is to write a > client that's supported from 2.7 to 3.x and supports /either/ > synchronous or asynchronous transports (not both at the same time). asyncio doesn't exist for 2.7 unless you're using trollius, which I understand is an incomplete port and also currently unmaintained. Even with trollius, I think that aiohttp is still going to restrict you to 3.5.3+. Unless your plan is to support synchronous transports only for 2.7. You definitely can't use "async def" with 2.7. To answer your question though, it sounds like you need your get_something method to return either the deserialized data if the transport is synchronous, or an awaitable that will resolve to the deserialized data when asynchronous. Since you don't want to implement the logic twice, I suggest breaking down the logic into transforms that can be applied generically, something like this (untested): def get_something(self): # Agnosticly get either synchronously fetched data # or an async awaitable. data = self.transport.get('https://example.com') return self._transform(data, json.loads) def _transform(self, value, func): # Transform value using func either synchronously or # asynchronously, depending on the transport regime. if self.transport.is_async(): async def await_and_transform(awaitable): new_value = func(await awaitable) if inspect.isawaitable(new_value): # In case func might also be async return await new_value else: return new_value return await_and_transform(value) else: return func(value) Note that if the async framework might be something other than asyncio then the above code probably wouldn't work. In that case perhaps it would be better to let the transport define the async transformation logic. From jfong at ms4.hinet.net Mon Apr 2 07:32:18 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 2 Apr 2018 04:32:18 -0700 (PDT) Subject: In asyncio, does the event_loop still running after run_until_complete returned? Message-ID: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> I am new to the asyncio subject, just trying to figure out how to use it. Below is the script I use for testing: --------------------------------- # asyncio_cancel_task2.py import asyncio @asyncio.coroutine def task_func(): print('in task_func, sleeping') try: yield from asyncio.sleep(1) except asyncio.CancelledError: print('task_func was canceled') raise print('return result') return 'the result' def task_canceller(task): task.cancel() print('canceled the task') @asyncio.coroutine def main(loop): print('first, scheduling a task') task = loop.create_task(task_func()) print('second, scheduling its cancellation') loop.call_later(0.5, task_canceller, task) try: print('waiting task to complete') yield from task except asyncio.CancelledError: print('main() also sees task as canceled') event_loop = asyncio.get_event_loop() try: event_loop.run_until_complete(main(event_loop)) finally: print('wait 3 seconds before closing event_loop') asyncio.sleep(3) print('event_loop was closed') event_loop.close() ----------------------------------- It schedules two tasks, the task_func and the task_canceller, in main. Before the task_func completed, the task_canceller was fired to cancel it. Hence its output below seems reasonable. D:\Works\Python>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import asyncio_cancel_task2 first, scheduling a task second, scheduling its cancellation waiting task to complete in task_func, sleeping canceled the task task_func was canceled main() also sees task as canceled wait 3 seconds before closing event_loop event_loop was closed >>> Then, I changed the call_later delay from 0.5 to 1.5, expect it to be called after the task_func completed and before the event loop closed. The output seems not quite right. Why the task_canceller hasn't been called? >>> import asyncio_cancel_task2 first, scheduling a task second, scheduling its cancellation waiting task to complete in task_func, sleeping return result wait 3 seconds before closing event_loop event_loop was closed >>> Best Regards, Jach Fong From p.f.moore at gmail.com Mon Apr 2 09:21:26 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 2 Apr 2018 14:21:26 +0100 Subject: Beta release of pip version 10 Message-ID: Unfortunately there was an issue in one of the release files (the CA Certificate bundle contained Windows line endings instead of Unix line endings) which caused crashes on older versions of MacOS. As a result we have just released 10.0.0b2, fixing this issue. Anyone on older MacOS versions who have had problems with the 10.0.0b1 release should upgrade to 10.0.0b2. Thanks, Paul On 31 March 2018 at 12:11, Paul Moore wrote: > On behalf of the PyPA, I am pleased to announce that a beta release > 10.0.0b1 of pip has just been released for testing by the community. > We're planning on a final release in 2 weeks' time, over the weekend > of 14/15 April. > > To install pip 10.0.0.b1, you can run > > python -m pip install --upgrade --pre pip > > (obviously, you should not do this in a production environment!) > > We would be grateful for all testing that users could do, to ensure > that when pip 10 is released it's as solid as we can make it. > > Highlights of the new release: > > * Python 2.6 is no longer supported - if you need pip on Python 2.6, > you should stay on pip 9, which is the last version to support Python > 2.6. > * Support for PEP 518, which allows projects to specify what packages > they require in order to build from source. (PEP 518 support is > currently limited, with full support coming in future versions - see > the documentation for details). > * Significant improvements in Unicode handling for non-ASCII locales on Windows. > * A new "pip config" command. > * The default upgrade strategy has become "only-if-needed" > * Many bug fixes and minor improvements. > > In addition, the previously announced reorganisation of pip's > internals has now taken place. Unless you are the author of code that > imports the pip module (or a user of such code), this change will not > affect you. If you are, please report the issue to the author of the > affected code (refer them to > https://mail.python.org/pipermail/distutils-sig/2017-October/031642.html > for the details of the announcement). > > Please note that there is a minor issue with the NEWS file for this > release - the new features in 10.0.0b1 are reported as being for > "9.0.3 (2018-03-31)". > > If you discover any bugs while testing the new release, please report > them at https://github.com/pypa/pip/issues. > > Thanks to everyone who put so much effort into the new release. Many > of the contributions came from community members, whether in the form > of code, participation in design discussions, or bug reports. The pip > development team is extremely grateful to everyone in the community > for their contributions. > > Thanks, > Paul From ian.g.kelly at gmail.com Mon Apr 2 09:36:11 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Apr 2018 07:36:11 -0600 Subject: In asyncio, does the event_loop still running after run_until_complete returned? In-Reply-To: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> Message-ID: On Mon, Apr 2, 2018 at 5:32 AM, wrote: > I am new to the asyncio subject, just trying to figure out how to use it. Below is the script I use for testing: > --------------------------------- > # asyncio_cancel_task2.py > > import asyncio > > @asyncio.coroutine > def task_func(): > print('in task_func, sleeping') > try: > yield from asyncio.sleep(1) > except asyncio.CancelledError: > print('task_func was canceled') > raise > print('return result') > return 'the result' > > def task_canceller(task): > task.cancel() > print('canceled the task') > > @asyncio.coroutine > def main(loop): > print('first, scheduling a task') > task = loop.create_task(task_func()) > print('second, scheduling its cancellation') > loop.call_later(0.5, task_canceller, task) > try: > print('waiting task to complete') > yield from task > except asyncio.CancelledError: > print('main() also sees task as canceled') > > > event_loop = asyncio.get_event_loop() > try: > event_loop.run_until_complete(main(event_loop)) > finally: > print('wait 3 seconds before closing event_loop') > asyncio.sleep(3) This won't actually wait 3 seconds. It just instantiates a sleep coroutine and then discards it. Inside the event loop you would need to await or yield from it. Outside the event loop, in order to sleep you have to block the thread, e.g. using time.sleep. That said, there is no reason to wait before closing the event loop. > print('event_loop was closed') > event_loop.close() > ----------------------------------- > > It schedules two tasks, the task_func and the task_canceller, in main. Before the task_func completed, the task_canceller was fired to cancel it. Hence its output below seems reasonable. > > D:\Works\Python>py > Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import asyncio_cancel_task2 > first, scheduling a task > second, scheduling its cancellation > waiting task to complete > in task_func, sleeping > canceled the task > task_func was canceled > main() also sees task as canceled > wait 3 seconds before closing event_loop > event_loop was closed >>>> > > Then, I changed the call_later delay from 0.5 to 1.5, expect it to be called after the task_func completed and before the event loop closed. The output seems not quite right. Why the task_canceller hasn't been called? > >>>> import asyncio_cancel_task2 > first, scheduling a task > second, scheduling its cancellation > waiting task to complete > in task_func, sleeping > return result > wait 3 seconds before closing event_loop > event_loop was closed >>>> Because, as your thread title suggests, after run_until_complete returns, the event loop is not running. How could it? It needs a thread to run on, but it doesn't create one, so whenever it returns from running it is relinquishing the thread and can't do anything unless it gets it back, since that thread is now running outer code. If you want to, you can restart the event loop by calling one of the run methods again; everything that was previously scheduled and everything that was scheduled after it stopped will remain scheduled. So, you can't have the event loop running in the background while also doing things within the code that started the loop in the same thread. If you really want this you can create a second thread to run the event loop on. However it is usually better to do that sort of thing within a coroutine running in the event loop, since single-threaded concurrency is the whole point of asyncio. The code that started the event loop will then only be used for cleanup after it terminates. From jfong at ms4.hinet.net Mon Apr 2 23:01:12 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 2 Apr 2018 20:01:12 -0700 (PDT) Subject: In asyncio, does the event_loop still running after run_until_complete returned? In-Reply-To: References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> Message-ID: <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> Ian? 2018?4?2???? UTC+8??9?37?08???? > On Mon, Apr 2, 2018 at 5:32 AM, wrote: > > I am new to the asyncio subject, just trying to figure out how to use it. Below is the script I use for testing: > > --------------------------------- > > # asyncio_cancel_task2.py > > > > import asyncio > > > > @asyncio.coroutine > > def task_func(): > > print('in task_func, sleeping') > > try: > > yield from asyncio.sleep(1) > > except asyncio.CancelledError: > > print('task_func was canceled') > > raise > > print('return result') > > return 'the result' > > > > def task_canceller(task): > > task.cancel() > > print('canceled the task') > > > > @asyncio.coroutine > > def main(loop): > > print('first, scheduling a task') > > task = loop.create_task(task_func()) > > print('second, scheduling its cancellation') > > loop.call_later(0.5, task_canceller, task) > > try: > > print('waiting task to complete') > > yield from task > > except asyncio.CancelledError: > > print('main() also sees task as canceled') > > > > > > event_loop = asyncio.get_event_loop() > > try: > > event_loop.run_until_complete(main(event_loop)) > > finally: > > print('wait 3 seconds before closing event_loop') > > asyncio.sleep(3) > > This won't actually wait 3 seconds. It just instantiates a sleep > coroutine and then discards it. Inside the event loop you would need > to await or yield from it. Outside the event loop, in order to sleep > you have to block the thread, e.g. using time.sleep. That said, there > is no reason to wait before closing the event loop. > Thank you for reminding my mistake. I shouldn't use asyncio.sleep there. > > print('event_loop was closed') > > event_loop.close() > > ----------------------------------- > > > > It schedules two tasks, the task_func and the task_canceller, in main. Before the task_func completed, the task_canceller was fired to cancel it. Hence its output below seems reasonable. > > > > D:\Works\Python>py > > Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import asyncio_cancel_task2 > > first, scheduling a task > > second, scheduling its cancellation > > waiting task to complete > > in task_func, sleeping > > canceled the task > > task_func was canceled > > main() also sees task as canceled > > wait 3 seconds before closing event_loop > > event_loop was closed > >>>> > > > > Then, I changed the call_later delay from 0.5 to 1.5, expect it to be called after the task_func completed and before the event loop closed. The output seems not quite right. Why the task_canceller hasn't been called? > > > >>>> import asyncio_cancel_task2 > > first, scheduling a task > > second, scheduling its cancellation > > waiting task to complete > > in task_func, sleeping > > return result > > wait 3 seconds before closing event_loop > > event_loop was closed > >>>> > > Because, as your thread title suggests, after run_until_complete > returns, the event loop is not running. How could it? It needs a > thread to run on, but it doesn't create one, so whenever it returns > from running it is relinquishing the thread and can't do anything > unless it gets it back, since that thread is now running outer code. > If you want to, you can restart the event loop by calling one of the > run methods again; everything that was previously scheduled and > everything that was scheduled after it stopped will remain scheduled. > I also do a quick check, with call_later delay keeps at 1.5, to see what the event loop status is after run_until_complete returns. Strangely, both is_closed and is_running return a False. try: event_loop.run_until_complete(main(event_loop)) finally: print(event_loop.is_closed()) # print(event_loop.is_running()) .... It's not closed(OK, the event_loop.close hasn't be executed yet) and neither it's running(quote your words, "it is relinquishing the thread and can't do anything")! Event loop, coroutine, task, yield from, ...etc, all these words' interaction makes asyncio has more mystery than I think:-( > So, you can't have the event loop running in the background while also > doing things within the code that started the loop in the same thread. > If you really want this you can create a second thread to run the > event loop on. However it is usually better to do that sort of thing > within a coroutine running in the event loop, since single-threaded > concurrency is the whole point of asyncio. The code that started the > event loop will then only be used for cleanup after it terminates. From ian.g.kelly at gmail.com Tue Apr 3 01:37:51 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Apr 2018 23:37:51 -0600 Subject: In asyncio, does the event_loop still running after run_until_complete returned? In-Reply-To: <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> Message-ID: On Mon, Apr 2, 2018 at 9:01 PM, wrote: > I also do a quick check, with call_later delay keeps at 1.5, to see what the event loop status is after run_until_complete returns. Strangely, both is_closed and is_running return a False. > > try: > event_loop.run_until_complete(main(event_loop)) > finally: > print(event_loop.is_closed()) # print(event_loop.is_running()) > .... > > It's not closed(OK, the event_loop.close hasn't be executed yet) and neither it's running(quote your words, "it is relinquishing the thread and can't do anything")! Correct. > Event loop, coroutine, task, yield from, ...etc, all these words' interaction makes asyncio has more mystery than I think:-( If it helps to demystify things, here is a simplified version of what run_until_complete actually does: def run_until_complete(self, future): """Run until the Future is done. If the argument is a coroutine, it is wrapped in a Task. Return the Future's result, or raise its exception. """ future = tasks.ensure_future(future, loop=self) future.add_done_callback(self.stop) self.run_forever() future.remove_done_callback(self.stop) return future.result() def run_forever(self): """Run until stop() is called.""" try: events._set_running_loop(self) while True: self._run_once() if self._stopping: break finally: self._stopping = False events._set_running_loop(None) def stop(self): """Stop running the event loop. Every callback already scheduled will still run. This simply informs run_forever to stop looping after a complete iteration. """ self._stopping = True run_until_complete sets up a callback on its argument that will stop the loop, and then it calls run_forever. The key thing to note is that inside run_forever, there is an actual while loop. This is the heart of the "event loop". On every iteration of the loop, it checks what callbacks need to be called and what coroutines need to be resumed. Then it checks whether it should stop, by breaking out of the loop. In order for run_until_complete to return, run_forever must first return. In order for run_forever to return, the loop in its body must be broken out of. Therefore, when run_forever or run_until_complete return, the loop can no longer be running. This is all that I mean when I say it relinquishes the thread: the function that contains the loop had to return, and therefore the loop is stopped. From kirillbalunov at gmail.com Tue Apr 3 05:24:51 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Tue, 3 Apr 2018 12:24:51 +0300 Subject: Python aliases under Windows? Message-ID: Perhaps this is a silly question but still...There is PEP 394 "The "python" Command on Unix-Like Systems" which I find very reasonable, no matter how it is respected. Why was not _somewhat_ the same done for Windows? Sometimes I use, especially in IPython, to run externally: ! python3 -m dis ! python3 -m timeit ... ! python3 -m pip install ... And to make this work the same under Windows, the first step which I do after installation is to copy `python.exe` and rename it to `python3.exe` (for python 2.7 copy `python.exe` and rename it to `python2.exe`). May be there is a better way to do this under Windows, I would like to know? This copy-rename works for me, but it will not work for someone who does not have administrative rights. p.s.: I know there is a `py` launcher under Windows, but is does not help in this situation. With kind regards, -gdg From rosuav at gmail.com Tue Apr 3 05:27:19 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Apr 2018 19:27:19 +1000 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2018 at 7:24 PM, Kirill Balunov wrote: > Perhaps this is a silly question but still...There is PEP 394 "The "python" > Command on Unix-Like Systems" which I find very reasonable, no matter how > it is respected. Why was not _somewhat_ the same done for Windows? > > Sometimes I use, especially in IPython, to run externally: > ! python3 -m dis > ! python3 -m timeit ... > ! python3 -m pip install ... > > And to make this work the same under Windows, the first step which I do > after installation is to copy `python.exe` and rename it to `python3.exe` > (for python 2.7 copy `python.exe` and rename it to `python2.exe`). May be > there is a better way to do this under Windows, I would like to know? This > copy-rename works for me, but it will not work for someone who does not > have administrative rights. > > p.s.: I know there is a `py` launcher under Windows, but is does not help > in this situation. Why doesn't it? That's what its job is. ChrisA From kirillbalunov at gmail.com Tue Apr 3 05:39:37 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Tue, 3 Apr 2018 12:39:37 +0300 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: 2018-04-03 12:27 GMT+03:00 Chris Angelico : > > Why doesn't it? That's what its job is. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > Because it affects my workflow under Windows and Linux. I have two options: 1. To wriie a shell script for `py` under Linux. 2. To copy-rename to python3 under Windows. Both are easy, but a little bit strange to do. With kind regards, -gdg From ian.g.kelly at gmail.com Tue Apr 3 09:15:30 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2018 07:15:30 -0600 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2018 at 3:24 AM, Kirill Balunov wrote: > Perhaps this is a silly question but still...There is PEP 394 "The "python" > Command on Unix-Like Systems" which I find very reasonable, no matter how > it is respected. Why was not _somewhat_ the same done for Windows? PEP 394 is meant to provide standardization between distributions of Linux which might make different choices about how to name the python aliases. Windows doesn't have distributions, and PEP 397 was being worked on at about the same time, so I suppose it wasn't considered necessary. Also, Windows and Linux are different enough that standardization between the two environments may not have been considered a realistic goal. > Sometimes I use, especially in IPython, to run externally: > ! python3 -m dis > ! python3 -m timeit ... > ! python3 -m pip install ... > > And to make this work the same under Windows, the first step which I do > after installation is to copy `python.exe` and rename it to `python3.exe` > (for python 2.7 copy `python.exe` and rename it to `python2.exe`). May be > there is a better way to do this under Windows, I would like to know? Creating python2.bat and python3.bat instead would take up less additional disk space and would not need to be modified every time you reinstall a new release of the same minor version. > This > copy-rename works for me, but it will not work for someone who does not > have administrative rights. They could put them under their user folder and add the folder to their path, although that's creeping into power user territory. Then again, they *are* using IPython... > p.s.: I know there is a `py` launcher under Windows, but is does not help > in this situation. I don't understand. Is 'py -3' that much harder to type than 'python3' when running in Windows? From p.f.moore at gmail.com Tue Apr 3 09:45:56 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Apr 2018 14:45:56 +0100 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On 3 April 2018 at 10:24, Kirill Balunov wrote: > Perhaps this is a silly question but still...There is PEP 394 "The "python" > Command on Unix-Like Systems" which I find very reasonable, no matter how > it is respected. Why was not _somewhat_ the same done for Windows? History, mainly. Plus the fact that the Unix convention is *not* that reasonable. Why should a system with only Python 3 installed (very common on Windows) not use "python" for that interpreter? The requirement that "python" must always refer to Python 2 comes from historical constraints on how Linux distributions chose to write their system scripts, AIUI. But debating why things are the way they are isn't that productive. It's the reality, so we need to deal with it. > p.s.: I know there is a `py` launcher under Windows, but is does not help > in this situation. Could you not use an alias? In [1]: import sys ...: if sys.platform.startswith('win'): ...: %alias python3 py -3 ...: else: ...: %alias python3 python3 ...: ...: ver = %python3 --version ...: ver ...: Python 3.6.2 Paul From kirillbalunov at gmail.com Tue Apr 3 10:26:39 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Tue, 3 Apr 2018 17:26:39 +0300 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: 2018-04-03 16:15 GMT+03:00 Ian Kelly : > Creating python2.bat and python3.bat instead would take up less > additional disk space and would not need to be modified every time you > reinstall a new release of the same minor version. > > Thank you! > > This > > copy-rename works for me, but it will not work for someone who does not > > have administrative rights. > > They could put them under their user folder and add the folder to > their path, although that's creeping into power user territory. Then > again, they *are* using IPython... > > > p.s.: I know there is a `py` launcher under Windows, but is does not help > > in this situation. > > I don't understand. Is 'py -3' that much harder to type than 'python3' > when running in Windows? > IPython is only one of the examples, instead you can substitute Jupyter, subprocess. As I wrote before: > I have two options: > 1. To wriie a shell script for `py` under Linux. > 2. To copy-rename to python3 under Windows. > Both are easy, but a little bit strange to do. > which seems unnecessary. There is already `pip.exe`, `pip3.exe`, `pip3.6.exe` in Scripts sub-folder which in my opinion solve the same problem. With kind regards, -gdg From kirillbalunov at gmail.com Tue Apr 3 11:00:28 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Tue, 3 Apr 2018 18:00:28 +0300 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: 2018-04-03 16:45 GMT+03:00 Paul Moore : > On 3 April 2018 at 10:24, Kirill Balunov wrote: > > Perhaps this is a silly question but still...There is PEP 394 "The > "python" > > Command on Unix-Like Systems" which I find very reasonable, no matter how > > it is respected. Why was not _somewhat_ the same done for Windows? > > History, mainly. Plus the fact that the Unix convention is *not* that > reasonable. Why should a system with only Python 3 installed (very > common on Windows) not use "python" for that interpreter? The > requirement that "python" must always refer to Python 2 comes from > historical constraints on how Linux distributions chose to write their > system scripts, AIUI. > I understand that general rules are not possible among the various OSs. If just `python` suits for Windows it is OK. But I have the same question, why should a system with Python 3 installed not use both "python" and "python3" for that interpreter? This `python3` will allow to slightly unify the workflow on different OSs, while it will be done almost for free. I want to add that there are plenty of tutorials which use `python3 ...` without reference to UNIX world, why are these mental overhead with `python3` or `py -3` necessary? In fact, I do not really understand why the _py launcher_ way is easier or better than `python3` or `python3.6` way even on Windows. There are already `pip.exe`, `pip3.exe`, `pip3.6.exe` which solve the same problem, but they are all redundant, when it is better to use `python3.6 -m pip ... ` or currently `py -3.6 -m pip install ...`. But debating why things are the way they are isn't that productive. > It's the reality, so we need to deal with it. > > > p.s.: I know there is a `py` launcher under Windows, but is does not help > > in this situation. > > Could you not use an alias? > > In [1]: import sys > ...: if sys.platform.startswith('win'): > ...: %alias python3 py -3 > ...: else: > ...: %alias python3 python3 > ...: > ...: ver = %python3 --version > ...: ver > ...: > Python 3.6.2 Thank you this works for me! With kind regards, -gdg From skip.montanaro at gmail.com Tue Apr 3 11:14:23 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 3 Apr 2018 10:14:23 -0500 Subject: logging.FileHandler diff Py2 v Py3 Message-ID: I've encountered a problem in an application I'm porting from Python 2.7 to 3.6. The logginng.FileHandler class likes "/dev/stderr" as a destination in Python 2, but complains in Python 3. Python 2.7.14: >>> import logging >>> logging.FileHandler("/dev/stderr") Python 3.6.4: >>> import logging >>> logging.FileHandler("/dev/stderr") Traceback (most recent call last): File "", line 1, in File "/home/skip/miniconda3/envs/python3/lib/python3.6/logging/__init__.py", line 1030, in __init__ StreamHandler.__init__(self, self._open()) File "/home/skip/miniconda3/envs/python3/lib/python3.6/logging/__init__.py", line 1059, in _open return open(self.baseFilename, self.mode, encoding=self.encoding) OSError: [Errno 29] Illegal seek I can see how to work around the error, pass mode="w" when passing /dev/{stdout,stderr} to the constructor. Shouldn't that bit of ugliness be hidden in the logging module? Skip From ian.g.kelly at gmail.com Tue Apr 3 11:43:14 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2018 09:43:14 -0600 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2018 at 9:00 AM, Kirill Balunov wrote: > In fact, I do not really understand why the _py launcher_ way is easier or > better than `python3` or `python3.6` way even on Windows. There are already > `pip.exe`, `pip3.exe`, `pip3.6.exe` which solve the same problem, but they > are all redundant, when it is better to use `python3.6 -m pip ... ` or > currently `py -3.6 -m pip install ...`. Because py.exe is really meant to solve a slightly different problem. On Unix if you have a .py script and you run it directly, without specifying which interpreter to use, the convention is to start the script with a shebang line, and the kernel will transparently use the interpreter specified there. Windows, however, doesn't respect shebang lines and instead associates programs with files by file extension. Here's the problem: Python 2 files have a .py extension. Python 3 files also have a .py extension. Windows doesn't allow both Python binaries to be associated with the same extension. So how can we set things up so that launching a Python file will invoke the correct Python version? To solve this, Python ships with py.exe and associates *that* with the .py extension. py.exe knows what Python versions are installed, and it inspects the shebang line to decide which one to run for this particular script. The fact that py.exe can also intelligently select versions from command line arguments is just an added bonus. From toby at tobiah.org Tue Apr 3 12:08:20 2018 From: toby at tobiah.org (Tobiah) Date: Tue, 3 Apr 2018 09:08:20 -0700 Subject: semicolon at end of python's statements References: Message-ID: On 04/01/2018 11:31 PM, dlt.joaquin at gmail.com wrote: > El mi?rcoles, 28 de agosto de 2013, 21:18:26 (UTC-3), Mohsen > Pahlevanzadeh escribi?: >> Dear all, >> >> I'm C++ programmer and unfortunately put semicolon at end of my >> statements in python. >> >> Quesion: What's really defferences between putting semicolon and >> don't put? >> >> Yours, Mohsen > > Well, if you have to program in both c and python, and switch between > them on intervals of time lowers than some hours I would suggest keep > on with the semicolons at the end of lines... It would be very > difficult to lose that habit, and while it is inoffensive on python, > it may cause some troubles on c. > I don't know. It's not Pep 8, or at least pycharm complains about it. I'd hate to inherit the semicolon riddled code. I switch between python and PHP twenty or so times a day since we use both at work. Once in a while I throw in a rogue semicolon, but it's not often enough to cause a bother. From karuse at gmail.com Tue Apr 3 12:48:57 2018 From: karuse at gmail.com (karuse at gmail.com) Date: Tue, 3 Apr 2018 09:48:57 -0700 (PDT) Subject: semicolon at end of python's statements In-Reply-To: References: Message-ID: <95d8a116-c884-4b0a-a328-a55110eb48cd@googlegroups.com> Semicolon is optional. If you put a semicolon at the end of the of a statement, you can keep writing statements. a=3;b=2 From __peter__ at web.de Tue Apr 3 12:54:15 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Apr 2018 18:54:15 +0200 Subject: logging.FileHandler diff Py2 v Py3 References: Message-ID: Skip Montanaro wrote: > I've encountered a problem in an application I'm porting from Python > 2.7 to 3.6. The logginng.FileHandler class likes "/dev/stderr" as a > destination in Python 2, but complains in Python 3. > > Python 2.7.14: > >>>> import logging >>>> logging.FileHandler("/dev/stderr") > > > Python 3.6.4: > >>>> import logging >>>> logging.FileHandler("/dev/stderr") > Traceback (most recent call last): > File "", line 1, in > File > "/home/skip/miniconda3/envs/python3/lib/python3.6/logging/__init__.py", > line 1030, in __init__ > StreamHandler.__init__(self, self._open()) > File > "/home/skip/miniconda3/envs/python3/lib/python3.6/logging/__init__.py", > line 1059, in _open > return open(self.baseFilename, self.mode, encoding=self.encoding) > OSError: [Errno 29] Illegal seek > > I can see how to work around the error, pass mode="w" when passing > /dev/{stdout,stderr} to the constructor. Shouldn't that bit of > ugliness be hidden in the logging module? I think the culprit is io.open() rather than the logging module. Why does >>> io.open("/dev/stderr", "a") Traceback (most recent call last): File "", line 1, in OSError: [Errno 29] Illegal seek even try to seek()? From p.f.moore at gmail.com Tue Apr 3 13:04:45 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 3 Apr 2018 18:04:45 +0100 Subject: logging.FileHandler diff Py2 v Py3 In-Reply-To: References: Message-ID: On 3 April 2018 at 17:54, Peter Otten <__peter__ at web.de> wrote: > I think the culprit is io.open() rather than the logging module. Why does > >>>> io.open("/dev/stderr", "a") > Traceback (most recent call last): > File "", line 1, in > OSError: [Errno 29] Illegal seek > > even try to seek()? Because it's append mode so it needs to go to the end? Paul From tjreedy at udel.edu Tue Apr 3 13:42:09 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 Apr 2018 13:42:09 -0400 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On 4/3/2018 11:43 AM, Ian Kelly wrote: > On Tue, Apr 3, 2018 at 9:00 AM, Kirill Balunov wrote: >> In fact, I do not really understand why the _py launcher_ way is easier or >> better than `python3` or `python3.6` way even on Windows. There are already >> `pip.exe`, `pip3.exe`, `pip3.6.exe` which solve the same problem, but they These are put in the pythonxy/Scripts directory. So they only work if the pythonxy/Scripts directory is on the path. But there really should only be 1 such directory on the path. Otherwise, the meaning of pip.exe and pip3.exe depends on the order of the multiple /Scripts directories. >> are all redundant, when it is better to use `python3.6 -m pip ... ` or >> currently `py -3.6 -m pip install ...`. Because the last works with multiple python installations. > Because py.exe is really meant to solve a slightly different problem. > On Unix if you have a .py script and you run it directly, without > specifying which interpreter to use, the convention is to start the > script with a shebang line, and the kernel will transparently use the > interpreter specified there. Windows, however, doesn't respect shebang > lines and instead associates programs with files by file extension. > > Here's the problem: Python 2 files have a .py extension. Python 3 > files also have a .py extension. Windows doesn't allow both Python > binaries to be associated with the same extension. So how can we set > things up so that launching a Python file will invoke the correct > Python version? To solve this, Python ships with py.exe and associates > *that* with the .py extension. py.exe knows what Python versions are > installed, and it inspects the shebang line to decide which one to run > for this particular script. > > The fact that py.exe can also intelligently select versions from > command line arguments is just an added bonus. I consider it essential, as I often run scripts with more than one version, so baking a version into the script is wrong. -- Terry Jan Reedy From toby at tobiah.org Tue Apr 3 13:45:08 2018 From: toby at tobiah.org (Tobiah) Date: Tue, 3 Apr 2018 10:45:08 -0700 Subject: semicolon at end of python's statements References: <95d8a116-c884-4b0a-a328-a55110eb48cd@googlegroups.com> Message-ID: On 04/03/2018 09:48 AM, karuse at gmail.com wrote: > Semicolon is optional. > If you put a semicolon at the end of the of a statement, you can keep writing statements. > > a=3;b=2 > PyCharm still complains about two statements on one line and sites Pep 8. I never used to pay much attention to Pep 8, but PyCharm has greatly eroded my resistance. From __peter__ at web.de Tue Apr 3 14:18:57 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Apr 2018 20:18:57 +0200 Subject: logging.FileHandler diff Py2 v Py3 References: Message-ID: Paul Moore wrote: > On 3 April 2018 at 17:54, Peter Otten <__peter__ at web.de> wrote: >> I think the culprit is io.open() rather than the logging module. Why does >> >>>>> io.open("/dev/stderr", "a") >> Traceback (most recent call last): >> File "", line 1, in >> OSError: [Errno 29] Illegal seek >> >> even try to seek()? > > Because it's append mode so it needs to go to the end? I expected that to be handled by the C library, and in C there is no error: $ cat open_stderr_in_appendmode.c #include main() { FILE * stderr = fopen("/dev/stderr", "a"); if (stderr == 0) { printf("failed\n"); } else { printf("succeded\n"); fprintf(stderr, "\nthis goes to stderr\n"); fclose(stderr); } } $ gcc open_stderr_in_appendmode.c $ ./a.out succeded this goes to stderr The same goes for Py2's built-in and codecs.open(): $ python Python 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import codecs >>> import io >>> with open("/dev/stderr", "a") as f: f.write("works\n") ... works >>> with codecs.open("/dev/stderr", "a") as f: f.write("works\n") ... works >>> with io.open("/dev/stderr", "a") as f: f.write("works\n") ... Traceback (most recent call last): File "", line 1, in IOError: [Errno 29] Illegal seek >>> So io.open() really seems to do its own thing, and differently. From eryksun at gmail.com Tue Apr 3 15:04:22 2018 From: eryksun at gmail.com (eryk sun) Date: Tue, 3 Apr 2018 19:04:22 +0000 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2018 at 3:43 PM, Ian Kelly wrote: > > Because py.exe is really meant to solve a slightly different problem. > On Unix if you have a .py script and you run it directly, without > specifying which interpreter to use, the convention is to start the > script with a shebang line, and the kernel will transparently use the > interpreter specified there. Windows, however, doesn't respect shebang > lines and instead associates programs with files by file extension. > > Here's the problem: Python 2 files have a .py extension. Python 3 > files also have a .py extension. Windows doesn't allow both Python > binaries to be associated with the same extension. So how can we set > things up so that launching a Python file will invoke the correct > Python version? To solve this, Python ships with py.exe and associates > *that* with the .py extension. py.exe knows what Python versions are > installed, and it inspects the shebang line to decide which one to run > for this particular script. > > The fact that py.exe can also intelligently select versions from > command line arguments is just an added bonus. Alternatively, there's the Windows Script Host (WSH) framework (cscript.exe console, wscript.exe GUI), which supports a generic WSF file extension that allows mixing multiple languages in a single script, and integrates with COM, ASP, and native debuggers. PyWin32 supports WSH. This could have been adapted to support Python 3 as a separate Windows scripting engine. That said, for general use, the py launcher's registration+shebang support is more flexible than the WSH registration-only approach. The launcher supports virtual Unix shebangs for cross-platform scripts and arbitrary executable paths for scripts that depend on virtual environments. I use it for the .py[w] file association and creating virtual environments. I still prefer `python` on the command line. Even on Linux I don't frequently use `python3` or `python3.X`. I do very little with the system Python. If you really miss typing "python3.6", I suggest using relative symbolic links (e.g. CMD's `mklink` command) created in the same directory as python[w].exe. Using relative symlinks requires installing Python on a NTFS volume that supports them, so it's not a viable solution for external drives that use FAT32 or exFAT. In the latter case, an alternative to batch scripts is to create a "python[w]3.6.lnk" shell shortcut to "python[w].exe". Leave the "start in" folder empty, so it will inherit the parent's working directory, and add .LNK to the system PATHEXT environment variable. One caveat is that, unlike symlinks or batch scripts, executing shell shortcuts requires ShellExecute[Ex] (called from Explorer, CMD, PowerShell, etc). CreateProcess (e.g. subprocess.Popen with shell=False) doesn't know anything about .LNK files. From kirillbalunov at gmail.com Tue Apr 3 16:16:29 2018 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Tue, 3 Apr 2018 23:16:29 +0300 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: 2018-04-03 22:04 GMT+03:00 eryk sun : > On Tue, Apr 3, 2018 at 3:43 PM, Ian Kelly wrote: > > > > Because py.exe is really meant to solve a slightly different problem. > > On Unix if you have a .py script and you run it directly, without > > specifying which interpreter to use, the convention is to start the > > script with a shebang line, and the kernel will transparently use the > > interpreter specified there. Windows, however, doesn't respect shebang > > lines and instead associates programs with files by file extension. > > > > Here's the problem: Python 2 files have a .py extension. Python 3 > > files also have a .py extension. Windows doesn't allow both Python > > binaries to be associated with the same extension. So how can we set > > things up so that launching a Python file will invoke the correct > > Python version? To solve this, Python ships with py.exe and associates > > *that* with the .py extension. py.exe knows what Python versions are > > installed, and it inspects the shebang line to decide which one to run > > for this particular script. > > > > The fact that py.exe can also intelligently select versions from > > command line arguments is just an added bonus. > Thank you Ian, Terry, Eryk! Now I understand the purpose of py launcher in general. I don't have Windows near, will `py -3.6 ...` work if Python36 is not on the Path? If not, it seems to me, that if `python3.exe` and `python3.6.exe` were provided they would be equivalent, and together they will complement together and unify UNIX and Windows workflow. Am I missing something? > Alternatively, there's the Windows Script Host (WSH) framework > (cscript.exe console, wscript.exe GUI), which supports a generic WSF > file extension that allows mixing multiple languages in a single > script, and integrates with COM, ASP, and native debuggers. PyWin32 > supports WSH. This could have been adapted to support Python 3 as a > separate Windows scripting engine. > > That said, for general use, the py launcher's registration+shebang > support is more flexible than the WSH registration-only approach. The > launcher supports virtual Unix shebangs for cross-platform scripts and > arbitrary executable paths for scripts that depend on virtual > environments. I use it for the .py[w] file association and creating > virtual environments. I still prefer `python` on the command line. > Even on Linux I don't frequently use `python3` or `python3.X`. I do > very little with the system Python. > > If you really miss typing "python3.6", I suggest using relative > symbolic links (e.g. CMD's `mklink` command) created in the same > directory as python[w].exe. Using relative symlinks requires > installing Python on a NTFS volume that supports them, so it's not a > viable solution for external drives that use FAT32 or exFAT. In the > latter case, an alternative to batch scripts is to create a > "python[w]3.6.lnk" shell shortcut to "python[w].exe". Leave the "start > in" folder empty, so it will inherit the parent's working directory, > and add .LNK to the system PATHEXT environment variable. One caveat is > that, unlike symlinks or batch scripts, executing shell shortcuts > requires ShellExecute[Ex] (called from Explorer, CMD, PowerShell, > etc). CreateProcess (e.g. subprocess.Popen with shell=False) doesn't > know anything about .LNK files. > -- > https://mail.python.org/mailman/listinfo/python-list > Thank you for your detailed advice, I'll try to understand. Why under Windows everything is so complicated... Concerning dealing with `python` vs `python3` it is a matter of habit, and I find the latter option more reliable and missing it under Windows. With kind regards, -gdg From skip.montanaro at gmail.com Tue Apr 3 17:07:29 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 03 Apr 2018 21:07:29 +0000 Subject: logging.FileHandler diff Py2 v Py3 In-Reply-To: References: Message-ID: > > >> I think the culprit is io.open() rather than the logging module. Why > does > Thanks, Peter. It never even occurred to me to look at the source code around the call. I saw open() and thought "built-in open". I forgot that the io package supplanted a bunch of lower level i/o. I'll poke around a little and maybe open a bug report if I can't find any explanation for the change in behavior. Skip > From tjreedy at udel.edu Tue Apr 3 22:09:01 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 Apr 2018 22:09:01 -0400 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On 4/3/2018 4:16 PM, Kirill Balunov wrote: > Thank you Ian, Terry, Eryk! Now I understand the purpose of py launcher in > general. I don't have Windows near, will `py -3.6 ...` work if Python36 is > not on the Path? Yes. -- Terry Jan Reedy From suabiut at gmail.com Tue Apr 3 22:24:44 2018 From: suabiut at gmail.com (sum abiut) Date: Wed, 4 Apr 2018 13:24:44 +1100 Subject: julian 0.14 library Message-ID: Hi, Has anyone try this https://pypi.python.org/pypi/julian/0.14 i got this error trying to import julian >>> import julian Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/julian/__init__.py", line 1, in from julian.julian import to_jd, from_jd File "/usr/local/lib/python2.7/dist-packages/julian/julian.py", line 5 def __to_format(jd: float, fmt: str) -> float: ^ SyntaxError: invalid syntax cheers, From steve+comp.lang.python at pearwood.info Tue Apr 3 22:28:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Apr 2018 02:28:46 +0000 (UTC) Subject: In asyncio, does the event_loop still running after run_until_complete returned? References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> Message-ID: On Mon, 02 Apr 2018 23:37:51 -0600, Ian Kelly wrote: > If it helps to demystify things, here is a simplified version of what > run_until_complete actually does: > > def run_until_complete(self, future): > """Run until the Future is done. > > If the argument is a coroutine, it is wrapped in a Task. > > Return the Future's result, or raise its exception. """ Demystify, he says. Future, he says. Coroutine. Task. What's self? What's tasks? What's events? Enquiring minds want to know. > future = tasks.ensure_future(future, loop=self) > future.add_done_callback(self.stop) > self.run_forever() > future.remove_done_callback(self.stop) > return future.result() > > def run_forever(self): > """Run until stop() is called.""" o_O That's obviously a different meaning to the word "forever" than I learnt at school. -- Steve From eryksun at gmail.com Tue Apr 3 22:46:11 2018 From: eryksun at gmail.com (eryk sun) Date: Wed, 4 Apr 2018 02:46:11 +0000 Subject: Python aliases under Windows? In-Reply-To: References: Message-ID: On Tue, Apr 3, 2018 at 8:16 PM, Kirill Balunov wrote: > > will `py -3.6 ...` work if Python36 is not on the Path? Yes, by default it will work. When installed for all users, the launcher is installed in the Windows directory. For a per-user install, the launcher is installed in a subdirectory of the user's program files, and the installer adds the launcher's directory to PATH. > Concerning dealing with `python` vs `python3` it is a matter of habit, and I find the > latter option more reliable and missing it under Windows. On Windows, I don't have any Python version permanently set in PATH. It's set by the current virtual environment. Even in Unix, an active virtual environment has a `python` command for Python 3. The issue is only with the system `python` command (i.e. /usr/bin/python), which I don't use directly. From jfong at ms4.hinet.net Tue Apr 3 23:20:20 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 3 Apr 2018 20:20:20 -0700 (PDT) Subject: In asyncio, does the event_loop still running after run_until_complete returned? In-Reply-To: References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> Message-ID: <39dffa2a-fa07-4240-97cd-82b6ea788b06@googlegroups.com> Ian? 2018?4?3???? UTC+8??1?38?57???? > On Mon, Apr 2, 2018 at 9:01 PM, wrote: > > def run_forever(self): > """Run until stop() is called.""" > try: > events._set_running_loop(self) > while True: > self._run_once() > if self._stopping: > break > finally: > self._stopping = False > events._set_running_loop(None) > What's the purpose of resetting self._stopping back to False in finally clause? --Jach From rosuav at gmail.com Tue Apr 3 23:44:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2018 13:44:41 +1000 Subject: julian 0.14 library In-Reply-To: References: Message-ID: On Wed, Apr 4, 2018 at 12:24 PM, sum abiut wrote: > Hi, > Has anyone try this https://pypi.python.org/pypi/julian/0.14 > > i got this error trying to import julian > >>>> import julian > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python2.7/dist-packages/julian/__init__.py", line 1, > in > from julian.julian import to_jd, from_jd > File "/usr/local/lib/python2.7/dist-packages/julian/julian.py", line 5 > def __to_format(jd: float, fmt: str) -> float: > ^ > SyntaxError: invalid syntax > Looks like that package requires Python 3, but was uploaded to PyPI without any version tags. You could try running it in Python 3.x, but there's no way to know which ".x" versions are going to work. ChrisA From ian.g.kelly at gmail.com Wed Apr 4 01:55:37 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Apr 2018 23:55:37 -0600 Subject: In asyncio, does the event_loop still running after run_until_complete returned? In-Reply-To: <39dffa2a-fa07-4240-97cd-82b6ea788b06@googlegroups.com> References: <5325545a-9fe8-4ffd-ab84-0e3468ff7bb9@googlegroups.com> <1c54182f-05f4-4e73-b39d-dd03a05e4bfe@googlegroups.com> <39dffa2a-fa07-4240-97cd-82b6ea788b06@googlegroups.com> Message-ID: On Tue, Apr 3, 2018 at 9:20 PM, wrote: > What's the purpose of resetting self._stopping back to False in finally clause? Presumably so that the loop won't immediately stop again if you restart it. From steve+comp.lang.python at pearwood.info Wed Apr 4 03:27:42 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Apr 2018 07:27:42 +0000 (UTC) Subject: Asynchronous processing is more efficient -- surely not? Message-ID: So, I'm, still trying to wrap my brain around async processing, and I started reading this tutorial: http://stackabuse.com/python-async-await-tutorial/ and the very first paragraph broke my brain. "Asynchronous programming has been gaining a lot of traction in the past few years, and for good reason. Although it can be more difficult than the traditional linear style, it is also much more efficient." I can agree with the first part of the first sentence (gaining a lot of traction), and the first part of the second sentence (more difficult than the traditional style), but the second part? Asynchronous processing is *more efficient*? I'm no expert, but it seems to me that this has surely got to be crazy talk. Whatever task you're doing, processing it asynchronously doesn't reduce the amount of work. For example, if you want to download ten files, you still have to download all ten files, and they're not any smaller or the network connection any faster because you're using async. On the contrary, surely it is *less efficient*: there's the amount of work you need to do, the *useful* work (downloading those files) PLUS a bunch of book-keeping work (most, but not all, done for you in the async framework or language) needed to swap jobs. I can see that the advantage of async is to *increase responsiveness*. You aren't waiting a long time for each file to download (or the page to render, or whatever task it is that you are doing) before being able to start the next one. Quoting the article: "With asynchronous programming, you allow your code to handle other tasks while waiting for these other resources to respond." Yes, this exactly. And if you're writing a web app, or certain kinds of desktop apps, these seems sensible. I don't want my browser to come to a complete halt just because some resource is taking a few seconds to respond. But honestly, from everything I've seen, outside of browser apps (and I'm not even sure about them), async processing looks to me like the wrong solution to, well, everything. It combines the worst of sequential and parallel processing with the benefits of neither. It's like cooperative multi-tasking, only without the actual multi-tasking and even less convenience. Its harder to use than threading or multiprocessing, but without their ability to run in parallel. It lacks the isolation of multiprocessing, and the preemptive task swapping of threads/processes. Its as hard to wrap your brain around as parallel processing in general, but with even worse performance than sequential processing. Am I totally wrong? -- Steve From songofacandy at gmail.com Wed Apr 4 03:53:53 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 4 Apr 2018 16:53:53 +0900 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: I agree with you. Async IO is more efficient than threading for **waiting** I/O. When there are thousands of idle connections, async I/O is best idea. On the other hand, async I/O uses more system calls for busy I/O. For example, when building chat application which handles thousands WebSocket connection and uses MySQL as backend, I recommend to use asyncio for WebSocket, but threadpool for transaction. Regards, From asphjt at laposte.net Wed Apr 4 06:03:42 2018 From: asphjt at laposte.net (asphjt at laposte.net) Date: Wed, 4 Apr 2018 03:03:42 -0700 (PDT) Subject: OSError: [Errno -9981] Input overflowed Message-ID: <9c3d1c93-42f0-4065-9452-c98e3d8c8bef@googlegroups.com> Here is my code: import pyaudio tim=1 chunk = 8 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 50000 p = pyaudio.PyAudio() s = p.open(format = FORMAT,channels = CHANNELS,rate = RATE,input = True,output=True,frames_per_buffer = chunk) d=[] print((RATE // chunk) * tim) for i in range(0, (RATE // chunk * tim)): data = s.read(chunk) d.append(data) s.close() p.terminate() There is no problem, but if I want to use the variable data during the loop for, I have this error: Traceback (most recent call last): File "", line 14, in data = s.read(chunk) File "c:\users\tissot\miniconda3\lib\site-packages\pyaudio.py", line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow) OSError: [Errno -9981] Input overflowed for example if i want to print data with this code: import pyaudio tim=1 chunk = 8 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 50000 p = pyaudio.PyAudio() s = p.open(format = FORMAT,channels = CHANNELS,rate = RATE,input = True,output=True,frames_per_buffer = chunk) d=[] print((RATE // chunk) * tim) for i in range(0, (RATE // chunk * tim)): data = s.read(chunk) d.append(data) print(data) # here is the problem s.close() p.terminate() In reality I would like to send it to my Arduino card as and when recording,(using: ser = serial.Serial('COM4', 115200) ser.write(data) ) but I have the same error as when I display it on the screen. If anyone knows an answer to this question, thank you in advance. From lists at mostrom.pp.se Wed Apr 4 06:28:15 2018 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Wed, 04 Apr 2018 12:28:15 +0200 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: <675ECEAA-442A-4B87-8AC7-81DBF029B8EE@mostrom.pp.se> On 4 Apr 2018, at 9:27, Steven D'Aprano wrote: > Its as hard to wrap your brain around as parallel processing in > general, > but with even worse performance than sequential processing. > > Am I totally wrong? I would say that it all depends on what kind of stuff you're doing. I'm no scheduling expert but our high performance centre run their jobs in batch mode, every job is allowed to finish before it removed from the processor (assuming they keep inside their time quota) but they are hight compute intensive jobs with little I/O. On the other hand, a desktop computer probably have "reactive jobs" with a high ratio of I/O which would make it desirable to have threads/async processing. Other systems are probably between these two cases. So saying that it's always good is probably not true but sometimes it can be a win. Also, assuming you have threads/processes and a multicore system the scheduling might take advantage of this giving higher performance ... I'm haven't thought about how co-routines would work here. (another plus for threads is that *I* think that the logical division/coding of the system becomes easier if threads and IPC is used ... but I don't have any data to support this - and yes I know that threads/processes/synchronization open up its own can of worms) = jem From p.f.moore at gmail.com Wed Apr 4 06:42:35 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 4 Apr 2018 11:42:35 +0100 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On 4 April 2018 at 08:27, Steven D'Aprano wrote: > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." > > I can agree with the first part of the first sentence (gaining a lot of > traction), and the first part of the second sentence (more difficult than > the traditional style), but the second part? Asynchronous processing is > *more efficient*? I'd need to know what "efficient" meant. Obviously you're never going to get more than 100% utilisation of a single core with async (because of the GIL) but I can easily imagine async making more complete use of that core by having less time spent waiting for I/O. Whether you describe that as "more efficient" use of the CPU, or something else, I don't know. Honestly, that paragraph reads more like sales blurb than anything else, so I'd be inclined to take it with a pinch of salt anyway. IMO, async has proved useful for handling certain types of IO bound workloads with lower overheads[1] than traditional multi-threaded or multi-process designs. Whether it's a good fit for any particular application is something you'd have to test, as with anything else. Paul [1] I found it really hard to avoid saying "more efficiently" there. Not sure what that implies other than that the phrase means whatever you want it to mean!!! From rosuav at gmail.com Wed Apr 4 06:45:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2018 20:45:12 +1000 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On Wed, Apr 4, 2018 at 5:27 PM, Steven D'Aprano wrote: > So, I'm, still trying to wrap my brain around async processing, and I > started reading this tutorial: > > http://stackabuse.com/python-async-await-tutorial/ > > and the very first paragraph broke my brain. > > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." > > I can agree with the first part of the first sentence (gaining a lot of > traction), and the first part of the second sentence (more difficult than > the traditional style), but the second part? Asynchronous processing is > *more efficient*? The only way it could be "more efficient" is if you assume that "sequential processing" == "well, let's parallelize it by going for multiple processes, each independently started". This is an assumption, but it's not wholly unreasonable - if you write your code in a purely sequential way (say, youtube-dl) and want to do more than one of these at a time, the easiest way is to pop open another terminal and fire up another copy of the program, with an entire copy of everything. But that isn't inherent to the design of sequential processing. It's a cost of a naive form of parallelism, one that could be alleviated by threading too. IMO asyncio should be compared to threads, not to sequential processing. *First* imagine reworking your code to use threads; then consider cutting out the actual OS-managed threads and using a cooperative single-threaded system instead. You depend on application-level scheduling, which means that gethostbyname() can utterly break you if you aren't careful, and you lose about thirty or forty years of collective experience in developing operating systems with intelligent schedulers, but in return, you gain the ability to manage a hundred thousand concurrent tasks in a single process. You also lose the ability to context-swap in the middle of a logical operation, but in return, you lose the ability to context-swap in the middle of a logical operation. For people who've grown up with actual real threads, this latter is not an advantage; for people who've grown up casually mutating global state, that's huge. IN THEORY, it would be possible to create a lock-free implementation of Python that is incapable of using multiple threads, but still able to use asyncio. In practice, since CPython has a highly efficient locking system (the GIL), the advantage is unlikely to be compelling. So, no, generally async processing will NOT be more efficient than sequential processing. It has other advantages, but not that. ChrisA From Richard at Damon-Family.org Wed Apr 4 07:02:03 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 4 Apr 2018 07:02:03 -0400 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On 4/4/18 3:27 AM, Steven D'Aprano wrote: > So, I'm, still trying to wrap my brain around async processing, and I > started reading this tutorial: > > http://stackabuse.com/python-async-await-tutorial/ > > and the very first paragraph broke my brain. > > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." > > I can agree with the first part of the first sentence (gaining a lot of > traction), and the first part of the second sentence (more difficult than > the traditional style), but the second part? Asynchronous processing is > *more efficient*? > > I'm no expert, but it seems to me that this has surely got to be crazy > talk. Whatever task you're doing, processing it asynchronously doesn't > reduce the amount of work. For example, if you want to download ten > files, you still have to download all ten files, and they're not any > smaller or the network connection any faster because you're using async. > > On the contrary, surely it is *less efficient*: there's the amount of > work you need to do, the *useful* work (downloading those files) PLUS a > bunch of book-keeping work (most, but not all, done for you in the async > framework or language) needed to swap jobs. > > I can see that the advantage of async is to *increase responsiveness*. > You aren't waiting a long time for each file to download (or the page to > render, or whatever task it is that you are doing) before being able to > start the next one. Quoting the article: > > "With asynchronous programming, you allow your code to handle other tasks > while waiting for these other resources to respond." > > Yes, this exactly. And if you're writing a web app, or certain kinds of > desktop apps, these seems sensible. I don't want my browser to come to a > complete halt just because some resource is taking a few seconds to > respond. > > But honestly, from everything I've seen, outside of browser apps (and I'm > not even sure about them), async processing looks to me like the wrong > solution to, well, everything. It combines the worst of sequential and > parallel processing with the benefits of neither. It's like cooperative > multi-tasking, only without the actual multi-tasking and even less > convenience. Its harder to use than threading or multiprocessing, but > without their ability to run in parallel. It lacks the isolation of > multiprocessing, and the preemptive task swapping of threads/processes. > > Its as hard to wrap your brain around as parallel processing in general, > but with even worse performance than sequential processing. > > Am I totally wrong? > > Asynchronous processing will use a bit more of some processing resources to handle the multi-processing, but it can be more efficient at fully using many of the resources that are available. Take your file download example. When you are downloading a file, your processor sends out a request for a chuck of the data, then waits for the response. The computer on the other end gets that requests, sends a packet, and then waits. You get that packet, send and acknowledgement, and then wait, the other computer gets that acknowledgement and sends more data, and then waits, and so on. Even if your pipe to the Internet is the limiting factor, there is a fair amount of dead time in this operation, so starting another download to fill more of that pipe can decrease the total time to get all the data downloaded. Yes, if your single path of execution can fully use the critical resources, then adding asynchronous processing won't help, but rarely does it. Very few large machines today a single-threaded, but most have multiple cores and often even those cores have the ability to handle multiple threads at once. Thus there normally are extra resources that the asynchronous processing can better use up, so even processor usage can be improved in many cases. In most cases I am familiar with, the type of asynchronous programming you are talking about is to move I/O bound operations into a second execution path, allowing your main path to focus on keeping the CPU busy. -- Richard Damon From rosuav at gmail.com Wed Apr 4 07:04:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2018 21:04:11 +1000 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On Wed, Apr 4, 2018 at 8:42 PM, Paul Moore wrote: > IMO, > async has proved useful for handling certain types of IO bound > workloads with lower overheads[1] than traditional multi-threaded or > multi-process designs. Whether it's a good fit for any particular > application is something you'd have to test, as with anything else. This I would agree with. There are certain types of tasks that really lend themselves spectacularly well to async I/O models - mainly those that are fundamentally reactive and can have inordinate numbers of connected users. Take a chat room, for example. The client establishes a connection to a server (maybe IRC, maybe a WebSocket, whatever), and the server just sits there doing nothing until some client sends a message. Then the server processes the message, does whatever it thinks is right, and sends messages out to one or more clients. It's essential that multiple concurrent clients be supported (otherwise you're chatting with yourself), so how do the different models hold up? 1) Multiple independent processes. Abysmal; they have to communicate with each other, so this would require a measure of persistence (eg a database) and some means of signalling other processes. A pain to write, and horribly inefficient. You probably would need two threads per process (one to read, one to write). 2) The multiprocessing module. Better than the above because you can notify other processes using a convenient API, but you still need an entire process for every connected client. Probably you'll top out at a few hundred clients, even if they're all quiet. Still need two threads per process. 3) Native OS threads using the threading module. Vast improvement; the coding work would be pretty much the same as for multiprocessing, but instead of a process, you need a thread. Probably would top out at a few thousand clients, maybe a few tens of thousands, as long as they're all fairly quiet. Since all state is now shared, you now need only one thread per process (its reading thread), and writing is done in the thread that triggered it. Everything that's global is now stored in just one place. 4) Asynchronous I/O with an event loop. Small improvement over the above; now that there's no OS threads involved, you're now limited only by available memory. You could have tens of millions of connected clients as long as they're all quiet. Concurrency is now 100% in the programmer's hands (with explicit yield points), instead of having automatic yield points any time a thread blocks for any reason; this restricts parallelism to the points where actual I/O is happening. One DNS lookup can bring you down, but 100K connected sockets would be no problem at all. Async I/O certainly has its place, but the performance advantages don't really kick in until you're scaling to ridiculous levels of dormant clients. (If you have a large number of *active* clients, your actual work is going to be more significant, and you'll need to spend more time in the CPU, making multiple processes look more attractive.) Its biggest advantages are in _code simplicity_, not performance. (And only for people who can't wrap their head around threads; if you're fluent in threads, the simplicity is comparable, so there's less advantage.) ChrisA From rosuav at gmail.com Wed Apr 4 07:21:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2018 21:21:02 +1000 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On Wed, Apr 4, 2018 at 9:02 PM, Richard Damon wrote: > Asynchronous processing will use a bit more of some processing resources > to handle the multi-processing, but it can be more efficient at fully > using many of the resources that are available. > > Take your file download example. When you are downloading a file, your > processor sends out a request for a chuck of the data, then waits for > the response. The computer on the other end gets that requests, sends a > packet, and then waits. You get that packet, send and acknowledgement, > and then wait, the other computer gets that acknowledgement and sends > more data, and then waits, and so on. Even if your pipe to the Internet > is the limiting factor, there is a fair amount of dead time in this > operation, so starting another download to fill more of that pipe can > decrease the total time to get all the data downloaded. Assuming that you're downloading this via a TCP/IP socket (eg from a web server), the acknowledgements are going to be handled by the OS kernel, not your process. Plus, TCP allows acknowledgements to stack, so you're not really waiting for each other's acks very much. A single socket is entirely capable of saturating one computer's uplink. I once proved to my employer that a particular host had gigabit internet by renting a dozen EC2 instances with 100Mbit uplinks and having each of them transfer data to the same host concurrently - via one socket connection each. Much more interesting is operating a high-bandwidth server (let's say, a web application) that is responding to requests from myriad low-bandwidth clients. Traditional servers such as Apache's prefork mode would follow a model like this: while "more sockets": newsock = mainsock.accept() fork_to_subprocess(handler, newsock) def handler(sock): while "need headers": sock.receive_headers() while "need body": sock.receive_body() generate_response() while "response still sending": sock.send_response() A threaded model does the same thing, but instead of forking a subprocess, it spawns a thread. The handler is pretty simple and straight-forward; it reads from the socket until it has everything it needs, then it sends off a response. Both reading and writing can and will block, and generating the response is the only part that's really CPU-bound. "Parallelism" here means two things: how many active clients can you support (throughput), and how many dormant clients can you support (saturation). In a forked model, you spend a lot of resources spinning up processes (you can reduce this with process pools and such, at the expense of code complexity and a slower spin-down when idle); in a threaded model, you spend far less, but you're still paying a significant price per connection, and saturation can be a problem. The beauty of async I/O is that saturation becomes almost completely insignificant; the cost is that throughput is capped at a single thread's capabilities. In theory, you could use async I/O with multiple threads pumping the same set of events. I'm not sure if anyone has ever actually done this, as it combines the complexities of both models, but it would maximize both throughput and saturation levels - dormant clients cost very little, and you're able to use multiple CPU cores. More commonly, you could run a thread pool, doling out clients to whichever thread is least busy, and then having each thread run an independent event loop, which would be fine in the average case. But that's still more complicated; you still have to think about threads. > Yes, if your single path of execution can fully use the critical > resources, then adding asynchronous processing won't help, but rarely > does it. Very few large machines today a single-threaded, but most have > multiple cores and often even those cores have the ability to handle > multiple threads at once. Thus there normally are extra resources that > the asynchronous processing can better use up, so even processor usage > can be improved in many cases. I'm not sure what tasks would allow you to reduce processor usage this way. Got an example? ChrisA From listes at salort.eu Wed Apr 4 08:16:59 2018 From: listes at salort.eu (Julien Salort) Date: Wed, 4 Apr 2018 14:16:59 +0200 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: <0b1a67c4-b9cc-4aff-3d1d-c585635ef0fd@salort.eu> Le 04/04/2018 ? 09:27, Steven D'Aprano a ?crit?: > Yes, this exactly. And if you're writing a web app, or certain kinds of > desktop apps, these seems sensible. I don't want my browser to come to a > complete halt just because some resource is taking a few seconds to > respond. > > But honestly, from everything I've seen, outside of browser apps (and I'm > not even sure about them), async processing looks to me like the wrong > solution to, well, everything. For what it's worth, I can give you an example that I have been playing with lately, and it has nothing to do with browser app. I have been doing scientific image acquisition with Python for some time, and was quite happy with my program. But then, I suddently needed to fetch from several cameras at once, and also query another device at another interval. Of course, it is possible to do that in a simple loop without asyncio, but I thought I would give asyncio a try, and I was amazed at how easy it makes this kind of task. And then it is simple to remove/add a camera, etc. My only concern is that I tend to have code duplication between the async version of the program and the sync version of the program. In this case, the script spends most of its time waiting for a frame to be available on the cameras, and the time interval to query the other device. The fetching and processing of the frames take negligible time. The library that I use is not asynchronous, but it was very easy to run_in_executor the C function that blocks until a frame is available on a given camera. Compared to a non-async version where I would have had to use that C function with some short timeout and iterate over all cameras, I think the async version is more efficient. The await will just be as long as it takes for the WaitFrame C function to run... When the C function ends, the asynchronous task resumes... There is no need to adjust some timeout by hand. Bests, Julien From rosuav at gmail.com Wed Apr 4 08:45:18 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Apr 2018 22:45:18 +1000 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: <0b1a67c4-b9cc-4aff-3d1d-c585635ef0fd@salort.eu> References: <0b1a67c4-b9cc-4aff-3d1d-c585635ef0fd@salort.eu> Message-ID: On Wed, Apr 4, 2018 at 10:16 PM, Julien Salort wrote: > In this case, the script spends most of its time waiting for a frame to be > available on the cameras, and the time interval to query the other device. > The fetching and processing of the frames take negligible time. The library > that I use is not asynchronous, but it was very easy to run_in_executor the > C function that blocks until a frame is available on a given camera. > > Compared to a non-async version where I would have had to use that C > function with some short timeout and iterate over all cameras, I think the > async version is more efficient. The await will just be as long as it takes > for the WaitFrame C function to run... When the C function ends, the > asynchronous task resumes... There is no need to adjust some timeout by > hand. Can you give an example? Let's say we have a simple blocking C function: int get_data() { sleep(2); return 42; } How do you use run_in_executor to turn this asynchronous, and how would this compare to creating one thread for each camera? AIUI, run_in_executor uses a thread pool under the surface, so all you're doing is using threads via an asyncio interface. Comparing to a timeout implementation is unfair; a threaded implementation is more comparable. ChrisA From mcepl at cepl.eu Wed Apr 4 10:19:18 2018 From: mcepl at cepl.eu (=?iso-8859-2?Q?Mat=ECj?= Cepl) Date: Wed, 4 Apr 2018 16:19:18 +0200 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: <20180404141914.GA15427@mitmanek.ceplovi.cz> On 2018-04-04, 07:27 GMT, Steven D'Aprano wrote: > I'm no expert, but it seems to me that this has surely got to > be crazy talk. Whatever task you're doing, processing it > asynchronously doesn't reduce the amount of work. For example, > if you want to download ten files, you still have to download > all ten files, and they're not any smaller or the network > connection any faster because you're using async. I agree that the formulation is unfortunate, but your argument seems to lie only on semantics. Anyway, this https://hackernoon.com/asynchronous-python-45df84b82434 seems to be a better explanation of cooperative green threads and eventually also asyncio. Best, Mat?j -- https://matej.ceplovi.cz/blog/, Jabber: mcepl at ceplovi.cz GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8 [...] sleep is no substitute for caffeine. -- Robert Storey in review of Debian (when describing re-compilation of kernel :-) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From listes at salort.eu Wed Apr 4 11:48:35 2018 From: listes at salort.eu (Julien Salort) Date: Wed, 4 Apr 2018 17:48:35 +0200 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: <0b1a67c4-b9cc-4aff-3d1d-c585635ef0fd@salort.eu> Message-ID: <193d32d8-e93a-7e82-67be-7241e30b8b07@salort.eu> Le 04/04/2018 ? 14:45, Chris Angelico a ?crit?: > Can you give an example? Let's say we have a simple blocking C function: > int get_data() { > sleep(2); > return 42; > } I am not saying that I understand 100% and that this is the best way, but it works for me: % cat get_data.c #include int get_data() { ??? sleep(2); ??? return 42; } % clang -shared -o libgetdata.dylib get_data.c % cat get_data_async.py import ctypes import asyncio mylib = ctypes.cdll.LoadLibrary('libgetdata.dylib') loop = asyncio.get_event_loop() async def get_data(): ??? result = await loop.run_in_executor(None, mylib.get_data) ??? print('C function returned', result) ??? return result async def another_task(): ??? for i in range(5): ??????? print(i) ??????? await asyncio.sleep(1) loop.run_until_complete(asyncio.gather(get_data(), another_task())) loop.close() % python get_data_async.py 0 1 C function returned 42 2 3 4 > How do you use run_in_executor to turn this asynchronous, and how > would this compare to creating one thread for each camera? This is exactely like creating a thread. Except that I have to do so only for blocking calls and without having to bother myself with threads or thread pools. > AIUI, > run_in_executor uses a thread pool under the surface, so all you're > doing is using threads via an asyncio interface. Comparing to a > timeout implementation is unfair; a threaded implementation is more > comparable. Agreed. It is just that it looks very simple to me. But I have never really done any asynchronous programming before. So, maybe using threads is just as simple, I don't know. What I find nice with asyncio is that it integrates easily with already written Python code, i.e. converting synchronous code to asynchronous code is relatively straightforward. Again, my problem is that it leads to code duplication. But that probably means that I should separate the logic into separate functions more. Bests, Julien From tjol at tjol.eu Wed Apr 4 12:21:13 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 4 Apr 2018 18:21:13 +0200 Subject: julian 0.14 library In-Reply-To: References: Message-ID: <378418fb-7b23-8b42-448d-0f7abb5488c1@tjol.eu> On 2018-04-04 05:44, Chris Angelico wrote: > On Wed, Apr 4, 2018 at 12:24 PM, sum abiut wrote: >> Hi, >> Has anyone try this https://pypi.python.org/pypi/julian/0.14 >> >> i got this error trying to import julian >> >>>>> import julian >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib/python2.7/dist-packages/julian/__init__.py", line 1, >> in >> from julian.julian import to_jd, from_jd >> File "/usr/local/lib/python2.7/dist-packages/julian/julian.py", line 5 >> def __to_format(jd: float, fmt: str) -> float: >> ^ >> SyntaxError: invalid syntax >> > > Looks like that package requires Python 3, but was uploaded to PyPI > without any version tags. You could try running it in Python 3.x, but > there's no way to know which ".x" versions are going to work. the cheeseshop description says 3.2+ From rosuav at gmail.com Wed Apr 4 12:47:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Apr 2018 02:47:12 +1000 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: <193d32d8-e93a-7e82-67be-7241e30b8b07@salort.eu> References: <0b1a67c4-b9cc-4aff-3d1d-c585635ef0fd@salort.eu> <193d32d8-e93a-7e82-67be-7241e30b8b07@salort.eu> Message-ID: On Thu, Apr 5, 2018 at 1:48 AM, Julien Salort wrote: > Le 04/04/2018 ? 14:45, Chris Angelico a ?crit : >> How do you use run_in_executor to turn this asynchronous, and how >> would this compare to creating one thread for each camera? > > This is exactely like creating a thread. Except that I have to do so only > for blocking calls and without having to bother myself with threads or > thread pools. > It is just that it looks very simple to me. But I have never really done any > asynchronous programming before. So, maybe using threads is just as simple, > I don't know. What I find nice with asyncio is that it integrates easily > with already written Python code, i.e. converting synchronous code to > asynchronous code is relatively straightforward. Again, my problem is that > it leads to code duplication. But that probably means that I should separate > the logic into separate functions more. Okay, that's fair. So you're basically using asyncio as a means of managing threads, without actually using threads. I do recommend looking into the threading module and getting a feel for actual threaded programming, but if you don't, so be it. In any case, asyncio is functioning as a wrapper around a thread pool; so it's never going to be more efficient or more effective than an actual thread pool, but might be easier to work with in your code. ChrisA From suabiut at gmail.com Wed Apr 4 18:35:40 2018 From: suabiut at gmail.com (sum abiut) Date: Thu, 5 Apr 2018 09:35:40 +1100 Subject: julian 0.14 library In-Reply-To: <378418fb-7b23-8b42-448d-0f7abb5488c1@tjol.eu> References: <378418fb-7b23-8b42-448d-0f7abb5488c1@tjol.eu> Message-ID: I got the error below, tryinig in on python 3.2. import julian Traceback (most recent call last): File "", line 1, in ImportError: No module named julian On Thu, Apr 5, 2018 at 3:21 AM, Thomas Jollans wrote: > On 2018-04-04 05:44, Chris Angelico wrote: > > On Wed, Apr 4, 2018 at 12:24 PM, sum abiut wrote: > >> Hi, > >> Has anyone try this https://pypi.python.org/pypi/julian/0.14 > >> > >> i got this error trying to import julian > >> > >>>>> import julian > >> Traceback (most recent call last): > >> File "", line 1, in > >> File "/usr/local/lib/python2.7/dist-packages/julian/__init__.py", > line 1, > >> in > >> from julian.julian import to_jd, from_jd > >> File "/usr/local/lib/python2.7/dist-packages/julian/julian.py", line > 5 > >> def __to_format(jd: float, fmt: str) -> float: > >> ^ > >> SyntaxError: invalid syntax > >> > > > > Looks like that package requires Python 3, but was uploaded to PyPI > > without any version tags. You could try running it in Python 3.x, but > > there's no way to know which ".x" versions are going to work. > > the cheeseshop description says 3.2+ > -- > https://mail.python.org/mailman/listinfo/python-list > From dmarv at dop.com Wed Apr 4 18:51:35 2018 From: dmarv at dop.com (Dale Marvin) Date: Wed, 4 Apr 2018 15:51:35 -0700 Subject: julian 0.14 library In-Reply-To: References: <378418fb-7b23-8b42-448d-0f7abb5488c1@tjol.eu> Message-ID: <32b1bebd-5b2a-1062-4a5b-fbcbac70585f@dop.com> >> On 2018-04-04 05:44, Chris Angelico wrote: >>> On Wed, Apr 4, 2018 at 12:24 PM, sum abiut wrote: >>>> Hi, >>>> Has anyone try this https://pypi.python.org/pypi/julian/0.14 >>>> >>>> i got this error trying to import julian >>>> >>>>>>> import julian >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> File "/usr/local/lib/python2.7/dist-packages/julian/__init__.py", >> line 1, >>>> in >>>> from julian.julian import to_jd, from_jd >>>> File "/usr/local/lib/python2.7/dist-packages/julian/julian.py", line >> 5 >>>> def __to_format(jd: float, fmt: str) -> float: >>>> ^ >>>> SyntaxError: invalid syntax >>>> >>> >>> Looks like that package requires Python 3, but was uploaded to PyPI >>> without any version tags. You could try running it in Python 3.x, but >>> there's no way to know which ".x" versions are going to work. >> >> the cheeseshop description says 3.2+ >> -- >> https://mail.python.org/mailman/listinfo/python-list >> On 4/4/18 3:35 PM, sum abiut wrote: > I got the error below, tryinig in on python 3.2. > > import julian > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named julian > > > On Thu, Apr 5, 2018 at 3:21 AM, Thomas Jollans wrote: > Did you pip install julian into your python 3.2 installation? You may need type pip3 install julian depending upon how your python was installed. Dale From tjreedy at udel.edu Wed Apr 4 22:52:24 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 4 Apr 2018 22:52:24 -0400 Subject: Asynchronous processing is more efficient -- surely not? In-Reply-To: References: Message-ID: On 4/4/2018 3:27 AM, Steven D'Aprano wrote: > So, I'm, still trying to wrap my brain around async processing, and I > started reading this tutorial: > > http://stackabuse.com/python-async-await-tutorial/ > > and the very first paragraph broke my brain. > > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." For multiple byte streams, async is more efficient in terms of bytes transmitted per unit time than transmitting each stream one at a time until completed. Indeed, multiple infinite streams can be interleaved. [snip] > But honestly, from everything I've seen, outside of browser apps (and I'm > not even sure about them), async processing looks to me like the wrong > solution to, well, everything. The async module is event-driven programming applied to transmission between cpu and disk, other processes, or other systems. The tkinter module does event-driven programming applied to transmission between cpu and humans (key and mouse input, screen output). Both tkinter and async have time events. One can even drive tkinter GUIs with the async loop instead of the tk loop. (And this allows use of 'async' and 'await' with tkinter programs.) Event-loop GUI applications and many games are 'asynchronous processing' in the generic sense. But these are a few decades old, not just a few years old. It combines the worst of sequential and > parallel processing with the benefits of neither. It's like cooperative > multi-tasking, only without the actual multi-tasking I am not sure what you mean by 'multi-tasking' here. > and even less > convenience. Its harder to use than threading or multiprocessing, but I can't imaging doing a gui with either, but maybe async is less convenient to use than async. > without their ability to run in parallel. It lacks the isolation of > multiprocessing, and the preemptive task swapping of threads/processes. > > Its as hard to wrap your brain around as parallel processing in general, > but with even worse performance than sequential processing. Do you have trouble with interactive games and GUIs? The async module is the same idea applied (mainly) to socket events. Indeed, key, mouse, and display events can be transmitted through sockets as byte streams. (I believe that this is how unix X-servers operate). > Am I totally wrong? -- Terry Jan Reedy From jfong at ms4.hinet.net Wed Apr 4 23:02:46 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 4 Apr 2018 20:02:46 -0700 (PDT) Subject: Is pdb suitable for debugging asyncio module? Message-ID: I have a module below and run it under pdb, the result seems not easy to xplain. (Note: the sleep periods are in reverse order) --------------- # asyncio_as_completed.py import asyncio @asyncio.coroutine def phase(i): print('in phase {}'.format(i)) yield from asyncio.sleep(0.5 - (0.1 * i)) print('done with phase {}'.format(i)) return 'phase {} result'.format(i) @asyncio.coroutine def main(num_phases): print('starting main') phases = [ phase(i) for i in range(num_phases) ] print('waiting for phases to complete') results = [] for next_to_complete in asyncio.as_completed(phases): answer = yield from next_to_complete # <--set breakpoint here print('received answer {!r}'.format(answer)) results.append(answer) print('results: {!r}'.format(results)) return results event_loop = asyncio.get_event_loop() try: event_loop.run_until_complete(main(3)) finally: event_loop.close() --------------- D:\Works\Python>py -m pdb asyncio_as_completed.py > d:\works\python\asyncio_as_completed.py(3)() -> import asyncio (Pdb) n > d:\works\python\asyncio_as_completed.py(5)() -> @asyncio.coroutine (Pdb) b 22 Breakpoint 1 at d:\works\python\asyncio_as_completed.py:22 (Pdb) c starting main waiting for phases to complete > d:\works\python\asyncio_as_completed.py(22)main() -> answer = yield from next_to_complete (Pdb) n in phase 1 in phase 0 in phase 2 Internal StopIteration # <--- > d:\works\python\asyncio_as_completed.py(8)phase() -> yield from asyncio.sleep(0.5 - (0.1 * i)) (Pdb) n > d:\works\python\asyncio_as_completed.py(9)phase() -> print('done with phase {}'.format(i)) (Pdb) n done with phase 2 > d:\works\python\asyncio_as_completed.py(10)phase() -> return 'phase {} result'.format(i) (Pdb) n Internal StopIteration: phase 2 result > d:\works\python\asyncio_as_completed.py(22)main() -> answer = yield from next_to_complete (Pdb) n > d:\works\python\asyncio_as_completed.py(23)main() -> print('received answer {!r}'.format(answer)) (Pdb) n received answer 'phase 2 result' # <--- > d:\works\python\asyncio_as_completed.py(24)main() -> results.append(answer) (Pdb) n > d:\works\python\asyncio_as_completed.py(21)main() -> for next_to_complete in asyncio.as_completed(phases): (Pdb) n > d:\works\python\asyncio_as_completed.py(22)main() -> answer = yield from next_to_complete (Pdb) n Internal StopIteration # <--- > d:\works\python\asyncio_as_completed.py(8)phase() -> yield from asyncio.sleep(0.5 - (0.1 * i)) (Pdb) n > d:\works\python\asyncio_as_completed.py(9)phase() -> print('done with phase {}'.format(i)) (Pdb) n done with phase 1 > d:\works\python\asyncio_as_completed.py(10)phase() -> return 'phase {} result'.format(i) (Pdb) n Internal StopIteration # <--- > d:\works\python\asyncio_as_completed.py(8)phase() -> yield from asyncio.sleep(0.5 - (0.1 * i)) (Pdb) n > d:\works\python\asyncio_as_completed.py(9)phase() -> print('done with phase {}'.format(i)) (Pdb) n done with phase 0 > d:\works\python\asyncio_as_completed.py(10)phase() -> return 'phase {} result'.format(i) (Pdb) n Internal StopIteration: phase 1 result # <--- > d:\works\python\asyncio_as_completed.py(22)main() -> answer = yield from next_to_complete (Pdb) n > d:\works\python\asyncio_as_completed.py(23)main() -> print('received answer {!r}'.format(answer)) (Pdb) n received answer 'phase 1 result' > d:\works\python\asyncio_as_completed.py(24)main() -> results.append(answer) (Pdb) n > d:\works\python\asyncio_as_completed.py(21)main() -> for next_to_complete in asyncio.as_completed(phases): (Pdb) n > d:\works\python\asyncio_as_completed.py(22)main() -> answer = yield from next_to_complete (Pdb) n > d:\works\python\asyncio_as_completed.py(23)main() -> print('received answer {!r}'.format(answer)) (Pdb) n received answer 'phase 0 result' > d:\works\python\asyncio_as_completed.py(24)main() -> results.append(answer) (Pdb) n > d:\works\python\asyncio_as_completed.py(21)main() -> for next_to_complete in asyncio.as_completed(phases): (Pdb) n > d:\works\python\asyncio_as_completed.py(25)main() -> print('results: {!r}'.format(results)) (Pdb) n results: ['phase 2 result', 'phase 1 result', 'phase 0 result'] > d:\works\python\asyncio_as_completed.py(26)main() -> return results (Pdb) n The program finished and will be restarted > d:\works\python\asyncio_as_completed.py(3)() -> import asyncio (Pdb) I saw three "Internal StopIteration" lines which match the three "phase" tasks, it's OK. But there are only two "Internal StopIteration: phase x result" lines, the "phase 0" was missed. Why is that? Best Regards, Jach Fong From paul.nospam at rudin.co.uk Thu Apr 5 02:40:21 2018 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 05 Apr 2018 07:40:21 +0100 Subject: Asynchronous processing is more efficient -- surely not? References: Message-ID: <87zi2ijgve.fsf@rudin.co.uk> Steven D'Aprano writes: > So, I'm, still trying to wrap my brain around async processing, and I > started reading this tutorial: > > http://stackabuse.com/python-async-await-tutorial/ > > and the very first paragraph broke my brain. > > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." > > I can agree with the first part of the first sentence (gaining a lot of > traction), and the first part of the second sentence (more difficult than > the traditional style), but the second part? Asynchronous processing is > *more efficient*? It really depends on your definition of "efficient". Using async generally introduces some overhead, so there's a cost. However it also allows for the possibility of making better use of your compute resources by doing useful work rather than idle-waiting for network interactions to complete. As with many things - it's a useful tool and can be used to your advantage, but you can also shoot yourself in the foot if used inappropriately. From acharbly at gmail.com Thu Apr 5 04:39:23 2018 From: acharbly at gmail.com (Prahallad Achar) Date: Thu, 5 Apr 2018 14:09:23 +0530 Subject: RegEx to match set of lines Message-ID: Hello, I would like to match set of lines from the below data. this data comes from one of the network Part of data : [ If circuit type is OCHCC then I need Circuit name and service ID from that group ] Circuit ID: ad8a0165:25 *Circuit Name: T3A_100G_SD20* Circuit Version: 0 Circuit Monitor: false Circuit Size: OCH-TRAIL *Circuit Type: Circuits::OCHCC_OVER_SUPER_CHANNEL_CIRCUIT* Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191.35(1566_72) [freq=19135000/dim=5000] Circuit OchncDir: 0 Circuit isGmpls: true *Circuit GmplsInfo.ServiceId: ad8a0165:25* Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191.35(1566_72) [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] *Circuit Source #0: NodeId=ad8a0165* PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] *Circuit Drop #0: NodeId=ad8a0169* PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected FULL data is below Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:14:21 telnet-1 at tcc102> Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:14:23 telnet-1 at tcc104> Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:14:25 telnet-1 at tcc103> Cmd: |dumpCircuitList| () Circuit object list: Circuit ID: ad8a0165:26 Circuit Name: TRAIL-T3A_100G_SD20 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::SUPER_CHANNEL_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191.35(1566_72) [freq=19135000/dim=5000] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:26 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191.35(1566_72) [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:27 Circuit Name: TRAIL-T3A_100G_SD20 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::CARRIER_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191350.00-32.20 [freq=19135000/dim=3220] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:26 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20_01 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191350.00-32.20 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:25 *Circuit Name: T3A_100G_SD20* Circuit Version: 0 Circuit Monitor: false Circuit Size: OCH-TRAIL *Circuit Type: Circuits::OCHCC_OVER_SUPER_CHANNEL_CIRCUIT* Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191.35(1566_72) [freq=19135000/dim=5000] Circuit OchncDir: 0 Circuit isGmpls: true *Circuit GmplsInfo.ServiceId: ad8a0165:25* Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191.35(1566_72) [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] *Circuit Source #0: NodeId=ad8a0165* PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] *Circuit Drop #0: NodeId=ad8a0169* PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:29 Circuit Name: TRAIL-T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::SUPER_CHANNEL_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-62.50 [freq=19140625/dim=6250] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:29 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-62.50 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:30 Circuit Name: TRAIL-T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::CARRIER_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-34.20 [freq=19140625/dim=3420] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:29 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25_01 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-34.20 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:28 Circuit Name: T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCH-TRAIL Circuit Type: Circuits::OCHCC_OVER_SUPER_CHANNEL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-62.50 [freq=19140625/dim=6250] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:28 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-62.50 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x300b StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x300b StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected End of Circuit List done 05:14:27 telnet-1 at tcc101> Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:18:50 telnet-1 at tcc102> Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:18:52 telnet-1 at tcc104> Cmd: |dumpCircuitList| () Circuit object list: End of Circuit List done 05:18:54 telnet-1 at tcc103> Cmd: |dumpCircuitList| () Circuit object list: Circuit ID: ad8a0165:28 Circuit Name: T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCH-TRAIL Circuit Type: Circuits::OCHCC_OVER_SUPER_CHANNEL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-62.50 [freq=19140625/dim=6250] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:28 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-62.50 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x300b StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x300b StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:30 Circuit Name: TRAIL-T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::CARRIER_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-34.20 [freq=19140625/dim=3420] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:29 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25_01 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-34.20 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:29 Circuit Name: TRAIL-T5_100G_SD25 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::SUPER_CHANNEL_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191406.25-62.50 [freq=19140625/dim=6250] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:29 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T5_100G_SD25 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191406.25-62.50 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x307d StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:25 Circuit Name: T3A_100G_SD20 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCH-TRAIL Circuit Type: Circuits::OCHCC_OVER_SUPER_CHANNEL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191.35(1566_72) [freq=19135000/dim=5000] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:25 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191.35(1566_72) [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x5002 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:27 Circuit Name: TRAIL-T3A_100G_SD20 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::CARRIER_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191350.00-32.20 [freq=19135000/dim=3220] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:26 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20_01 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191350.00-32.20 [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected Circuit ID: ad8a0165:26 Circuit Name: TRAIL-T3A_100G_SD20 Circuit Version: 0 Circuit Monitor: false Circuit Size: OCHNC-NOSPEC Circuit Type: Circuits::SUPER_CHANNEL_TRAIL_CIRCUIT Circuit Dir: Bidirectional Circuit SLA: 0 Circuit OchncChannel: 191.35(1566_72) [freq=19135000/dim=5000] Circuit OchncDir: 0 Circuit isGmpls: true Circuit GmplsInfo.ServiceId: ad8a0165:26 Circuit GmplsInfo.AllowedOptOperZone: 4 Circuit GmplsInfo.IsUni: false Circuit GmplsInfo.restorationMode: 0 Circuit GmplsInfo.revertiveMode: 0 Circuit GmplsInfo.revertiveSoakTime: 60 Circuit GmplsInfo.restorationStatus: 0 Circuit GmplsInfo.operZone: 3 Circuit GmplsInfo.priority: 0 Circuit GmplsInfo.circuitLabel: T3A_100G_SD20 Circuit GmplsInfo.downstreamPwrOffset: 0 Circuit GmplsInfo.upstreamPwrOffset: 0 Circuit GmplsInfo.allowRegens: 0 Circuit GmplsInfo.isRegenerated: 0 Circuit GmplsInfo.ochncChannels [n: 1] 0] 191.35(1566_72) [1] Circuit GmplsInfo.diversity [n: 0] Circuit GmplsInfo.wsonSignalingVersion: Circuits::WSON_VER_UPGRADED Circuit Flags: 0x0 --> numb of sources[1] Circuit Source #0: NodeId=ad8a0165 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE --> numb of drops[1] Circuit Drop #0: NodeId=ad8a0169 PortNum=0x5003 StsNum=0 VtNum=0 OduNum=0 memberNumber=0 DropProtection=FALSE PathProtection=Path Unprotected End of Circuit List done 05:18:56 telnet-1 at tcc101> From ankit.singh at 42hertz.com Thu Apr 5 04:59:19 2018 From: ankit.singh at 42hertz.com (ankit.singh at 42hertz.com) Date: Thu, 5 Apr 2018 01:59:19 -0700 (PDT) Subject: # of Months between two dates In-Reply-To: References: Message-ID: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> On Sunday, August 8, 2010 at 11:46:51 PM UTC+5:30, MRAB wrote: > Greg Lindstrom wrote: > > I work for a company that processes claims for the health care industry > > (Novasys Health, recently purchased by Centene Corp). My current > > assignment has me writing a routine to compute insurance premiums. One > > of the requirements is to determine how many months a policy has been in > > effect. The datetime module will give me the number of days but, with > > months having different lengths, that does not do me much good. I've > > looked in the calendar library but didn't see anything there, either. > > > > I've written a function to return the months between date1 and date2 but > > I'd like to know if anyone is aware of anything in the standard library > > to do the same? For bonus points, does anyone know if postgres can do > > the same (we use a lot of date/time funcitons in postgres, already, but > > didn't see this problem addressed). > > > [snip] > A simple expression is: > > diff = (current_year - start_year) * 12 + (current_month - start_month) > > According to this, if a policy started on 31 July 2010, then on 1 August > 2010 it has been in effect for 1 month. Is this reasonable? It depends! > > It's probably better to write the function yourself according to what > makes sense in your use-case, and document its behaviour clearly. Thanks for that answer From steve+comp.lang.python at pearwood.info Thu Apr 5 11:03:31 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Apr 2018 15:03:31 +0000 (UTC) Subject: RegEx to match set of lines References: Message-ID: On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote: > Hello, > I would like to match set of lines from the below data. this data comes > from one of the network Good grief! You don't need to post your entire data set! We don't need or want to see hundreds of lines. Cut your data down to a SMALL representative sample. Explain how it is coming to you: it looks like you are reading the data in something similar to key:value format. Is that correct? If so, you don't need a regex. This is not Perl, we have more than one tool in our toolbox and don't have to force everything to be a regex. The way I would process it would be to write a small accumulator function to group the lines into records, then a filter function to extract the records you want, and finally a function to extract the specific values you want from the record. Far more understandable and maintainable, and less fragile, than a horribly complex regex. -- Steve From supswain at gmail.com Thu Apr 5 11:06:10 2018 From: supswain at gmail.com (supswain at gmail.com) Date: Thu, 5 Apr 2018 08:06:10 -0700 (PDT) Subject: want to export some of the packets from a big pacp file to another file. Message-ID: Hi, I am using dpkt python package to parse .pcap file and I am able to do successfully. My requirement is to filter some of the traffic from the big .pcap file and to export the result to another file. I don't know how to do this. PFB the setup details I am using. ####################################### OS-windows 7 32 bit python->2.7.6 32 bit Highly appreciating your effort to help me. Thanks, Supriya From wegge at wegge.dk Thu Apr 5 13:59:50 2018 From: wegge at wegge.dk (Anders Wegge Keller) Date: Thu, 5 Apr 2018 19:59:50 +0200 Subject: want to export some of the packets from a big pacp file to another file. In-Reply-To: References: Message-ID: <20180405195950.69a0a14d@wegge.dk> P? Thu, 5 Apr 2018 08:06:10 -0700 (PDT) supswain at gmail.com skrev: > Hi, > > I am using dpkt python package to parse .pcap file and I am able to do > successfully. > > My requirement is to filter some of the traffic from the big .pcap file > and to export the result to another file. > > I don't know how to do this. What kind of filtering do you need? In many cases it would be faster and more convenient to use wireshark or other similar tools as a pass-through filter, rather than rolling your own. -- //Wegge From grant.b.edwards at gmail.com Thu Apr 5 14:33:56 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 5 Apr 2018 18:33:56 +0000 (UTC) Subject: want to export some of the packets from a big pacp file to another file. References: Message-ID: On 2018-04-05, supswain at gmail.com wrote: > Hi, > > I am using dpkt python package to parse .pcap file and I am able to do successfully. > > My requirement is to filter some of the traffic from the big .pcap > file and to export the result to another file. > > I don't know how to do this. The easiest way is to use tcpdump on the command line. Let's say you've got a huge file (huge.pcap), and all you want to see is TCP traffic to/from 10.0.0.104: tcpdump -r huge.pcap -w output.pcap tcp and host 10.0.0.104 If you insist on doing it in Python, then use can use pylibpcap to read/parse the file. https://sourceforge.net/projects/pylibpcap/files/pylibpcap/ When reading the file, you can use the normal capture filters that you use with tcpdump. Once you've read the packet, you can apply your own logic if you want. I don't recall ever trying to install it on windows. It requires the pcap library, which is available for Windows. I don't recall that it has methods to write a file, so you may have to roll that bit yourself. If you want to write something from scratch, here's the file format: https://wiki.wireshark.org/Development/LibpcapFileFormat You should be able to use ctypes to directly access the winpcap library if you want to: https://www.winpcap.org/ -- Grant Edwards grant.b.edwards Yow! ! Up ahead! It's a at DONUT HUT!! gmail.com From tjreedy at udel.edu Thu Apr 5 15:01:44 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Apr 2018 15:01:44 -0400 Subject: RegEx to match set of lines In-Reply-To: References: Message-ID: On 4/5/2018 11:03 AM, Steven D'Aprano wrote: > On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote: > >> I would like to match set of lines from the below data. this data comes >> from one of the network > > Good grief! You don't need to post your entire data set! We don't need or > want to see hundreds of lines. +100 > Cut your data down to a SMALL representative sample. Explain how it is > coming to you: it looks like you are reading the data in something > similar to key:value format. Is that correct? > > If so, you don't need a regex. This is not Perl, we have more than one > tool in our toolbox and don't have to force everything to be a regex. +10 Your bloated post will go to at least 10 archives and some unknown 1000s of people. > The way I would process it would be to write a small accumulator function > to group the lines into records, then a filter function to extract the > records you want, and finally a function to extract the specific values > you want from the record. In Python, I would write a generator to yield records (groups of lines pertaining to one circuit. It appears that each group starts with a circuid ID and ends with a blank line. Then for record in file: if wanted(record): process(record) > Far more understandable and maintainable, and less fragile, than a > horribly complex regex. I have done this sort of thing in C, but mixing together the code for separating, identifying, and processing records made it less transparent than the above. -- Terry Jan Reedy From skip.montanaro at gmail.com Thu Apr 5 15:41:25 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 5 Apr 2018 14:41:25 -0500 Subject: logging.FileHandler diff Py2 v Py3 In-Reply-To: References: Message-ID: > I'll poke around a little and maybe open a bug report if I can't find any > explanation for the change in behavior. Turns out to be a known problem with a bit of history: https://bugs.python.org/issue27805 Skip From ilias.taj at live.fr Thu Apr 5 16:02:44 2018 From: ilias.taj at live.fr (Ilias taj) Date: Thu, 5 Apr 2018 20:02:44 +0000 Subject: A problem ! Message-ID: Hello, I?m send you a mail because I have a book of Python for kids and it?s write to open the turtle mode. But when my turtle mode is open the code ? t.forward(50) ? doesn?t work and the picture I send you appear. Thank you for have riding my message BR Taj Ilias From elchino at cnn.cn Thu Apr 5 17:04:18 2018 From: elchino at cnn.cn (ElChino) Date: Thu, 5 Apr 2018 23:04:18 +0200 Subject: try-except syntax Message-ID: I'm trying to simplify a try-except construct. E.g. how come this: try: _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % pathname) except ImportError: pass except RuntimeError: pass return ("") Cannot be simplified into this: try: _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % pathname) except ImportError: except RuntimeError: pass return ("") Like a "fall-through" in a C-switch statement. From rgaddi at highlandtechnology.invalid Thu Apr 5 17:34:15 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 5 Apr 2018 14:34:15 -0700 Subject: try-except syntax In-Reply-To: References: Message-ID: On 04/05/2018 02:04 PM, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come > this: > ? try: > ??? _x, pathname, _y = imp.find_module (mod, mod_path) > ??? return ("%s" % pathname) > ? except ImportError: > ??? pass > ? except RuntimeError: > ??? pass > ??? return ("") > > Cannot be simplified into this: > ? try: > ??? _x, pathname, _y = imp.find_module (mod, mod_path) > ??? return ("%s" % pathname) > ? except ImportError: > ? except RuntimeError: > ??? pass > ??? return ("") > > Like a "fall-through" in a C-switch statement. try: _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % pathname) except (ImportError, RuntimeError): pass return ("") That handles the identical case. C-style fall-throughs where you have one switch have just a bit of code before the fall-through kicks in (the slightly non-identical case) is often the source of disastrous code errors. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ian.g.kelly at gmail.com Thu Apr 5 17:34:41 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Apr 2018 15:34:41 -0600 Subject: try-except syntax In-Reply-To: References: Message-ID: On Thu, Apr 5, 2018 at 3:04 PM, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come > this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > pass > except RuntimeError: > pass > return ("") > > Cannot be simplified into this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > except RuntimeError: > pass > return ("") > > Like a "fall-through" in a C-switch statement. You're looking for: try: _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % pathname) except (ImportError, RuntimeError): return ("") From ben.lists at bsb.me.uk Thu Apr 5 17:51:44 2018 From: ben.lists at bsb.me.uk (Ben Bacarisse) Date: Thu, 05 Apr 2018 22:51:44 +0100 Subject: try-except syntax References: Message-ID: <87bmexjp8v.fsf@bsb.me.uk> ElChino writes: > I'm trying to simplify a try-except construct. E.g. how come > this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > pass > except RuntimeError: > pass > return ("") > > Cannot be simplified into this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > except RuntimeError: > pass > return ("") > > Like a "fall-through" in a C-switch statement. The except parts don't fall through, and each one needs a "suite". Also, the "pass" before the return is mysterious which makes me think there's an indent error in what you posted. Anyway, to coalesce two or more exception handlers, you are probably looking for except (ImportError, RuntimeError): which matches both. -- Ben. From greg.ewing at canterbury.ac.nz Thu Apr 5 18:59:08 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 06 Apr 2018 10:59:08 +1200 Subject: try-except syntax In-Reply-To: <87bmexjp8v.fsf@bsb.me.uk> References: <87bmexjp8v.fsf@bsb.me.uk> Message-ID: Ben Bacarisse wrote: > Anyway, to coalesce two or more exception handlers, you are probably > looking for > > except (ImportError, RuntimeError): To the OP: Are you sure you really want to mask RuntimeError here? Usually it means something has gone seriously wrong, and is a symptom that shouldn't be ignored. -- Greg From stevenzhaoyi at gmail.com Thu Apr 5 19:12:08 2018 From: stevenzhaoyi at gmail.com (yi zhao) Date: Thu, 5 Apr 2018 16:12:08 -0700 (PDT) Subject: install MySQL-python failed .... Message-ID: $ python -m pip install MySQL-python Collecting MySQL-python Downloading MySQL-python-1.2.5.zip (108kB) 100% |????????????????????????????????| 112kB 260kB/s 930 [main] python2.7 12948 child_info_fork::abort: address space needed by 'datetime.dll' (0x870000) is already occupied Error [Errno 11] Resource temporarily unavailable while executing command python setup.py egg_info Exception: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run requirement_set.prepare_files(finder) File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file abstract_dist.prep_for_dist() File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist self.req_to_install.run_egg_info() File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 439, in run_egg_info command_desc='python setup.py egg_info') File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 667, in call_subprocess cwd=cwd, env=env) File "/usr/lib/python2.7/subprocess.py", line 390, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 917, in _execute_child self.pid = os.fork() OSError: [Errno 11] Resource temporarily unavailable anything hit similar issue? From larry.martell at gmail.com Thu Apr 5 19:33:32 2018 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 5 Apr 2018 19:33:32 -0400 Subject: install MySQL-python failed .... In-Reply-To: References: Message-ID: On Thu, Apr 5, 2018 at 7:12 PM, yi zhao wrote: > $ python -m pip install MySQL-python > Collecting MySQL-python > Downloading MySQL-python-1.2.5.zip (108kB) > 100% |????????????????????????????????| 112kB 260kB/s > 930 [main] python2.7 12948 child_info_fork::abort: address space needed by 'datetime.dll' (0x870000) is already occupied > Error [Errno 11] Resource temporarily unavailable while executing command python setup.py egg_info > Exception: > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main > status = self.run(options, args) > File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run > requirement_set.prepare_files(finder) > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files > ignore_dependencies=self.ignore_dependencies)) > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file > abstract_dist.prep_for_dist() > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist > self.req_to_install.run_egg_info() > File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 439, in run_egg_info > command_desc='python setup.py egg_info') > File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 667, in call_subprocess > cwd=cwd, env=env) > File "/usr/lib/python2.7/subprocess.py", line 390, in __init__ > errread, errwrite) > File "/usr/lib/python2.7/subprocess.py", line 917, in _execute_child > self.pid = os.fork() > OSError: [Errno 11] Resource temporarily unavailable > > > anything hit similar issue? Is this happening in cygwin? Or in a native linux? From songofacandy at gmail.com Thu Apr 5 19:36:33 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 6 Apr 2018 08:36:33 +0900 Subject: install MySQL-python failed .... In-Reply-To: References: Message-ID: https://stackoverflow.com/questions/11107155/how-to-fix-address-space-is-already-occupied-error-on-fetch-commit On Fri, Apr 6, 2018 at 8:12 AM, yi zhao wrote: > $ python -m pip install MySQL-python > Collecting MySQL-python > Downloading MySQL-python-1.2.5.zip (108kB) > 100% |????????????????????????????????| 112kB 260kB/s > 930 [main] python2.7 12948 child_info_fork::abort: address space needed by 'datetime.dll' (0x870000) is already occupied > Error [Errno 11] Resource temporarily unavailable while executing command python setup.py egg_info > Exception: > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main > status = self.run(options, args) > File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run > requirement_set.prepare_files(finder) > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files > ignore_dependencies=self.ignore_dependencies)) > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file > abstract_dist.prep_for_dist() > File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist > self.req_to_install.run_egg_info() > File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 439, in run_egg_info > command_desc='python setup.py egg_info') > File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 667, in call_subprocess > cwd=cwd, env=env) > File "/usr/lib/python2.7/subprocess.py", line 390, in __init__ > errread, errwrite) > File "/usr/lib/python2.7/subprocess.py", line 917, in _execute_child > self.pid = os.fork() > OSError: [Errno 11] Resource temporarily unavailable > > > anything hit similar issue? > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From steve+comp.lang.python at pearwood.info Thu Apr 5 22:09:21 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Apr 2018 02:09:21 +0000 (UTC) Subject: try-except syntax References: Message-ID: On Thu, 05 Apr 2018 23:04:18 +0200, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) imp.find_module is deprecated and should not be used in new code. Putting that aside, pathname is already a string. Why are you wasting time interpolating it into a bare "%s" string? Just say `return pathname`. > except ImportError: > pass > except RuntimeError: > pass > return ("") Unnecessary parens surrounding a single value. Possible indentation error. Surely the return "" needs to be indented level with the try/except statements? > Cannot be simplified into this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % > pathname) > except ImportError: > except RuntimeError: > pass > return ("") > > Like a "fall-through" in a C-switch statement. Because fall-through C switch syntax is an abomination, and fortunately the designer of Python has more sense than to allow that awfulness. The syntax you are looking for is: try: block except (ImportError, RuntimeError): block By the way, RuntimeError is almost never something you want to catch (except to log before bailing out). It should represent a fatal coding error, not something safe to ignore. -- Steve From jsf80238 at gmail.com Fri Apr 6 00:03:07 2018 From: jsf80238 at gmail.com (Jason Friedman) Date: Thu, 5 Apr 2018 22:03:07 -0600 Subject: # of Months between two dates In-Reply-To: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> References: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> Message-ID: > > > > I've written a function to return the months between date1 and date2 > but > > > I'd like to know if anyone is aware of anything in the standard library > > > to do the same? For bonus points, does anyone know if postgres can do > > > the same (we use a lot of date/time funcitons in postgres, already, but > > > didn't see this problem addressed). > > > It's probably better to write the function yourself according to what > > makes sense in your use-case, and document its behaviour clearly. > I suggest using the dateutil module ( https://pypi.python.org/pypi/python-dateutil) before writing your own. From steve+comp.lang.python at pearwood.info Fri Apr 6 02:16:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Apr 2018 06:16:37 +0000 (UTC) Subject: # of Months between two dates References: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> Message-ID: On Thu, 05 Apr 2018 22:03:07 -0600, Jason Friedman wrote: >> > > I've written a function to return the months between date1 and >> > > date2 >> but >> > > I'd like to know if anyone is aware of anything in the standard >> > > library to do the same? For bonus points, does anyone know if >> > > postgres can do the same (we use a lot of date/time funcitons in >> > > postgres, already, but didn't see this problem addressed). >> >> > >> > It's probably better to write the function yourself according to what >> > makes sense in your use-case, and document its behaviour clearly. >> >> > I suggest using the dateutil module ( > https://pypi.python.org/pypi/python-dateutil) before writing your own. I'm not seeing a "months between" function in dateutil. Have I missed something? The question of how many months are between two dates is hard to answer. For example: - between Jan 1 and Feb 1 is clearly one month (31 days); - unless you think all months should be 30 days, in which case its one month and one day; - giving one month from Jan 1 as Jan 31, which seems weird; - either way, the period between Feb 1 and Mar 1 is only four weeks and so obviously less than one month; - unless you think a month is four weeks precisely; - in which case it is one month between Jan 1 and Jan 29; - one month forward from Jun 30 is clearly Jul 30; - but one month back from Jul 31 is either Jun 30 or Jul 1; - instead of counting days, with all the difficulty that causes, we could just count how many times the month changes; - in which case, Jan 31 to Feb 1 is one month. I wish the calendar designers had made the year 13 months of exactly 4 weeks each, with one intercalary day left over (two in leap years). Half a year becomes exactly 6 months and two weeks; a quarter of a year becomes three months and one week. A third is a bit more than four weeks. Date calculations would be much simpler, with only one (or two in leap years) special case, the intercalary day, instead of 36. -- Steve From elchino at cnn.cn Fri Apr 6 04:08:06 2018 From: elchino at cnn.cn (ElChino) Date: Fri, 6 Apr 2018 10:08:06 +0200 Subject: try-except syntax In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > imp.find_module is deprecated and should not be used in new code. ... > try: > block > except (ImportError, RuntimeError): > block Thanks Steven and others who replied. Looks more elegant. > By the way, RuntimeError is almost never something you want to catch > (except to log before bailing out). It should represent a fatal coding > error, not something safe to ignore. I was simply playing around with 'imp'. Hence I blocked RuntimeError. From bc at freeuk.com Fri Apr 6 05:56:21 2018 From: bc at freeuk.com (bartc) Date: Fri, 6 Apr 2018 10:56:21 +0100 Subject: # of Months between two dates In-Reply-To: References: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> Message-ID: On 06/04/2018 07:16, Steven D'Aprano wrote: > - instead of counting days, with all the difficulty that > causes, we could just count how many times the month > changes; > > - in which case, Jan 31 to Feb 1 is one month. If you book airport parking in the UK, the charge period runs from the midnight before the drop-off time to the midnight following the pick-up time (so that the first and last days are a full 24 hours). So parking for 24 hours from 2pm one day to 2pm the next, you are charged for 48 hours. That suggests you will also be charged for two full days for the two minutes' parking between 23:59 and 00:01, but I haven't tried it to see one happens. Agree with the messiness of dealing with months, but I think it's one of those quirks that make life more interesting, like imperial measure. I don't think we really want metric applied to time and to dates. (10-day weeks? I don't think so.) -- bartc From steve+comp.lang.python at pearwood.info Fri Apr 6 07:32:01 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Apr 2018 11:32:01 +0000 (UTC) Subject: # of Months between two dates References: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> Message-ID: On Fri, 06 Apr 2018 10:56:21 +0100, bartc wrote: > Agree with the messiness of dealing with months, but I think it's one of > those quirks that make life more interesting, like imperial measure. I > don't think we really want metric applied to time and to dates. (10-day > weeks? I don't think so.) Ah, but five day weeks (there are exactly 73 such "weeks" in a year, excluding leap days) would be grand. The Discordians agree with me. https://en.wikipedia.org/wiki/Discordian_calendar -- Steve From steve+comp.lang.python at pearwood.info Fri Apr 6 07:49:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Apr 2018 11:49:37 +0000 (UTC) Subject: A bit of Python history Message-ID: I stumbled across this post from the Timbot, Tim Peters, back in 2000, where he correctly predicted that Python would get generators and iterators in Python 2: https://mail.python.org/pipermail/python-list/2000-January/033955.html as well as list comprehensions. -- Steve From arj.python at gmail.com Fri Apr 6 13:05:40 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 06 Apr 2018 17:05:40 +0000 Subject: A bit of Python history In-Reply-To: References: Message-ID: amazing ! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Fri, 6 Apr 2018, 15:52 Steven D'Aprano, < steve+comp.lang.python at pearwood.info> wrote: > I stumbled across this post from the Timbot, Tim Peters, back in 2000, > where he correctly predicted that Python would get generators and > iterators in Python 2: > > https://mail.python.org/pipermail/python-list/2000-January/033955.html > > as well as list comprehensions. > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > From jsf80238 at gmail.com Fri Apr 6 19:55:30 2018 From: jsf80238 at gmail.com (Jason Friedman) Date: Fri, 6 Apr 2018 17:55:30 -0600 Subject: # of Months between two dates In-Reply-To: References: <3994bb4b-1855-4ef1-a565-3f3098569c6b@googlegroups.com> Message-ID: > > >> > It's probably better to write the function yourself according to what > >> > makes sense in your use-case, and document its behaviour clearly. > >> > >> > > I suggest using the dateutil module ( > > https://pypi.python.org/pypi/python-dateutil) before writing your own. > > I'm not seeing a "months between" function in dateutil. Have I missed > something? > > Huh, you are correct. I've used dateutil often and incorrectly assumed it does everything. From supswain at gmail.com Sat Apr 7 06:39:06 2018 From: supswain at gmail.com (supswain at gmail.com) Date: Sat, 7 Apr 2018 03:39:06 -0700 (PDT) Subject: want to export some of the packets from a big pacp file to another file. In-Reply-To: References: <20180405195950.69a0a14d@wegge.dk> Message-ID: <5ee80c2d-fae5-4763-b451-dd465c881011@googlegroups.com> Hi Anders, Actually in my setup I am capturing packets from Spirent using wire-shark and need to parse those captured files using python code. Sometimes captured .pcap file is too big so parsing each packet one by one is being too time consuming during TC automation. So instead of that I was searching for a python library package which will help me to export the required packets(IP,TCP,UDP,Ethernet frame) from te big captured file and store in another .pcap file. Later I can use dpkt package to parse the content of the smaller captured file. From aspodgorski at gmail.com Sat Apr 7 13:19:18 2018 From: aspodgorski at gmail.com (Andrew Podgorski) Date: Sat, 7 Apr 2018 13:19:18 -0400 Subject: Installing Paraview 5.4.1-704g7198de6 (64) and Python 3.7.)b3 (64) on W10 Message-ID: I am trying to find out how to install the above programs together so that ParaView will recognize Python? I see so many responses on the web that I am confused. I NEED TO READ only vtk file? Andrew Podgorski a.podgorski at ieee.org From anton.alley at gmail.com Sat Apr 7 20:45:06 2018 From: anton.alley at gmail.com (Anton Alley) Date: Sat, 7 Apr 2018 19:45:06 -0500 Subject: pip problems Message-ID: (I am on Windows 10) When I install a new Python version, pip does not update all of the way. In the command line 'pip' still runs the old pip.exe, so I've had to manually move the new pip to C:\Windows . It would be great if you fixed this for future python versions! Thanks, Anton From murugesanpmc at hotmail.com Sun Apr 8 04:48:47 2018 From: murugesanpmc at hotmail.com (Murugesan R) Date: Sun, 8 Apr 2018 08:48:47 +0000 Subject: python.exe - Not able to access Message-ID: Hi, I have installed Python in my system Windows - 7 SP1, While accessing Python terminal i am facing below error message, Please help me to resolve this issue. [cid:05c05c66-16b2-46f1-99db-423c04a69dc4]l Regards, Murugesan From gurkeerat.kalsi at gmail.com Sun Apr 8 08:01:39 2018 From: gurkeerat.kalsi at gmail.com (Gurkeerat Singh) Date: Sun, 8 Apr 2018 05:01:39 -0700 Subject: python is not recognised Message-ID: hi, in my cmd when i type python it said python is not recognised as nternal or external command. please help me to solve the issues. -- Warm regards, Gurkeerat Singh Kalsi From python at mrabarnett.plus.com Sun Apr 8 19:10:13 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 9 Apr 2018 00:10:13 +0100 Subject: python is not recognised In-Reply-To: References: Message-ID: <99aed7cb-97a1-435e-0998-44f519072665@mrabarnett.plus.com> On 2018-04-08 13:01, Gurkeerat Singh wrote: > hi, > in my cmd when i type python it said python is not recognised as nternal or > external command. please help me to solve the issues. > You should either type the path to python.exe or include it in the PATH environment variable. Better yet, use py.exe instead. From python at mrabarnett.plus.com Sun Apr 8 19:11:21 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 9 Apr 2018 00:11:21 +0100 Subject: A problem ! In-Reply-To: References: Message-ID: <4bc14374-8a72-130e-80a0-4718bb8f8a77@mrabarnett.plus.com> On 2018-04-05 21:02, Ilias taj wrote: > Hello, > > I?m send you a mail because I have a book of Python for kids and it?s write to open the turtle mode. But when my turtle mode is open the code ? t.forward(50) ? doesn?t work and the picture I send you appear. > Thank you for have riding my message > > BR Taj Ilias > This is a text-only list, pictures are removed. From brgrt2 at gmail.com Mon Apr 9 01:44:50 2018 From: brgrt2 at gmail.com (brgrt2 at gmail.com) Date: Sun, 8 Apr 2018 22:44:50 -0700 (PDT) Subject: Python Idle not giving my prompt after If line Message-ID: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> I typed the If part of an If/Else statement, but did not get a prompt at the beginning of the next line when I hit return. Instead, the cursor lined up under the "p" of "print." Here is the line of text (it's part of a longer bit of coding, I copied out of a textbook). >>> if right_this_minute in odds: print("This minute seems a little odd.") [Return] You can't see it, but the cursor is blinking under the "p." Why is this happening and what's the fix? Thanks, Tamara From __peter__ at web.de Mon Apr 9 03:07:52 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Apr 2018 09:07:52 +0200 Subject: Python Idle not giving my prompt after If line References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: brgrt2 at gmail.com wrote: > I typed the If part of an If/Else statement, but did not get a prompt at > the beginning of the next line when I hit return. Instead, the cursor > lined up under the "p" of "print." Here is the line of text (it's part of > a longer bit of coding, I copied out of a textbook). > >>>> if right_this_minute in odds: > print("This minute seems a little odd.") [Return] > > You can't see it, but the cursor is blinking under the "p." > > Why is this happening and what's the fix? > > Thanks, > > Tamara It works as designed; the interpreter has no way of knowing whether you are about to write another line belonging to the if suite, like in if foo: print("clearing foo") foo = False That's why you have to hit twice to trigger execution of the code. By the way, when you copy (or write) a "longer bit" I recomend that you put the code into a py file so that you don't have to retype it when you want to make a small modification. Instead you can just hit F5 and see the effect of your changes. From tjol at tjol.eu Mon Apr 9 10:06:59 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 9 Apr 2018 16:06:59 +0200 Subject: pip problems In-Reply-To: References: Message-ID: On 2018-04-08 02:45, Anton Alley wrote: > (I am on Windows 10) When I install a new Python version, pip does not > update all of the way. In the command line 'pip' still runs the old > pip.exe, so I've had to manually move the new pip to C:\Windows . Was there a pip.exe in C:\Windows? That doesn't sound right! > It would be great if you fixed this for future python versions! > Does running "python" from the command line give you the right version? I expect it's just a matter of the Pythons being installed side-by-side and the old version taking precedence in the PATH. Having multiple Python versions side-by-side can be a bit difficult at times. I gather the standard advice on Windows is to call "py -3.6 -m pip" and so on instead of "pip" most of the time, just to be sure. Perhaps the Python installer should have an option to remove old Pythons from the PATH. Maybe it does. I wouldn't know. -- Thomas From brgrt2 at gmail.com Mon Apr 9 12:06:37 2018 From: brgrt2 at gmail.com (brgrt2 at gmail.com) Date: Mon, 9 Apr 2018 09:06:37 -0700 (PDT) Subject: Python Idle not giving my prompt after If line In-Reply-To: References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: On Monday, April 9, 2018 at 3:08:28 AM UTC-4, Peter Otten wrote: > brgrt2 at gmail.com wrote: > > > I typed the If part of an If/Else statement, but did not get a prompt at > > the beginning of the next line when I hit return. Instead, the cursor > > lined up under the "p" of "print." Here is the line of text (it's part of > > a longer bit of coding, I copied out of a textbook). > > > >>>> if right_this_minute in odds: > > print("This minute seems a little odd.") [Return] > > > > You can't see it, but the cursor is blinking under the "p." > > > > Why is this happening and what's the fix? > > > > Thanks, > > > > Tamara > > It works as designed; the interpreter has no way of knowing whether you are > about to write another line belonging to the if suite, like in > > if foo: > print("clearing foo") > foo = False > > That's why you have to hit twice to trigger execution of the code. > > By the way, when you copy (or write) a "longer bit" I recomend that you put > the code into a py file so that you don't have to retype it when you want to > make a small modification. Instead you can just hit F5 and see the effect of > your changes. Thanks, Peter, for your quick reply. But here's what happened. When I hit twice, the cursor did go back to the margin, but skipped two lines before doing so. Then when I hit after "else:" I got an error message again. What did I do wrong? Also, could you please tell me how to create a py file. Thanks. From tjreedy at udel.edu Mon Apr 9 13:18:46 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 9 Apr 2018 13:18:46 -0400 Subject: Python Idle not giving my prompt after If line In-Reply-To: References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: On 4/9/2018 3:07 AM, Peter Otten wrote: > brgrt2 at gmail.com wrote: > >> I typed the If part of an If/Else statement, but did not get a prompt at >> the beginning of the next line when I hit return. Instead, the cursor >> lined up under the "p" of "print." Here is the line of text (it's part of >> a longer bit of coding, I copied out of a textbook). >> >>>>> if right_this_minute in odds: >> print("This minute seems a little odd.") [Return] >> >> You can't see it, but the cursor is blinking under the "p." >> >> Why is this happening and what's the fix? > It works as designed; the interpreter has no way of knowing whether you are > about to write another line belonging to the if suite, like in > > if foo: > print("clearing foo") > foo = False To enter 'else', instead of another line under 'if', hit backspace. > That's why you have to hit twice to trigger execution of the code. When you are done entering the complete multiline statement. > By the way, when you copy (or write) a "longer bit" I recomend that you put > the code into a py file so that you don't have to retype it when you want to > make a small modification. Instead you can just hit F5 and see the effect of > your changes. -- Terry Jan Reedy From __peter__ at web.de Mon Apr 9 13:33:35 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Apr 2018 19:33:35 +0200 Subject: Python Idle not giving my prompt after If line References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: brgrt2 at gmail.com wrote: > On Monday, April 9, 2018 at 3:08:28 AM UTC-4, Peter Otten wrote: >> brgrt2 at gmail.com wrote: >> >> > I typed the If part of an If/Else statement, but did not get a prompt >> > at the beginning of the next line when I hit return. Instead, the >> > cursor lined up under the "p" of "print." Here is the line of text >> > (it's part of a longer bit of coding, I copied out of a textbook). >> > >> >>>> if right_this_minute in odds: >> > print("This minute seems a little odd.") [Return] >> > >> > You can't see it, but the cursor is blinking under the "p." >> > >> > Why is this happening and what's the fix? >> > >> > Thanks, >> > >> > Tamara >> >> It works as designed; the interpreter has no way of knowing whether you >> are about to write another line belonging to the if suite, like in >> >> if foo: >> print("clearing foo") >> foo = False >> >> That's why you have to hit twice to trigger execution of the >> code. >> >> By the way, when you copy (or write) a "longer bit" I recomend that you >> put the code into a py file so that you don't have to retype it when you >> want to make a small modification. Instead you can just hit F5 and see >> the effect of your changes. > > Thanks, Peter, for your quick reply. But here's what happened. When I hit > twice, the cursor did go back to the margin, but skipped two > lines before doing so. Then when I hit after "else:" I got an > error message again. What did I do wrong? I'm sorry, I did not read your question carefully enough, and missed the "else" part. Please read Terry's correction of my advice. > Also, could you please tell me > how to create a py file. Thanks. Choose "New File" in the "File" menu, then write your code in the window that pops up, save with "Save" (pick a meaningful name that does not collide with any name in Python's standard library) and finally run with "Run Module" in the "Run" menu. From brgrt2 at gmail.com Tue Apr 10 00:41:55 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 9 Apr 2018 21:41:55 -0700 (PDT) Subject: Python Idle not giving my prompt after If line In-Reply-To: References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: On Monday, April 9, 2018 at 1:19:13 PM UTC-4, Terry Reedy wrote: > On 4/9/2018 3:07 AM, Peter Otten wrote: > > brgrt2 at gmail.com wrote: > > > >> I typed the If part of an If/Else statement, but did not get a prompt at > >> the beginning of the next line when I hit return. Instead, the cursor > >> lined up under the "p" of "print." Here is the line of text (it's part of > >> a longer bit of coding, I copied out of a textbook). > >> > >>>>> if right_this_minute in odds: > >> print("This minute seems a little odd.") [Return] > >> > >> You can't see it, but the cursor is blinking under the "p." > >> > >> Why is this happening and what's the fix? > > > It works as designed; the interpreter has no way of knowing whether you are > > about to write another line belonging to the if suite, like in > > > > if foo: > > print("clearing foo") > > foo = False > > To enter 'else', instead of another line under 'if', hit backspace. > > > That's why you have to hit twice to trigger execution of the code. > > When you are done entering the complete multiline statement. > > > By the way, when you copy (or write) a "longer bit" I recomend that you put > > the code into a py file so that you don't have to retype it when you want to > > make a small modification. Instead you can just hit F5 and see the effect of > > your changes. > > -- > Terry Jan Reedy Thanks, Terry, for your help. From brgrt2 at gmail.com Tue Apr 10 00:43:30 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 9 Apr 2018 21:43:30 -0700 (PDT) Subject: Python Idle not giving my prompt after If line In-Reply-To: References: <8763717d-ef74-493d-bb92-7015f9644181@googlegroups.com> Message-ID: On Monday, April 9, 2018 at 1:34:04 PM UTC-4, Peter Otten wrote: > brgrt2 at gmail.com wrote: > > > On Monday, April 9, 2018 at 3:08:28 AM UTC-4, Peter Otten wrote: > >> brgrt2 at gmail.com wrote: > >> > >> > I typed the If part of an If/Else statement, but did not get a prompt > >> > at the beginning of the next line when I hit return. Instead, the > >> > cursor lined up under the "p" of "print." Here is the line of text > >> > (it's part of a longer bit of coding, I copied out of a textbook). > >> > > >> >>>> if right_this_minute in odds: > >> > print("This minute seems a little odd.") [Return] > >> > > >> > You can't see it, but the cursor is blinking under the "p." > >> > > >> > Why is this happening and what's the fix? > >> > > >> > Thanks, > >> > > >> > Tamara > >> > >> It works as designed; the interpreter has no way of knowing whether you > >> are about to write another line belonging to the if suite, like in > >> > >> if foo: > >> print("clearing foo") > >> foo = False > >> > >> That's why you have to hit twice to trigger execution of the > >> code. > >> > >> By the way, when you copy (or write) a "longer bit" I recomend that you > >> put the code into a py file so that you don't have to retype it when you > >> want to make a small modification. Instead you can just hit F5 and see > >> the effect of your changes. > > > > Thanks, Peter, for your quick reply. But here's what happened. When I hit > > twice, the cursor did go back to the margin, but skipped two > > lines before doing so. Then when I hit after "else:" I got an > > error message again. What did I do wrong? > > I'm sorry, I did not read your question carefully enough, and missed the > "else" part. Please read Terry's correction of my advice. > > > Also, could you please tell me > > how to create a py file. Thanks. > > Choose "New File" in the "File" menu, then write your code in the window > that pops up, save with "Save" (pick a meaningful name that does not collide > with any name in Python's standard library) and finally run with "Run > Module" in the "Run" menu. Thanks, Peter, for your help. From brgrt2 at gmail.com Tue Apr 10 01:06:57 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 9 Apr 2018 22:06:57 -0700 (PDT) Subject: Filtering computer.lang.python Message-ID: This is the first time I've joined a google group and I don't understand the setup. Why are most of the posts in this group unrelated to python, and how do I filter this junk (sorry) out? From brgrt2 at gmail.com Tue Apr 10 01:10:13 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 9 Apr 2018 22:10:13 -0700 (PDT) Subject: How to apply filters to posts Message-ID: This is the first time I've joined a google group and I don't understand the setup. Why are most of the posts in this group unrelated to python, and how do I filter this junk (sorry) out? From rosuav at gmail.com Tue Apr 10 01:21:30 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Apr 2018 15:21:30 +1000 Subject: How to apply filters to posts In-Reply-To: References: Message-ID: On Tue, Apr 10, 2018 at 3:10 PM, T Berger wrote: > This is the first time I've joined a google group and I don't understand the setup. Why are most of the posts in this group unrelated to python, and how do I filter this junk (sorry) out? > Probably most of them ARE junk. Google Groups has a lot of spam in it. I recommend, instead, joining the mailing list: https://mail.python.org/mailman/listinfo/python-list Other people recommend Gmane, which is also a highly viable option. ChrisA From info at egenix.com Tue Apr 10 02:49:30 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 10 Apr 2018 08:49:30 +0200 Subject: ANN: PyDDF Python Spring Sprint 2018 Message-ID: <2fc59802-5af3-49b0-6b32-c4706d466d0e@egenix.com> [This announcement is in German since it targets a Python sprint in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG PyDDF Python Sprint Sprint 2018 in D?sseldorf Samstag, 14.04.2018, 10:00-18:00 Uhr Sonntag, 15.04.2018, 10:00-18:00 Uhr trivago GmbH, Karl-Arnold-Platz 1A, 40474 D?sseldorf Python Meeting D?sseldorf https://pyddf.de/sprint2018/ https://www.egenix.com/company/news/PyDDF-Spring-Sprint-2018 ________________________________________________________________________ INFORMATION Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher Unterst?tzung der *trivago GmbH* ein Python Sprint Wochenende im April. Der Sprint findet am Wochenende 14./15.4.2018 in der trivago Niederlassung am Karl-Arnold-Platz 1A statt (nicht am Bennigsen-Platz 1). Folgende Themengebiete haben wir als Anregung angedacht: * Openpyxl - https://pythonhosted.org/openpyxl/ * Python auf einem Raspberry Pi - Cluster * BeeWare - https://pybee.org/ * Virtualenv-Boot-Datei - https://github.com/jedie/bootstrap_env * Django-CMS Zusammenstellung - https://github.com/jedie/pylucid * Django Blog Bot zu federierten Messaging Platformen * PyEditor - https://github.com/PyEditor/PyEditor * PyRun Portierung auf Python 3.6 - http://pyrun.org/ * mxDateTime Portierung auf Python 3.6 Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen und umsetzen. Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: http://pyddf.de/sprint2018/ Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir uns dort koordinieren: https://www.egenix.com/mailman/listinfo/pyddf ________________________________________________________________________ ?BER UNS Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 10 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From tjol at tjol.eu Tue Apr 10 03:23:45 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 10 Apr 2018 09:23:45 +0200 Subject: Filtering computer.lang.python In-Reply-To: References: Message-ID: On 2018-04-10 07:06, T Berger wrote: > This is the first time I've joined a google group and I don't understand the setup. Why are most of the posts in this group unrelated to python, and how do I filter this junk (sorry) out? > Welcome to python-list/comp.lang.python! This isn't originally a Google group. Google just mirrors the old USENET group, which is awash with spam. There is also a mailing list version of this group (posts are mirrored both ways) at https://mail.python.org/mailman/listinfo/python-list The mailing list has proper spam filtering and some moderation. None (or barely any) of the regulars use Google Groups. Some people use USENET directly and maintain their own extensive filtering regime to make it readable. Probably most of us use the mailing list, because it's just so much nicer! -- Thomas From gheskett at shentel.net Tue Apr 10 06:03:05 2018 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 10 Apr 2018 06:03:05 -0400 Subject: Filtering computer.lang.python In-Reply-To: References: Message-ID: <201804100603.05426.gheskett@shentel.net> On Tuesday 10 April 2018 01:06:57 T Berger wrote: > This is the first time I've joined a google group and I don't > understand the setup. Why are most of the posts in this group > unrelated to python, and how do I filter this junk (sorry) out? google-groups is an spamvertizing madhouse. Many send any incoming that originates there to /dev/null. It looks like you got thru because they've registered a new name that doesn't quite match my procmail rules. But as long as it stays on topic I won't add it to the ruleset just yet. Python does have its own mailing list, and if you are genuinely interested in python and aren't put off by snarky comments as students try to get somebody else to do their homework for them, please join that mailing list. From the headers of this message: Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Subscribing to this list at the above address will do a lot of filtering for you. Ditch google-groups. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From wanderer at dialup4less.com Tue Apr 10 11:28:58 2018 From: wanderer at dialup4less.com (Wanderer) Date: Tue, 10 Apr 2018 08:28:58 -0700 (PDT) Subject: Filtering computer.lang.python In-Reply-To: References: Message-ID: On Tuesday, April 10, 2018 at 3:28:05 AM UTC-4, Thomas Jollans wrote: > On 2018-04-10 07:06, T Berger wrote: > > This is the first time I've joined a google group and I don't understand the setup. Why are most of the posts in this group unrelated to python, and how do I filter this junk (sorry) out? > > > > Welcome to python-list/comp.lang.python! > > This isn't originally a Google group. Google just mirrors the old USENET > group, which is awash with spam. > > There is also a mailing list version of this group (posts are mirrored > both ways) at https://mail.python.org/mailman/listinfo/python-list > > The mailing list has proper spam filtering and some moderation. None (or > barely any) of the regulars use Google Groups. Some people use USENET > directly and maintain their own extensive filtering regime to make it > readable. Probably most of us use the mailing list, because it's just so > much nicer! > > -- Thomas Here's my python code for filtering google groups again. You need to bookmark pyc files to run them from the bookmarks in firefox. You also need to create the bannedAuthors.txt and bannedSubjects.txt files. # remove banned author and authors with mostly caps # to compile to pyc #>>>import py_compile #>>>py_compile.compile("file.py") import urllib2 import webbrowser import os from bs4 import BeautifulSoup import argparse class Usage(Exception): def __init__(self, msg): self.msg = msg PALEMOON = 'Mozilla/5.0 (Windows NT 6.1; WOW64) KHTML/4.11 Gecko/20130308 Firefox/33.0 (PaleMoon/25.2)' WATERFOX = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 Firefox/51.1.0 Waterfox/51.1.0' USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 ' BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe' FILENAME = 'C:\\Pystuff\\pygroup.htm' SEDFILENAME = 'C:\\Pystuff\\SED.htm' WEBPAGE_START = "https://groups.google.com/forum/?_escaped_fragment_=forum/" PYGROUP_WEBPAGE = "comp.lang.python%5B" SED_WEBPAGE = "sci.electronics.design%5B" WEBPAGE_END = "%5D" BANNED_AUTHORS_FILE = 'C:\\Pystuff\\bannedAuthors.txt' BANNED_SUBJECTS_FILE = 'C:\\Pystuff\\bannedSubjects.txt' def getUserAgentVersion(): """ get the useragent version returns agentVersion -- user agent version in format Firefox/51.0.1 Waterfox/51.0.1 """ bvers = os.popen(BROWSERPATH + " -v").read() bversList = bvers.split() agentVersion = 'Firefox/' + bversList[2] + ' ' + bversList[1] + '/' + bversList[2] return agentVersion def getwebpage(url): """ Open a webpage url -- the url to the webpage returns page -- the source for the webpage """ user_agent = USERAGENTBASE + getUserAgentVersion() headers = { 'User-Agent' : user_agent } req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req) page = response.read() return page def getBannedAuthors(): """ Convert the banned authors text file into a list returns bannedAuthors -- list of banned author strings """ f = open(BANNED_AUTHORS_FILE, 'r') bannedAuthors = f.read().split('\n') f.close() return bannedAuthors def getBannedSubjects(): """ Convert the banned subjects text file into a list returns bannedAuthors -- list of banned author strings """ f = open(BANNED_SUBJECTS_FILE, 'r') bannedSubjects = f.read().split('\n') f.close() return bannedSubjects def removeBadAuthors(html_doc, filecode): """ Remove posts from google group by authors that are mostly caps or on the Banned List html_doc -- an html document """ bannedAuthors = getBannedAuthors() bannedSubjects = getBannedSubjects() #print bannedAuthors soup = BeautifulSoup(html_doc) #print soup.prettify() post = soup.find("tr") postcount = 0 banNoneCount = 0 banNameCount = 0 banBigCount = 0 banSubjectCount = 0 while post is not None: postcount += 1 author = post.find("td", "author") subject = post.find("td", "subject") if author is None or subject is None: print "Author is None" oldpost = post post = oldpost.find_next_sibling('tr') oldpost.decompose() postcount = postcount - 1 banNoneCount += 1 else: aname = author.get_text() print aname.encode("ascii", "ignore") asubject = ((subject.get_text()).lower()).replace(" ", "") bannedsubject = False for badsubject in bannedSubjects: print "BAD SUBJECT", badsubject if badsubject in asubject and len(badsubject) > 3: print "ASUBJECT", asubject.encode("ascii", "ignore") bannedsubject = True break if bannedsubject: print "Subject is Banned" oldpost = post post = oldpost.find_next_sibling('tr') oldpost.decompose() postcount = postcount - 1 banSubjectCount += 1 elif aname in bannedAuthors or \ 'smtb' in aname: print "Author is Banned" oldpost = post post = oldpost.find_next_sibling('tr') oldpost.decompose() postcount = postcount - 1 banNameCount += 1 else: print author numCaps = 1.0 * sum(1 for c in aname if c.isupper()) ratio = numCaps/(1.0*len(aname)) print ratio oldpost = post post = oldpost.find_next_sibling('tr') if ratio > 0.7 or len(aname) > 35: oldpost.decompose() postcount = postcount - 1 banBigCount += 1 print "BIG" if post is None: print "Post is NONE" f = open(FILENAME, filecode) f.write(soup.prettify().encode('ascii', 'ignore') + '
\n\r') f.write(' Banned No Name: ' + str(banNoneCount) + ', ') f.write(' Banned Name: ' + str(banNameCount) + ', ') f.write(' All Uppercase Name: ' + str(banBigCount) + ', ') f.write(' Banned Subject: ' + str(banSubjectCount) + ', ') f.write(' Total Banned: ' + str(banNoneCount +banNameCount + banBigCount + banSubjectCount) + '
\n\r') f.close() return postcount def main(sed = None): if sed is None: parser = argparse.ArgumentParser() parser.add_argument('-s', '--sed' , help="load sci.electronics.design group", action="store_true") args = parser.parse_args() if args.sed: webgroup = SED_WEBPAGE else: webgroup = PYGROUP_WEBPAGE else: if sed: webgroup = SED_WEBPAGE else: webgroup = PYGROUP_WEBPAGE postcount = 0 numberOposts = 0 filecode = 'w' while postcount < 10: webpage = WEBPAGE_START + webgroup + str(numberOposts + 1) + '-' + str(numberOposts + 50) + WEBPAGE_END print webpage html_doc = getwebpage(webpage) postcount += removeBadAuthors(html_doc, filecode) if postcount < 10: numberOposts += 50 filecode = 'a' print "postcount less than 10", postcount print "number of posts", numberOposts webbrowser.open(FILENAME) print 'done' if __name__ == "__main__": main() From srfpala at gmail.com Tue Apr 10 12:40:51 2018 From: srfpala at gmail.com (srfpala at gmail.com) Date: Tue, 10 Apr 2018 09:40:51 -0700 (PDT) Subject: Resolve ModuleNotFoundError: No module named 'wx' Message-ID: Running Win10 64-Bit and Pyscripter 3.3.2 Beta and/or VS 2017 with Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32. Interpreter sees import wx so will it attempt to find a specific file or reference to wx ? Exactly what is the interpreter looking for? I thought an environment variable D:\Python36\wxPython\site-packages would resolve the issue .. but I was wrong ! Advice please From cwr at seckford.org Tue Apr 10 16:06:17 2018 From: cwr at seckford.org (C W Rose) Date: Tue, 10 Apr 2018 21:06:17 +0100 Subject: Filtering computer.lang.python References: Message-ID: Thomas Jollans wrote: > > Welcome to python-list/comp.lang.python! > > This isn't originally a Google group. Google just mirrors the old USENET > group, which is awash with spam. > > There is also a mailing list version of this group (posts are mirrored > both ways) at https://mail.python.org/mailman/listinfo/python-list > > The mailing list has proper spam filtering and some moderation. None (or > barely any) of the regulars use Google Groups. Some people use USENET > directly and maintain their own extensive filtering regime to make it > readable. Probably most of us use the mailing list, because it's just so > much nicer! > > -- Thomas I fetch comp.lang.python from eternal.september with leafnode, and after 30 years of Usenet I recently had to install a news filter to remove the garbage. After the initial flurry the filter doesn't need much updating, but here's why it's necessary: Feb 1 comp.lang.python: 39 articles fetched 73 killed Feb 2 comp.lang.python: 43 articles fetched 57 killed Feb 3 comp.lang.python: 19 articles fetched 108 killed Feb 4 comp.lang.python: 36 articles fetched 122 killed Feb 5 comp.lang.python: 45 articles fetched 79 killed Feb 6 comp.lang.python: 68 articles fetched 93 killed Feb 7 comp.lang.python: 32 articles fetched 118 killed Feb 8 comp.lang.python: 41 articles fetched 100 killed Feb 9 comp.lang.python: 47 articles fetched 201 killed Feb 10 comp.lang.python: 44 articles fetched 137 killed Feb 11 comp.lang.python: 36 articles fetched 130 killed Feb 12 comp.lang.python: 13 articles fetched 79 killed Feb 13 comp.lang.python: 18 articles fetched 65 killed Feb 14 comp.lang.python: 34 articles fetched 72 killed Feb 15 comp.lang.python: 15 articles fetched 63 killed Feb 16 comp.lang.python: 14 articles fetched 72 killed Feb 17 comp.lang.python: 50 articles fetched 62 killed Feb 18 comp.lang.python: 37 articles fetched 35 killed Feb 19 comp.lang.python: 58 articles fetched 57 killed Feb 20 comp.lang.python: 71 articles fetched 46 killed Feb 21 comp.lang.python: 63 articles fetched 95 killed Feb 22 comp.lang.python: 35 articles fetched 91 killed Feb 23 comp.lang.python: 38 articles fetched 91 killed Feb 25 comp.lang.python: 51 articles fetched 153 killed Feb 26 comp.lang.python: 70 articles fetched 89 killed Feb 27 comp.lang.python: 64 articles fetched 68 killed Mar 1 comp.lang.python: 98 articles fetched 133 killed Mar 2 comp.lang.python: 65 articles fetched 110 killed Mar 3 comp.lang.python: 38 articles fetched 113 killed Mar 4 comp.lang.python: 31 articles fetched 16 killed Mar 5 comp.lang.python: 51 articles fetched 104 killed Mar 6 comp.lang.python: 46 articles fetched 40 killed Mar 7 comp.lang.python: 18 articles fetched 71 killed Mar 8 comp.lang.python: 44 articles fetched 85 killed Mar 9 comp.lang.python: 43 articles fetched 65 killed Mar 10 comp.lang.python: 16 articles fetched 39 killed Mar 11 comp.lang.python: 25 articles fetched 59 killed Mar 13 comp.lang.python: 43 articles fetched 186 killed Mar 14 comp.lang.python: 20 articles fetched 76 killed Mar 15 comp.lang.python: 32 articles fetched 33 killed Mar 16 comp.lang.python: 16 articles fetched 79 killed Mar 17 comp.lang.python: 11 articles fetched 69 killed Mar 18 comp.lang.python: 4 articles fetched 70 killed Mar 19 comp.lang.python: 10 articles fetched 67 killed Mar 20 comp.lang.python: 42 articles fetched 33 killed Mar 21 comp.lang.python: 43 articles fetched 77 killed Mar 22 comp.lang.python: 14 articles fetched 35 killed Mar 23 comp.lang.python: 37 articles fetched 39 killed Mar 26 comp.lang.python: 139 articles fetched 144 killed Mar 27 comp.lang.python: 83 articles fetched 86 killed Mar 28 comp.lang.python: 39 articles fetched 45 killed Mar 29 comp.lang.python: 12 articles fetched 29 killed Mar 31 comp.lang.python: 67 articles fetched 125 killed for totals of 2168 fetched and 4384 killed; that is, the group is now 2/3 spam and the volume doesn't seem to be decreasing. I don't understand why other groups gatewayed to Google Groups aren't spammed, but from a limited sample they don't seem to be. Will -- "That which is hateful to you, do not do to your fellow. That is the whole Torah; the rest is commentary." -- Hillel the Elder From tkadm30 at yandex.com Tue Apr 10 16:10:21 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Tue, 10 Apr 2018 16:10:21 -0400 Subject: Django-hotsauce 0.9.2 is out! Message-ID: <40144d98-f537-1092-fcc3-ebfe9fa85dfc@yandex.com> Hi everyone, I'm very happy to announce the Django-hotsauce 0.9.2 release: https://www.isotopesoftware.ca/pub/django-hotsauce-0.9.2.tar.gz https://pypi.python.org/pypi/Django-hotsauce/0.9.2 This is a minor bugfix/maintenance release. *What's new** * - It's now possible to use ZODB databases with Schevo backend without requiring libdurus library installed. - Updated support for PyPy 5.10 (CPython 2.7), uWSGI 2.0.17, and Django 1.11.10. For more info on Django-hotsauce, see: https://www.isotopesoftware.ca/software/django-hotsauce/ https://www.isotopesoftware.ca/wiki/DjangoHotSauce Have fun! Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From cuddlycaveman at gmail.com Wed Apr 11 02:36:27 2018 From: cuddlycaveman at gmail.com (cuddlycaveman at gmail.com) Date: Tue, 10 Apr 2018 23:36:27 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <67752e1d-bbe1-4152-9651-5cb5d4341b4e@googlegroups.com> Message-ID: <77335aab-68c2-42e4-96c2-b5978e8bd797@googlegroups.com> 387420479 00110011 00111000 00110111 00110100 00110010 00110000 00110100 00110111 00111001 72 bits Equal to (9^9)-10 00101000 00111001 01011110 00111001 00101001 00101101 00110001 00110000 64 bits 387420499 00110011 00111000 00110111 00110100 00110010 00110000 00110100 00111001 00111001 72 bits Equal to (9^9)+10 00101000 00111001 01011110 00111001 00101001 00101011 00110001 00110000 64 bits Or 387,420,489 387,420,499 00110011 00111000 00110111 00101100 00110100 00110010 00110000 00101100 00110100 00111000 00111001 00100000 00110011 00111000 00110111 00101100 00110100 00110010 00110000 00101100 00110100 00111001 00111001 184 bits Equal to ((9^9)-10) ((9^9)+10) 00101000 00101000 00111001 01011110 00111001 00101001 00101101 00110001 00110000 00101001 00100000 00101000 00101000 00111001 01011110 00111001 00101001 00101011 00110001 00110000 00101001 168 bits Or 387420479 387420499 00110011 00111000 00110111 00110100 00110010 00110000 00110100 00110111 00111001 0001010 00110011 00111000 00110111 00110100 00110010 00110000 00110100 00111001 00111001 152 bits Equal to (9^9)-10 (9^9)+10 00101000 00111001 01011110 00111001 00101001 00101101 00110001 00110000 0001010 00101000 00111001 01011110 00111001 00101001 00101011 00110001 00110000 136 bits Don?t know if that helps From sapna.intell at gmail.com Wed Apr 11 02:38:04 2018 From: sapna.intell at gmail.com (Priya Singh) Date: Tue, 10 Apr 2018 23:38:04 -0700 (PDT) Subject: Levenberg-Marquardt Algorithm Message-ID: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> Good morning. I need some suggestion from you if you have encountered this problem ever. I have two 2D arrays one R and another T (which is also a 2D array). Do you know how can I fit T with R in order to find central coordinate x0,y0 for T relative to R??? So the main question is do you know in python how can I fit two 2D arrays to find x0,y0 for one array relative to other. I shall use LM fit in python. But for fitting, I need to have some fittable model but here I am having only two 2D arrays. I know simple cross-correlation would have solved my problem but I have been instructed to do fitting using one array to other. Any comment or suggestion would be helpful. Thanks in advanced. Cheers!! From auriocus at gmx.de Wed Apr 11 03:19:44 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 11 Apr 2018 09:19:44 +0200 Subject: Levenberg-Marquardt Algorithm In-Reply-To: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> References: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> Message-ID: Am 11.04.18 um 08:38 schrieb Priya Singh: > I have two 2D arrays one R and another T (which is also a 2D array). > Do you know how can I fit T with R in order to find central > coordinate x0,y0 for T relative to R??? > > So the main question is do you know in python how can I fit two 2D arrays to find > x0,y0 for one array relative to other. I shall use LM fit in python. But for fitting, I need to have some fittable model but here I am having only two 2D arrays. I know simple cross-correlation would have solved my problem but I have been instructed to do fitting using one array to other. The request is nonsense. LM fits an analytical model to data, if you don't have an analytical model, you need another tool. Cross correlation is widely used and works well for many such tasks. In principle you could also interpolate the one array to new coordinates, e.g. using scipy.ndimage.interpolation.shift, and minimize the sum of squared differences. But still LM is the wrong tool here, it would get trapped in local minima soon, and it uses derivatives. Look for "image registration" to find typical algorithms used in this context. Christian From Karsten.Hilbert at gmx.net Wed Apr 11 06:13:19 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 11 Apr 2018 12:13:19 +0200 Subject: ANN: PyDDF Python Spring Sprint 2018 In-Reply-To: <2fc59802-5af3-49b0-6b32-c4706d466d0e@egenix.com> References: <2fc59802-5af3-49b0-6b32-c4706d466d0e@egenix.com> Message-ID: <20180411101319.GB5098@hermes.hilbert.loc> > * mxDateTime Portierung auf Python 3.6 +1 !! Karsten Hilbert -- From mrsikorarafal at gmail.com Wed Apr 11 06:30:24 2018 From: mrsikorarafal at gmail.com (Rafal Sikora) Date: Wed, 11 Apr 2018 03:30:24 -0700 (PDT) Subject: beacons and geofences Message-ID: Hi! I want users? devices to be able to monitor the maximum amount of POIs at once (geo-fences/beacons) and I need to prepare an algorithm solution for monitoring the POIs. How should it be implemented in Python? From tejaswidprakash at gmail.com Wed Apr 11 07:09:03 2018 From: tejaswidprakash at gmail.com (tejaswi prakash) Date: Wed, 11 Apr 2018 16:39:03 +0530 Subject: Levenberg-Marquardt Algorithm In-Reply-To: References: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> Message-ID: I am sorry, but I thought Levenberg marquardt was used quite bit in Image registration. Computing/refining homographies between two related views for instance. On Wed, Apr 11, 2018 at 12:49 PM, Christian Gollwitzer wrote: > Am 11.04.18 um 08:38 schrieb Priya Singh: > >> I have two 2D arrays one R and another T (which is also a 2D array). >> Do you know how can I fit T with R in order to find central >> coordinate x0,y0 for T relative to R??? >> >> So the main question is do you know in python how can I fit two 2D arrays >> to find >> x0,y0 for one array relative to other. I shall use LM fit in python. But >> for fitting, I need to have some fittable model but here I am having only >> two 2D arrays. I know simple cross-correlation would have solved my problem >> but I have been instructed to do fitting using one array to other. >> > > > The request is nonsense. LM fits an analytical model to data, if you don't > have an analytical model, you need another tool. Cross correlation is > widely used and works well for many such tasks. > > In principle you could also interpolate the one array to new coordinates, > e.g. using scipy.ndimage.interpolation.shift, and minimize the sum of > squared differences. But still LM is the wrong tool here, it would get > trapped in local minima soon, and it uses derivatives. Look for "image > registration" to find typical algorithms used in this context. > > > > Christian > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Wed Apr 11 07:21:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 11 Apr 2018 11:21:04 +0000 (UTC) Subject: Compression of random binary data References: <67752e1d-bbe1-4152-9651-5cb5d4341b4e@googlegroups.com> <77335aab-68c2-42e4-96c2-b5978e8bd797@googlegroups.com> Message-ID: On Tue, 10 Apr 2018 23:36:27 -0700, cuddlycaveman wrote: [snip a number of carefully chosen, non-random numbers shown in binary] > Don?t know if that helps Helps what? With no context, we don't know who you are replying to, what they asked, or why you think this is helpful. According to my archives, such as they are, you appear to be responding to a post made in either July 2016 or October 2017. -- Steve From zljubisic at gmail.com Wed Apr 11 14:48:46 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 11 Apr 2018 11:48:46 -0700 (PDT) Subject: Pandas, create new column if previous column(s) are not in [None, '', np.nan] Message-ID: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> I have a dataframe: import pandas as pd import numpy as np df = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan], 'B' : [None, np.nan, 'a', 'b', '']}) A B 0 a None 1 b NaN 2 a 3 None b 4 NaN I would like to create column C in the following way: column C = column B if column B is not in [None, '', np.nan] else column A How to do that? I tried: df['C'] = df[['A', 'B']].apply(lambda x: x[1] if x[1] in [None, '', np.nan] else x[0]) but I got all np.nan's. Where am I wrong? I am expecting to get column C as ['a', 'b', 'a', 'b', NaN] Regards. From breamoreboy at gmail.com Wed Apr 11 15:07:47 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Wed, 11 Apr 2018 20:07:47 +0100 Subject: Filtering computer.lang.python In-Reply-To: References: Message-ID: On 10/04/18 21:06, C W Rose via Python-list wrote: > Thomas Jollans wrote: >> >> Welcome to python-list/comp.lang.python! >> >> This isn't originally a Google group. Google just mirrors the old USENET >> group, which is awash with spam. >> >> There is also a mailing list version of this group (posts are mirrored >> both ways) at https://mail.python.org/mailman/listinfo/python-list >> >> The mailing list has proper spam filtering and some moderation. None (or >> barely any) of the regulars use Google Groups. Some people use USENET >> directly and maintain their own extensive filtering regime to make it >> readable. Probably most of us use the mailing list, because it's just so >> much nicer! >> >> -- Thomas > > I fetch comp.lang.python from eternal.september with leafnode, and after > 30 years of Usenet I recently had to install a news filter to remove the > garbage. After the initial flurry the filter doesn't need much updating, > but here's why it's necessary: > > Feb 1 comp.lang.python: 39 articles fetched 73 killed > Feb 2 comp.lang.python: 43 articles fetched 57 killed > Feb 3 comp.lang.python: 19 articles fetched 108 killed > Feb 4 comp.lang.python: 36 articles fetched 122 killed > Feb 5 comp.lang.python: 45 articles fetched 79 killed > Feb 6 comp.lang.python: 68 articles fetched 93 killed > Feb 7 comp.lang.python: 32 articles fetched 118 killed > Feb 8 comp.lang.python: 41 articles fetched 100 killed > Feb 9 comp.lang.python: 47 articles fetched 201 killed > Feb 10 comp.lang.python: 44 articles fetched 137 killed > Feb 11 comp.lang.python: 36 articles fetched 130 killed > Feb 12 comp.lang.python: 13 articles fetched 79 killed > Feb 13 comp.lang.python: 18 articles fetched 65 killed > Feb 14 comp.lang.python: 34 articles fetched 72 killed > Feb 15 comp.lang.python: 15 articles fetched 63 killed > Feb 16 comp.lang.python: 14 articles fetched 72 killed > Feb 17 comp.lang.python: 50 articles fetched 62 killed > Feb 18 comp.lang.python: 37 articles fetched 35 killed > Feb 19 comp.lang.python: 58 articles fetched 57 killed > Feb 20 comp.lang.python: 71 articles fetched 46 killed > Feb 21 comp.lang.python: 63 articles fetched 95 killed > Feb 22 comp.lang.python: 35 articles fetched 91 killed > Feb 23 comp.lang.python: 38 articles fetched 91 killed > Feb 25 comp.lang.python: 51 articles fetched 153 killed > Feb 26 comp.lang.python: 70 articles fetched 89 killed > Feb 27 comp.lang.python: 64 articles fetched 68 killed > Mar 1 comp.lang.python: 98 articles fetched 133 killed > Mar 2 comp.lang.python: 65 articles fetched 110 killed > Mar 3 comp.lang.python: 38 articles fetched 113 killed > Mar 4 comp.lang.python: 31 articles fetched 16 killed > Mar 5 comp.lang.python: 51 articles fetched 104 killed > Mar 6 comp.lang.python: 46 articles fetched 40 killed > Mar 7 comp.lang.python: 18 articles fetched 71 killed > Mar 8 comp.lang.python: 44 articles fetched 85 killed > Mar 9 comp.lang.python: 43 articles fetched 65 killed > Mar 10 comp.lang.python: 16 articles fetched 39 killed > Mar 11 comp.lang.python: 25 articles fetched 59 killed > Mar 13 comp.lang.python: 43 articles fetched 186 killed > Mar 14 comp.lang.python: 20 articles fetched 76 killed > Mar 15 comp.lang.python: 32 articles fetched 33 killed > Mar 16 comp.lang.python: 16 articles fetched 79 killed > Mar 17 comp.lang.python: 11 articles fetched 69 killed > Mar 18 comp.lang.python: 4 articles fetched 70 killed > Mar 19 comp.lang.python: 10 articles fetched 67 killed > Mar 20 comp.lang.python: 42 articles fetched 33 killed > Mar 21 comp.lang.python: 43 articles fetched 77 killed > Mar 22 comp.lang.python: 14 articles fetched 35 killed > Mar 23 comp.lang.python: 37 articles fetched 39 killed > Mar 26 comp.lang.python: 139 articles fetched 144 killed > Mar 27 comp.lang.python: 83 articles fetched 86 killed > Mar 28 comp.lang.python: 39 articles fetched 45 killed > Mar 29 comp.lang.python: 12 articles fetched 29 killed > Mar 31 comp.lang.python: 67 articles fetched 125 killed > > for totals of 2168 fetched and 4384 killed; that is, the group > is now 2/3 spam and the volume doesn't seem to be decreasing. > I don't understand why other groups gatewayed to Google Groups > aren't spammed, but from a limited sample they don't seem to be. > > Will > I have recently given up killing all the crap directly on gg as I can't be bothered any more. That is I would go onto gg and directly mark all the spam as spam. Is this coincidence? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From chema at rinzewind.org Wed Apr 11 15:19:22 2018 From: chema at rinzewind.org (=?utf-8?Q?Jos=C3=A9=20Mar=C3=ADa=20Mateos?=) Date: Wed, 11 Apr 2018 15:19:22 -0400 Subject: Pandas, create new column if previous column(s) are not in [None, '', np.nan] In-Reply-To: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> References: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> Message-ID: <1523474362.3233009.1334745384.6E947640@webmail.messagingengine.com> On Wed, Apr 11, 2018, at 14:48, zljubisic at gmail.com wrote: > I have a dataframe: > [...] This seems to work: df1 = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan], 'B' : [None, np.nan, 'a', 'b', '']}) df1['C'] = df1[['A', 'B']].apply(lambda x: x[0] if x[1] in [None, '', np.nan] else x[1], axis = 1) Two notes: - Do apply() on axis = 1, so you process every row. - You lambda function wasn't entirely correct, if I understood what you wanted to do. Cheers, -- Jos? Mar?a (Chema) Mateos https://rinzewind.org/blog-es || https://rinzewind.org/blog-en From sjeik_appie at hotmail.com Wed Apr 11 15:37:21 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Wed, 11 Apr 2018 19:37:21 +0000 Subject: Pandas, create new column if previous column(s) are not in [None, '', np.nan] Message-ID: On Apr 11, 2018 20:52, zljubisic at gmail.com wrote: > > I have a dataframe: > > import pandas as pd > import numpy as np > > df = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan], > 'B' : [None, np.nan, 'a', 'b', '']}) > > A B > 0 a None > 1 b NaN > 2 a > 3 None b > 4 NaN > > > I would like to create column C in the following way: > column C = column B if column B is not in [None, '', np.nan] > else column A > > How to do that? > > I tried: > > df['C'] = df[['A', 'B']].apply(lambda x: x[1] if x[1] in [None, '', np.nan] else x[0]) > > but I got all np.nan's. This is another approach: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html From codewizard at gmail.com Wed Apr 11 16:30:24 2018 From: codewizard at gmail.com (codewizard at gmail.com) Date: Wed, 11 Apr 2018 13:30:24 -0700 (PDT) Subject: Pandas, create new column if previous column(s) are not in [None, '', np.nan] In-Reply-To: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> References: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> Message-ID: <247fe7de-102e-4231-a4ce-b2c0fb4601e2@googlegroups.com> On Wednesday, April 11, 2018 at 2:49:01 PM UTC-4, zlju... at gmail.com wrote: > I have a dataframe: > > import pandas as pd > import numpy as np > > df = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan], > 'B' : [None, np.nan, 'a', 'b', '']}) > > A B > 0 a None > 1 b NaN > 2 a > 3 None b > 4 NaN > > > I would like to create column C in the following way: > column C = column B if column B is not in [None, '', np.nan] > else column A > > How to do that? > > I tried: > > df['C'] = df[['A', 'B']].apply(lambda x: x[1] if x[1] in [None, '', np.nan] else x[0]) > > but I got all np.nan's. > > Where am I wrong? > > I am expecting to get column C as ['a', 'b', 'a', 'b', NaN] > > Regards. Try this: df['C'] = df['B'].where(df['B'], other=df['A']) Regards, Igor. From hjp-python at hjp.at Wed Apr 11 16:55:43 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 11 Apr 2018 22:55:43 +0200 Subject: [OT] multicore/cpu history In-Reply-To: References: <5A8AB7870200001B0001DF67@smtp1.astron.nl> <20180325212907.wu545d46ajru6waj@hjp.at> Message-ID: <20180411205543.zqvcajm55lt4pekj@hjp.at> On 2018-03-25 22:52:59 +0000, Steven D'Aprano wrote: > On Sun, 25 Mar 2018 23:29:07 +0200, Peter J. Holzer wrote: > >> >> By the way, multiple CPU machines are different from CPUs with > >> >> multiple cores: > >> >> > >> >> http://smallbusiness.chron.com/multiple-cpu-vs-multicore-33195.html > >> > > >> > Yeah, it was always "multiple CPUs", not "multiple cores" when I was > >> > growing up. > > > > Yes, but the difference is only an implementation detail. > > Not really. With multiple CPUs, you have the option of running two > distinct OSes in isolation, not merely virtual machines but actual > distinct machines in the same box. Not in general, no. There may be hardware architectures which allow this (if I remember correctly, hardware partitioning on HP and IBM unix machines in the early noughties worked like this), but on a typical PC motherboard this wouldn't work: There is a lot of shared hardware outside of the CPUs, and two OSes running on different processors would have to be aware of each other to avoid stepping on each other's toes. And if they can do that, they can also do it on two cores of the same CPU. In a normal SMP system, there is no real difference between having 2 8-core processors and 1 16-core processor from the OS's point of view. The scheduler cares about it because caches and NUMA may make migrating a process from one core to another more expensive depending on where that other core is physically, but otherwise a core is processor. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From grant.b.edwards at gmail.com Wed Apr 11 17:48:39 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 11 Apr 2018 21:48:39 +0000 (UTC) Subject: [OT] multicore/cpu history References: <5A8AB7870200001B0001DF67@smtp1.astron.nl> <20180325212907.wu545d46ajru6waj@hjp.at> Message-ID: On 2018-03-25, Steven D'Aprano wrote: > Not really. With multiple CPUs, you have the option of running two > distinct OSes in isolation, not merely virtual machines but actual > distinct machines in the same box. Not on any of the multi-CPU motherboards I ever worked with. The CPUs shared SDRAM and used the same physical address space. They both saw the same PCI/ISA buses and all other peripherals. There was no way you could run two different OSes without some sort of hypervisor -- there was no practical difference between them and a modern multi-core CPU. -- Grant Edwards grant.b.edwards Yow! All of life is a blur at of Republicans and meat! gmail.com From elchino at cnn.cn Wed Apr 11 18:33:39 2018 From: elchino at cnn.cn (ElChino) Date: Thu, 12 Apr 2018 00:33:39 +0200 Subject: beacons and geofences In-Reply-To: References: Message-ID: Rafal Sikora wrote: > Hi! I want users? devices to be able to monitor the maximum amount of POIs at > once (geo-fences/beacons) and I need to prepare an algorithm solution for > monitoring the POIs. How should it be implemented in Python? What? You'll have to describe the problem in more details if you want any sensible answers. From skip.montanaro at gmail.com Wed Apr 11 19:46:32 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 11 Apr 2018 18:46:32 -0500 Subject: Filtering computer.lang.python In-Reply-To: References: Message-ID: > I fetch comp.lang.python from eternal.september with leafnode, and after > 30 years of Usenet I recently had to install a news filter to remove the > garbage. After the initial flurry the filter doesn't need much updating, > but here's why it's necessary: ... > for totals of 2168 fetched and 4384 killed; that is, the group > is now 2/3 spam and the volume doesn't seem to be decreasing. > I don't understand why other groups gatewayed to Google Groups > aren't spammed, but from a limited sample they don't seem to be. Just a thought, but you could maybe use SpamBayes to write your own spam filter for comp.lang.python. The gate_news program on mail.python.org does just that, using the training database I maintain. If anyone is interested, contact me. I can help set you up with the gate_news code. Skip From cuddlycaveman at gmail.com Wed Apr 11 21:29:09 2018 From: cuddlycaveman at gmail.com (cuddlycaveman at gmail.com) Date: Wed, 11 Apr 2018 18:29:09 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <67752e1d-bbe1-4152-9651-5cb5d4341b4e@googlegroups.com> <77335aab-68c2-42e4-96c2-b5978e8bd797@googlegroups.com> Message-ID: <3a9155ce-0bea-4a15-bb11-1854a244d356@googlegroups.com> I?m replying to your post on January 28th Nice carefully chosen non random numbers Steven D'Aprano. Was just doing what you asked, but you don?t remember ??? From jfong at ms4.hinet.net Thu Apr 12 00:16:58 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 11 Apr 2018 21:16:58 -0700 (PDT) Subject: How to write partial of a buffer which was returned from a C function to a file? Message-ID: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? Best Regards, Jach Fong From rosuav at gmail.com Thu Apr 12 01:31:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Apr 2018 15:31:17 +1000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> Message-ID: On Thu, Apr 12, 2018 at 2:16 PM, wrote: > This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. > > In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? > You suppose? Or have you tested it? ChrisA From jfong at ms4.hinet.net Thu Apr 12 02:20:14 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 11 Apr 2018 23:20:14 -0700 (PDT) Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> Message-ID: Chris Angelico? 2018?4?12???? UTC+8??1?31?35???? > On Thu, Apr 12, 2018 at 2:16 PM, wrote: > > This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. > > > > In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? > > > > You suppose? Or have you tested it? > > ChrisA Yes, I had test it once before. Now, I re-do it again to make sure. After a call which returns 3 bytes of data, I use len(buf) to check the length and get the number 24. I can see the first 24 bytes of data by using buf[:30] but buf[24] will cause an "index out of range" error. I don't know how to see what the buf[24] exactly is but I suppose it might be a zero byte. --Jach From cs at cskk.id.au Thu Apr 12 02:28:53 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 12 Apr 2018 16:28:53 +1000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> Message-ID: <20180412062853.GA66195@cskk.homeip.net> On 11Apr2018 21:16, jfong at ms4.hinet.net wrote: >This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. Could you show us the function? >In every call I know how much the valid data size is, but I suppose I can't >use slice to get it because there may be zero byte in it. What to do? Why not just return bytes? Allocate one of the correct size and copy the bytes into it, then return? Of course it is all hard to say without seeing some actual code. Cheers, Cameron Simpson From rosuav at gmail.com Thu Apr 12 04:05:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Apr 2018 18:05:07 +1000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> Message-ID: On Thu, Apr 12, 2018 at 4:20 PM, wrote: > Chris Angelico? 2018?4?12???? UTC+8??1?31?35???? >> On Thu, Apr 12, 2018 at 2:16 PM, wrote: >> > This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. >> > >> > In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? >> > >> >> You suppose? Or have you tested it? >> >> ChrisA > > Yes, I had test it once before. Now, I re-do it again to make sure. After a call which returns 3 bytes of data, I use len(buf) to check the length and get the number 24. I can see the first 24 bytes of data by using buf[:30] but buf[24] will cause an "index out of range" error. I don't know how to see what the buf[24] exactly is but I suppose it might be a zero byte. > If you have 24 bytes, they're numbered 0 through 23. So there is no byte at 24. ChrisA From jfong at ms4.hinet.net Thu Apr 12 04:11:48 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Thu, 12 Apr 2018 16:11:48 +0800 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: <20180412062853.GA66195@cskk.homeip.net> References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> <20180412062853.GA66195@cskk.homeip.net> Message-ID: This is the first time I am using python-list to interact with comp.lang.python forum (because there are so many spam when using browser to view it) so forgive me if something goes wrong. Python already treat the returned buffer as 'bytes'. The problem is Python don't know its size (or decides it wrong:-). --Jach Cameron Simpson at 2018/4/12 PM 02:28 wrote: > On 11Apr2018 21:16, jfong at ms4.hinet.net wrote: >> This C function returns a buffer which I declared it as a >> ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid >> data may vary from a few bytes to the whole size. > > Could you show us the function? > >> In every call I know how much the valid data size is, but I suppose I >> can't use slice to get it because there may be zero byte in it. What >> to do? > > Why not just return bytes? Allocate one of the correct size and copy the > bytes into it, then return? > > Of course it is all hard to say without seeing some actual code. > > Cheers, > Cameron Simpson > > > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jfong at ms4.hinet.net Thu Apr 12 05:14:57 2018 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 12 Apr 2018 02:14:57 -0700 (PDT) Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: <28fc220d-06af-447a-8c19-36a72c47b45a@googlegroups.com> Message-ID: <9e644770-c5a6-403a-802f-b06bd544566e@googlegroups.com> Chris Angelico? 2018?4?12???? UTC+8??4?05?29???? > On Thu, Apr 12, 2018 at 4:20 PM, wrote: > > Chris Angelico? 2018?4?12???? UTC+8??1?31?35???? > >> On Thu, Apr 12, 2018 at 2:16 PM, wrote: > >> > This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. > >> > > >> > In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? > >> > > >> > >> You suppose? Or have you tested it? > >> > >> ChrisA > > > > Yes, I had test it once before. Now, I re-do it again to make sure. After a call which returns 3 bytes of data, I use len(buf) to check the length and get the number 24. I can see the first 24 bytes of data by using buf[:30] but buf[24] will cause an "index out of range" error. I don't know how to see what the buf[24] exactly is but I suppose it might be a zero byte. > > > > If you have 24 bytes, they're numbered 0 through 23. So there is no byte at 24. > > ChrisA Using a technique you mentioned in subject "how to memory dump an object?" at 16/5/21, I confirm the length of buf was decided by a \x00 byte: >>> len(buf) 24 >>> id(buf) 13553888 >>> ptr = ctypes.cast(id(buf), ctypes.POINTER(ctypes.c_ubyte)) >>> buf[:24] b'\x05ALLOTNPUT_BUFFER_SIZE\x02+' >>> bytes([ptr[i] for i in range(50)]) b'\x02\x00\x00\x00X\xa1%\x1e\x18\x00\x00\x00\xff\xff\xff\xff\x05ALLOTNPUT_BUFFER_SIZE\x02+\x00\n\x00\x00\x00\x00\x00\x00\xb0\x9b' >>> but it won't help on solving my problem. Still need someone's help:-) --Jach From Karsten.Hilbert at gmx.net Thu Apr 12 05:31:46 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 12 Apr 2018 11:31:46 +0200 Subject: beacons and geofences In-Reply-To: References: Message-ID: <20180412093146.GA5044@hermes.hilbert.loc> On Thu, Apr 12, 2018 at 12:33:39AM +0200, ElChino wrote: > Rafal Sikora wrote: > > > Hi! I want users? devices to be able to monitor the maximum amount of POIs at > > once (geo-fences/beacons) and I need to prepare an algorithm solution for > > monitoring the POIs. How should it be implemented in Python? > > What? You'll have to describe the problem in more details > if you want any sensible answers. I just might so happen that the homework assignment did not contain much more in terms of description. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From sjeik_appie at hotmail.com Thu Apr 12 07:40:35 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Thu, 12 Apr 2018 11:40:35 +0000 Subject: How to write partial of a buffer which was returned from a C function to a file? Message-ID: On Apr 12, 2018 09:39, jfong at ms4.hinet.net wrote: > > Chris Angelico? 2018?4?12???? UTC+8??1?31?35???? > > On Thu, Apr 12, 2018 at 2:16 PM, wrote: > > > This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid data may vary from a few bytes to the whole size. > > > > > > In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be zero byte in it. What to do? > > > > > > > You suppose? Or have you tested it? > > > > ChrisA > > Yes, I had test it once before. Now, I re-do it again to make sure. After a call which returns 3 bytes of data, I use len(buf) to check the length and get the number 24. I can see the first 24 bytes of data by using buf[:30] but buf[24] will cause an "index out of range" error. I don't know how to see what the buf[24] exactly is but I suppose it might be a zero byte. Aren't you looking for the .value or the .raw property? From ned at nedbatchelder.com Thu Apr 12 07:50:08 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 12 Apr 2018 07:50:08 -0400 Subject: Compression of random binary data In-Reply-To: <3a9155ce-0bea-4a15-bb11-1854a244d356@googlegroups.com> References: <67752e1d-bbe1-4152-9651-5cb5d4341b4e@googlegroups.com> <77335aab-68c2-42e4-96c2-b5978e8bd797@googlegroups.com> <3a9155ce-0bea-4a15-bb11-1854a244d356@googlegroups.com> Message-ID: On 4/11/18 9:29 PM, cuddlycaveman at gmail.com wrote: > I?m replying to your post on January 28th > Nice carefully chosen non random numbers Steven D'Aprano. > Was just doing what you asked, but you don?t remember ??? Best practice is to include a quote of the thing you are replying to.? It makes it much easier for people to follow the thread of the discussion, especially when there are large gaps in the timeline. --Ned. From zljubisic at gmail.com Thu Apr 12 10:54:16 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 12 Apr 2018 07:54:16 -0700 (PDT) Subject: Pandas, create new column if previous column(s) are not in [None, '', np.nan] In-Reply-To: References: <05f88be5-f9ee-45cc-a4c0-7723d4650639@googlegroups.com> <1523474362.3233009.1334745384.6E947640@webmail.messagingengine.com> Message-ID: On Wednesday, 11 April 2018 21:19:44 UTC+2, Jos? Mar?a Mateos wrote: > On Wed, Apr 11, 2018, at 14:48, zlj...com wrote: > > I have a dataframe: > > [...] > > This seems to work: > > df1 = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan], > 'B' : [None, np.nan, 'a', 'b', '']}) > df1['C'] = df1[['A', 'B']].apply(lambda x: x[0] if x[1] in [None, '', np.nan] else x[1], axis = 1) > > Two notes: > > - Do apply() on axis = 1, so you process every row. > - You lambda function wasn't entirely correct, if I understood what you wanted to do. > > Cheers, > > -- > Jos? Mar?a (Chema) Mateos > https://rinzewind.org/blog-es || https://rinzewind.org/blog-en Thanks Jose, this what I needed. Thanks also to all others. Regards. From cs at cskk.id.au Thu Apr 12 18:52:55 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 13 Apr 2018 08:52:55 +1000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: <20180412225255.GA53897@cskk.homeip.net> On 12Apr2018 16:11, Jach Fong wrote: >This is the first time I am using python-list to interact with >comp.lang.python forum (because there are so many spam when using >browser to view it) so forgive me if something goes wrong. > >Python already treat the returned buffer as 'bytes'. The problem is >Python don't know its size (or decides it wrong:-). I think you'll need to show us your code. It isn't clear to me your problem is. Cheers, Cameron Simpson From steffie.booij at gmail.com Thu Apr 12 18:53:10 2018 From: steffie.booij at gmail.com (steffie.booij at gmail.com) Date: Thu, 12 Apr 2018 15:53:10 -0700 (PDT) Subject: Making matrix solver/ solver for X Message-ID: Hee guys, I'm learning Python partly for school and wanted to see if I could figure some things out myself. I wanted to make like a value finder, sort of like numpy.solve (sounds more ambitious than it is) but I'm sort of stuck, since I'm a beginner. Let's say I want to find the values of matrix X with X1, X2, X3 and X4. And that X is multiplied with matrix Q and then X substracted from it. I thought about: X = np.array(['X1', 'X2', 'X3', 'X4']) Q = np.array(['Q1', 'Q2', 'Q3', 'Q4']) P = (X*Q)-X I chose array's since all the X and Q values can be different. How would I be able to find the values of X if the Q-array would be given and it would have to be solved under the condition that out of 4 P values, at least 2 would be more or equal to sum of X. So solve condition: P[0]+P[1] ,P[0]+P[2] ,P[0]+P[3] ,P[1]+P[2] ,P[1]+P[3] ,P[2]+P[3] >= np.sum(X) So summary: If Q is given here, and only X is unknown, and P has only one unknown (X-array), how can I calculate the X-matrix with the solve condition? Can you guys help me? I feel like it's an easy set of lines of code, but like I said I'm still trying to learn. And improvise to see if I understand it. From greg.ewing at canterbury.ac.nz Thu Apr 12 19:25:48 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 13 Apr 2018 11:25:48 +1200 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: >>> On Thu, Apr 12, 2018 at 2:16 PM, wrote: >>> >>>> This C function returns a buffer which I declared it as a >>>> ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid >>>> data may vary from a few bytes to the whole size. I think we need to see the code you're using to call this C function. The crucial issue is: are *you* allocating this 0x10000 byte buffer and telling the function to read data into it, or does the function allocate the memory itself and return a pointer to it? If the function is allocating the buffer, then I don't think there's any way to make this work. The ctypes docs say this: > Fundamental data types, when returned as foreign function call results ... are > transparently converted to native Python types. In other words, if a foreign > function has a restype of c_char_p, you will always receive a Python bytes > object, not a c_char_p instance. The problem is that the only way ctypes can tell how long a bytes object to create for a c_char_p is by assuming that it points to a nul-terminated string. If it actually points to a char array that can legitimately contain zero bytes, then you're out of luck. To get around this, you may need to declare the return type as POINTER(c_char) instead: > For a general character pointer that may also point to binary data, > POINTER(c_char) must be used. I'm not sure where to go from here, though, because the ctypes documentation peters out before explaining exactly what can be done with a POINTER object. Another approach would be to allocate the buffer yourself and pass it into the C function, but whether that's possible depends on the details of the C API you're using. -- Greg From jfong at ms4.hinet.net Thu Apr 12 20:38:36 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Fri, 13 Apr 2018 08:38:36 +0800 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: Gregory Ewing at 2018/4/13 ?? 07:25 wrote: >>>> On Thu, Apr 12, 2018 at 2:16 PM,? wrote: >>>> >>>>> This C function returns a buffer which I declared it as a >>>>> ctypes.c_char_p. The buffer has size 0x10000 bytes long and the valid >>>>> data may vary from a few bytes to the whole size. > > I think we need to see the code you're using to call this > C function. > > The crucial issue is: are *you* allocating this 0x10000 byte > buffer and telling the function to read data into it, or > does the function allocate the memory itself and return a > pointer to it? I am working on a DLL's function. > > If the function is allocating the buffer, then I don't > think there's any way to make this work. The ctypes docs > say this: > >> Fundamental data types, when returned as foreign function call results >> ... are >> transparently converted to native Python types. In other words, if a >> foreign >> function has a restype of c_char_p, you will always receive a Python >> bytes >> object, not a c_char_p instance. > > The problem is that the only way ctypes can tell how long > a bytes object to create for a c_char_p is by assuming that > it points to a nul-terminated string. If it actually points > to a char array that can legitimately contain zero bytes, > then you're out of luck. > > To get around this, you may need to declare the return type > as POINTER(c_char) instead: > >> For a general character pointer that may also point to binary data, > > POINTER(c_char) must be used. I had missed this statement:-( To make a quick try, I set the function's restype to ctypes.POINTER(ctypes.c_ubyte), instead of ctypes.c_char_p. It's amazing, the \x00 trap can be avoided in this way. Now I can use "mydata = bytes(buf[:n])" to extract n bytes of data and write it to file. The problem was solved, and thanks for all your help. --Jach > > I'm not sure where to go from here, though, because the > ctypes documentation peters out before explaining exactly > what can be done with a POINTER object. > > Another approach would be to allocate the buffer yourself > and pass it into the C function, but whether that's possible > depends on the details of the C API you're using. > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From eryksun at gmail.com Thu Apr 12 21:08:18 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 13 Apr 2018 01:08:18 +0000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: On Thu, Apr 12, 2018 at 11:25 PM, Gregory Ewing wrote: > > To get around this, you may need to declare the return type > as POINTER(c_char) instead: > >> For a general character pointer that may also point to binary data, > >> POINTER(c_char) must be used. > > I'm not sure where to go from here, though, because the > ctypes documentation peters out before explaining exactly > what can be done with a POINTER object. Pointers can be indexed and sliced. You have to be careful, however, since there's no bounds checking. Alternatively, without copying, you can create an array view on the buffer, which is bounded and thus doesn't risk an access violation (segfault). For example: Say the function returns a pointer to a buffer with the contents b"spam\x00". Let's simulate the function result using a void * pointer to initialize a char * pointer: >>> buf0 = ctypes.create_string_buffer(b'spam') >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) >>> result = ctypes.POINTER(ctypes.c_char).from_buffer_copy(pvoid) This pointer object has just the address of the buffer, without supporting references in _b_base_ or _objects: >>> result._b_base_ is result._objects is None True (In other words, ctypes isn't responsible for the buffer, as simulated here. Libraries that allocate their own memory for results have to provide a function to free it. Especially on Windows, you cannot rely on both Python and the DLL to use the same heap.) You can slice the pointer: >>> result[:5] b'spam\x00' Or you can access the buffer more safely as a new array view: >>> array_t = ctypes.c_char * 5 >>> pointer_t = ctypes.POINTER(array_t) >>> result.contents c_char(b's') >>> buf1 = pointer_t(result.contents)[0] >>> buf1[:] b'spam\x00' This buf1 array is a view on the buffer, not a copy. It reflects whatever changes are made to the underlying buffer: >>> buf0[:] = b'eggs\x00' >>> buf1[:] b'eggs\x00' As such, ctypes knows it doesn't have to free this memory: >>> buf1._b_needsfree_ 0 From eryksun at gmail.com Fri Apr 13 00:16:06 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 13 Apr 2018 04:16:06 +0000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: On Fri, Apr 13, 2018 at 12:38 AM, Jach Fong wrote: > Gregory Ewing at 2018/4/13 ?? 07:25 wrote: > >> To get around this, you may need to declare the return type >> as POINTER(c_char) instead: >> >>> For a general character pointer that may also point to binary data, >> >> > POINTER(c_char) must be used. > > I had missed this statement:-( > > To make a quick try, I set the function's restype to > ctypes.POINTER(ctypes.c_ubyte), instead of ctypes.c_char_p. It's amazing, > the \x00 trap can be avoided in this way. Now I can use "mydata = > bytes(buf[:n])" to extract n bytes of data and write it to file. Slicing a ctypes.POINTER(ctypes.c_char) pointer returns bytes without having to make a third copy via the bytes constructor. (Note that c_char is the fundamental C char integer type, not to be confused with c_char_p, which is a char * pointer.) However, if you're working with multi-megabyte data buffers,it's more efficient and safer to use an array view (ctypes or NumPy) on the returned buffer. In most cases, you should free the returned pointer after you're finished processing the data buffer, else you'll have a memory leak. The library should export a function for this. From shalu.ashu50 at gmail.com Fri Apr 13 00:41:58 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Thu, 12 Apr 2018 21:41:58 -0700 (PDT) Subject: Installing NETCDF4 in windows using python 3.4 Message-ID: <143dad88-05d8-4b3a-8145-ac3f1feb889c@googlegroups.com> Hi All, I have downloaded NETCDF4 module from https://pypi.python.org/pypi/netCDF4 e.g. netCDF4-1.3.1-cp34-cp34m-win_amd64.whl I have installed it using pip install netCDF4-1.3.1-cp34-cp34m-win_amd64.whl through the command prompt in Spyder. It has successfully installed. C:\python3>pip install netCDF4-1.3.1-cp34-cp34m-win_amd64.whl Processing c:\python3\netcdf4-1.3.1-cp34-cp34m-win_amd64.whl Requirement already satisfied: numpy>=1.7 in c:\python3\winpython-64bit-3.4.4.5qt5\python-3.4.4.amd64\lib\site-packages (from netCDF4==1.3.1) Installing collected packages: netCDF4 Found existing installation: netCDF4 1.3.2 Uninstalling netCDF4-1.3.2: Successfully uninstalled netCDF4-1.3.2 Successfully installed netCDF4-1.3.1 But when I am trying to import, it is giving an error: import netCDF4 as nc4 Traceback (most recent call last): File "", line 1, in import netCDF4 as nc4 File "C:\python3\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\netCDF4__init__.py", line 3, in from ._netCDF4 import * File "netCDF4_netCDF4.pyx", line 2988, in init netCDF4._netCDF4 AttributeError: type object 'netCDF4._netCDF4.Dimension' has no attribute 'reduce_cython' How can I fix it? Suggestions would be appreciated. From jfong at ms4.hinet.net Fri Apr 13 04:44:10 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Fri, 13 Apr 2018 16:44:10 +0800 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: eryk sun at 2018/4/13 PM 12:16 wrote: > On Fri, Apr 13, 2018 at 12:38 AM, Jach Fong wrote: >> Gregory Ewing at 2018/4/13 ?? 07:25 wrote: >> >>> To get around this, you may need to declare the return type >>> as POINTER(c_char) instead: >>> >>>> For a general character pointer that may also point to binary data, >>> >>> > POINTER(c_char) must be used. >> >> I had missed this statement:-( >> >> To make a quick try, I set the function's restype to >> ctypes.POINTER(ctypes.c_ubyte), instead of ctypes.c_char_p. It's amazing, >> the \x00 trap can be avoided in this way. Now I can use "mydata = >> bytes(buf[:n])" to extract n bytes of data and write it to file. > > Slicing a ctypes.POINTER(ctypes.c_char) pointer returns bytes without > having to make a third copy via the bytes constructor. (Note that > c_char is the fundamental C char integer type, not to be confused with > c_char_p, which is a char * pointer.) However, if you're working with > multi-megabyte data buffers,it's more efficient and safer to use an > array view (ctypes or NumPy) on the returned buffer. After studying the example you explained in your previous post replied to Gregory Ewing, I had noticed that until today I was totally misunderstand the meaning of the c_char_p. I always think it "is" a pointer, but actually it's just a ctypes type, maybe literarily looks like a C pointer, but not a pointer from the ctypes view at all:-) from the ctypes document: "Pointer instances are created by calling the pointer() function on a ctypes type" "Fundamental data types, when returned as foreign function call results, or, for example, by retrieving structure field members or array items, are transparently converted to native Python types. In other words, if a foreign function has a restype of c_char_p, you will always receive a Python bytes object, not a c_char_p instance" That's the reason I was failed at first using c_char_p as a pointer to the returned C buffer. There is no fundamental pointer type in ctypes. If a pointer was needed, you have to create it manually. That's why the second try works. Anyway, thanks for help on cleaning my head:-) --Jach > > In most cases, you should free the returned pointer after you're > finished processing the data buffer, else you'll have a memory leak. > The library should export a function for this. > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From naoki_morihira at outlook.jp Fri Apr 13 08:48:55 2018 From: naoki_morihira at outlook.jp (?? ??) Date: Fri, 13 Apr 2018 12:48:55 +0000 Subject: Python Import Impossibility Message-ID: Hello, Could you tell me how to import the installed modules ? I have successfully installed openpyxl, but When I executed ?import openpyxl?, The following message is displayed: Traceback (most recent call last): File "", line 1, in import openpyxl ModuleNotFoundError: No module named 'openpyxl' My folder is formed as follows: [cid:image003.png at 01D3D312.38C82830] Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- From phamp at mindspring.com Fri Apr 13 11:23:10 2018 From: phamp at mindspring.com (pyotr filipivich) Date: Fri, 13 Apr 2018 08:23:10 -0700 Subject: Filtering computer.lang.python References: Message-ID: Mark Lawrence on Wed, 11 Apr 2018 20:07:47 +0100 typed in comp.lang.python the following: > >> for totals of 2168 fetched and 4384 killed; that is, the group >> is now 2/3 spam and the volume doesn't seem to be decreasing. >> I don't understand why other groups gatewayed to Google Groups >> aren't spammed, but from a limited sample they don't seem to be. >> >> Will >> > >I have recently given up killing all the crap directly on gg as I can't >be bothered any more. That is I would go onto gg and directly mark all >the spam as spam. Is this coincidence? There's your problem "Google Groups". Whatever it is, Google Groups doesn't seem to be "Usenet". -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From daiyueweng at gmail.com Fri Apr 13 12:08:33 2018 From: daiyueweng at gmail.com (Daiyue Weng) Date: Fri, 13 Apr 2018 17:08:33 +0100 Subject: python notifying calling script that multiprocessing tasks have finished at lower level scripts Message-ID: Hi, I have a master script that executes two sequences (lists) of child scripts, i.e. script_1 to script_3, and script_4 to_script_6 (the structure is attached as a png file). The execution is sequential, e.g. running script_1, then 2 then 3. After executing the 1st sequence (script_1 to 3), master will execute the 2nd sequence (script_4 to 6). Each child script will be calling a multiprocessing function to process a task. Master script is like, for seq in seqs_to_launch: for script in seq: script().execute(data) Each child script is like, import multi_process_update class Script_n(): def execute(self, data): # some data processing multi_process_task(data_task, task_name) The multiprocessing function is like, def multi_process_task(tasks, task_name): cores_to_use = how_many_core() handler = task_handling(task_name) # task handling class task_blocks = slice_list(tasks, cores_to_use) for block in task_blocks: # spawn processes for each row block assigned to every cpu core p = multiprocessing.Process(target=handler.execute, args=(block,)) p.start() I like to know how to notify the master when the 2nd sequence is finished that all multiprocess tasks (seq 1 and 2) are completed, and then maybe close the multiprocessing. thanks From tjol at tjol.eu Fri Apr 13 12:36:55 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 13 Apr 2018 18:36:55 +0200 Subject: python notifying calling script that multiprocessing tasks have finished at lower level scripts In-Reply-To: References: Message-ID: <608c86b2-689d-e597-b729-a11706737b74@tjol.eu> On 13/04/18 18:08, Daiyue Weng wrote: > (the structure > is attached as a png file). No it's not. This is a text-only list. (you know what, I'm sick of saying that) > > The execution is sequential, e.g. running script_1, then 2 then 3. > > After executing the 1st sequence (script_1 to 3), master will execute the > 2nd sequence (script_4 to 6). > > Each child script will be calling a multiprocessing function to process a > task. I could ask what motivates this convoluted-sounding structure... > > [snip] > > > I like to know how to notify the master when the 2nd sequence is finished > that all multiprocess tasks (seq 1 and 2) are completed, and then maybe > close the multiprocessing. Well, I suppose you'll have to keep all the Process objects around somewhere where they can be checked on. You might want to use a multiprocessing.Pool. From tjol at tjol.eu Fri Apr 13 12:38:15 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 13 Apr 2018 18:38:15 +0200 Subject: Python Import Impossibility In-Reply-To: References: Message-ID: <6a842341-f462-7b81-c1ba-b9d5b8f74426@tjol.eu> On 13/04/18 14:48, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, but > When I executed ?import openpyxl?, > The following message is displayed: > Traceback (most recent call last): > File "", line 1, in > import openpyxl > ModuleNotFoundError: No module named 'openpyxl' > > My folder is formed as follows: > [cid:image003.png at 01D3D312.38C82830] Is it possible that you installed the module in the wrong Python installation? From steve+comp.lang.python at pearwood.info Fri Apr 13 12:48:55 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Apr 2018 16:48:55 +0000 (UTC) Subject: Python Import Impossibility References: Message-ID: On Fri, 13 Apr 2018 12:48:55 +0000, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, How do you know it was successful? What did you do to install it? How many different Python installations do you have on your system? but When I executed ?import > openpyxl?, The following message is displayed: > Traceback (most recent call last): > File "", line 1, in > import openpyxl > ModuleNotFoundError: No module named 'openpyxl' > > My folder is formed as follows: > [cid:image003.png at 01D3D312.38C82830] There are no attachments permitted on this list. -- Steve From jcasale at activenetwerx.com Fri Apr 13 13:28:01 2018 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 13 Apr 2018 17:28:01 +0000 Subject: Python regex pattern from array of hex chars Message-ID: I have an array of hex chars which designate required characters. and one happens to be \x5C or "\". What foo is required to build the pattern to exclude all but: regex = re.compile('[^{}]+'.format(''.join(c for c in character_class))) I would use that in a re.sub to collapse and replace all but those in the character_class. Obviously the escape issues break the \x5C character. Thanks, jlc From python at mrabarnett.plus.com Fri Apr 13 14:05:14 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Apr 2018 19:05:14 +0100 Subject: Python regex pattern from array of hex chars In-Reply-To: References: Message-ID: On 2018-04-13 18:28, Joseph L. Casale wrote: > I have an array of hex chars which designate required characters. > and one happens to be \x5C or "\". What foo is required to build the > pattern to exclude all but: > > regex = re.compile('[^{}]+'.format(''.join(c for c in character_class))) > > I would use that in a re.sub to collapse and replace all but those > in the character_class. Obviously the escape issues break the \x5C > character. > Use re.escape: regex = re.compile('[^{}]+'.format(re.escape(''.join(c for c in character_class)))) From jcasale at activenetwerx.com Fri Apr 13 14:50:15 2018 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 13 Apr 2018 18:50:15 +0000 Subject: Python regex pattern from array of hex chars In-Reply-To: References: Message-ID: <70f48f604cdc4c1eb553ac0eb5dc3c52@activenetwerx.com> -----Original Message----- From: Python-list On Behalf Of MRAB Sent: Friday, April 13, 2018 12:05 PM To: python-list at python.org Subject: Re: Python regex pattern from array of hex chars > Use re.escape: > > regex = re.compile('[^{}]+'.format(re.escape(''.join(c for c in > character_class)))) Brilliant, thanks! From eryksun at gmail.com Fri Apr 13 17:27:34 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 13 Apr 2018 21:27:34 +0000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: On Fri, Apr 13, 2018 at 8:44 AM, Jach Fong wrote: > > After studying the example you explained in your previous post replied to > Gregory Ewing, I had noticed that until today I was totally misunderstand > the meaning of the c_char_p. I always think it "is" a pointer, but actually > it's just a ctypes type, maybe literarily looks like a C pointer, but not a > pointer from the ctypes view at all:-) Here's a list of type classes in ctypes: class metaclass ================================= _SimpleCData PyCSimpleType _Pointer PyCPointerType _CFuncPtr PyCFuncPtrType Array PyCArrayType Structure PyCStructType Union UnionType These classes share a common _CData base class. Note that the _ctypes extension module doesn't directly expose _CData, nor any of the metaclasses. ctypes type checking primarily uses Python type checking, so we generally do not subclass these types directly, except for Structure and Union. Instead we have a set of predefined simple types that subclass _SimpleCData (e.g. c_int, c_char), and we use factory functions to create pointer types (e.g. POINTER, CFUNCTYPE), which cache the created type. For arrays, we rely on the base _CData sequence-repeat functionality (e.g. c_int * 3), which also caches the Array subclass that it creates. Type caching ensures that two expressions that create an equivalent C type return the same class. For example, if you have `c_char * 3` in two places, it should be the same type: >>> cls = ctypes.c_char * 3 >>> (ctypes.c_char * 3) is cls True The simple types c_void_p, c_char_p, and c_wchar_p are pointers. However, since they subclass _SimpleCData instead of _Pointer, they inherit the behavior of simple types. In particular they have get/set functions that implicitly convert to and from native Python types when they're used in aggregate types (arrays, structs, unions), when indexing or slicing a _Pointer instance, or as the result or argument of a function pointer (i.e. _CFuncPtr subclass). From jfong at ms4.hinet.net Fri Apr 13 21:57:53 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sat, 14 Apr 2018 09:57:53 +0800 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: Message-ID: <1190f530-42f3-c279-7fe9-4dd23c270cb6@ms4.hinet.net> eryk sun at 2018/4/14 PM 05:27 wrote: > On Fri, Apr 13, 2018 at 8:44 AM, Jach Fong wrote: >> >> After studying the example you explained in your previous post replied to >> Gregory Ewing, I had noticed that until today I was totally misunderstand >> the meaning of the c_char_p. I always think it "is" a pointer, but actually >> it's just a ctypes type, maybe literarily looks like a C pointer, but not a >> pointer from the ctypes view at all:-) > > Here's a list of type classes in ctypes: > > class metaclass > ================================= > _SimpleCData PyCSimpleType > _Pointer PyCPointerType > _CFuncPtr PyCFuncPtrType > Array PyCArrayType > Structure PyCStructType > Union UnionType > > These classes share a common _CData base class. Note that the _ctypes > extension module doesn't directly expose _CData, nor any of the > metaclasses. > > ctypes type checking primarily uses Python type checking, so we > generally do not subclass these types directly, except for Structure > and Union. Instead we have a set of predefined simple types that > subclass _SimpleCData (e.g. c_int, c_char), and we use factory > functions to create pointer types (e.g. POINTER, CFUNCTYPE), which > cache the created type. For arrays, we rely on the base _CData > sequence-repeat functionality (e.g. c_int * 3), which also caches the > Array subclass that it creates. > > Type caching ensures that two expressions that create an equivalent C > type return the same class. For example, if you have `c_char * 3` in > two places, it should be the same type: > > >>> cls = ctypes.c_char * 3 > >>> (ctypes.c_char * 3) is cls > True Thanks for your description. To digest it, I may need to dive into its source jungle:-( > The simple types c_void_p, c_char_p, and c_wchar_p are pointers. > However, since they subclass _SimpleCData instead of _Pointer, they > inherit the behavior of simple types. The ctypes document says: "Pointer instances have a contents attribute which returns the object to which the pointer points" >>> buf0 = ctypes.create_string_buffer(b'spam') >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) >>> pvoid.contents Traceback (most recent call last): File "", line 1, in AttributeError: 'c_void_p' object has no attribute 'contents' >>> pvoid.value 35425816 >>> pp = ctypes.pointer(buf0) >>> pp.contents >>> pp.value Traceback (most recent call last): File "", line 1, in AttributeError: 'LP_c_char_Array_5' object has no attribute 'value' It looks like the c_void_p is not of a pointer type:-) --Jach > In particular they have get/set > functions that implicitly convert to and from native Python types when > they're used in aggregate types (arrays, structs, unions), when > indexing or slicing a _Pointer instance, or as the result or argument > of a function pointer (i.e. _CFuncPtr subclass). > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jatin.rajpura at EF.com Fri Apr 13 22:19:50 2018 From: jatin.rajpura at EF.com (Jatin Rajpura) Date: Sat, 14 Apr 2018 02:19:50 +0000 Subject: Python issue on Win64 Message-ID: Hi Team, I am having an issue with Python on win 64, could you help me here? Installed: [cid:image001.png at 01D3D1A6.6108F670] CMD doesn't work: [cid:image002.png at 01D3D1A6.6108F670] ---------------- Regards, Jatin Rajpura AWS Engineer | E1 Technology | EF Kids & Teens | Education First 3F Jiu An Plaza,258 Tongren Road,Jing An District,Shanghai,China | 200040 Skype: Jatin.Rajpura at ef.com From eryksun at gmail.com Sat Apr 14 00:34:02 2018 From: eryksun at gmail.com (eryk sun) Date: Sat, 14 Apr 2018 04:34:02 +0000 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: <1190f530-42f3-c279-7fe9-4dd23c270cb6@ms4.hinet.net> References: <1190f530-42f3-c279-7fe9-4dd23c270cb6@ms4.hinet.net> Message-ID: On Sat, Apr 14, 2018 at 1:57 AM, Jach Fong wrote: > eryk sun at 2018/4/14 PM 05:27 wrote: > >> The simple types c_void_p, c_char_p, and c_wchar_p are pointers. >> However, since they subclass _SimpleCData instead of _Pointer, they >> inherit the behavior of simple types. > > The ctypes document says: > "Pointer instances have a contents attribute which returns the object to > which the pointer points" > >>>> buf0 = ctypes.create_string_buffer(b'spam') > >>>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) >>>> pvoid.contents > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'c_void_p' object has no attribute 'contents' >>>> pvoid.value > 35425816 > >>>> pp = ctypes.pointer(buf0) >>>> pp.contents > >>>> pp.value > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'LP_c_char_Array_5' object has no attribute 'value' > > It looks like the c_void_p is not of a pointer type:-) c_void_p is a `void *` pointer type, but it's a simple pointer type that subclasses _SimpleCData instead of _Pointer, so it doesn't have a `contents` property but instead has a `value` property. >>> hasattr(ctypes._SimpleCData, 'contents') False >>> hasattr(ctypes._SimpleCData, 'value') True >>> hasattr(ctypes._Pointer, 'contents') True >>> hasattr(ctypes._Pointer, 'value') False Don't take the Python class hierarchy so literally that you overlook what these types ultimately are in C. Just because they don't subclass _Pointer, that doesn't mean they're not pointer types. c_void_p, c_char_p, and c_wchar_p are unquestionably pointer types. This is what the "_p" suffix means in their names. It's just these particular pointer types were implemented as simple types to get the convenience of implicit conversion. That said, sometimes the implicit conversion is a problem, in which case we use, for example, POINTER(c_char) instead of c_char_p. Look in Lib/ctypes/__init__.py to review the definitions for yourself. Here they are without the __repr__ methods: class c_void_p(_SimpleCData): _type_ = "P" class c_char_p(_SimpleCData): _type_ = "z" class c_wchar_p(_SimpleCData): _type_ = "Z" This doesn't tell you much. You have to go looking for what it means to be a simple "P" type, and in particular we're concerned with how conversion to and from native Python types is implemented. You'll find the get and set C implementations for types "P", "z", and "Z" defined in Modules/_ctypes/cfield.c. For example, for type "P", it's P_get() and P_set(). For P_get(), we use PyLong_FromVoidPtr to convert the pointer value to a Python integer, except we return None for a NULL pointer. For P_set(), we require an integer value or None (NULL). Note that the function to convert a Python integer to an integral address in C depends on the size of a C `long` or `long long` compared to the size of a C `void *` pointer. In particular, this design accommodates 64-bit Windows, on which a `long` is 32-bit and thus too small for a 64-bit pointer value, so we call PyLong_AsUnsignedLongLongMask instead of PyLong_AsUnsignedLongMask. From jobmattcon at gmail.com Sat Apr 14 07:51:58 2018 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sat, 14 Apr 2018 04:51:58 -0700 (PDT) Subject: joblib AttributeError: 'module' object has no attribute Message-ID: <35a383a0-3efe-4f4c-a14b-669e04e88b63@googlegroups.com> Process PoolWorker-1: Traceback (most recent call last): File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap self.run() File "C:\Python27\lib\multiprocessing\process.py", line 114, in run self._target(*self._args, **self._kwargs) File "C:\Python27\lib\multiprocessing\pool.py", line 102, in worker task = get() File "C:\Python27\lib\site-packages\joblib\pool.py", line 362, in get return recv() AttributeError: 'module' object has no attribute 'easysearch' how to solve this bug? import re import string from itertools import permutations from itertools import combinations from joblib import Parallel, delayed import multiprocessing from multiprocessing import Process, freeze_support all_normal_characters = string.ascii_letters + string.digits def is_special(character): return character not in all_normal_characters def easysearch(content): if len(str(content[0]).strip()) == 0 or len(str(content[1]).strip()) == 0: return "" row1 = content[0] keywords = content[1] ....... num_cores = multiprocessing.cpu_count() def segmentsearch(content, findwhat, lensize): chunks, chunk_size = len(content), lensize result = Parallel(n_jobs=num_cores)(delayed(easysearch)([content[j:j+chunk_size], findwhat]) for j in range(0, chunks, chunk_size)) print(result) return result def main(): result = segmentsearch("search key $ @ $ wrds today", "key words", 77) print(result) if __name__=="__main__": freeze_support() main() From p.f.moore at gmail.com Sat Apr 14 08:47:04 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 14 Apr 2018 13:47:04 +0100 Subject: Pip 10.0 has been released Message-ID: On behalf of the PyPA, I am pleased to announce that pip 10.0 has just been released. This release has been the culmination of many months of work by the community. To install pip 10.0, you can run python -m pip install --upgrade pip or use get-pip, as described in https://pip.pypa.io/en/latest/installing. If you are using a version of pip supplied by your distribution vendor, vendor-supplied upgrades will be available in due course (or you can use pip 10 in a virtual environment). (One minor issue with using get-pip on Windows - when you download get-pip.py, rename it to something that doesn't include "pip" in the name, such as "gp.py", as the standard name triggers a check in pip that aborts the run - this is being tracked in https://github.com/pypa/pip/issues/5219). Highlights of the new release: * Python 2.6 is no longer supported - if you need pip on Python 2.6, you should stay on pip 9, which is the last version to support Python 2.6. * Support for PEP 518, which allows projects to specify what packages they require in order to build from source. (PEP 518 support is currently limited, with full support coming in future versions - see the documentation for details). * Significant improvements in Unicode handling for non-ASCII locales on Windows. * A new "pip config" command. * The default upgrade strategy has become "only-if-needed" * Many bug fixes and minor improvements. In addition, the previously announced reorganisation of pip's internals has now taken place. Unless you are the author of code that imports the pip module (or a user of such code), this change will not affect you. If you are affected, please report the issue to the author of the offending code (refer them to https://mail.python.org/pipermail/distutils-sig/2017-October/031642.html for the details of the announcement). Thanks to everyone who put so much effort into the new release. Many of the contributions came from community members, whether in the form of code, participation in design discussions, or bug reports. The pip development team is extremely grateful to everyone in the community for their contributions. Thanks, Paul From sapna.intell at gmail.com Sat Apr 14 14:25:56 2018 From: sapna.intell at gmail.com (Priya Singh) Date: Sat, 14 Apr 2018 11:25:56 -0700 (PDT) Subject: Levenberg-Marquardt Algorithm In-Reply-To: References: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> Message-ID: <673bbced-9143-47ba-b243-76d507867532@googlegroups.com> On On Wednesday, April 11, 2018 at 12:49:59 PM UTC+5:30, Christian Gollwitzer wrote: > Am 11.04.18 um 08:38 schrieb Priya Singh: > > I have two 2D arrays one R and another T (which is also a 2D array). > > Do you know how can I fit T with R in order to find central > > coordinate x0,y0 for T relative to R??? > > > > So the main question is do you know in python how can I fit two 2D arrays to find > > x0,y0 for one array relative to other. I shall use LM fit in python. But for fitting, I need to have some fittable model but here I am having only two 2D arrays. I know simple cross-correlation would have solved my problem but I have been instructed to do fitting using one array to other. > > > The request is nonsense. LM fits an analytical model to data, if you > don't have an analytical model, you need another tool. Cross correlation > is widely used and works well for many such tasks. > > In principle you could also interpolate the one array to new > coordinates, e.g. using scipy.ndimage.interpolation.shift, and minimize > the sum of squared differences. But still LM is the wrong tool here, it > would get trapped in local minima soon, and it uses derivatives. Look > for "image registration" to find typical algorithms used in this context. > > > > Christian I am really sorry, I should rather ask this way. I have two 2D arrays and one array I want to present in cubic spline way. And with this cubic spline representation of one array, I want to fit the other array. But the problem is that in python I have only cubic spline interpolation task, I want to get the form of this representation and then with this form I want to fit another 2D array to get the position of centers of the second array relative to the first array. I have used image registration for the centering which is based on FFT. But I have been instructed to use this method only. So basically can anyone tell me how to get functional for of 2D cubic spline function in python? For 1D I have got many helps but not for 2D. Thanks in advance!! From sapna.intell at gmail.com Sat Apr 14 14:31:04 2018 From: sapna.intell at gmail.com (Priya Singh) Date: Sat, 14 Apr 2018 11:31:04 -0700 (PDT) Subject: Levenberg-Marquardt Algorithm In-Reply-To: References: <55716c11-1664-47f5-a283-9a1e968e70e2@googlegroups.com> Message-ID: <220e7d37-e950-4be5-978d-ae0b72b63598@googlegroups.com> On Wednesday, April 11, 2018 at 12:49:59 PM UTC+5:30, Christian Gollwitzer wrote: > Am 11.04.18 um 08:38 schrieb Priya Singh: > > I have two 2D arrays one R and another T (which is also a 2D array). > > Do you know how can I fit T with R in order to find central > > coordinate x0,y0 for T relative to R??? > > > > So the main question is do you know in python how can I fit two 2D arrays to find > > x0,y0 for one array relative to other. I shall use LM fit in python. But for fitting, I need to have some fittable model but here I am having only two 2D arrays. I know simple cross-correlation would have solved my problem but I have been instructed to do fitting using one array to other. > > > The request is nonsense. LM fits an analytical model to data, if you > don't have an analytical model, you need another tool. Cross correlation > is widely used and works well for many such tasks. > > In principle you could also interpolate the one array to new > coordinates, e.g. using scipy.ndimage.interpolation.shift, and minimize > the sum of squared differences. But still LM is the wrong tool here, it > would get trapped in local minima soon, and it uses derivatives. Look > for "image registration" to find typical algorithms used in this context. > > > > Christian I am really sorry, I should rather ask this way. I have two 2D arrays and one array I want to present in cubic spline way. And with this cubic spline representation of one array, I want to fit the other array. But the problem is that in python I have only cubic spline interpolation task, I want to get the form of this representation and then with this form I want to fit another 2D array to get the position of centers of the second array relative to the first array. I have used image registration for the centering which is based on FFT. But I have been instructed to use this method only. So basically can anyone tell me how to get functional for of 2D cubic spline function in python? For 1D I have got many helps but not for 2D. Thanks in advance!! From greg.ewing at canterbury.ac.nz Sat Apr 14 20:20:02 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 15 Apr 2018 12:20:02 +1200 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: <1190f530-42f3-c279-7fe9-4dd23c270cb6@ms4.hinet.net> Message-ID: Jach Fong wrote: > >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) > >>> pvoid.contents > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'c_void_p' object has no attribute 'contents' I think the 'contents' attribute only applies to pointers that are pointing at part of another Python object. Your c_void_p instance is not that kind of pointer. I must say the ctypes documentation is rather confusing when it comes to these kinds of details. It doesn't help that the "Pointers and Arrays" section is marked as "Not yet written". Does anyone have any plans to finish it? -- Greg From greg.ewing at canterbury.ac.nz Sat Apr 14 20:49:33 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 15 Apr 2018 12:49:33 +1200 Subject: Making matrix solver/ solver for X In-Reply-To: References: Message-ID: steffie.booij at gmail.com wrote: > Q = np.array(['Q1', 'Q2', 'Q3', 'Q4']) > > P = (X*Q)-X I'm assuming that 'Q1', etc. are placeholders for numbers here? Otherwise, you're doing arithmetic with strings, which doesn't make sense. > So solve condition: > P[0]+P[1] ,P[0]+P[2] ,P[0]+P[3] ,P[1]+P[2] ,P[1]+P[3] ,P[2]+P[3] >= np.sum(X) This looks like a linear programming problem: https://en.wikipedia.org/wiki/Linear_programming except that there's no objective function (something to be maximised or minimised) so there won't be a unique solution. If you can frame it as a linear programming problem, you could use this: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html If there are no other constraints that the solution needs to satisfy, then you could just make up an objective function, e.g. tell it to minimise sum(X). Also, if you can tell us more about the original problem you're trying to solve, we may be able to help more. -- Greg From python at mrabarnett.plus.com Sat Apr 14 21:15:55 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Apr 2018 02:15:55 +0100 Subject: Python issue on Win64 In-Reply-To: References: Message-ID: <0a335c1d-1ace-af82-e01d-be5182a90c87@mrabarnett.plus.com> On 2018-04-14 03:19, Jatin Rajpura wrote: > > Hi Team, > > I am having an issue with Python on win 64, could you help me here? > > Installed: > > [cid:image001.png at 01D3D1A6.6108F670] > > CMD doesn't work: > > [cid:image002.png at 01D3D1A6.6108F670] > ---------------- > Regards, > Jatin Rajpura > This is a text-only list; images are removed. From jfong at ms4.hinet.net Sat Apr 14 21:51:39 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 15 Apr 2018 09:51:39 +0800 Subject: How to write partial of a buffer which was returned from a C function to a file? In-Reply-To: References: <1190f530-42f3-c279-7fe9-4dd23c270cb6@ms4.hinet.net> Message-ID: Gregory Ewing at 2018/4/15 PM 08:20 wrote: > Jach Fong wrote: >> ?>>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) >> ?>>> pvoid.contents >> Traceback (most recent call last): >> ? File "", line 1, in >> AttributeError: 'c_void_p' object has no attribute 'contents' > > I think the 'contents' attribute only applies to pointers that are > pointing at part of another Python object. Your c_void_p instance > is not that kind of pointer. > > I must say the ctypes documentation is rather confusing when it > comes to these kinds of details. It doesn't help that the "Pointers > and Arrays" section is marked as "Not yet written". Does anyone > have any plans to finish it? >>> pt = ctypes.cast(buf0, ctypes.POINTER(ctypes.c_void_p)) >>> type(pt) >>> pt.contents c_void_p(1835102323) From the API point of view, I think it's better not to dive into the ocean of "type" too deeply, especially when foreign language was involved. You may get totally confused. (unless you want to write code like in the IOCCC contest:-) I have to admit that the ctypes' document was written pretty well. Most of my problems were caused by that I didn't read it thoughtfully:-( --Jach --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From benjamin at python.org Sat Apr 14 22:41:19 2018 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 14 Apr 2018 19:41:19 -0700 Subject: [RELEASE] Python 2.7.15 release candidate 1 Message-ID: <1523760079.2728906.1338273840.27DC2547@webmail.messagingengine.com> I'm pleased to announce the immediate availability of Python 2.7.15 release candidate 1. Python 2.7.15rc1 is a preview release of the next bug fix release in the Python 2.7.x series. Python 2.7.15rc1 may be downloaded in source and binary forms from https://www.python.org/downloads/release/python-2715rc1/ Please consider testing this release with your applications and libraries and reporting bugs to https://bugs.python.org/ A final release is expected in 2 weeks time. 2.7.15 includes some noteworthy changes to the macOS installers: All python.org macOS installers now ship with a built-in copy of OpenSSL. Additionally, there is a new additional installer variant for macOS 10.9+ that includes a built-in version of Tcl/Tk 8.6. See the installer README for more information. Thank you, Benjamin (on behalf of 2.7's release team and contributors) From jobmattcon at gmail.com Sun Apr 15 07:01:21 2018 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sun, 15 Apr 2018 04:01:21 -0700 (PDT) Subject: how to set timeout for os.popen Message-ID: while 1: runner = os.popen("tracert -d www.hello.com") o=runner.read() print(o) runner.close() runner = os.popen("tracert -d www.hello.com") o=runner.read() print(o) runner.close() runner = os.popen("tracert -d www.hello.com") o=runner.read() print(o) runner.close() after running over 1 hour, it stop and not return in one of tracert how to set timeout and know that this is timeout? From ablacktshirt at gmail.com Sun Apr 15 09:58:03 2018 From: ablacktshirt at gmail.com (Yubin Ruan) Date: Sun, 15 Apr 2018 21:58:03 +0800 Subject: Ways to make a free variable local to a function? In-Reply-To: References: <20180415075841.hwzmimnofllnipnj@HP> Message-ID: <20180415135803.7iav7c3dmuqzr24o@HP> On 2018-04-15 13:31, Kirill Balunov wrote: > > > 2018-04-15 10:58 GMT+03:00 Yubin Ruan : > > [this is a bit late...] > > Did you really have any benchmark for it? I know what you are doing but it > seems to be a pre-mature optimization. If this really is the case, then we > can > optimize the Python interpreter. > > > I don't know if you intentionally send this message privately to me and not to > the entire python-list. If it was a mistake, post it there and I will answer > there too. Sorry I mistakenly hit the 'Reply' button instead of 'Group-reply'. > Yes I've measured: > > > def func(numb): > ? ? res = [] > ? ? for i in range(numb): > ? ? ? ? res.append(int(i) + float(i)) > ? ? return res > > def func_local(numb, _int = int, _float = float): > ? ? res = [] > ? ? for i in range(numb): > ? ? ? ? res.append(_int(i) + _float(i)) > ? ? return res Wouldn't this kind of things better be (implicitly) used in the Python interpreter instead of in this kind of hand-optimized code? That looks strange. Nevertheless, if need be, I would opt for that 'static-declared' approach you described earlier, which give semantic hint on the optimization used. Thanks, Yubin > %timeit func(100000) > > 85.8 ms ? 2.47 ms per loop (mean ? std. dev. of 7 runs, 10 loops each) > > > %timeit func_local(100000) > > 72.2 ms ? 892 ?s per loop (mean ? std. dev. of 7 runs, 10 loops each) > > So in the tight loop it is 16% faster. From jsf80238 at gmail.com Sun Apr 15 12:25:09 2018 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 15 Apr 2018 10:25:09 -0600 Subject: how to set timeout for os.popen In-Reply-To: References: Message-ID: > > while 1: > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > > > after running over 1 hour, it stop and not return in one of tracert > > how to set timeout and know that this is timeout? > There are a number of answers on Stackoverflow, for example https://stackoverflow.com/questions/492519/timeout-on-a-function-call. The first few answers there seem to be Nix-specific, with OS-agnostic multiprocessing answers below. From python at mrabarnett.plus.com Sun Apr 15 14:14:18 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Apr 2018 19:14:18 +0100 Subject: how to set timeout for os.popen In-Reply-To: References: Message-ID: <123e868d-f666-d310-b5f5-52b79bb8be51@mrabarnett.plus.com> On 2018-04-15 12:01, Ho Yeung Lee wrote: > while 1: > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > > > after running over 1 hour, it stop and not return in one of tracert > > how to set timeout and know that this is timeout? > Try using the 'subprocess' module instead. From jtshah619 at gmail.com Mon Apr 16 04:51:18 2018 From: jtshah619 at gmail.com (jtshah619 at gmail.com) Date: Mon, 16 Apr 2018 01:51:18 -0700 (PDT) Subject: Python installer hangs in Windows 7 In-Reply-To: References: <765703485.1601081.1486357381135.ref@mail.yahoo.com> <765703485.1601081.1486357381135@mail.yahoo.com> Message-ID: <4937231c-f798-4ee5-852e-d22d3f6c8ef3@googlegroups.com> On Monday, February 6, 2017 at 10:46:24 AM UTC+5:30, Jean-Claude Roy wrote: > ? I am trying to install Python 3.6.0 on a Windows 7 computer. > The download of 29.1 MB is successful and I get the nextwindow.? I?choose the "install now" selection and thatopens the Setup Program window. > Now the trouble starts:I get "Installing:" and the Initialization progress...and nothing else. > There is no additional disk activity, no progress on initialization, andeverything appears dead.? Even after 20 minutes there is zero progress. > I've repeated this as both a user and the administrator of this Windowscomputer.? I get the same results in either case. > If I go to the task manager it shows that Python 3.6.0 (32-bit) setup is running.? If I try to end the task Iget the message that the program is not responding. > Do you have any suggestions as to how I can get past this? > Thank you. Uncheck the install for all users part and it will work and log into each user individually and then install. From jugurtha.hadjar at gmail.com Mon Apr 16 09:33:54 2018 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Mon, 16 Apr 2018 14:33:54 +0100 Subject: how to set timeout for os.popen In-Reply-To: References: Message-ID: <5813acd7-c471-2a80-e892-c86a7767c95c@gmail.com> On 04/15/2018 12:01 PM, Ho Yeung Lee wrote: > while 1: > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > runner = os.popen("tracert -d www.hello.com") > o=runner.read() > print(o) > runner.close() > > > after running over 1 hour, it stop and not return in one of tracert > > how to set timeout and know that this is timeout? import signal import time from contextlib import contextmanager @contextmanager def timeout(duration, handler): ??? """Timeout after `duration` seconds.""" ??? signal.signal(signal.SIGALRM, handler) ??? signal.alarm(duration) ??? try: ??????? yield ??? finally: ??????? signal.alarm(0) def interrupt_handler(signum, frame): ??? print('Interrupt handler saves the day') ??? raise TimeoutError # You can use that in many ways: # At definition time: @timeout(10, interrupt_handler) def foo(): ??? print('Begin foo') ??? while True: ??????? print('foo is printing') ??????? time.sleep(3) # At use time, define foo normally: def bar(): ??? print('Begin bar') ??? while True: ??????? print('bar is printing') ??????? time.sleep(3) with timeout(10, interrupt_handler): ??? print('I am inside with, above bar') ??? bar() From info at egenix.com Mon Apr 16 10:12:38 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 16 Apr 2018 16:12:38 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_18.04.2018?= Message-ID: [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 18.04.2018, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2018-04-18 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Philipp Hagemeister "5 Sicherheitsl?cken in Deiner Python-Anwendung" Johannes Spielmann "Python auf dem ESP32" Charlie Clark "Verborgene Sch?tze - Das itertools Modul" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm' in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 16 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From shalu.ashu50 at gmail.com Mon Apr 16 10:55:43 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Mon, 16 Apr 2018 07:55:43 -0700 (PDT) Subject: How to save xarray data to csv Message-ID: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> Hello All, I have used xarray to merge several netcdf files into one file and then I subset the data of my point of interest using lat/long. Now I want to save this array data (time,lat,long) into csv file but I am getting an error with my code: dsmerged = xarray.open_mfdataset('F:/NTU_PDF__Work/1_Codes/1_Python/testing/netcdf/*.nc') #save to netcdf file dsmerged.to_netcdf('combine.nc') # Extraction of data as per given coordinates #values (lat/long with their upper and lower bound) fin = netCDF4.Dataset("combine.nc" ,"r") # print the all the variables in this file print (fin.variables) # print the dimensions of the variable print (fin.variables["clt"].shape) #Out: (20075, 90, 144) # retrieve time step from the variable clt0 = (fin.variables["clt"]) # extract a subset of the full dataset contained in the file clt0sub = clt0[10:30,20:30] # xarray to numpy array clt1=numpy.array(clt0sub) # saving data into csv file with open('combine11.csv', 'wb') as f: writer = csv.writer(f, delimiter=',') writer.writerows(enumerate(clt1)) getting this error - TypeError: a bytes-like object is required, not 'str' when I am removing "b" the error disappears but the data saving in wrong format example:- 0,"[[ 99.93312836 99.99977112 100. ..., 98.53624725 99.98111725 99.9799881 ] [ 99.95301056 99.99489594 99.99998474 ..., 99.9998703 99.99951172 99.97265625] [ 99.67852783 99.96372986 99.99999237 ..., 99.96694946 99.9842453 99.96450806] ..., [ 78.29571533 45.00857544 24.39345932 ..., 90.86527252 84.48490143 62.53995895] [ 42.03381348 46.1696701 22.71044922 ..., 80.88492584 71.15007019 50.95384216] [ 34.75331879 49.99913025 17.66173935 ..., 57.12231827 62.56645584 40.6435585 ]]" 1,"[[ 100. 100. 100. ..., 99.93876648 99.98928833 100. ] [ 99.9773941 100. 99.4933548 ..., 97.93031311 97.36623383 97.07974243] [ 98.5934906 99.72555542 99.44548035 ..., 79.59191132 85.77541351 94.40919495] ..., suggestions would be appreciated From Irv at furrypants.com Mon Apr 16 12:03:47 2018 From: Irv at furrypants.com (Irv Kalb) Date: Mon, 16 Apr 2018 09:03:47 -0700 Subject: Instance variables question Message-ID: I have been writing OOP code for many years in other languages and for the past few years in Python. I am writing new curriculum for a course on OOP in Python. In order to see how others are explaining OOP concepts, I have been reading as many books and watching as many videos as I can. I've been watching some videos created by Dr. Chuck Severance in a series called "Python For Everyone". I think "Dr. Chuck" is an excellent teacher and I think his videos are outstanding. Today I watched this video: https://www.youtube.com/watch?v=b2vc5uzUfoE which is about 10 minutes long. In that video he gives a very basic overview of OOP and classes. He gives a demonstration using the following example: class PartyAnimal(): x = 0 def party(self): self.x = self.x + 1 print('So far', self.x) an = PartyAnimal() an.party() an.party() an.party() # I added this line just to see what it would do print('Class variable', PartyAnimal.x) And the output is: So far 1 So far 2 So far 3 Class variable 0 But there is something there that seems odd. My understanding is that the "x = 0" would be defining a class variable, that can be shared by all PartyAnimal objects. But he explains that because x is defined between the class statement and the "party" method, that this defines an instance variable x. That way, it can be used in the first line of the "party" method as self.x to increment itself. At the end of the video, he creates two objects from the same class, and each one gets its own self.x where each correctly starts at zero. Again, I expected x to be a class variable (accessible through PartyAnimal.x). When I want to create an instance variable and to be used later in other methods, I do this: class PartyAnimal(): def __init__(self): self.x = 0 def party(self): self.x = self.x + 1 print('So far', self.x) an = PartyAnimal() an.party() an.party() an.party() That is, I would assign the instance variable in the __init__ method. Both approaches give the same results. I'm certainly not trying to argue with Dr. Chuck. I am trying to understand his approach, but it's not clear to me why his code works. Specifically, can anyone explain how his "x = 0" turns x into an instance variable - while also allowing the syntax for a class variable PartyAnimal.x to be used? Thanks, Irv From jim.macarthur+python at codethink.co.uk Mon Apr 16 12:10:47 2018 From: jim.macarthur+python at codethink.co.uk (Jim MacArthur) Date: Mon, 16 Apr 2018 17:10:47 +0100 Subject: Slow tarfile extract on armv7l Linux machine Message-ID: Hi, I'm seeing a very slow extraction of an uncompressed tar file using 'tarfile' in Python 3.5.3 vs. the native Debian tar tool. This is a console log from my machine: jimm at scw-000001:~$ time tar xf update.tar real??? 0m3.436s user??? 0m0.430s sys???? 0m2.870s jimm at scw-000001:~$ rm -rf home jimm at scw-000001:~$ cat untar-test.py #!/usr/bin/env python3 import tarfile tar = tarfile.open('update.tar') tar.extractall() jimm at scw-000001:~$ time ./untar-test.py real??? 0m12.216s user??? 0m8.730s sys???? 0m3.030s jimm at scw-000001:~$ uname -a Linux scw-000001 4.3.5-std-1 #1 SMP Fri Feb 19 11:52:18 UTC 2016 armv7l GNU/Linux jimm at scw-000001:~$ python3 Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ---- I also tried this with 3.7.0b3 and I get the same result. On my desktop, an x86_64 running Ubuntu, there's little difference between tarfile and native tar. Obviously there will be some time spent starting Python but the above seems too much. Does anyone have any ideas what might cause this or where to look next? Does x86_64 do more of this in C code that's interpreted on armv7l, for example? From jcasale at activenetwerx.com Mon Apr 16 12:22:46 2018 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 16 Apr 2018 16:22:46 +0000 Subject: Instance variables question In-Reply-To: References: Message-ID: <0e1be5af251440b9a1d6e2553fb8cfa7@activenetwerx.com> From: Python-list on behalf of Irv Kalb Sent: Monday, April 16, 2018 10:03 AM To: python-list at python.org Subject: Instance variables question ? > class PartyAnimal(): > ??? x = 0 > > ??? def party(self): > ??????? self.x = self.x + 1 > ??????? print('So far', self.x) Your not accessing the class variable here, self.x != PartyAnimal.x. From tjol at tjol.eu Mon Apr 16 12:36:28 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 16 Apr 2018 18:36:28 +0200 Subject: Instance variables question In-Reply-To: References: Message-ID: <7a9ca596-fb41-3a1c-1feb-c68623a1e5d7@tjol.eu> On 2018-04-16 18:03, Irv Kalb wrote: > He gives a demonstration using the following example: > > class PartyAnimal(): > x = 0 > > def party(self): > self.x = self.x + 1 > print('So far', self.x) > > [snip] > > But there is something there that seems odd. My understanding is that the "x = 0" would be defining a class variable, that can be shared by all PartyAnimal objects. But he explains that because x is defined between the class statement and the "party" method, that this defines an instance variable x. That way, it can be used in the first line of the "party" method as self.x to increment itself. > > At the end of the video, he creates two objects from the same class, and each one gets its own self.x where each correctly starts at zero. Again, I expected x to be a class variable (accessible through PartyAnimal.x). > > When I want to create an instance variable and to be used later in other methods, I do this: > > class PartyAnimal(): > def __init__(self): > self.x = 0 > > def party(self): > self.x = self.x + 1 > print('So far', self.x) > > [snip] > > That is, I would assign the instance variable in the __init__ method. Both approaches give the same results. > > I'm certainly not trying to argue with Dr. Chuck. I am trying to understand his approach, but it's not clear to me why his code works. Specifically, can anyone explain how his "x = 0" turns x into an instance variable - while also allowing the syntax for a class variable PartyAnimal.x to be used? > "self.x = y", whatever self and y are, sets the attribute "x" of the object "self". Whether "self.x" previously existed does not matter (ignoring descriptors and the like). If you access self.x, whether x exists obviously does matter, and there's a fallback to looking in the class if the instance doesn't have it. FWIW, I think this business of defining class attributes for things that are instance-specific a bit daft. Your version strikes me as much more pythonic. -- Thomas From duncan at invalid.invalid Mon Apr 16 12:48:03 2018 From: duncan at invalid.invalid (duncan smith) Date: Mon, 16 Apr 2018 17:48:03 +0100 Subject: Instance variables question In-Reply-To: References: Message-ID: <9t4BC.15099$CQ1.3935@fx29.iad> On 16/04/18 17:03, Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for the past few years in Python. I am writing new curriculum for a course on OOP in Python. In order to see how others are explaining OOP concepts, I have been reading as many books and watching as many videos as I can. I've been watching some videos created by Dr. Chuck Severance in a series called "Python For Everyone". I think "Dr. Chuck" is an excellent teacher and I think his videos are outstanding. > > Today I watched this video: https://www.youtube.com/watch?v=b2vc5uzUfoE which is about 10 minutes long. In that video he gives a very basic overview of OOP and classes. He gives a demonstration using the following example: > > class PartyAnimal(): > x = 0 > > def party(self): > self.x = self.x + 1 > print('So far', self.x) > > an = PartyAnimal() > an.party() > an.party() > an.party() > > # I added this line just to see what it would do > print('Class variable', PartyAnimal.x) > > > And the output is: > > So far 1 > So far 2 > So far 3 > Class variable 0 > > But there is something there that seems odd. My understanding is that the "x = 0" would be defining a class variable, that can be shared by all PartyAnimal objects. But he explains that because x is defined between the class statement and the "party" method, that this defines an instance variable x. That way, it can be used in the first line of the "party" method as self.x to increment itself. > > At the end of the video, he creates two objects from the same class, and each one gets its own self.x where each correctly starts at zero. Again, I expected x to be a class variable (accessible through PartyAnimal.x). > > When I want to create an instance variable and to be used later in other methods, I do this: > > class PartyAnimal(): > def __init__(self): > self.x = 0 > > def party(self): > self.x = self.x + 1 > print('So far', self.x) > > an = PartyAnimal() > an.party() > an.party() > an.party() > > That is, I would assign the instance variable in the __init__ method. Both approaches give the same results. > > I'm certainly not trying to argue with Dr. Chuck. I am trying to understand his approach, but it's not clear to me why his code works. Specifically, can anyone explain how his "x = 0" turns x into an instance variable - while also allowing the syntax for a class variable PartyAnimal.x to be used? > > Thanks, > > Irv > My understanding of this: x is a class variable. Initially an instance has no instance variable self.x. So on the first call to self.party the name 'x' is looked up in the class. This value is incremented and the result is assigned to self.x. This is where the instance variable x is created and set. On subsequent calls to self.party there exists an instance variable x, so the name 'x' is not looked up in the class. Duncan From __peter__ at web.de Mon Apr 16 13:34:00 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Apr 2018 19:34 +0200 Subject: Instance variables question References: Message-ID: Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for the > past few years in Python. I am writing new curriculum for a course on OOP > in Python. In order to see how others are explaining OOP concepts, I have > been reading as many books and watching as many videos as I can. I've > been watching some videos created by Dr. Chuck Severance in a series > called "Python For Everyone". I think "Dr. Chuck" is an excellent teacher > and I think his videos are outstanding. > > Today I watched this video: https://www.youtube.com/watch?v=b2vc5uzUfoE > which is about 10 minutes > long. In that video he gives a very basic overview of OOP and classes. > He gives a demonstration using the following example: > > class PartyAnimal(): > x = 0 > > def party(self): > self.x = self.x + 1 > print('So far', self.x) > > an = PartyAnimal() > an.party() > an.party() > an.party() This style is rather brittle. Consider the following variant: >>> class A: ... x = "" ... >>> a = A() >>> b = A() >>> a.x += "a" >>> a.x += "a" >>> b.x += "b" >>> a.x 'aa' >>> b.x 'b' >>> A.x '' Seems to work. Now let's change x to something mutable: >>> A.x = [] >>> a = A() >>> b = A() >>> a.x += "a" >>> a.x += "a" >>> b.x += "b" >>> a.x ['a', 'a', 'b'] >>> b.x ['a', 'a', 'b'] >>> A.x ['a', 'a', 'b'] Conclusion: don't do this except to learn how attributes work in Python. From Irv at furrypants.com Mon Apr 16 13:37:02 2018 From: Irv at furrypants.com (Irv Kalb) Date: Mon, 16 Apr 2018 10:37:02 -0700 Subject: Instance variables question In-Reply-To: <9t4BC.15099$CQ1.3935@fx29.iad> References: <9t4BC.15099$CQ1.3935@fx29.iad> Message-ID: <626C6BBD-5368-4B43-A84A-0B9C08448C28@furrypants.com> > On Apr 16, 2018, at 9:48 AM, duncan smith wrote: > > On 16/04/18 17:03, Irv Kalb wrote: >> I have been writing OOP code for many years in other languages and for the past few years in Python. I am writing new curriculum for a course on OOP in Python. In order to see how others are explaining OOP concepts, I have been reading as many books and watching as many videos as I can. I've been watching some videos created by Dr. Chuck Severance in a series called "Python For Everyone". I think "Dr. Chuck" is an excellent teacher and I think his videos are outstanding. >> >> Today I watched this video: https://www.youtube.com/watch?v=b2vc5uzUfoE which is about 10 minutes long. In that video he gives a very basic overview of OOP and classes. He gives a demonstration using the following example: >> >> class PartyAnimal(): >> x = 0 >> >> def party(self): >> self.x = self.x + 1 >> print('So far', self.x) >> >> an = PartyAnimal() >> an.party() >> an.party() >> an.party() >> >> # I added this line just to see what it would do >> print('Class variable', PartyAnimal.x) >> >> >> And the output is: >> >> So far 1 >> So far 2 >> So far 3 >> Class variable 0 >> >> snip > > My understanding of this: > > x is a class variable. > > Initially an instance has no instance variable self.x. So on the first > call to self.party the name 'x' is looked up in the class. This value is > incremented and the result is assigned to self.x. This is where the > instance variable x is created and set. On subsequent calls to > self.party there exists an instance variable x, so the name 'x' is not > looked up in the class. > > Duncan > -- > https://mail.python.org/mailman/listinfo/python-list > Thanks for the responses. I thought it was something like this, but it hadn't realized that the first time the method was called, the right hand side would access the class variable x, but the second time (and later) it would access the instance variable x. I'll stick with the more "standard" approach of assigning the instance variable in the __init__ method. Thanks, Irv From rhodri at kynesim.co.uk Mon Apr 16 13:50:45 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Apr 2018 18:50:45 +0100 Subject: How to save xarray data to csv In-Reply-To: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> References: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> Message-ID: <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> On 16/04/18 15:55, shalu.ashu50 at gmail.com wrote: > Hello All, > > I have used xarray to merge several netcdf files into one file and then I subset the data of my point of interest using lat/long. Now I want to save this array data (time,lat,long) into csv file but I am getting an error with my code: You don't say, but I assume you're using Python 2.x [snip] > # xarray to numpy array > clt1=numpy.array(clt0sub) > # saving data into csv file > with open('combine11.csv', 'wb') as f: > writer = csv.writer(f, delimiter=',') > writer.writerows(enumerate(clt1)) > > getting this error - TypeError: a bytes-like object is required, not 'str' Copy and paste the entire traceback please if you want help. We have very little chance of working out what produced that error without it. > when I am removing "b" the error disappears Which "b"? Don't leave us guessing, we might guess wrong. > but the data saving in wrong format Really? It looks to me like you are getting exactly what you asked for. What format were you expecting? What are you getting that doesn't belong. I suspect that you don't want the "enumerate", but beyond that I have no idea what you're after. -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Mon Apr 16 14:01:00 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Apr 2018 04:01:00 +1000 Subject: How to save xarray data to csv In-Reply-To: <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> References: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> Message-ID: On Tue, Apr 17, 2018 at 3:50 AM, Rhodri James wrote: > You don't say, but I assume you're using Python 2.x > > [snip] > >> getting this error - TypeError: a bytes-like object is required, not 'str' Actually, based on this error, I would suspect Python 3.x. But you're right that (a) the Python version should be stated for clarity (there's a LOT of difference between Python 3.3 and Python 3.7), and (b) the full traceback is very helpful. ChrisA From rosuav at gmail.com Mon Apr 16 14:05:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Apr 2018 04:05:14 +1000 Subject: Instance variables question In-Reply-To: References: Message-ID: On Tue, Apr 17, 2018 at 3:34 AM, Peter Otten <__peter__ at web.de> wrote: > Irv Kalb wrote: > >> I have been writing OOP code for many years in other languages and for the >> past few years in Python. I am writing new curriculum for a course on OOP >> in Python. In order to see how others are explaining OOP concepts, I have >> been reading as many books and watching as many videos as I can. I've >> been watching some videos created by Dr. Chuck Severance in a series >> called "Python For Everyone". I think "Dr. Chuck" is an excellent teacher >> and I think his videos are outstanding. >> >> Today I watched this video: https://www.youtube.com/watch?v=b2vc5uzUfoE >> which is about 10 minutes >> long. In that video he gives a very basic overview of OOP and classes. >> He gives a demonstration using the following example: >> >> class PartyAnimal(): >> x = 0 >> >> def party(self): >> self.x = self.x + 1 >> print('So far', self.x) >> >> an = PartyAnimal() >> an.party() >> an.party() >> an.party() > > This style is rather brittle. Consider the following variant: > >>>> class A: > ... x = "" > ... >>>> a = A() >>>> b = A() >>>> a.x += "a" >>>> a.x += "a" >>>> b.x += "b" >>>> a.x > 'aa' >>>> b.x > 'b' >>>> A.x > '' > > Seems to work. Now let's change x to something mutable: > >>>> A.x = [] >>>> a = A() >>>> b = A() >>>> a.x += "a" >>>> a.x += "a" >>>> b.x += "b" >>>> a.x > ['a', 'a', 'b'] >>>> b.x > ['a', 'a', 'b'] >>>> A.x > ['a', 'a', 'b'] > > Conclusion: don't do this except to learn how attributes work in Python. Be careful: Your example looks nice and tidy because you're adding single-character strings onto a list. They happen to work as you'd expect. Normally, though, if you're adding onto a list, you probably want to use another list: a.x += ["a"] But you've successfully - if partly unwittingly - shown how hairy this can be :) ChrisA From __peter__ at web.de Mon Apr 16 14:45:28 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Apr 2018 20:45:28 +0200 Subject: Instance variables question References: Message-ID: Chris Angelico wrote: > On Tue, Apr 17, 2018 at 3:34 AM, Peter Otten <__peter__ at web.de> wrote: >> Irv Kalb wrote: >> >>> I have been writing OOP code for many years in other languages and for >>> the >>> past few years in Python. I am writing new curriculum for a course on >>> OOP >>> in Python. In order to see how others are explaining OOP concepts, I >>> have >>> been reading as many books and watching as many videos as I can. I've >>> been watching some videos created by Dr. Chuck Severance in a series >>> called "Python For Everyone". I think "Dr. Chuck" is an excellent >>> teacher and I think his videos are outstanding. >>> >>> Today I watched this video: >>> https://www.youtube.com/watch?v=b2vc5uzUfoE >>> which is about 10 minutes >>> long. In that video he gives a very basic overview of OOP and classes. >>> He gives a demonstration using the following example: >>> >>> class PartyAnimal(): >>> x = 0 >>> >>> def party(self): >>> self.x = self.x + 1 >>> print('So far', self.x) >>> >>> an = PartyAnimal() >>> an.party() >>> an.party() >>> an.party() >> >> This style is rather brittle. Consider the following variant: >> >>>>> class A: >> ... x = "" >> ... >>>>> a = A() >>>>> b = A() >>>>> a.x += "a" >>>>> a.x += "a" >>>>> b.x += "b" >>>>> a.x >> 'aa' >>>>> b.x >> 'b' >>>>> A.x >> '' >> >> Seems to work. Now let's change x to something mutable: >> >>>>> A.x = [] >>>>> a = A() >>>>> b = A() >>>>> a.x += "a" >>>>> a.x += "a" >>>>> b.x += "b" >>>>> a.x >> ['a', 'a', 'b'] >>>>> b.x >> ['a', 'a', 'b'] >>>>> A.x >> ['a', 'a', 'b'] >> >> Conclusion: don't do this except to learn how attributes work in Python. > > Be careful: Your example looks nice and tidy because you're adding > single-character strings onto a list. They happen to work as you'd > expect. Normally, though, if you're adding onto a list, you probably > want to use another list: > > a.x += ["a"] > > But you've successfully - if partly unwittingly - shown how hairy this can > be :) That was not an accident -- it was an attempt to make the two examples look as similar and harmless as possible. If the use of strings as a sequence distracts you use tuples instead: >>> class A: ... x = () ... >>> a = A() >>> b = A() >>> a.x += "alpha", >>> a.x += "alpha", >>> b.x += "beta", >>> a.x ('alpha', 'alpha') >>> b.x ('beta',) >>> A.x () >>> A.x = [] >>> a = A() >>> b = A() >>> a.x += "alpha", >>> a.x += "alpha", >>> b.x += "beta", >>> a.x ['alpha', 'alpha', 'beta'] >>> b.x ['alpha', 'alpha', 'beta'] >>> A.x ['alpha', 'alpha', 'beta'] From vinay_sajip at yahoo.co.uk Mon Apr 16 15:52:39 2018 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 16 Apr 2018 19:52:39 +0000 (UTC) Subject: ANN: distlib 0.2.7 released on PyPI References: <550252852.1474676.1523908359024.ref@mail.yahoo.com> Message-ID: <550252852.1474676.1523908359024@mail.yahoo.com> I've just released version 0.2.7 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be usable as the basis for third-party packaging tools. The main changes in this release are as follows: * Addressed #102: InstalledDistributions now have a modules attribute which is a list ? of top-level modules as read from top_level.txt, if that is in the distribution info. * Fixed #103: Now https downloads are preferred to those over http. Thanks to ? Saulius ?emaitaitis for the patch. * Fixed #104: Updated launcher binaries to properly handle interpreter paths with spaces. ? Thanks to Atsushi Odagiri for the diagnosis and fix. * Fixed #105: cache_from_source is now imported from importlib.util where available. * Added support for PEP 566 / Metadata 2.1. A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for?improvements, please give some feedback using the issue tracker! [3] Regards, Vinay Sajip [1]?https://pypi.org/project/distlib/0.2.7/? [2] https://goo.gl/M3kQzR [3] https://bitbucket.org/pypa/distlib/issues/new From drsalists at gmail.com Mon Apr 16 16:54:44 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 16 Apr 2018 13:54:44 -0700 Subject: Slow tarfile extract on armv7l Linux machine In-Reply-To: References: Message-ID: I'm not super-familiar with tarfile, though I did use it in one project. First off, note that CPython is commonly 4x slower than C. In fact, it can be much worse at times. Also... Have you considered trying your code on Pypy3? On Mon, Apr 16, 2018 at 9:10 AM, Jim MacArthur wrote: > Hi, I'm seeing a very slow extraction of an uncompressed tar file using > 'tarfile' in Python 3.5.3 vs. the native Debian tar tool. This is a console > log from my machine: > > jimm at scw-000001:~$ time tar xf update.tar > > real 0m3.436s > user 0m0.430s > sys 0m2.870s > jimm at scw-000001:~$ rm -rf home > jimm at scw-000001:~$ cat untar-test.py > #!/usr/bin/env python3 > > import tarfile > > tar = tarfile.open('update.tar') > > tar.extractall() > > jimm at scw-000001:~$ time ./untar-test.py > > real 0m12.216s > user 0m8.730s > sys 0m3.030s > jimm at scw-000001:~$ uname -a > Linux scw-000001 4.3.5-std-1 #1 SMP Fri Feb 19 11:52:18 UTC 2016 armv7l > GNU/Linux > jimm at scw-000001:~$ python3 > Python 3.5.3 (default, Jan 19 2017, 14:11:04) > [GCC 6.3.0 20170118] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> > > ---- > > I also tried this with 3.7.0b3 and I get the same result. On my desktop, an > x86_64 running Ubuntu, there's little difference between tarfile and native > tar. Obviously there will be some time spent starting Python but the above > seems too much. Does anyone have any ideas what might cause this or where to > look next? Does x86_64 do more of this in C code that's interpreted on > armv7l, for example? > > > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Mon Apr 16 17:08:34 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 16 Apr 2018 21:08:34 +0000 Subject: how to set timeout for os.popen In-Reply-To: <5813acd7-c471-2a80-e892-c86a7767c95c@gmail.com> References: <5813acd7-c471-2a80-e892-c86a7767c95c@gmail.com> Message-ID: On Mon, Apr 16, 2018 at 1:33 PM, Jugurtha Hadjar wrote: > On 04/15/2018 12:01 PM, Ho Yeung Lee wrote: >> >> while 1: >> runner = os.popen("tracert -d www.hello.com") >> o=runner.read() >> >> how to set timeout and know that this is timeout? > > @contextmanager > def timeout(duration, handler): > """Timeout after `duration` seconds.""" > signal.signal(signal.SIGALRM, handler) > signal.alarm(duration) > try: > yield > finally: > signal.alarm(0) The OP is most likely using Windows, which has tracert.exe instead of traceroute. Windows doesn't implement POSIX signals. The C runtime emulates the ones required by standard C. This includes SIGSEGV, SIGFPE, SIGILL based on OS exceptions; SIGINT (Ctrl+C) and SIGBREAK (Ctrl+Break) for console applications; and SIGABRT and SIGTERM for use in-process via C raise() and abort(). There's no alarm function to interrupt a thread that's waiting on synchronous I/O. You could implement something similar using another thread that calls CancelSynchronousIo(). Altertable waits can also be interrupted, but code has to be designed with this in mind. That said, the OP can simply switch to using subprocess.check_output(command_line, timeout=TIMEOUT). subprocess supports a timeout on Windows by joining a worker thread that reads from stdout. From larry.martell at gmail.com Mon Apr 16 17:31:48 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 16 Apr 2018 17:31:48 -0400 Subject: specifying the same argument multiple times with argparse Message-ID: Is there a way using argparse to be able to specify the same argument multiple times and have them all go into the same list? For example, I'd like to do this: script.py -foo bar -foo baz -foo blah and have the dest for foo have ['bar', 'baz', 'blah'] From __peter__ at web.de Mon Apr 16 18:01:25 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Apr 2018 00:01:25 +0200 Subject: specifying the same argument multiple times with argparse References: Message-ID: Larry Martell wrote: > Is there a way using argparse to be able to specify the same argument > multiple times and have them all go into the same list? action="append" > For example, I'd like to do this: > > script.py -foo bar -foo baz -foo blah > > and have the dest for foo have ['bar', 'baz', 'blah'] $ cat script.py #!/usr/bin/env python3 import argparse parser = argparse.ArgumentParser() parser.add_argument("--foo", action="append", default=[]) print(parser.parse_args().foo) $ ./script.py --foo one --foo two --foo three ['one', 'two', 'three'] From gherron at digipen.edu Mon Apr 16 18:19:26 2018 From: gherron at digipen.edu (Gary Herron) Date: Mon, 16 Apr 2018 15:19:26 -0700 Subject: specifying the same argument multiple times with argparse In-Reply-To: References: Message-ID: <120cbc43-17c9-0c3d-b571-f1faa1ab7ec5@digipen.edu> On 04/16/2018 02:31 PM, larry.martell at gmail.com wrote: > Is there a way using argparse to be able to specify the same argument > multiple times and have them all go into the same list? > > For example, I'd like to do this: > > script.py -foo bar -foo baz -foo blah > > and have the dest for foo have ['bar', 'baz', 'blah'] From the argparse web page (https://docs.python.org/3/library/argparse.html): 'append' - This stores a list, and appends each argument value to the list. This is useful to allow an option to be specified multiple times. Example usage: >>> >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='append') >>> parser.parse_args('--foo 1 --foo 2'.split()) Namespace(foo=['1', '2']) I hope that helps. -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From larry.martell at gmail.com Mon Apr 16 19:33:29 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 16 Apr 2018 19:33:29 -0400 Subject: specifying the same argument multiple times with argparse In-Reply-To: <120cbc43-17c9-0c3d-b571-f1faa1ab7ec5@digipen.edu> References: <120cbc43-17c9-0c3d-b571-f1faa1ab7ec5@digipen.edu> Message-ID: On Mon, Apr 16, 2018 at 6:19 PM, Gary Herron wrote: > On 04/16/2018 02:31 PM, larry.martell at gmail.com wrote: >> >> Is there a way using argparse to be able to specify the same argument >> multiple times and have them all go into the same list? >> >> For example, I'd like to do this: >> >> script.py -foo bar -foo baz -foo blah >> >> and have the dest for foo have ['bar', 'baz', 'blah'] > > > > From the argparse web page > (https://docs.python.org/3/library/argparse.html): > > 'append' - This stores a list, and appends each argument value to the list. > This is useful to allow an option to be specified multiple times. Example > usage: > >>>> >>>> parser = argparse.ArgumentParser() >>>> parser.add_argument('--foo', action='append') >>>> parser.parse_args('--foo 1 --foo 2'.split()) > Namespace(foo=['1', '2']) Thanks! I did not see that in the docs. From steve+comp.lang.python at pearwood.info Mon Apr 16 20:52:30 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Apr 2018 00:52:30 +0000 (UTC) Subject: Instance variables question References: Message-ID: On Mon, 16 Apr 2018 09:03:47 -0700, Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for > the past few years in Python. I am writing new curriculum for a course > on OOP in Python. If you're going to be teaching Python, please don't teach terminology which is ambiguous and non-standard in the Python community. The terminology we use is class and instance ATTRIBUTE, not "variable". The name is reflected in Python built-in functions getattr, setattr, delattr, as well as special dunder methods. While there are certain similarities, attributes and variables are quite different kinds of entities. The syntax, semantics and implementation of variable and attribute access are different: Syntax: - variable access: uses bare names like `foo` - attribute access: uses the dot pseudo-operator following almost any expression, such as `(result or calculation() + 1).attribute` Semantics: - variables are named values associated with a calculation; they are looked up across a relatively simple model involving a set of fixed scopes: locals, nonlocals (nested functions), globals, builtins - attributes are intended as an abstraction of components of objects, for example dog.tail, car.engine, page.margins, etc, and are looked up by a much more complex model involving not just object inheritance but also the so-called "descriptor protocol"; unlike variables, attributes can also be computed on need Implementation: - variables are generally name/value pairs in a dictionary namespace, but in CPython at least, local variables are implemented using a faster table implementation - attributes are also generally name/value pairs in a dictionary namespace, but they can also be computed at need using the special dunder methods __getattr__ and __getattribute__ or the property decorator Additionally, the terms "class variable" and "instance variable" are ambiguous in Python, because classes and instances are first-class (pun not intended) values in Python. In the same way that people can talk about a variable intended to hold a string as a string variable, or one holding a float as a float variable, so we can talk about a variable intended to hold a class (or type) as a "class variable". for s in ("hello", "world"): print("s is a string variable:", repr(s)) for t in (list, tuple, set, frozenset): print("t is a class variable:", repr(t)) [...] > But there is something there that seems odd. My understanding is that > the "x = 0" would be defining a class variable, that can be shared by > all PartyAnimal objects. But he explains that because x is defined > between the class statement and the "party" method, that this defines an > instance variable x. That way, it can be used in the first line of the > "party" method as self.x to increment itself. Indeed. Unlike some languages like Java, attributes are looked up at runtime, and instance attributes may shadow class attributes of the same name. If you want to assign to a class attribute, rather than writing self.x = value you need to specify that you're writing to the class: type(self).x = value -- Steve From shalu.ashu50 at gmail.com Mon Apr 16 22:25:54 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Mon, 16 Apr 2018 19:25:54 -0700 (PDT) Subject: How to save xarray data to csv In-Reply-To: References: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> Message-ID: <45a35874-8171-4da0-8499-f9e1c7381b2a@googlegroups.com> On Tuesday, 17 April 2018 01:56:25 UTC+8, Rhodri James wrote: > On 16/04/18 15:55, shalu.ashu50 at gmail.com wrote: > > Hello All, > > > > I have used xarray to merge several netcdf files into one file and then I subset the data of my point of interest using lat/long. Now I want to save this array data (time,lat,long) into csv file but I am getting an error with my code: > > > You don't say, but I assume you're using Python 2.x Hi James, I am using WinPython Spyder 3.6. > > [snip] > > > # xarray to numpy array > > clt1=numpy.array(clt0sub) > > # saving data into csv file > > with open('combine11.csv', 'wb') as f: > > writer = csv.writer(f, delimiter=',') > > writer.writerows(enumerate(clt1)) > > > > getting this error - TypeError: a bytes-like object is required, not 'str' > > Copy and paste the entire traceback please if you want help. We have > very little chance of working out what produced that error without it. > > > when I am removing "b" the error disappears here i mean [with open('combine11.csv', 'wb') as f:] wb: writing binaries if i am using "wb" so i m getting "TypeError: a bytes-like object is required, not 'str'" if i am removing "b" and using only "w" so this error disappears and when i am writing data into txt/csv so it is just pasting what i am seeing in my console window. I mean i have 20045 time steps but i am getting 100.2...like that as previously mentioned. Not getting full time steps. It is like printscreen of my python console. My question is how can i save multi-dimentional (3d: time series values, lat, long) data (xarrays) into csv. Thanks > > Which "b"? Don't leave us guessing, we might guess wrong. > > > but the data saving in wrong format > > Really? It looks to me like you are getting exactly what you asked for. > What format were you expecting? What are you getting that doesn't > belong. I suspect that you don't want the "enumerate", but beyond that > I have no idea what you're after. > > -- > Rhodri James *-* Kynesim Ltd From shalu.ashu50 at gmail.com Mon Apr 16 22:27:00 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Mon, 16 Apr 2018 19:27:00 -0700 (PDT) Subject: How to save xarray data to csv In-Reply-To: References: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> Message-ID: On Tuesday, 17 April 2018 02:01:19 UTC+8, Chris Angelico wrote: > On Tue, Apr 17, 2018 at 3:50 AM, Rhodri James wrote: > > You don't say, but I assume you're using Python 2.x > > > > [snip] > > > >> getting this error - TypeError: a bytes-like object is required, not 'str' > > Actually, based on this error, I would suspect Python 3.x. Yes Chris, I am using 3.x only But you're > right that (a) the Python version should be stated for clarity > (there's a LOT of difference between Python 3.3 and Python 3.7), and > (b) the full traceback is very helpful. > > ChrisA From naoki_morihira at outlook.jp Mon Apr 16 23:19:41 2018 From: naoki_morihira at outlook.jp (?? ??) Date: Tue, 17 Apr 2018 03:19:41 +0000 Subject: Python Import Impossibility Message-ID: Hello, Could you tell me how to import the installed modules ? I have successfully installed openpyxl, but When I executed ?import openpyxl?, The following message is displayed: Traceback (most recent call last): File "", line 1, in import openpyxl ModuleNotFoundError: No module named 'openpyxl' My folder is formed as follows: [cid:image003.png at 01D3D371.38FF7FB0] Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- From rishika21sen at gmail.com Tue Apr 17 01:00:49 2018 From: rishika21sen at gmail.com (Rishika Sen) Date: Mon, 16 Apr 2018 22:00:49 -0700 (PDT) Subject: Can I execute a python code written in Python 2.7 (using numpy and tensor flow executed in linux) in Winpython 3.6 on Windows? Message-ID: <2a979064-d7c6-4faf-b8d8-7f7574091624@googlegroups.com> Here is the code that has been written in Python 2.7, numpy, tensorflow: https://drive.google.com/open?id=1JZe7wfRcdlEF6Z5C0ePBjtte_2L4Kk-7 Can you please let me know what changes I have to make to execute it on WinPython 3.6? Else, is there a version on Python 2.7 in Winpython? I have Winpython, I do not have Linux. From naoki_morihira at outlook.jp Tue Apr 17 02:28:11 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Tue, 17 Apr 2018 06:28:11 +0000 Subject: Python Import Impossibility In-Reply-To: References: , Message-ID: Steven, When I installed ?openpyxl?, there is no error message in the command prompt screen. So I think that my installation is successfully completed. I installed by typing ?py -m install openpyxl?. In my PC, python is installed in the following folder: C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\DLLs C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Doc C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\include C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Lib C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\libs C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Scripts C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\tcl C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Tools But old version is left in the following folder: C:\Python27\Lib\site-packages C:\Python27\Scripts Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Steven D'Aprano ?????? ????: Friday, April 13, 2018 9:48:55 AM ??: python-list at python.org ??: Re: Python Import Impossibility On Fri, 13 Apr 2018 12:48:55 +0000, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, How do you know it was successful? What did you do to install it? How many different Python installations do you have on your system? but When I executed ?import > openpyxl?, The following message is displayed: > Traceback (most recent call last): > File "", line 1, in > import openpyxl > ModuleNotFoundError: No module named 'openpyxl' > > My folder is formed as follows: > [cid:image003.png at 01D3D312.38C82830] There are no attachments permitted on this list. -- Steve -- https://mail.python.org/mailman/listinfo/python-list From naoki_morihira at outlook.jp Tue Apr 17 02:32:05 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Tue, 17 Apr 2018 06:32:05 +0000 Subject: Python Import Impossibility In-Reply-To: <6a842341-f462-7b81-c1ba-b9d5b8f74426@tjol.eu> References: , <6a842341-f462-7b81-c1ba-b9d5b8f74426@tjol.eu> Message-ID: Thomas, I installed by typing the following command in the MS-Windows command prompt screen. ?py -m pip install openpyxl?. Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Thomas Jollans ?????? ????: Friday, April 13, 2018 9:38:15 AM ??: python-list at python.org ??: Re: Python Import Impossibility On 13/04/18 14:48, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, but > When I executed ?import openpyxl?, > The following message is displayed: > Traceback (most recent call last): > File "", line 1, in > import openpyxl > ModuleNotFoundError: No module named 'openpyxl' > > My folder is formed as follows: > [cid:image003.png at 01D3D312.38C82830] Is it possible that you installed the module in the wrong Python installation? -- https://mail.python.org/mailman/listinfo/python-list From naoki_morihira at outlook.jp Tue Apr 17 02:35:42 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Tue, 17 Apr 2018 06:35:42 +0000 Subject: Python Import Impossibility In-Reply-To: References: , , Message-ID: Steven, I would like to modify then following: (Error) ?py -m install openpyxl? (Correct) ?py -m pip install openpyxl? Sorry for my carelessness. Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ???: ?? ?? ????: 2018?4?16? 23:28 ??: Steven D'Aprano; python-list at python.org ??: RE: Python Import Impossibility Steven, When I installed ?openpyxl?, there is no error message in the command prompt screen. So I think that my installation is successfully completed. I installed by typing ?py -m pip install openpyxl?. In my PC, python is installed in the following folder: C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\DLLs C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Doc C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\include C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Lib C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\libs C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Scripts C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\tcl C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Tools But old version is left in the following folder: C:\Python27\Lib\site-packages C:\Python27\Scripts Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ???: Python-list ? Steven D'Aprano ?????? ????: Friday, April 13, 2018 9:48:55 AM ??: python-list at python.org ??: Re: Python Import Impossibility On Fri, 13 Apr 2018 12:48:55 +0000, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, How do you know it was successful? What did you do to install it? How many different Python installations do you have on your system? but When I executed ?import > openpyxl?, The following message is displayed: > Traceback (most recent call last): > File "", line 1, in > import openpyxl > ModuleNotFoundError: No module named 'openpyxl' > > My folder is formed as follows: > [cid:image003.png at 01D3D312.38C82830] There are no attachments permitted on this list. -- Steve -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Apr 17 03:00:26 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Apr 2018 03:00:26 -0400 Subject: Can I execute a python code written in Python 2.7 (using numpy and tensor flow executed in linux) in Winpython 3.6 on Windows? In-Reply-To: <2a979064-d7c6-4faf-b8d8-7f7574091624@googlegroups.com> References: <2a979064-d7c6-4faf-b8d8-7f7574091624@googlegroups.com> Message-ID: On 4/17/2018 1:00 AM, Rishika Sen wrote: > Here is the code that has been written in Python 2.7, numpy, tensorflow: > https://drive.google.com/open?id=1JZe7wfRcdlEF6Z5C0ePBjtte_2L4Kk-7 One must 'sign in' to read this. > Can you please let me know what changes I have to make to execute it on WinPython 3.6? Else, is there a version on Python 2.7 in Winpython? > > I have Winpython, I do not have Linux. If you has searched 'python tensorflow install' like I did you would have found https://www.tensorflow.org/install/install_windows and discovered that TensorFlow on Windows requires 64 bit 3.5 or 3.6. Learn to use Google, Bing, Yahoo, or whatever. I believe WinPython is the Python from python.org plus some extras. It may come with or have an easy option to install numpy (which is also available for 3.6). You may have to use 'py -m pip' instead of 'pip3' in the install instruction. Use the 3.6 2to3 tool to convert any custom 2.7 code to 3.6. See the manual. You may need to do additional conversion. -- Terry Jan Reedy From tjol at tjol.eu Tue Apr 17 04:12:48 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 17 Apr 2018 10:12:48 +0200 Subject: Python Import Impossibility In-Reply-To: References: Message-ID: <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> On 2018-04-17 08:35, ?? ?? wrote: > I installed by typing ?py -m pip install openpyxl?. > > > > In my PC, python is installed in the following folder: > > C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32 > > But old version is left in the following folder: > > C:\Python27 > There you go. py.exe probably used Python 2.7 rather than Python 3.6. What Python version starts if you just run "py"? If it *is* Python 2.7 that's the default, you can use "py -3 -m pip" etc. Or, frankly, if you don't use Python 2.7, you might as well just uninstall it to save you the headaches. -- Thomas From shalu.ashu50 at gmail.com Tue Apr 17 06:34:12 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Tue, 17 Apr 2018 03:34:12 -0700 (PDT) Subject: Problem in extracting and saving multi-dimensional time series data from netcdf file to csv file Message-ID: Hi All, I am using winpython spyder 3.6. I am trying to extract a variable with their time series values (daily from 1950 to 2004). The data structure is as follows: Dimensions: (bnds: 2, lat: 90, lon: 144, time: 20075) Coordinates: * lat (lat) float64 -89.0 -87.0 -85.0 -83.0 -81.0 -79.0 -77.0 ... * lon (lon) float64 1.25 3.75 6.25 8.75 11.25 13.75 16.25 18.75 ... * time (time) datetime64[ns] 1950-01-01T12:00:00 ... Dimensions without coordinates: bnds Data variables: time_bnds (time, bnds) datetime64[ns] ... lat_bnds (time, lat, bnds) float64 ... lon_bnds (time, lon, bnds) float64 ... clt (time, lat, lon) float32 ... Now I am extracting "clt" variable values based on my area of interest using lat/long boxes (latbounds = [ -13.0 , 31.0 ]# 22 grid numbers lonbounds = [ 89.75 , 151.25 ]#26 grid numbers My code is here: import netCDF4 import xarray as xr import numpy as np import csv import pandas as pd from pylab import * import datetime # NetCDF4-Python can read a remote OPeNDAP dataset or a local NetCDF file: nc = netCDF4.Dataset('clt_day_GFDL-CM3_historical_r1i1p1_19500101-20041231.nc.nc') nc.variables.keys() lat = nc.variables['lat'][:] lon = nc.variables['lon'][:] time_var = nc.variables['time'] dtime = netCDF4.num2date(time_var[:],time_var.units) lat_bnds, lon_bnds = [-13.0 , 31.0], [89.75 , 151.25] # determine what longitude convention is being used [-180,180], [0,360] print (lon.min(),lon.max()) print (lat.min(),lat.max()) # latitude lower and upper index latli = np.argmin( np.abs( lat - lat_bnds[0] ) ) latui = np.argmin( np.abs( lat - lat_bnds[1] ) ) # longitude lower and upper index lonli = np.argmin( np.abs( lon - lon_bnds[0] ) ) lonui = np.argmin( np.abs( lon - lon_bnds[1] ) ) print(lat) clt_subset = nc.variables['clt'][:,latli:latui , lonli:lonui] upto here I am able to extract the data but I am not able to save these values in csv file. I am also able to save values for one location but when I am going with multi-dimentional extracted values so it is giving an error when i am executing this: hs = clt_subset[istart:istop,latli:latui , lonli:lonui] tim = dtime[istart:istop] print(tim) # Create Pandas time series object ts = pd.Series(hs,index=tim,name=clt_subset) Error: - ts = pd.Series(hs,index=tim,name=clt_subset) Traceback (most recent call last): File "", line 1, in ts = pd.Series(hs,index=tim,name=clt_subset) File "C:\python3\WinPython\python-3.6.5.amd64\lib\site-packages\pandas\core\series.py", line 264, in __init__ raise_cast_failure=True) File "C:\python3\WinPython\python-3.6.5.amd64\lib\site-packages\pandas\core\series.py", line 3275, in _sanitize_array raise Exception('Data must be 1-dimensional') Exception: Data must be 1-dimensional Suggestions would be appreciated. Thanks Vishu From rhodri at kynesim.co.uk Tue Apr 17 06:59:46 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Apr 2018 11:59:46 +0100 Subject: How to save xarray data to csv In-Reply-To: <45a35874-8171-4da0-8499-f9e1c7381b2a@googlegroups.com> References: <96522059-28c7-4e5c-b611-46741c4d1419@googlegroups.com> <90b6983b-8034-95b7-8786-87accdf06c3f@kynesim.co.uk> <45a35874-8171-4da0-8499-f9e1c7381b2a@googlegroups.com> Message-ID: On 17/04/18 03:25, shalu.ashu50 at gmail.com wrote: > My question is how can i save multi-dimentional (3d: time series values, lat, long) data (xarrays) into csv. What do you want each line of the CSV file to look like? That's the key question. Once you know that you can arrange your data into a (one dimensional) list of that form and then write it out. Since I have exactly no idea what netCDF4.Dataset() does (and less interest in finding out), I can't offer much advice. The slicing that you're doing looks like some weird limiting selection, but there must be some way of iterating through entries, surely? -- Rhodri James *-* Kynesim Ltd From shalu.ashu50 at gmail.com Tue Apr 17 07:00:27 2018 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Tue, 17 Apr 2018 04:00:27 -0700 (PDT) Subject: How to save multi-dimentional array values into CSV/Test file Message-ID: <559c052d-8540-4d07-a149-eca0f6e7ef6e@googlegroups.com> Hi All, I am using winpy 6.3 I have this array: code: clt_subset = nc.variables['clt'][:,latli:latui , lonli:lonui] print(clt_subset): [[[ 96.07967377 32.5813179 30.86773872 ..., 99.99996185 99.99997711 99.99997711] [ 93.75789642 86.78536987 46.51786423 ..., 99.99756622 99.99769592 99.99931335] [ 99.19438171 99.71717834 97.34263611 ..., 99.99707794 99.99639893 99.93907928] ..., [ 7.65702724 1.1814307 4.02125835 ..., 39.58660126 37.71473694 42.10451508] [ 9.48283291 18.4249897 45.22411346 ..., 70.95629883 72.82741547 72.89440155] [ 33.2973175 46.50339508 88.39287567 ..., 98.50241089 98.47457123 91.32685089]] [[ 85.40306854 28.19069862 19.56433678 ..., 99.96898651 99.99860382 100. ] [ 80.49911499 49.17562485 25.18140984 ..., 99.99198151 99.99337006 99.99979401] [ 99.9821167 91.44667816 78.83125305 ..., 99.99027252 99.99280548 99.99995422] ..., so on.............. print (clt_subset.shape) (20075, 22, 25) I am not able to save this array into csv file with time series using datetime function. The code is here: # 2. Specify the exact time period you want: start = datetime.datetime(1950,1,1,0,0,0) stop = datetime.datetime(2004,12,1,0,0,0) istart = netCDF4.date2index(start,time_var,select='nearest') istop = netCDF4.date2index(stop,time_var,select='nearest') print (istart,istop) hs = clt_subset[istart:istop,latli:latui , lonli:lonui] tim = dtime[istart:istop] ts = pd.Series(hs,index=tim,name=clt_subset) ts.to_csv('time_series_from_netcdf.csv') while executing this, saying: Error- File "C:\python3\WinPython\python-3.6.5.amd64\lib\site-packages\pandas\core\series.py", line 3275, in _sanitize_array raise Exception('Data must be 1-dimensional') Exception: Data must be 1-dimensional From zobeid.zuma at gmail.com Tue Apr 17 09:20:59 2018 From: zobeid.zuma at gmail.com (Zobeid Zuma) Date: Tue, 17 Apr 2018 08:20:59 -0500 Subject: tkinter frame not expanding to fit window? Message-ID: <6LudnQY2qOQmaUjHnZ2dnUU7-a-dnZ2d@giganews.com> I've just started working through the tutorial here ? http:// www.tkdocs.com/tutorial/firstexample.html and I already hit some behavior that I don't understand. The frame doesn't expand when I resize the window! The tutorial says these lines should do it: mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) As an experiment I tried commenting those lines out, just to see if anything would change, and nothing did. So it seems they aren't working for me, but I don't know why. Any suggestions? This is all running on Ubuntu MATE 17.10 and tk8.6. From naoki_morihira at outlook.jp Tue Apr 17 10:08:49 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Tue, 17 Apr 2018 14:08:49 +0000 Subject: Python Import Impossibility In-Reply-To: <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> References: , <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> Message-ID: Thomas, I deleted ?C:\Python27?, and executed in Windows Command prompt screen, ?C:Users/N.Morihira>py -m install openpyxl?, But the following message was displayed * Requirement already satisfied: openpyxl in c:\users\n.morihira\anaconda3\lib\site-packages * Requirement already satisfied: jdcal in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl) * Requirement already satisfied: et_xmlfile in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl), And it also displays the following message in Python3.6.4 Shell screen. >>> import openpyxl Traceback (most recent call last): File "", line 1, in import openpyxl ModuleNotFoundError: No module named 'openpyxl' Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Thomas Jollans ?????? ????: Tuesday, April 17, 2018 1:12:48 AM ??: python-list at python.org ??: Re: Python Import Impossibility On 2018-04-17 08:35, ?? ?? wrote: > I installed by typing ?py -m pip install openpyxl?. > > > > In my PC, python is installed in the following folder: > > C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32 > > But old version is left in the following folder: > > C:\Python27 > There you go. py.exe probably used Python 2.7 rather than Python 3.6. What Python version starts if you just run "py"? If it *is* Python 2.7 that's the default, you can use "py -3 -m pip" etc. Or, frankly, if you don't use Python 2.7, you might as well just uninstall it to save you the headaches. -- Thomas -- https://mail.python.org/mailman/listinfo/python-list From travisgriggs at gmail.com Tue Apr 17 12:02:52 2018 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 17 Apr 2018 09:02:52 -0700 Subject: Most pythonic way to implement byte stuffing algorithm Message-ID: I posted this on SO, but? yeah? I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is ?what is the most pythonic way to transform one sequence of bytes where some bytes are passed through 1:1, but others are transformed to longer subsequences of bytes?? I?m pretty sure this rules out the use of transform() which expects a 1:1 mapping. So far, I've come with 5 different approaches, and each of them has something I don't like about it: 1 Via Generator def stuff1(bits): for byte in bits: if byte in _EscapeCodes: yield PacketCode.Escape yield byte ^ 0xFF else: yield byte This may be my favorite, but maybe just because I'm kind of fascinated by yield based generators. I worried that the generator would make it slow, but it's actually the second fastest of the bunch. 2 Simply bytes() def stuff2(bits): result = bytes() for byte in bits: if byte in _EscapeCodes: result += bytes([PacketCode.Escape, byte ^ 0xFF]) else: result += bytes([byte]) return result Constantly has to create single element arrays just to throw them out because I'm not aware of any "copy with one additional element" operation. It ties for the slowest of the bunch. 3 Use bytearray() def stuff3(bits): result = bytearray() for byte in bits: if byte in _EscapeCodes: result.append(PacketCode.Escape) result.append(byte ^ 0xFF) else: result.append(byte) return result Seems better than the direct bytes() approach. Actually slower than the yield generator and can do one byte at a time (instead of needing intermediate 1 element collections). But it feels brutish. It's middle of the pack performance. 4 BytesIO() def stuff4(bits): bio = BytesIO() for byte in bits: if byte in _EscapeCodes: bio.write(bytes([PacketCode.Escape, byte ^ 0xFF])) else: bio.write(bytes([byte])) return bio.getbuffer() I like the stream based approach here. But it is annoying that there doesn't seem to be something like a write1() API that could just add 1 byte, so I have to make those intermediate bytes again. If there was a "write single byte", I'd like this one. It ties for slowest. 5 Use replace() def stuff5(bits): escapeStuffed = bytes(bits).replace(bytes([PacketCode.Escape]), bytes([PacketCode.Escape, PacketCode.Escape ^ 0xFF])) stopStuffed= escapeStuffed.replace(bytes([PacketCode.Stop]), bytes([PacketCode.Escape, PacketCode.Stop ^ 0xFF])) return stopStuffed.replace(bytes([PacketCode.Start]), bytes([PacketCode.Escape, PacketCode.Start ^ 0xFF])) This is the fastest. But I don't like the way the code reads and the intermediate sweeps. From grant.b.edwards at gmail.com Tue Apr 17 13:06:42 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 17 Apr 2018 17:06:42 +0000 (UTC) Subject: Most pythonic way to implement byte stuffing algorithm References: Message-ID: On 2018-04-17, Travis Griggs wrote: > I posted this on SO, but? yeah? > > I'm doing some serial protocol stuff and want to implement a basic > byte stuffing algorithm in python. Though really what this really > generalizes to is ?what is the most pythonic way to transform one > sequence of bytes where some bytes are passed through 1:1, but > others are transformed to longer subsequences of bytes?? I?m pretty > sure this rules out the use of transform() which expects a 1:1 > mapping. > > > So far, I've come with 5 different approaches, and each of them has something I don't like about it: > > 1 Via Generator > > def stuff1(bits): > for byte in bits: > if byte in _EscapeCodes: > yield PacketCode.Escape > yield byte ^ 0xFF > else: > yield byte > > This may be my favorite, but maybe just because I'm kind of > fascinated by yield based generators. I worried that the generator > would make it slow, but it's actually the second fastest of the > bunch. I find that the most readible, and would certainly get my vote -- even if it was the slowest (unless it was so slow as to be a problem). [...] > def stuff5(bits): > escapeStuffed = bytes(bits).replace(bytes([PacketCode.Escape]), bytes([PacketCode.Escape, PacketCode.Escape ^ 0xFF])) > stopStuffed= escapeStuffed.replace(bytes([PacketCode.Stop]), bytes([PacketCode.Escape, PacketCode.Stop ^ 0xFF])) > return stopStuffed.replace(bytes([PacketCode.Start]), bytes([PacketCode.Escape, PacketCode.Start ^ 0xFF])) > > This is the fastest. But I don't like the way the code reads and the intermediate sweeps. Yow, that's ugly -- I don't think I'd be able to tell you what it actually does without actually running it. If speed is that important, I might just write a function in C and call it with ctypes. :) -- Grant Edwards grant.b.edwards Yow! HAIR TONICS, please!! at gmail.com From python at mrabarnett.plus.com Tue Apr 17 14:15:28 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Apr 2018 19:15:28 +0100 Subject: Most pythonic way to implement byte stuffing algorithm In-Reply-To: References: Message-ID: On 2018-04-17 17:02, Travis Griggs wrote: > I posted this on SO, but? yeah? > > I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is ?what is the most pythonic way to transform one sequence of bytes where some bytes are passed through 1:1, but others are transformed to longer subsequences of bytes?? I?m pretty sure this rules out the use of transform() which expects a 1:1 mapping. > [snip] There are only 256 possible input bytes, so just put them into a dict and look them up. From __peter__ at web.de Tue Apr 17 14:24:16 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Apr 2018 20:24:16 +0200 Subject: tkinter frame not expanding to fit window? References: <6LudnQY2qOQmaUjHnZ2dnUU7-a-dnZ2d@giganews.com> Message-ID: Zobeid Zuma wrote: > I've just started working through the tutorial here ? http:// > www.tkdocs.com/tutorial/firstexample.html and I already hit some behavior > that I don't understand. The frame doesn't expand when I resize the > window! The tutorial says these lines should do it: > > mainframe.columnconfigure(0, weight=1) > mainframe.rowconfigure(0, weight=1) > > As an experiment I tried commenting those lines out, just to see if > anything would change, and nothing did. So it seems they aren't working > for me, but I don't know why. Any suggestions? > > This is all running on Ubuntu MATE 17.10 and tk8.6. Here is a minimalistic example with a red Frame in a blue window: import tkinter as tk root = tk.Tk() root["background"] = "blue" frame = tk.Frame(root, background="red") frame.grid(row=0, column=0, sticky=tk.NSEW) root.rowconfigure(0, weight=1) root.columnconfigure(0, weight=1) root.mainloop() When you run it as is you should see the red frame. When you remove the lines root.rowconfigure(0, weight=1) root.columnconfigure(0, weight=1) you should see the blue window instead. When you put those lines back in, but change the line frame.grid(row=0, column=0, sticky=tk.NSEW) to frame.grid(row=0, column=0) you will also see blue. So my crystal ball says that in the code that you don't show you forgot to make the Frame "sticky". From travisgriggs at gmail.com Tue Apr 17 14:37:15 2018 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 17 Apr 2018 11:37:15 -0700 Subject: Most pythonic way to implement byte stuffing algorithm In-Reply-To: References: Message-ID: <61C6C32E-0C1B-4F8F-82D2-0CBB88DDA6F5@gmail.com> > On Apr 17, 2018, at 11:15 AM, MRAB wrote: > > On 2018-04-17 17:02, Travis Griggs wrote: >> I posted this on SO, but? yeah? >> I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is ?what is the most pythonic way to transform one sequence of bytes where some bytes are passed through 1:1, but others are transformed to longer subsequences of bytes?? I?m pretty sure this rules out the use of transform() which expects a 1:1 mapping. > [snip] > There are only 256 possible input bytes, so just put them into a dict and look them up. > -- > https://mail.python.org/mailman/listinfo/python-list So something like this? LUT = list(bytes([x]) for x in range(256)) LUT[PacketCode.Escape] = bytes([PacketCode.Escape, PacketCode.Escape ^ 0xFF]) LUT[PacketCode.Start] = bytes([PacketCode.Escape, PacketCode.Start ^ 0xFF]) LUT[PacketCode.Stop] = bytes([PacketCode.Escape, PacketCode.Stop ^ 0xFF]) def stuff6(bits): return b''.join(LUT[x] for x in bits) From drsalists at gmail.com Tue Apr 17 17:06:10 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 17 Apr 2018 14:06:10 -0700 Subject: Fwd: Python Import Impossibility In-Reply-To: References: Message-ID: Given that the list does not allow pictures, would it make sense to have the software that strips the pictures also send an e-mail to the picture sender indicating that pictures are disallowed? I see a lot of people responding individually saying that images are stripped. It's looking like a bit of a traffic increaser. In a more draconian world, we could even bounce such messages. ---------- Forwarded message ---------- From: ?? ?? Date: Mon, Apr 16, 2018 at 8:19 PM Subject: Python Import Impossibility To: "Python-list at python.org" Hello, Could you tell me how to import the installed modules ? I have successfully installed openpyxl, but When I executed ?import openpyxl?, The following message is displayed: Traceback (most recent call last): File "", line 1, in import openpyxl ModuleNotFoundError: No module named 'openpyxl' My folder is formed as follows: [cid:image003.png at 01D3D371.38FF7FB0] Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Apr 17 18:09:24 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Apr 2018 18:09:24 -0400 Subject: Fwd: Python Import Impossibility In-Reply-To: References: Message-ID: On 4/17/2018 5:06 PM, Dan Stromberg wrote: > Given that the list does not allow pictures, would it make sense to > have the software that strips the pictures also send an e-mail to the > picture sender indicating that pictures are disallowed? > > I see a lot of people responding individually saying that images are > stripped. It's looking like a bit of a traffic increaser. My impression is that attachments are more common than 20 years ago. > In a more draconian world, we could even bounce such messages. If Tim Golden does not reply to this, send suggestion to python-list-owner at python.org -- Terry Jan Reedy From kai.peters at gmail.com Tue Apr 17 18:09:53 2018 From: kai.peters at gmail.com (TUA) Date: Tue, 17 Apr 2018 15:09:53 -0700 (PDT) Subject: Newbie ARGPARSE question Message-ID: <394b2e4e-3236-4739-bb36-defcda7c00b8@googlegroups.com> I just discovered ARGPARSE 5 minutes ago and cannot figure this one out: What does the Parser.add_argument() call have to look like when I need an option 'add' that requires the mandatory parameters 'type' (string), 'size' (int), 'sid' (string) and must also handle the optional parameters 'comment' (string) and 'auto-start' (bool, defaults to TRUE). Thanks to all helping me preserve my sanity! From daniel.chmielewski at gmail.com Tue Apr 17 19:11:52 2018 From: daniel.chmielewski at gmail.com (daniel.chmielewski at gmail.com) Date: Tue, 17 Apr 2018 16:11:52 -0700 (PDT) Subject: error from Popen only when run from cron In-Reply-To: References: Message-ID: <1bb8597b-0116-4f71-a828-bbbf9aed243c@googlegroups.com> W dniu sobota, 27 stycznia 2018 16:59:50 UTC+1 u?ytkownik Larry.... at gmail.com napisa?: > I have a script that does this: > > subprocess.Popen(['service', 'some_service', 'status'], > stdout=subprocess.PIPE, stderr=subprocess.STDOUT) > > When I run it from the command line it works fine. When I run it from > cron I get: > > subprocess.Popen(['service', 'some_service', 'status'], > stdout=subprocess.PIPE, stderr=subprocess.STDOUT) > File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__ > errread, errwrite) > File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > Anyone have any clue as to what file it's complaining about? Or how I > can debug this further? Larry, I have exactly the same problem. I'd like to run a script and from normal user it works, and from cron doesn't. In sumarry I was googled to find information how to set two or more env. variables and pass them to subprocess.open. I also try to read $HOME/.profile where usually these env. var. are setting. Have anyone see any example how to do it? Please let me know. Regards, Daniel From kai.peters at gmail.com Tue Apr 17 20:09:33 2018 From: kai.peters at gmail.com (TUA) Date: Tue, 17 Apr 2018 17:09:33 -0700 (PDT) Subject: ARGPARSE Newbie question Message-ID: <1c3b756f-1017-448f-ac01-0bfffe6c0654@googlegroups.com> I'd like to create a script that handles a number of verbs with mandatory and /or optional parameters like listed in the table below. Can ARGPARSE do this and how? Thanks for all help! Script Verb Mandatory parameters Optional parameters ------------------------------------------------------------------------------ myprog.py list --- verbose myprog.py add sid(string), type (string), memory (int) comment (string), autostart (bool, default=TRUE) myprog.py memory sid (string), memory (integer) myprog.py comment sid(string), comment (string) myprog.py restore sid(string), srcpath (string) myprog.py backup sid(string), dstpath(string) myprog.py remove sid (string) From paulclarke345 at gmail.com Tue Apr 17 21:08:37 2018 From: paulclarke345 at gmail.com (paulclarke345 at gmail.com) Date: Tue, 17 Apr 2018 18:08:37 -0700 (PDT) Subject: ARGPARSE Newbie question In-Reply-To: <1c3b756f-1017-448f-ac01-0bfffe6c0654@googlegroups.com> References: <1c3b756f-1017-448f-ac01-0bfffe6c0654@googlegroups.com> Message-ID: <80c6d2ca-67d8-401d-8f57-690095850cd1@googlegroups.com> On Tuesday, April 17, 2018 at 7:09:45 PM UTC-5, TUA wrote: > I'd like to create a script that handles a number of verbs with mandatory and /or optional parameters like listed in the table below. > > Can ARGPARSE do this and how? > > Thanks for all help! > > > > > > Script Verb Mandatory parameters Optional parameters > ------------------------------------------------------------------------------ > myprog.py list --- verbose > > myprog.py add sid(string), type (string), memory (int) comment (string), autostart (bool, default=TRUE) > > myprog.py memory sid (string), memory (integer) > > myprog.py comment sid(string), comment (string) > > myprog.py restore sid(string), srcpath (string) > > myprog.py backup sid(string), dstpath(string) > > myprog.py remove sid (string) you can use subparsers for this. The syntax goes something like this: parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subparser_name') list_parser = subparsers.add_parser("list", help="help for list") list_parse.add_argument("-v", "--verbose", help="show verbose output", action="store_true") add_parser = subparsers.add_parser("add", help="help for add") add.add_argument("sid", type=str, help="help for sid") ... etc. see the documentation on argparse for more on this. From kai.peters at gmail.com Tue Apr 17 21:35:35 2018 From: kai.peters at gmail.com (TUA) Date: Tue, 17 Apr 2018 18:35:35 -0700 (PDT) Subject: ARGPARSE Newbie question In-Reply-To: <80c6d2ca-67d8-401d-8f57-690095850cd1@googlegroups.com> References: <1c3b756f-1017-448f-ac01-0bfffe6c0654@googlegroups.com> <80c6d2ca-67d8-401d-8f57-690095850cd1@googlegroups.com> Message-ID: <99f0c539-b864-4f62-b3a2-7e2bb458c87c@googlegroups.com> Thanks for the pointers! From drsalists at gmail.com Tue Apr 17 21:54:02 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 17 Apr 2018 18:54:02 -0700 Subject: error from Popen only when run from cron In-Reply-To: <1bb8597b-0116-4f71-a828-bbbf9aed243c@googlegroups.com> References: <1bb8597b-0116-4f71-a828-bbbf9aed243c@googlegroups.com> Message-ID: On Tue, Apr 17, 2018 at 4:11 PM, wrote: > W dniu sobota, 27 stycznia 2018 16:59:50 UTC+1 u?ytkownik Larry.... at gmail.com napisa?: >> I have a script that does this: >> >> subprocess.Popen(['service', 'some_service', 'status'], >> stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >> >> When I run it from the command line it works fine. When I run it from >> cron I get: >> >> subprocess.Popen(['service', 'some_service', 'status'], >> stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >> File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__ >> errread, errwrite) >> File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> >> Anyone have any clue as to what file it's complaining about? Or how I >> can debug this further? > > Larry, I have exactly the same problem. I'd like to run a script and from normal user it works, and from cron doesn't. > > In sumarry I was googled to find information how to set two or more env. variables and pass them to subprocess.open. I also try to read $HOME/.profile where usually these env. var. are setting. Have anyone see any example how to do it? Please let me know. Regards, Daniel Is service on your $PATH in the cronjob? What if you set the variables you need in the program, and test it with "env - myscript" in a login shell, to run myscript with an empty environment? This tends to make under cron and not under cron more similar. HTH From tejaswidprakash at gmail.com Wed Apr 18 00:51:36 2018 From: tejaswidprakash at gmail.com (tejaswi prakash) Date: Wed, 18 Apr 2018 10:21:36 +0530 Subject: Finding set difference between ranges Message-ID: Hello all, I have 3 continuous (steps of 1) ranges a,a1,a2. All of them sorted. I am performing the following operations on them a = a.difference (a1) a = a.difference(a2) Now, this doesn't seem to make use of the fact that 1. They are sorted 2. They increase in steps of 1 . Could someone suggest a better way of doing this to make these operations more efficient? Thank you, Tejaswi D Prakash From Cecil at decebal.nl Wed Apr 18 02:47:24 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 18 Apr 2018 08:47:24 +0200 Subject: After update to pip 10 I get: Cache entry deserialization failed, entry ignored Message-ID: <87604pdn9f.fsf@munus.decebal.nl> After I updated pip2/3 to 10 from 9 I sometimes get: Cache entry deserialization failed, entry ignored For example when I execute: pip3 list --outdated But not always. What could be happening here? And how would I solve this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From zljubisic at gmail.com Wed Apr 18 03:25:23 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 18 Apr 2018 00:25:23 -0700 (PDT) Subject: Regex for changing :variable to ${variable} in sql query Message-ID: <8878d94c-d0b9-407b-b9f5-8a051acd3f2f@googlegroups.com> Hi, I have a sql query in which all variables declared as :variable should be changed to ${variable}. for example this sql: select * from table where ":x" = "1" and :y=2 and field in (:string) and time between :from and :to should be translated to: select * from table where "${x}" = "1" and ${y} = 2 and field in ( ${string} ) and time between ${from} and ${to} As far as I have come is to find the group as (:(.+?)\b) and than replace it as ${$2} (it would be nice if before and after the ${variable} it is always one space) For opposite change (from ${variable} notation to :variable) I am using: sql.replace('${', ':').replace('}', '') Can someone please help? Regards. From supswain at gmail.com Wed Apr 18 05:32:51 2018 From: supswain at gmail.com (supswain at gmail.com) Date: Wed, 18 Apr 2018 02:32:51 -0700 (PDT) Subject: how to create auto generated mail from robo framework upon execution completion of TCs Message-ID: <519538c8-e5e1-4592-82f2-094f67fb0454@googlegroups.com> Hi, I am having below setup robofraemwork setup info -> Robot Framework 2.8.1 32 bit python->Python 2.7.6 32 bit OS->windows 7 64 bit I am running test cases from Robo framework and want to create any library proc through which I can get auto generated mail from robo-framework regarding execution of the Tcs upon completion of execution. I want the mail message body to be as below 1->name of the TC 2->execution status 3->path to find execution log for the TC Could anyone please help me on this. Thanks, Supriya From sjeik_appie at hotmail.com Wed Apr 18 06:41:35 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Wed, 18 Apr 2018 10:41:35 +0000 Subject: Flask test generator code review? Message-ID: Hi, I am writing my first unittests for a Flask app. First modest goal is to test whether a selected subset of the templates return the expected status 200. I am using a nose test generator in a class for this. Is the code below the correct way to do this? And is there a way to dynamically set the docstring of test_generator? This would make the nosetests output a bit more understandable. Thanks! Albert-Jan import os import sys from os.path import splitext from http import HTTPStatus as status import nose from MyFabulousApp import app app.testing = True template_folder = app.config['TEMPLATE_FOLDER'] class Test_MyFabulousApp_HTTP_Status_OK: def __init__(self): self.setup() # with unittest, setUp is called automatically, but not with nose def setup(self): self.client = app.test_client() self.client.post('/login', follow_redirects=True) def teardown(self): self.client.post('/logout', follow_redirects=True) def test_generator(self): """Does template return HTTP Status 200?""" def the_test(self, template): # the following line throws an error: AttributeError: attribute '__doc__' of 'method' objects is not writable #self.test_generator.__doc__ = 'Does template "%s" return HTTP Status 200?' % template respons = self.client.get('/' + template) actual = respons.status_code desired = status.OK.value assert actual == desired, \ 'Template "%s" returns status code %d' % (template, actual) templates = [splitext(item)[0] for item in os.listdir(template_folder)] for template in templates: yield the_test, self, template if __name__ == '__main__': nose.run(defaultTest=__name__, argv=[sys.argv[0], '__main__', '--verbosity=2']) From zbyszek at in.waw.pl Wed Apr 18 08:15:00 2018 From: zbyszek at in.waw.pl (Zbigniew =?utf-8?Q?J=C4=99drzejewski-Szmek?=) Date: Wed, 18 Apr 2018 12:15:00 +0000 Subject: New PyPI launched, legacy PyPI shutting down April 30 In-Reply-To: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> References: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> Message-ID: <20180418121500.GJ7873@in.waw.pl> On Mon, Apr 16, 2018 at 01:21:50PM -0400, Laura Hampton wrote: > New PyPI launched, legacy PyPI shutting down April 30[1] > > Starting today, the canonical Python Package Index is at https://pypi.org and uses the new Warehouse codebase. We announced the https://pypi.org beta on March 26 and your feedback and test usage have helped us get it production-ready. Search seems to be broken: > https://pypi.org/search/?q=numpy There were no results for 'numpy' Zbyszek From noah at neo.co.tz Wed Apr 18 09:15:09 2018 From: noah at neo.co.tz (Noah) Date: Wed, 18 Apr 2018 16:15:09 +0300 Subject: New PyPI launched, legacy PyPI shutting down April 30 In-Reply-To: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> References: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> Message-ID: Awesome........ On Mon, Apr 16, 2018 at 8:21 PM, Laura Hampton wrote: > New PyPI launched, legacy PyPI shutting down April 30[1] > > Starting today, the canonical Python Package Index is at https://pypi.org > and uses the new Warehouse codebase. We announced the https://pypi.org > beta on March 26 and your feedback and test usage have helped us get it > production-ready. > > Monday April 16 (2018-04-16): We launched the new PyPI, redirecting > browser traffic and API calls (including "pip install") from > pypi.python.org to the new site. The old codebase is still available at > https://legacy.pypi.org for now. > > Monday April 30 (2018-04-30): We plan to shut down legacy PyPI > https://legacy.pypi.org . The address pypi.python.org will continue to > redirect to Warehouse. > > For more details, see our roadmap: https://wiki.python.org/psf/ > WarehouseRoadmap > > If your site/service links to or uses pypi.python.org, you should start > using pypi.org instead: https://warehouse.readthedocs. > io/api-reference/integration-guide/#migrating-to-the-new-pypi > > Thank you. > > [1] https://blog.python.org/2018/04/new-pypi-launched-legacy- > pypi-shutting.html > > Laura Hampton > laura at laura-hampton dot com > -- > https://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -- *./noah* From jon+usenet at unequivocal.eu Wed Apr 18 09:54:06 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 18 Apr 2018 13:54:06 -0000 (UTC) Subject: New PyPI launched, legacy PyPI shutting down April 30 References: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> Message-ID: Going live with the new site while its search function is mostly inoperative seems a bit brave. https://github.com/pypa/warehouse/issues/3746 On 2018-04-18, Noah wrote: > Awesome........ > > On Mon, Apr 16, 2018 at 8:21 PM, Laura Hampton > wrote: > >> New PyPI launched, legacy PyPI shutting down April 30[1] >> >> Starting today, the canonical Python Package Index is at https://pypi.org >> and uses the new Warehouse codebase. We announced the https://pypi.org >> beta on March 26 and your feedback and test usage have helped us get it >> production-ready. >> >> Monday April 16 (2018-04-16): We launched the new PyPI, redirecting >> browser traffic and API calls (including "pip install") from >> pypi.python.org to the new site. The old codebase is still available at >> https://legacy.pypi.org for now. >> >> Monday April 30 (2018-04-30): We plan to shut down legacy PyPI >> https://legacy.pypi.org . The address pypi.python.org will continue to >> redirect to Warehouse. >> >> For more details, see our roadmap: https://wiki.python.org/psf/ >> WarehouseRoadmap >> >> If your site/service links to or uses pypi.python.org, you should start >> using pypi.org instead: https://warehouse.readthedocs. >> io/api-reference/integration-guide/#migrating-to-the-new-pypi >> >> Thank you. >> >> [1] https://blog.python.org/2018/04/new-pypi-launched-legacy- >> pypi-shutting.html >> >> Laura Hampton >> laura at laura-hampton dot com >> -- >> https://mail.python.org/mailman/listinfo/python-announce-list >> >> Support the Python Software Foundation: >> http://www.python.org/psf/donations/ From jon+usenet at unequivocal.eu Wed Apr 18 10:09:29 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 18 Apr 2018 14:09:29 -0000 (UTC) Subject: please test the new PyPI (now in beta) References: Message-ID: On 2018-03-27, Chris Angelico wrote: > Any time you see something that requires JavaScript for this, you know > you've found a web site that dates back to... uhh, actually I don't > know. I only have versioning info on MDN back as far as HTML 4.01 ergo > 1999, and the placeholder attribute is there. Of course, that doesn't > mean everyone *used* it, but it was certainly available. 'placeholder' was most certainly not in HTML 4 - it was an HTML 5 addition (i.e. it was standardised in 2014). Browser support arrived mainly in 2011/2012, so if a web site is 5 years old it probably could not have relied on this feature. From neilc at norwich.edu Wed Apr 18 11:09:38 2018 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 18 Apr 2018 15:09:38 +0000 (UTC) Subject: Finding set difference between ranges References: Message-ID: On 2018-04-18, tejaswi prakash wrote: > Hello all, > I have 3 continuous (steps of 1) ranges a,a1,a2. All of them sorted. > I am performing the following operations on them > > a = a.difference (a1) > a = a.difference(a2) If they are each stored as a set I don't see how they can be sorted. Are you converting to set and then calling difference? It may still be more efficient than writing your own loop to take advantage of the sorted status of the original objects. -- Neil Cerutti From lists at vanderhoff.org Wed Apr 18 12:02:44 2018 From: lists at vanderhoff.org (Tony van der Hoff) Date: Wed, 18 Apr 2018 17:02:44 +0100 Subject: New PyPI launched, legacy PyPI shutting down April 30 In-Reply-To: <20180418121500.GJ7873@in.waw.pl> References: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> <20180418121500.GJ7873@in.waw.pl> Message-ID: <129e7338-253f-98ae-6026-381daca6492a@vanderhoff.org> On 18/04/18 13:15, Zbigniew J?drzejewski-Szmek wrote: > On Mon, Apr 16, 2018 at 01:21:50PM -0400, Laura Hampton wrote: >> New PyPI launched, legacy PyPI shutting down April 30[1] >> >> Starting today, the canonical Python Package Index is at https://pypi.org and uses the new Warehouse codebase. We announced the https://pypi.org beta on March 26 and your feedback and test usage have helped us get it production-ready. > Search seems to be broken: >> https://pypi.org/search/?q=numpy > There were no results for 'numpy' > > Zbyszek *Using your link: 2,797*?projects for "/numpy/" From francescor82 at gmail.com Wed Apr 18 12:51:12 2018 From: francescor82 at gmail.com (Francesco Russo) Date: Wed, 18 Apr 2018 18:51:12 +0200 Subject: unittest.Testsuite and execution order Message-ID: Hello! I'm reading the documentation of unittest.TestSuite (Python 2 and 3), but I can't find any explicit sentence stating that TestSuite will honor the order. I can only read that TestSuite can group test cases together. Please blame it on my poor English skills if I'm not interpreting the documentation correctly. My use case: my SUT is split into modules. Besides writing unit tests for each module, I want to write an integration test, and I also need to perform some actions between two calls to the SUT. In my case, the order of the execution is important. Now, the current implementation of TestSuite uses a list, internally, so, today, the order is honored if I create a TestSuite calling addTest() in the proper order, or if I pass a list to the constructor. I've seen examples like this: class MyTestCode(unittest.TestCase): def test_func_1(self): # do something to test func_1 on the SUT sut.func_1() self.assert(...) def perform_intermediate_step(self): # do something between func_1 and func_2 def test_func_2(self): # do something to test func_2 on the SUT sut.func_2() self.assert(...) suite = unittest.TestSuite() suite.addTest(MyTestCode("test_func_1")) suite.addTest(MyTestCode("perform_intermediate_step")) suite.addTest(MyTestCode("test_func_2")) Such an example works, today, since TestSuite uses a list, and addTest() appends to the list. My question is: is this something that I can rely on for the future? I definitely don't want to rely on the current implementation, unless I see it in the documentation. If it's something that I can't rely on for the future, then I'd rather write my test code in a different way. Regards, Francesco P.S.: I strongly believe that there are better ways to implement a test like the one I just described, but what I'm interested in now is whether TestSuite is meant to be future-proof for such a case. -- Francesco Russo The White Rabbit put on his spectacles. 'Where shall I begin, please your Majesty?' he asked. 'Begin at the beginning,' the King said gravely, 'and go on till you come to the end: then stop.' From alexander.hempfing at googlemail.com Wed Apr 18 13:19:35 2018 From: alexander.hempfing at googlemail.com (Alexander Hempfing) Date: Wed, 18 Apr 2018 10:19:35 -0700 (PDT) Subject: Generating list of rsquared_adj regression values for variating i with loop Message-ID: <61a71c4a-5ff1-4e40-a6e7-f6ed2624e8ef@googlegroups.com> Dear all, I am wondering if someone could please help me with an issue I am currently trying to solve: I have a "static" code which looks as follows: tsd_res_fra_08 =res_fra_08['D_Cummulative'][100] tsd_res_fra_09 =res_fra_09['D_Cummulative'][100] tsd_res_fra_10 =res_fra_10['D_Cummulative'][100] tsd_res_fra_11 =res_fra_11['D_Cummulative'][100] tsd_res_fra_12 =res_fra_12['D_Cummulative'][100] tsd_res_fra_13 =res_fra_13['D_Cummulative'][100] tsd_res_fra_14 =res_fra_14['D_Cummulative'][100] tsd_res_fra_15 =res_fra_15['D_Cummulative'][100] reg_list_fra = list([tsd_res_fra_08,tsd_res_fra_09,tsd_res_fra_10,tsd_res_fra_11,tsd_res_fra_12,tsd_res_fra_13,tsd_res_fra_14,tsd_res_fra_15]) fra_gdp = fra_gdpseries.tolist() import statsmodels.api as sm X = reg_list_fra y = fra_gdp X = sm.add_constant(X) model = sm.OLS(y, X).fit() predictions = model.predict(X) model.rsquared_adj Now I would like to generate a "dynamic" code by replacing 100 in the top eight rows to i and let it run from 1 to 1000, thereby running the regression below for every i and save its rsquared_adjvalue in a new list, which contains the rsquared_adj values for i=1, i=2,... i=1000. y stays "static" the whole time. Can someone please help me here? From python at mrabarnett.plus.com Wed Apr 18 13:34:19 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Apr 2018 18:34:19 +0100 Subject: Regex for changing :variable to ${variable} in sql query In-Reply-To: <8878d94c-d0b9-407b-b9f5-8a051acd3f2f@googlegroups.com> References: <8878d94c-d0b9-407b-b9f5-8a051acd3f2f@googlegroups.com> Message-ID: <1cd270bb-ccd0-09ba-ab32-5072ca8a0801@mrabarnett.plus.com> On 2018-04-18 08:25, zljubisic at gmail.com wrote: > Hi, > > I have a sql query in which all variables declared as :variable should be changed to ${variable}. > > for example this sql: > > select * > from table > where ":x" = "1" and :y=2 > and field in (:string) > and time between :from and :to > > > should be translated to: > > select * > from table > where "${x}" = "1" and ${y} = 2 > and field in ( ${string} ) > and time between ${from} and ${to} > > As far as I have come is to find the group as (:(.+?)\b) > and than replace it as ${$2} > > (it would be nice if before and after the ${variable} it is always one space) > > For opposite change (from ${variable} notation to :variable) I am using: > > sql.replace('${', ':').replace('}', '') > > Can someone please help? > Try this: new_query = re.sub(r':([a-z][a-z0-9_]*)', r'${\1}', query) To convert the other way, try this: new_query = re.sub(r'\$\{([a-z][a-z0-9_]*)\}', r':\1', query) From rosuav at gmail.com Wed Apr 18 14:26:36 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Apr 2018 04:26:36 +1000 Subject: unittest.Testsuite and execution order In-Reply-To: References: Message-ID: On Thu, Apr 19, 2018 at 2:51 AM, Francesco Russo wrote: > My use case: my SUT is split into modules. Besides writing unit tests for > each module, I want to write an integration test, and I also need to > perform some actions between two calls to the SUT. In my case, the order of > the execution is important. In that case, make these tests into a single test. If you have to do the steps together to correctly test it, they're not separate tests, they're separate parts of the same test. > class MyTestCode(unittest.TestCase): > def test_func_1(self): > # do something to test func_1 on the SUT > sut.func_1() > self.assert(...) > > def perform_intermediate_step(self): > # do something between func_1 and func_2 > > def test_func_2(self): > # do something to test func_2 on the SUT > sut.func_2() > self.assert(...) This is a bad idea. Each function that starts test_ should be completely independent. You should be able to run any one of them on its own (say, if you're trying to figure out why your latest change caused a test failure), and it should have the same result. Make it so that test_func_1 and test_func_2 are completely independent, and then, if you need a single test that uses both, have a test that calls on each function. > Such an example works, today, since TestSuite uses a list, and addTest() > appends to the list. > My question is: is this something that I can rely on for the future? I > definitely don't want to rely on the current implementation, unless I see > it in the documentation. I would say no, you can't rely on it. If you can't find it in the docs, don't assume it's true. Test order randomization can be controlled with a simple command line flag. ChrisA From kai.peters at gmail.com Wed Apr 18 15:37:29 2018 From: kai.peters at gmail.com (TUA) Date: Wed, 18 Apr 2018 12:37:29 -0700 (PDT) Subject: RE newbie question Message-ID: import re compval = 'A123456_8' regex = '[a-zA-Z]\w{0,7}' if re.match(regex, compval): print('Yes') else: print('No') My intention is to implement a max. length of 8 for an input string. The above works well in all other respects, but does allow for strings that are too long. What is the proper way to fix this? Thanks for any help! From sjeik_appie at hotmail.com Wed Apr 18 15:54:23 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Wed, 18 Apr 2018 19:54:23 +0000 Subject: RE newbie question Message-ID: On Apr 18, 2018 21:42, TUA wrote: > > import re > > compval = 'A123456_8' > regex = '[a-zA-Z]\w{0,7}' > > if re.match(regex, compval): > print('Yes') > else: > print('No') > > > My intention is to implement a max. length of 8 for an input string. The above works well in all other respects, but does allow for strings that are too long. > > What is the proper way to fix this? Use a $ sign at the end of the regex From rgaddi at highlandtechnology.invalid Wed Apr 18 15:57:53 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 18 Apr 2018 12:57:53 -0700 Subject: RE newbie question In-Reply-To: References: Message-ID: On 04/18/2018 12:37 PM, TUA wrote: > import re > > compval = 'A123456_8' > regex = '[a-zA-Z]\w{0,7}' > > if re.match(regex, compval): > print('Yes') > else: > print('No') > > > My intention is to implement a max. length of 8 for an input string. The above works well in all other respects, but does allow for strings that are too long. > > What is the proper way to fix this? > > Thanks for any help! > You could put the end marker $ on your regex so that it won't match if it's not the end. Or, you know, you could just check len(compval) <= 8 and not get bogged down in regexes. They tend to be excellent solutions to only a very specific complexity of problem. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From zljubisic at gmail.com Wed Apr 18 16:04:58 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 18 Apr 2018 13:04:58 -0700 (PDT) Subject: Regex for changing :variable to ${variable} in sql query In-Reply-To: References: <8878d94c-d0b9-407b-b9f5-8a051acd3f2f@googlegroups.com> <1cd270bb-ccd0-09ba-ab32-5072ca8a0801@mrabarnett.plus.com> Message-ID: <386c8fd6-abf6-40e5-8f11-a3123c75325a@googlegroups.com> On Wednesday, 18 April 2018 19:34:37 UTC+2, MRAB wrote: > > Hi, > > > > I have a sql query in which all variables declared as :variable should be changed to ${variable}. > > > > for example this sql: > > > > select * > > from table > > where ":x" = "1" and :y=2 > > and field in (:string) > > and time between :from and :to > > > > > > should be translated to: > > > > select * > > from table > > where "${x}" = "1" and ${y} = 2 > > and field in ( ${string} ) > > and time between ${from} and ${to} > > > > As far as I have come is to find the group as (:(.+?)\b) > > and than replace it as ${$2} > > > > (it would be nice if before and after the ${variable} it is always one space) > > > > For opposite change (from ${variable} notation to :variable) I am using: > > > > sql.replace('${', ':').replace('}', '') > > > > Can someone please help? > > > Try this: > > new_query = re.sub(r':([a-z][a-z0-9_]*)', r'${\1}', query) > > To convert the other way, try this: > > new_query = re.sub(r'\$\{([a-z][a-z0-9_]*)\}', r':\1', query) Thanks a lot. Regards. From zljubisic at gmail.com Wed Apr 18 16:06:37 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 18 Apr 2018 13:06:37 -0700 (PDT) Subject: python 3 creating hard links on ntfs Message-ID: Is it possible to create hard links on windows with ntfs? On linux I can use os.link, but how about windows? Regards. From ian.g.kelly at gmail.com Wed Apr 18 16:06:57 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Apr 2018 14:06:57 -0600 Subject: RE newbie question In-Reply-To: References: Message-ID: On Wed, Apr 18, 2018 at 1:57 PM, Rob Gaddi wrote: > On 04/18/2018 12:37 PM, TUA wrote: >> >> import re >> >> compval = 'A123456_8' >> regex = '[a-zA-Z]\w{0,7}' >> >> if re.match(regex, compval): >> print('Yes') >> else: >> print('No') >> >> >> My intention is to implement a max. length of 8 for an input string. The >> above works well in all other respects, but does allow for strings that are >> too long. >> >> What is the proper way to fix this? >> >> Thanks for any help! >> > > You could put the end marker $ on your regex so that it won't match if it's > not the end. > > Or, you know, you could just check len(compval) <= 8 and not get bogged down > in regexes. They tend to be excellent solutions to only a very specific > complexity of problem. In Python 3.4+ you can also use re.fullmatch which requires a match against the entire string. From kai.peters at gmail.com Wed Apr 18 16:11:11 2018 From: kai.peters at gmail.com (TUA) Date: Wed, 18 Apr 2018 13:11:11 -0700 (PDT) Subject: RE newbie question In-Reply-To: References: Message-ID: Thanks much! From steve+comp.lang.python at pearwood.info Wed Apr 18 19:57:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 18 Apr 2018 23:57:39 +0000 (UTC) Subject: RE newbie question References: Message-ID: On Wed, 18 Apr 2018 12:37:29 -0700, TUA wrote: > My intention is to implement a max. length of 8 for an input string. The > above works well in all other respects, but does allow for strings that > are too long. if len(input_string) > 8: raise ValueError('string is too long') -- Steve From steve+comp.lang.python at pearwood.info Wed Apr 18 20:31:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 19 Apr 2018 00:31:44 +0000 (UTC) Subject: python 3 creating hard links on ntfs References: Message-ID: On Wed, 18 Apr 2018 13:06:37 -0700, zljubisic wrote: > Is it possible to create hard links on windows with ntfs? On linux I can > use os.link, but how about windows? According to the documentation, creating hard links on Windows has worked since version 3.2: https://docs.python.org/3/library/os.html#os.link -- Steve From eryksun at gmail.com Wed Apr 18 20:37:10 2018 From: eryksun at gmail.com (eryk sun) Date: Thu, 19 Apr 2018 00:37:10 +0000 Subject: python 3 creating hard links on ntfs In-Reply-To: References: Message-ID: On Wed, Apr 18, 2018 at 8:06 PM, wrote: > Is it possible to create hard links on windows with ntfs? > On linux I can use os.link, but how about windows? Windows support was added for os.link years ago in version 3.2. Internally it's implemented via WinAPI CreateHardLink, which in turn calls NTAPI NtSetInformationFile to to set the FileLinkInformation. The only Microsoft filesystem that implements hard links is NTFS, and it's implemented for files only, not directories. Non-Microsoft file-system drivers may also implement it, e.g. a driver that allows mounting ext2 or ext3 filesystems. Percival linked an old topic that has ctypes code to call CreateHardLinkA. Do not use that code. It's dangerously sloppy crash-bait and unreliable with how Python 2 ctypes creates the call stack for 64-bit Windows. Do imports, DLL loading, type definitions, and function prototyping (i.e. errcheck, restype, argtypes) one time only, at module or class scope. Use `kernel32 = WinDLL('kernel32', use_last_error=True)` instead of windll.kernel32. Use Windows typedefs from the ctypes.wintypes module. Use None for a NULL pointer, not 0. If a WinAPI function fails, use ctypes.get_last_error() to get the error code, and raise a useful exception via `raise ctypes.WinError(error_code)`. Always use Unicode, especially for file-system functions, e.g. call CreateHardlinkW, not CreateHardLinkA. The [A]NSI function wrappers were added in the 1990s for compatibility with Windows 9x systems, which didn't have Unicode support. That era is ancient history. From skip.montanaro at gmail.com Wed Apr 18 21:00:48 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 18 Apr 2018 20:00:48 -0500 Subject: The basics of the logging module mystify me Message-ID: This session is from Python 3.6.5 on Linux: >>> import logging >>> log = logging.getLogger() >>> log.level 30 >>> logging.WARN 30 >>> log.warn("Awk! Goodbye...") Awk! Goodbye... >>> log.level = logging.INFO >>> log.info("Awk! Goodbye...") >>> log.level 20 >>> log.level == logging.INFO True >>> log.setLevel(logging.INFO) >>> log.info("Awk! Goodbye...") >>> log.isEnabledFor(logging.INFO) True Why do the two log.info(...) calls not produce output on stderr when the level has clearly been set to logging.INFO? There is an active stream handler as demonstrated by the successful log.warn(...) call. I really don't like the logging module, but it looks like I'm stuck with it. Why aren't simple/obvious things either simple or obvious? Skip From afylot at gmail.com Wed Apr 18 21:16:05 2018 From: afylot at gmail.com (simona bellavista) Date: Wed, 18 Apr 2018 18:16:05 -0700 (PDT) Subject: best parallelisation strategy on python Message-ID: I have a code fortran 90 that is parallelised with MPI. I would like to traslate it in python, but I am not sure on the parallelisation strategy and libraries. I work on clusters, with each node with 5GB memory and 12 processors or 24 processors (depending on the cluster I am using). Ideally I would like to split the computation on several nodes. Let me explain what this code does: It read ~100GB data, they are divided in hdf5 files of ~25GB each. The code should read the data, go through it and then select a fraction of the data, ~1GB and then some CPU intensive work on it, and repeat this process many times, say 1000 times, then write the results to a single final file. I was thinking that the CPU intensive part would be written as a shared object in C. Do you have suggestions about which library to use? From rosuav at gmail.com Wed Apr 18 21:31:52 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Apr 2018 11:31:52 +1000 Subject: The basics of the logging module mystify me In-Reply-To: References: Message-ID: On Thu, Apr 19, 2018 at 11:00 AM, Skip Montanaro wrote: > This session is from Python 3.6.5 on Linux: > >>>> import logging >>>> log = logging.getLogger() >>>> log.level > 30 >>>> logging.WARN > 30 >>>> log.warn("Awk! Goodbye...") > Awk! Goodbye... >>>> log.level = logging.INFO >>>> log.info("Awk! Goodbye...") >>>> log.level > 20 >>>> log.level == logging.INFO > True >>>> log.setLevel(logging.INFO) >>>> log.info("Awk! Goodbye...") >>>> log.isEnabledFor(logging.INFO) > True > > Why do the two log.info(...) calls not produce output on stderr when > the level has clearly been set to logging.INFO? There is an active > stream handler as demonstrated by the successful log.warn(...) call. > > I really don't like the logging module, but it looks like I'm stuck > with it. Why aren't simple/obvious things either simple or obvious? I've no idea what setting log.level does; I would normally use logging.basicConfig to set that sort of thing. logging.basicConfig(level=logging.INFO) ChrisA From zljubisic at gmail.com Thu Apr 19 03:06:00 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 19 Apr 2018 00:06:00 -0700 (PDT) Subject: python 3 creating hard links on ntfs In-Reply-To: References: Message-ID: <2cb51e1a-c91d-4e63-9a2f-8314083734a2@googlegroups.com> Thanks guys. From zljubisic at gmail.com Thu Apr 19 03:39:40 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 19 Apr 2018 00:39:40 -0700 (PDT) Subject: Open (txt) editor and get its content Message-ID: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> Hi, I have a script that should accept sql query as a parameter and change it in a way. For now I have a file in which I have put sql query and than python script opens it and do everything else. Is it possible to run python script that will open editor and let me paste sql query in the editor, and than after closing editor, get editor's content in python script? Is there any other option for getting interactive multi line input from user. Regards. From p.f.moore at gmail.com Thu Apr 19 04:19:42 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 19 Apr 2018 09:19:42 +0100 Subject: The basics of the logging module mystify me In-Reply-To: References: Message-ID: On 19 April 2018 at 02:00, Skip Montanaro wrote: > I really don't like the logging module, but it looks like I'm stuck > with it. Why aren't simple/obvious things either simple or obvious? If you can use non-stdlib things there are alternatives. I've heard good things about logbok (https://logbook.readthedocs.io/en/stable/) although I will say I've never tried it myself. I do agree that the stdlib logging module, while technically powerful, is frustratingly clumsy to use in all of the relatively simple situations I've felt it might be helpful to me :-( Paul From tjol at tjol.eu Thu Apr 19 05:52:34 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 19 Apr 2018 11:52:34 +0200 Subject: The basics of the logging module mystify me In-Reply-To: References: Message-ID: On 2018-04-19 03:00, Skip Montanaro wrote: > This session is from Python 3.6.5 on Linux: > >>>> import logging >>>> log = logging.getLogger() >>>> log.level > 30 >>>> logging.WARN > 30 >>>> log.warn("Awk! Goodbye...") > Awk! Goodbye... >>>> log.level = logging.INFO >>>> log.info("Awk! Goodbye...") >>>> log.level > 20 >>>> log.level == logging.INFO > True >>>> log.setLevel(logging.INFO) >>>> log.info("Awk! Goodbye...") >>>> log.isEnabledFor(logging.INFO) > True > > Why do the two log.info(...) calls not produce output on stderr when > the level has clearly been set to logging.INFO? There is an active > stream handler as demonstrated by the successful log.warn(...) call. Loggers have levels, and log handlers have levels. To get log messages to display, you have to add a log handler (with the right level) to your logger. Now, you never added a handler, so why are the warnings printing? Log messages that have nowhere to go are given to the "last resort" handler, logging.lastResort , which has its level set to WARNING. You *could* change this: Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> log = logging.getLogger() >>> log.setLevel(logging.INFO) >>> log.warn('warning 1') warning 1 >>> log.info('info 1') >>> logging.lastResort <_StderrHandler (WARNING)> >>> logging.lastResort.setLevel(logging.INFO) # DON'T DO THIS THOUGH >>> log.info('info 2') info 2 >>> Of course you should rather be creating your own handler >>> handler = logging.StreamHandler() >>> handler.setLevel(logging.DEBUG) >>> log.addHandler(handler) >>> log.setLevel(logging.DEBUG) >>> log.debug('test test test') test test test >>> Or, more often than not, it's best to use the logging module's configuration system that creates the right web of handlers and formatters for you. -- Thomas > > I really don't like the logging module, but it looks like I'm stuck > with it. Why aren't simple/obvious things either simple or obvious? From steve+comp.lang.python at pearwood.info Thu Apr 19 07:41:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 19 Apr 2018 11:41:19 +0000 (UTC) Subject: Open (txt) editor and get its content References: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> Message-ID: On Thu, 19 Apr 2018 00:39:40 -0700, zljubisic wrote: > Is it possible to run python script that will open editor and let me > paste sql query in the editor, and than after closing editor, get > editor's content in python script? Try this recipe: it will work for many, but not all editors. https://code.activestate.com/recipes/578926 Bug reports, improvements and comments welcome. -- Steve From rhodri at kynesim.co.uk Thu Apr 19 07:46:25 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 19 Apr 2018 12:46:25 +0100 Subject: Open (txt) editor and get its content In-Reply-To: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> References: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> Message-ID: On 19/04/18 08:39, zljubisic at gmail.com wrote: > Hi, > > I have a script that should accept sql query as a parameter and change it in a way. For now I have a file in which I have put sql query and than python script opens it and do everything else. > > Is it possible to run python script that will open editor and let me paste sql query in the editor, and than after closing editor, get editor's content in python script? You already have the query in a file, so you can just use subprocess.run() to start your favourite editor and wait until it exits, then *check the return code* (if you don't, you will wish you had) and read the file back. > Is there any other option for getting interactive multi line input from user. input() and patience :-) -- Rhodri James *-* Kynesim Ltd From jon+usenet at unequivocal.eu Thu Apr 19 12:29:58 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 19 Apr 2018 16:29:58 -0000 (UTC) Subject: New PyPI launched, legacy PyPI shutting down April 30 References: <1523899310.3079733.1339904128.0C3BB932@webmail.messagingengine.com> <20180418121500.GJ7873@in.waw.pl> <129e7338-253f-98ae-6026-381daca6492a@vanderhoff.org> Message-ID: On 2018-04-18, Tony van der Hoff wrote: > On 18/04/18 13:15, Zbigniew J?drzejewski-Szmek wrote: >> On Mon, Apr 16, 2018 at 01:21:50PM -0400, Laura Hampton wrote: >>> New PyPI launched, legacy PyPI shutting down April 30[1] >>> >>> Starting today, the canonical Python Package Index is at >>> https://pypi.org and uses the new Warehouse codebase. We >>> announced the https://pypi.org beta on March 26 and your feedback >>> and test usage have helped us get it production-ready. >> Search seems to be broken: >>> https://pypi.org/search/?q=numpy >> There were no results for 'numpy' >> >> Zbyszek > *Using your link: > 2,797*?projects for "/numpy/" The search system is indeed intermittently broken: https://github.com/pypa/warehouse/issues/3746 From random832 at fastmail.com Thu Apr 19 13:13:38 2018 From: random832 at fastmail.com (Random832) Date: Thu, 19 Apr 2018 13:13:38 -0400 Subject: Open (txt) editor and get its content In-Reply-To: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> References: <880b4c79-ce70-42f5-97c2-a794e303c6a3@googlegroups.com> Message-ID: <1524158018.3010468.1343924392.1DC8DFE6@webmail.messagingengine.com> On Thu, Apr 19, 2018, at 03:39, zljubisic at gmail.com wrote: > Is there any other option for getting interactive multi line input from user. If you don't need a full-featured text editor, you could build a simple input popup with the Textbox widget in tkinter. From p.f.moore at gmail.com Thu Apr 19 15:18:16 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 19 Apr 2018 20:18:16 +0100 Subject: Pip 10.0.1 has been released Message-ID: On behalf of the PyPA, I am pleased to announce that pip 10.0.1 has just been released. This release fixes a number of issues with the initial release of pip 10.0, notably: * A problem with running the "pip.exe" wrapper script on Windows from a directory with a space in the name. * A problem with get-pip.py needing to be renamed on Windows to avoid triggering a check in pip that aborts the run. * A problem with build isolation when pip is installed as --user * An issue with the vendored msgpack library on older versions of Python 2.7 * A problem with pip installing from non-editable VCS URLs Thanks to all the people who reported issues and helped with the fixes. Paul From viplued at qq.com Thu Apr 19 23:19:36 2018 From: viplued at qq.com (=?ISO-8859-1?B?dmlwbHVlZA==?=) Date: Fri, 20 Apr 2018 11:19:36 +0800 Subject: Thanks Message-ID: Thank you very much for python, From ben+python at benfinney.id.au Thu Apr 19 23:56:36 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 20 Apr 2018 13:56:36 +1000 Subject: Thanks References: Message-ID: <85r2nav8cr.fsf@benfinney.id.au> "viplued" writes: > Thank you very much for python, We're glad that Python is useful to people! Can you say a little about how Python has helped you? -- \ Eccles: ?I'll get [the job] too, you'll see. I'm wearing a | `\ Cambridge tie.? Greenslade: ?What were you doing there?? | _o__) Eccles: ?Buying a tie.? ?The Goon Show, _The Greenslade Story_ | Ben Finney From francescor82 at gmail.com Fri Apr 20 01:01:49 2018 From: francescor82 at gmail.com (Francesco Russo) Date: Fri, 20 Apr 2018 07:01:49 +0200 Subject: unittest.Testsuite and execution order In-Reply-To: References: Message-ID: <232eb1c7-0233-f71c-84f5-344399993e46@gmail.com> On 18/04/18 20:26, Chris Angelico wrote: > On Thu, Apr 19, 2018 at 2:51 AM, Francesco Russo wrote: >> My use case: my SUT is split into modules. Besides writing unit tests for >> each module, I want to write an integration test, and I also need to >> perform some actions between two calls to the SUT. In my case, the order of >> the execution is important. > > In that case, make these tests into a single test. If you have to do > the steps together to correctly test it, they're not separate tests, > they're separate parts of the same test. Clear, thank you. >> class MyTestCode(unittest.TestCase): >> def test_func_1(self): >> # do something to test func_1 on the SUT >> sut.func_1() >> self.assert(...) >> >> def perform_intermediate_step(self): >> # do something between func_1 and func_2 >> >> def test_func_2(self): >> # do something to test func_2 on the SUT >> sut.func_2() >> self.assert(...) > > This is a bad idea. Each function that starts test_ should be > completely independent. You should be able to run any one of them on > its own (say, if you're trying to figure out why your latest change > caused a test failure), and it should have the same result. > > Make it so that test_func_1 and test_func_2 are completely > independent, and then, if you need a single test that uses both, have > a test that calls on each function. I'm not sure I understand you here. I understood that (besides, or instead of, making an integration test by making those tests into one test, as you wrote above) I could make a test for func_2 making it independent from func_1, for example this way: class MyTestFunc2(unittest.TestCase): def setUp(self): # Prepare preconditions for func_2 def test_func_2(self): sut.func_2() self.assert(...) Such a test case wouldn't even need a test suite. Is this what you meant? >> Such an example works, today, since TestSuite uses a list, and addTest() >> appends to the list. >> My question is: is this something that I can rely on for the future? I >> definitely don't want to rely on the current implementation, unless I see >> it in the documentation. > > I would say no, you can't rely on it. If you can't find it in the > docs, don't assume it's true. Test order randomization can be > controlled with a simple command line flag. > > ChrisA The official "unittest" web pages for Python 2 and 3 say this, for the TestSuite class: *This class represents an aggregation of individual tests cases and test suites* saying nothing about the order. But the docstring of the TestSuite class says: *It will run the individual test cases in the order in which they were added, aggregating the results* Can I consider the docstring an official documentation as well? -- Francesco Russo The White Rabbit put on his spectacles. 'Where shall I begin, please your Majesty?' he asked. 'Begin at the beginning,' the King said gravely, 'and go on till you come to the end: then stop.' From rosuav at gmail.com Fri Apr 20 02:34:39 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Apr 2018 16:34:39 +1000 Subject: unittest.Testsuite and execution order In-Reply-To: <232eb1c7-0233-f71c-84f5-344399993e46@gmail.com> References: <232eb1c7-0233-f71c-84f5-344399993e46@gmail.com> Message-ID: On Fri, Apr 20, 2018 at 3:01 PM, Francesco Russo wrote: > On 18/04/18 20:26, Chris Angelico wrote: >> This is a bad idea. Each function that starts test_ should be >> completely independent. You should be able to run any one of them on >> its own (say, if you're trying to figure out why your latest change >> caused a test failure), and it should have the same result. >> >> Make it so that test_func_1 and test_func_2 are completely >> independent, and then, if you need a single test that uses both, have >> a test that calls on each function. > > I'm not sure I understand you here. > I understood that (besides, or instead of, making an integration test by > making those tests into one test, as you wrote above) I could make a > test for func_2 making it independent from func_1, for example this way: > > class MyTestFunc2(unittest.TestCase): > def setUp(self): > # Prepare preconditions for func_2 > > def test_func_2(self): > sut.func_2() > self.assert(...) > > Such a test case wouldn't even need a test suite. > Is this what you meant? What I mean is that test_func_1 and test_func_2 should be able to pass or fail regardless of whether the other has been run or not. That kind of independence. If you then want to write an integration test that verifies that data created by func_1 can be read by func_2, that is a separate test. > The official "unittest" web pages for Python 2 and 3 say this, for the > TestSuite class: > *This class represents an aggregation of individual tests cases and test > suites* > saying nothing about the order. But the docstring of the TestSuite class > says: > *It will run the individual test cases in the order in which they were > added, aggregating the results* > Can I consider the docstring an official documentation as well? > That's something for other people to answer; I don't know whether TestSuite is a replaceable class. I'm not sure what the mechanics are for test randomization, but it is most definitely a thing. ChrisA From jklinken at gmail.com Fri Apr 20 04:12:02 2018 From: jklinken at gmail.com (jklinken at gmail.com) Date: Fri, 20 Apr 2018 01:12:02 -0700 (PDT) Subject: Python installer hangs in Windows 7 In-Reply-To: References: <765703485.1601081.1486357381135.ref@mail.yahoo.com> <765703485.1601081.1486357381135@mail.yahoo.com> Message-ID: <4b179a57-8968-4a00-9326-28a3f5fb4a3b@googlegroups.com> On Monday, February 6, 2017 at 6:16:24 AM UTC+1, Jean-Claude Roy wrote: > ? I am trying to install Python 3.6.0 on a Windows 7 computer. > The download of 29.1 MB is successful and I get the nextwindow.? I?choose the "install now" selection and thatopens the Setup Program window. > Now the trouble starts:I get "Installing:" and the Initialization progress...and nothing else. > There is no additional disk activity, no progress on initialization, andeverything appears dead.? Even after 20 minutes there is zero progress. > I've repeated this as both a user and the administrator of this Windowscomputer.? I get the same results in either case. > If I go to the task manager it shows that Python 3.6.0 (32-bit) setup is running.? If I try to end the task Iget the message that the program is not responding. > Do you have any suggestions as to how I can get past this? > Thank you. Disabling/enabling options had no effect for me. In the end I simply had to wait for something like 5 minutes, perhaps even longer, but then it continued to install normally. Seems there's something happening at the initialization stage, as if it is waiting for a time-out... JWK From sjeik_appie at hotmail.com Fri Apr 20 04:46:36 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 20 Apr 2018 08:46:36 +0000 Subject: The basics of the logging module mystify me Message-ID: On Apr 19, 2018 03:03, Skip Montanaro wrote: > > > I really don't like the logging module, but it looks like I'm stuck > with it. Why aren't simple/obvious things either simple or obvious? Agreed. One thing that, in my opinion, ought to be added to the docs is sample code to log uncaught exceptions using an excepthook, with correctly formatted traceback. Another thing I always do is to define a custom log level named 'message', which is always logged. Basically it's logging.FATAL + 1, but with a friendlier label. Would be a nice enhancement of the logging module IMHO. From tkadm30 at yandex.com Fri Apr 20 04:49:09 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 20 Apr 2018 04:49:09 -0400 Subject: [ZODB] Multithreaded connection pooling support for ZODB databases? In-Reply-To: <19a832b9-f926-ffb4-931e-0db639a88026@yandex.com> References: <2d24615f-0fb8-a8a4-2c53-1112d6f82a26@yandex.com> <19a832b9-f926-ffb4-931e-0db639a88026@yandex.com> Message-ID: <85938779-9d7c-481b-bcbc-cb15c414952a@yandex.com> Heads up people! I've finally managed to make a working `ThreadedConnectionPool` class for supporting multiple ZODB databases connections on top of libschevo API! :) Technically, I decided to use gevent.Greenlet under the hood to spawn multiple cooperative ClientStorage client/server connections. I'm also making all my testing and development under PyPy 5.9. You can check out the code here: https://bitbucket.org/tkadm30/libschevo/commits/37feb029615d76f3d81233990e509b6eb6ffb5d7 Comments are welcome! :) Etienne Le 2018-04-16 ? 18:27, Etienne Robillard a ?crit?: > Hi Jason, > > I just made some more changes to my ThreadedConnectionPool class here: > https://bitbucket.org/tkadm30/django-hotsauce/commits/81d2e8f30019840d9c8bbdf7f82df6de2be024fc > > In summary, the `ThreadedConnectionPool` class is now a subclass of > `threading.Thread` and is extending the `run` method to populate a > thread local dictionary with ClientStorage connections. > > Kind regards, > > Etienne > Le 2018-04-16 ? 09:14, Jason Madden a ?crit?: >>>>> On Apr 15, 2018, at 8:17 PM, Etienne Robillard >>>>> wrote: >>>>> >>>>> I would like to define a `ThreadedConnectionPoll` class to allow >>>>> multithreaded caching of ZODB databases into memory. >> >> The ZODB.DB object is *already* thread safe for connection >> management. You shouldn't need to do anything other than use >> ZODB.DB().open() and conn.close() from all the threads you're using. >> (That is, create exactly one ZODB.DB object for each database you are >> using and share that object amongst your threads, using >> db.open()/conn.close() as needed. For storages like RelStorage that >> have caches at the ZODB.DB level---which are also thread safe---this >> is important.) >> >> If you are managing multiple databases and want to be able to make >> references between them (a multiple-database) it is critical that >> they share the same `databases` object. But that is an advanced usage. >> >> >>> Here's a updated version of my code so far using threading.local : >>> >>> from threading import local >>> from notmm.dbapi.orm import ClientStorageProxy >>> >>> class ThreadedConnectionPool(object): >>> >>> ???? def __init__(self, d, debug=True): >>> ???????? if debug: >>> ???????????? assert isinstance(d, dict) == True >>> ???????? local.pool = d >>> ???????? for key,value in local.pool.iteritems(): >> Unless you left out part of the code, it appears that you're trying >> to set (and read) a class attribute on the threading.local class. >> This does not create thread-local state. It is also not portable and >> doesn't work when local is an extension type: >> >> py> from threading import local >> py> import sys >> py> sys.version_info # CPython 3.7; same result in 2.7 >> sys.version_info(major=3, minor=7, micro=0, releaselevel='beta', >> serial=3) >> py> local >> >> py> local.foo = 1 >> Traceback (most recent call last): >> ?? File "", line 1, in >> TypeError: can't set attributes of built-in/extension type >> '_thread._local' >> >> pypy> sys.version_info # pypy 2 >> (major=2, minor=7, micro=13, releaselevel='final', serial=42) >> pypy> from threading import local >> pypy> local.foo = 1 >> Traceback (most recent call last): >> ?? File "", line 1, in >> TypeError: can't set attributes on type object '_local' >> >> It generally also shouldn't be necessary as the parameters to >> __init__ are preserved and used again in each thread; you can use >> this to share information if those parameters are mutable: >> >> py> from threading import get_ident >> py> from threading import Thread >> py> class MyLocal(local): >> ...???? def __init__(self, l): >> ...???????? print("Creating in thread", get_ident(), "param", l) >> ...???????? l.append(get_ident()) >> ... >> py> l = [] >> py> mylocal = MyLocal(l) >> Creating in thread 140736147411840 param [] >> py> l >> [140736147411840] >> py> def target(): >> ...???? mylocal.foo = 1 >> ... >> py> t = Thread(target=target) >> py> t.start() >> Creating in thread 123145538318336 param [140736147411840] >> None >> py> l >> [140736147411840, 123145538318336] >> >> Jason >> > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From sankarramanv at gmail.com Fri Apr 20 06:24:46 2018 From: sankarramanv at gmail.com (sankarramanv at gmail.com) Date: Fri, 20 Apr 2018 03:24:46 -0700 (PDT) Subject: Custom Python import module failed (protobuf) Message-ID: Hi, I need to use the google protobuf for my task. 1. Yum install protobuf worked for default python 2.7.5 in my VM. But I need to test with Python 2.7.14. I installed protobuf using yum on "/usr/lib64/python2.7/site-packages" I added the above path to PYTHONPATH and its not recognizing when run as ordinary user. But when run through sudo cmd its working. But due to lower Python 2.7.5, it fails. I ran like: sudo python test.py 2. My main requirement is to test things from Python 2.7.14. Also I installed python 2.7.14 in /usr/local/bin. When I try to use /usr/local/bin/python it fails to import google protobuf installed through yum. sudo PYTHONPATH=/usr/lib64/python2.7/site-packages /usr/local/bin/python test.py Re-installing protobuf also does not help. 3. For this purpose, When I don't use yum and build protobuf from src code, added /usr/local/include to PYTHONPATH (where google.protobuf present), it still import fails. "from google.protobuf import *" or import google.protobuf fails. Appreciate inputs. Thanks. From sankarramanv at gmail.com Fri Apr 20 06:33:34 2018 From: sankarramanv at gmail.com (Sankar Raman V) Date: Fri, 20 Apr 2018 03:33:34 -0700 (PDT) Subject: Custom Python import module failed (protobuf) In-Reply-To: References: Message-ID: <334fdd67-91cb-475a-92b8-da04f4a7ae4a@googlegroups.com> Error: ImportError: No module named google.protobuf From tejaswidprakash at gmail.com Fri Apr 20 06:34:40 2018 From: tejaswidprakash at gmail.com (tejaswi prakash) Date: Fri, 20 Apr 2018 10:34:40 +0000 Subject: Finding set difference between ranges In-Reply-To: References: Message-ID: I generate the values using range and then convert them to sets. I am thinking about an approach which involves subtracting the ranges, or something along those lines, nothing concrete yet. On Wed 18 Apr, 2018, 8:43 PM Neil Cerutti, wrote: > On 2018-04-18, tejaswi prakash wrote: > > Hello all, > > I have 3 continuous (steps of 1) ranges a,a1,a2. All of them sorted. > > I am performing the following operations on them > > > > a = a.difference (a1) > > a = a.difference(a2) > > If they are each stored as a set I don't see how they can be > sorted. Are you converting to set and then calling difference? > > It may still be more efficient than writing your own loop to take > advantage of the sorted status of the original objects. > > -- > Neil Cerutti > > -- > https://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Fri Apr 20 08:05:28 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 Apr 2018 13:05:28 +0100 Subject: Fwd: Python Import Impossibility In-Reply-To: References: Message-ID: <7334363f-9353-24b0-082b-50149193b39d@timgolden.me.uk> On 17/04/2018 23:09, Terry Reedy wrote: > On 4/17/2018 5:06 PM, Dan Stromberg wrote: >> Given that the list does not allow pictures, would it make sense to >> have the software that strips the pictures also send an e-mail to the >> picture sender indicating that pictures are disallowed? >> >> I see a lot of people responding individually saying that images are >> stripped.? It's looking like a bit of a traffic increaser. > > My impression is that attachments are more common than 20 years ago. > >> In a more draconian world, we could even bounce such messages. > > If Tim Golden does not reply to this, send suggestion to > python-list-owner at python.org > Just seen this. I'll ping the Mailman devs to see if it's an easy option. If it is, we can decide whether it's a good idea for the list. If it's complicated from the Mailman POV then I'm afraid it's unlikely to go anywhere. Thanks for the suggestion; we'll take a look TJG From rosuav at gmail.com Fri Apr 20 08:48:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Apr 2018 22:48:04 +1000 Subject: Finding set difference between ranges In-Reply-To: References: Message-ID: On Fri, Apr 20, 2018 at 8:34 PM, tejaswi prakash wrote: > I generate the values using range and then convert them to sets. > I am thinking about an approach which involves subtracting the ranges, or > something along those lines, nothing concrete yet. (Please don't top-post) I would recommend keeping them as ranges. You know for certain that they are ranges of consecutive integers, so the only info you actually need to work with is start,stop (step is guaranteed to be 1). How many ways are there for the set difference to be calculated? minu.difference(sub) 1) sub.stop <= sub.start # Empty subtrahend, nothing to remove difference = minu 2) sub.stop < minu.start or sub.start >= minu.stop # No overlap difference = minu 3) sub.start <= minu.start < sub.stop < minu.stop # minuend overlaps start of subtrahend difference = range(sub.stop, minu.stop) 4) minu.start < sub.start < minu.stop <= sub.stop # minuend overlaps end of subtrahend difference = range(minu.start, sub.start) 5) minu.start < sub.start < sub.stop < minu.stop # minuend is entirely surrounded by subtrahend Situation 5 is the only complicated one. It's now fractured the range into two halves (removing the middle). So now you have to work with two minuends for the next step, subtracting the same subtrahend from each of them. If either of them is completely emptied by the second step, you can ignore it, but otherwise, you now have two pieces. (Or three, if you get a second fracturing.) This would be the easiest way to handle this, I think. ChrisA From arequipeno at gmail.com Fri Apr 20 11:01:55 2018 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 20 Apr 2018 10:01:55 -0500 Subject: The basics of the logging module mystify me In-Reply-To: References: Message-ID: On 04/19/2018 04:52 AM, Thomas Jollans wrote: > Or, more often than not, it's best to use the logging module's > configuration system that creates the right web of handlers and > formatters for you. Wow! This is the first I've heard of logging.config (although it's easy to find now that I know that it exists). As far as I can remember, none of the logging tutorials that I read ever mentioned it. -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From skip.montanaro at gmail.com Fri Apr 20 11:50:52 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 20 Apr 2018 10:50:52 -0500 Subject: The basics of the logging module mystify me In-Reply-To: References: Message-ID: > I've no idea what setting log.level does; I would normally use > logging.basicConfig to set that sort of thing. > > logging.basicConfig(level=logging.INFO) The log.level setting is what calling log.setLevel(...) does under the covers. What neither apparently do is have any effect on whatever handlers exist (thank you Thomas Jollans for the clue on the handler of last resort). Now that I know, perhaps I can begin to use it more effectively. It still seems to me like there are at least one too many calls necessary to have a working logger. In simple systems logging should basically be no more difficult to use than print statements. Create a logger and go. No configuration should be required. I understand that the call to basicConfig() isn't too difficult, but its name does not suggest that it performs any actions. It is also a bit surprising to me that its names didn't go through a PEP8 purification step for Python 3.x. I thought basicConfig wasn't always present, but looking back in time, I see it was there in Guido's initial commit (Nov 13, 2002, I think, for 2.3a1). Looking at git blame output for the docs I saw my name. I checked in the (rough) initial version of the docs the next day (followed quickly by LaTeX markup cleanup by several other devs). I have absolutely no recollection of that activity. Lotta water under the mental bridge since then. Paul Moore mentioned logbook. I'll take a look at that when I have a moment. I have played with Eliot (https://eliot.readthedocs.io/) a bit. Even if it doesn't suit you, I think it's a worthwhile read to consider other ways to think about logging. Skip From lab at 2020fresno.com Fri Apr 20 13:28:24 2018 From: lab at 2020fresno.com (20/20 Lab) Date: Fri, 20 Apr 2018 10:28:24 -0700 Subject: Looking for advice Message-ID: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> Going to write my first python program that uses a database. Going to store 50-100 rows with 5-10 columns.? Which database / module would you advise me to use?? It's basically going to be processing order status emails for the sales staff.? Producing a webpage (2-3 times daily, as updates arrive) that has the sales staff orders and status on it.?? I'm thinking just a simple sqlite, but dont want to waste time going down the wrong path. Thank you for your time From joel.goldstick at gmail.com Fri Apr 20 13:58:16 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 20 Apr 2018 13:58:16 -0400 Subject: Looking for advice In-Reply-To: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> References: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> Message-ID: On Fri, Apr 20, 2018 at 1:28 PM, 20/20 Lab wrote: > Going to write my first python program that uses a database. Going to store > 50-100 rows with 5-10 columns. Which database / module would you advise me > to use? It's basically going to be processing order status emails for the > sales staff. Producing a webpage (2-3 times daily, as updates arrive) that > has the sales staff orders and status on it. I'm thinking just a simple > sqlite, but dont want to waste time going down the wrong path. > > > Thank you for your time > > -- > https://mail.python.org/mailman/listinfo/python-list sqlite is a small, in memory db that comes standard with python (i'm pretty sure). Great place to start -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rgaddi at highlandtechnology.invalid Fri Apr 20 14:06:46 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 20 Apr 2018 11:06:46 -0700 Subject: Looking for advice In-Reply-To: References: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> Message-ID: On 04/20/2018 10:28 AM, 20/20 Lab wrote: > Going to write my first python program that uses a database. Going to > store 50-100 rows with 5-10 columns.? Which database / module would you > advise me to use?? It's basically going to be processing order status > emails for the sales staff.? Producing a webpage (2-3 times daily, as > updates arrive) that has the sales staff orders and status on it.?? I'm > thinking just a simple sqlite, but dont want to waste time going down > the wrong path. > > > Thank you for your time > SQLite, without question. It just works in a way that server-based solutions will give you all manner of initial bootstrap issues. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rosuav at gmail.com Fri Apr 20 15:06:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Apr 2018 05:06:56 +1000 Subject: Looking for advice In-Reply-To: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> References: <946269e4-a053-4ebf-cd24-7c3fb75e5cfe@2020fresno.com> Message-ID: On Sat, Apr 21, 2018 at 3:28 AM, 20/20 Lab wrote: > Going to write my first python program that uses a database. Going to store > 50-100 rows with 5-10 columns. Which database / module would you advise me > to use? It's basically going to be processing order status emails for the > sales staff. Producing a webpage (2-3 times daily, as updates arrive) that > has the sales staff orders and status on it. I'm thinking just a simple > sqlite, but dont want to waste time going down the wrong path. > Use SQLite, but spend an hour or so reading about PostgreSQL, so you have some idea of what it can do. As your requirements grow, you'll eventually outgrow SQLite, and the most obvious next step is Postgres; you'll do well to at least have a nodding familiarity with it, so you can decide when to move up. Also, since you're asking for advice: I advise you to write good subject lines on your posts. It'll make your questions easier to find. :) Something like: "Selecting database for small Python app - looking for recommendations". ChrisA From naoki_morihira at outlook.jp Sat Apr 21 00:46:49 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Sat, 21 Apr 2018 04:46:49 +0000 Subject: Python Import Impossibility In-Reply-To: References: , <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> , Message-ID: Dennis, Thank you for your response. The following is the results of what you pointed oit. Could you find out how to cope with this situation ? -=-=-=- Microsoft Windows [Version 10.0.16299.371] (c) 2017 Microsoft Corporation. All rights reserved. C:\Users\N.Morihira>echo %path% C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\Scripts\; C:\Users\N.Morihira\AppData\Local\Programs\Python\Python36-32\; C:\Users\N.Morihira>python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys File "", line 1 print sys.path ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(sys.path)? ['', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs?, 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages'] >>> -=-=-=- Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Dennis Lee Bieber ?????? ????: Wednesday, April 18, 2018 8:12:36 AM ??: python-list at python.org ??: Re: Python Import Impossibility On Tue, 17 Apr 2018 14:08:49 +0000, ?? ?? declaimed the following: > > >I deleted ?C:\Python27?, and executed in Windows Command prompt screen, But did you UNINSTALL it? If you didn't, there may be remnants left in the registry... > >?C:Users/N.Morihira>py -m install openpyxl?, > >But the following message was displayed > > * Requirement already satisfied: openpyxl in c:\users\n.morihira\anaconda3\lib\site-packages > * Requirement already satisfied: jdcal in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl) > * Requirement already satisfied: et_xmlfile in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl), > > >And it also displays the following message in Python3.6.4 Shell screen. >>>> import openpyxl > >Traceback (most recent call last): > > File "", line 1, in > That (pyshell#3) seems to imply you are using some third-party program as your "shell"... A direct OS shell would report . What do you get if you open a proper OS command-line shell and type "python" -- as in -=-=-=- Microsoft Windows [Version 10.0.16299.371] (c) 2017 Microsoft Corporation. All rights reserved. C:\Users\Wulfraed>echo %path% C:\Python27\;C:\Python27\Scripts\;C:\Python27\Tools\scripts\;C:\WINDOWS\system32;C:\WINDOWS; C:\Users\Wulfraed> C:\Users\Wulfraed>python ActivePython 2.7.13.2716 (ActiveState Software Inc.) based on Python 2.7.13 (default, Jun 26 2017, 14:28:43) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print sys.path ['', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin'] >>> -=-=-=- {Yes, I'm configured to use Python 2.7 as the default, and that is the version on my system (not Python) PATH -- it is also not installed as a single-user application} -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- https://mail.python.org/mailman/listinfo/python-list From jedzry at gmail.com Sat Apr 21 13:43:16 2018 From: jedzry at gmail.com (jedzry at gmail.com) Date: Sat, 21 Apr 2018 10:43:16 -0700 (PDT) Subject: Cant uninstall, modify or repair python Message-ID: <437fd095-da6c-4ab5-bb9a-fbd081776951@googlegroups.com> I currently have python version 3.6.1 32 bit version on my laptop and when i try to repair, it gives an error saying "The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2503". After i clicked ok there is a message pop-up saying: "One or more issues caused the setup to fail. Please fix the issues and then retry setup. 0x80070643- Fatal error during installation. When i try to uninstall, it says no python 3.6 installation was detected. When i try to modify, it says that there is a fatal error during installation. From raymond.nusbaum at gmail.com Sat Apr 21 16:00:39 2018 From: raymond.nusbaum at gmail.com (raymond.nusbaum at gmail.com) Date: Sat, 21 Apr 2018 13:00:39 -0700 (PDT) Subject: best parallelisation strategy on python In-Reply-To: References: Message-ID: <3ad8abaf-62fa-43f1-91f5-32f1e77c8b0f@googlegroups.com> On Wednesday, April 18, 2018 at 7:16:19 PM UTC-6, simona bellavista wrote: > I have a code fortran 90 that is parallelised with MPI. I would like to traslate it in python, but I am not sure on the parallelisation strategy and libraries. I work on clusters, with each node with 5GB memory and 12 processors or 24 processors (depending on the cluster I am using). Ideally I would like to split the computation on several nodes. > > Let me explain what this code does: It read ~100GB data, they are divided in hdf5 files of ~25GB each. The code should read the data, go through it and then select a fraction of the data, ~1GB and then some CPU intensive work on it, and repeat this process many times, say 1000 times, then write the results to a single final file. > > I was thinking that the CPU intensive part would be written as a shared object in C. > > Do you have suggestions about which library to use? I would suggest the Python multiprocessing package. In Python you have to use processes to get full parallelism as there is a single lock on the Python interpreter. The multiprocessing package supports this computing model. From janlydie19 at gmail.com Sat Apr 21 17:36:31 2018 From: janlydie19 at gmail.com (janlydie19 at gmail.com) Date: Sat, 21 Apr 2018 14:36:31 -0700 (PDT) Subject: Can't install Python Message-ID: <7dbd7137-0b20-4a5d-a5c5-05112fa660f1@googlegroups.com> Hi! I installed Python and anaconda by following the instructions of the site, but when I open Pysos it is written in the shell: 'c: \ users \ lyjan \ miniconda3 \ python.exe' is not recognized as an internal command or external, an executable program or a batch file. The process failed to start (invalid command?). (1 = I do not know what to do ... Thanks in advance From bc at freeuk.com Sat Apr 21 19:08:03 2018 From: bc at freeuk.com (bartc) Date: Sun, 22 Apr 2018 00:08:03 +0100 Subject: Can't install Python In-Reply-To: <7dbd7137-0b20-4a5d-a5c5-05112fa660f1@googlegroups.com> References: <7dbd7137-0b20-4a5d-a5c5-05112fa660f1@googlegroups.com> Message-ID: <5vPCC.612987$K43.447155@fx31.am4> On 21/04/2018 22:36, janlydie19 at gmail.com wrote: > Hi! > > I installed Python and anaconda by following the instructions of the site, but when I open Pysos it is written in the shell: > > 'c: \ users \ lyjan \ miniconda3 \ python.exe' is not recognized as an internal command > or external, an executable program or a batch file. > > The process failed to start (invalid command?). (1 = > > > I do not know what to do ... Thanks in advance > Try clicking the Start button and typing python.exe into the search box. (Unless this is Windows 10, then try right-clicking Start and choose Search.) -- bartc From torriem at gmail.com Sat Apr 21 19:51:49 2018 From: torriem at gmail.com (Michael Torrie) Date: Sat, 21 Apr 2018 17:51:49 -0600 Subject: best parallelisation strategy on python In-Reply-To: References: Message-ID: On 04/18/2018 07:16 PM, simona bellavista wrote: > I have a code fortran 90 that is parallelised with MPI. I would like to traslate it in python, but I am not sure on the parallelisation strategy and libraries. I work on clusters, with each node with 5GB memory and 12 processors or 24 processors (depending on the cluster I am using). Ideally I would like to split the computation on several nodes. > > Let me explain what this code does: It read ~100GB data, they are divided in hdf5 files of ~25GB each. The code should read the data, go through it and then select a fraction of the data, ~1GB and then some CPU intensive work on it, and repeat this process many times, say 1000 times, then write the results to a single final file. > > I was thinking that the CPU intensive part would be written as a shared object in C. > > Do you have suggestions about which library to use? Since your Fortran code already uses MPI, why not use MPI with Python as well? I know there are python bindings for MPI. That way you could use python while keeping the MPI workflow. From torriem at gmail.com Sat Apr 21 19:53:09 2018 From: torriem at gmail.com (Michael Torrie) Date: Sat, 21 Apr 2018 17:53:09 -0600 Subject: Cant uninstall, modify or repair python In-Reply-To: <437fd095-da6c-4ab5-bb9a-fbd081776951@googlegroups.com> References: <437fd095-da6c-4ab5-bb9a-fbd081776951@googlegroups.com> Message-ID: On 04/21/2018 11:43 AM, jedzry at gmail.com wrote: > I currently have python version 3.6.1 32 bit version on my laptop and when i try to repair, it gives an error saying "The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2503". After i clicked ok there is a message pop-up saying: "One or more issues caused the setup to fail. Please fix the issues and then retry setup. 0x80070643- Fatal error during installation. > > When i try to uninstall, it says no python 3.6 installation was detected. When i try to modify, it says that there is a fatal error during installation. Try installing the same version of Python again. The reinstall might clean up the corrupted install and let you remove it. From python at mrabarnett.plus.com Sat Apr 21 19:59:04 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Apr 2018 00:59:04 +0100 Subject: Can't install Python In-Reply-To: <7dbd7137-0b20-4a5d-a5c5-05112fa660f1@googlegroups.com> References: <7dbd7137-0b20-4a5d-a5c5-05112fa660f1@googlegroups.com> Message-ID: <9e5f5e5f-e110-7fba-4a9c-d25613612b36@mrabarnett.plus.com> On 2018-04-21 22:36, janlydie19 at gmail.com wrote: > Hi! > > I installed Python and anaconda by following the instructions of the site, but when I open Pysos it is written in the shell: > > 'c: \ users \ lyjan \ miniconda3 \ python.exe' is not recognized as an internal command > or external, an executable program or a batch file. > > The process failed to start (invalid command?). (1 = > > > I do not know what to do ... Thanks in advance > Are there really spaces in the path, or is the path: c:\users\lyjan\miniconda3\python.exe ? Is there such a file at that place? From naoki_morihira at outlook.jp Sat Apr 21 22:57:23 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Sun, 22 Apr 2018 02:57:23 +0000 Subject: Python Import Impossibility In-Reply-To: <6vjndddjmkk82re05k3sp16jo2lcc0d4i5@4ax.com> References: , <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> , , <6vjndddjmkk82re05k3sp16jo2lcc0d4i5@4ax.com> Message-ID: Dennis, Thank you very much ! Based on your suggestion, I uninstalled Anaconda and tried installing openpyxl again. After that, I finally found that it was installed correctly. (I confirmed that ?import openpyxl? has no error message. ) I deeply appreciate your cooperation. Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Dennis Lee Bieber ?????? ????: Saturday, April 21, 2018 5:02:15 PM ??: python-list at python.org ??: Re: Python Import Impossibility On Sat, 21 Apr 2018 04:46:49 +0000, ?? ?? declaimed the following: > >Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys > > File "", line 1 > > print sys.path > > ^ > > > >SyntaxError: Missing parentheses in call to 'print'. Did you mean print(sys.path)? > My default Python is 2.7 -- "print" was a language statement, whereas 3.x made it a function. >['', > >'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs?, > >'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages'] > Note that you are NOT RUNNING the "Anaconda" installation there... yet... >>?C:Users/N.Morihira>py -m install openpyxl?, >> >>But the following message was displayed >> >> * Requirement already satisfied: openpyxl in c:\users\n.morihira\anaconda3\lib\site-packages >> * Requirement already satisfied: jdcal in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl) >> * Requirement already satisfied: et_xmlfile in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl), >> ... this command IS running the "Anaconda" installation. You appear to have TWO Python installations -- both configured for user-only mode. And somehow "py" accesses one, while "python" accesses the other. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- https://mail.python.org/mailman/listinfo/python-list From naoki_morihira at outlook.jp Sat Apr 21 23:16:05 2018 From: naoki_morihira at outlook.jp (=?iso-2022-jp?B?GyRCPzlKPxsoQiAbJEJEPjx5GyhC?=) Date: Sun, 22 Apr 2018 03:16:05 +0000 Subject: Python Import Impossibility In-Reply-To: References: , <4b1159e8-4a5d-3ea0-ff79-efc5dbdccdcf@tjol.eu> , , <6vjndddjmkk82re05k3sp16jo2lcc0d4i5@4ax.com>, Message-ID: Dennis, Could you tell me how to set the path for working derectory in Python ? Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: ?? ?? ????: Saturday, April 21, 2018 7:57:23 PM ??: Dennis Lee Bieber; python-list at python.org ??: RE: Python Import Impossibility Dennis, Thank you very much ! Based on your suggestion, I uninstalled Anaconda and tried installing openpyxl again. After that, I finally found that it was installed correctly. (I confirmed that ?import openpyxl? has no error message. ) I deeply appreciate your cooperation. Best Regards, --------------------- Naoki Morihira TEL: 01181-90-6460-6265 --------------------- ________________________________ ???: Python-list ? Dennis Lee Bieber ?????? ????: Saturday, April 21, 2018 5:02:15 PM ??: python-list at python.org ??: Re: Python Import Impossibility On Sat, 21 Apr 2018 04:46:49 +0000, ?? ?? declaimed the following: > >Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys > > File "", line 1 > > print sys.path > > ^ > > > >SyntaxError: Missing parentheses in call to 'print'. Did you mean print(sys.path)? > My default Python is 2.7 -- "print" was a language statement, whereas 3.x made it a function. >['', > >'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs?, > >'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\N.Morihira\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages'] > Note that you are NOT RUNNING the "Anaconda" installation there... yet... >>?C:Users/N.Morihira>py -m install openpyxl?, >> >>But the following message was displayed >> >> * Requirement already satisfied: openpyxl in c:\users\n.morihira\anaconda3\lib\site-packages >> * Requirement already satisfied: jdcal in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl) >> * Requirement already satisfied: et_xmlfile in c:\users\n.morihira\anaconda3\lib\site-packages (from openpyxl), >> ... this command IS running the "Anaconda" installation. You appear to have TWO Python installations -- both configured for user-only mode. And somehow "py" accesses one, while "python" accesses the other. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Sat Apr 21 23:38:38 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 Apr 2018 23:38:38 -0400 Subject: Cant uninstall, modify or repair python In-Reply-To: References: <437fd095-da6c-4ab5-bb9a-fbd081776951@googlegroups.com> Message-ID: On 4/21/2018 7:53 PM, Michael Torrie wrote: > On 04/21/2018 11:43 AM, jedzry at gmail.com wrote: >> I currently have python version 3.6.1 32 bit version on my laptop and when i try to repair, it gives an error saying "The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2503". After i clicked ok there is a message pop-up saying: "One or more issues caused the setup to fail. Please fix the issues and then retry setup. 0x80070643- Fatal error during installation. >> >> When i try to uninstall, it says no python 3.6 installation was detected. When i try to modify, it says that there is a fatal error during installation. > > Try installing the same version of Python again. The reinstall might > clean up the corrupted install and let you remove it. Or install 3.6.5, with at least a hundred bug fixes. This should overwrite the bad 3.6.1. If this does not work, you may need to run chkdsk /F or the equivalent to fix one of the files. -- Terry Jan Reedy From rudy at matela.com.br Sun Apr 22 16:06:26 2018 From: rudy at matela.com.br (Rudy Matela) Date: Sun, 22 Apr 2018 17:06:26 -0300 Subject: ANN: Concise Python Cheat Sheet Message-ID: <20180422200626.GB1263@oubli> Hello All, I have started building a Python Cheat Sheet. It aims to have Python's most common language features and functions condensed in two pages. It still needs a lot of improvement and better content. If someone wants to use it as a reference, the first version can be found on [1] and the TeX source can be found on GitHub [2]. I would appreciate help on it: feel free to fork and make pull requests with new additions. It is dual licensed under CC-BY-SA 3.0 / GFDL 1.3. I am aware there are other Python cheat sheets / reference cards flying around on the internet. But I did not feel completely satisfied with them: I feel some sheets are too long or cluttered while other sheets leave out important content (IMHO). Regards, Rudy [1]: https://github.com/rudymatela/concise-cheat-sheets/releases/download/python-v0.1/python-cs-0.1.pdf [2]: https://github.com/rudymatela/concise-cheat-sheets From francesco.maida at gmail.com Mon Apr 23 06:50:50 2018 From: francesco.maida at gmail.com (francesco.maida at gmail.com) Date: Mon, 23 Apr 2018 03:50:50 -0700 (PDT) Subject: I wrote my very basic mkdocs plugin, hoping that it will inspire you to write your owns Message-ID: <92feab85-de25-46b2-94cb-bc56161a0943@googlegroups.com> I wanted to write mkdocs plugins, so I read the docs (well, at least part of them) and I wrote a very simple, very basic plugin. I called it "Hello dolly", because when I wrote it I was inspired by the (once built-in) WordPress plugin of the same name that teached me the basic of plugin writing for that blog platform. It does a very simple, very basic tasks. In each document, the plugin looks for the specific tag {{dolly}} and replaces it with a random line from the "Hello dolly!" lyrics; I tried to keep the code as simple as possible, so you won't find any unit-testing code and even the search and replace part was done by using the str.replace method instead of using a regular expression. I tried to comment the code whenever possible, but english is not my native language and you're likely to find a lot of grammar mistakes and typos in my comments, but I hope that my code will speak better than my own words. If, like me, you're looking forward writing your own plugin then you might find useful to have a look at it. You'll find it here: https://github.com/fmaida/hello-dolly-mkdocs-plugin If you have any questions, please contact me on GitHub and I'll try to help you. Thank you for your time and best regards From samakshkaushik at gmail.com Mon Apr 23 13:24:20 2018 From: samakshkaushik at gmail.com (Hac4u) Date: Mon, 23 Apr 2018 10:24:20 -0700 (PDT) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python Message-ID: I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. This is my code import os import re filename="filename.dmp" read_data=2**24 searchtext="bd:mongo:" he=searchtext.encode('hex') with open(filename, 'rb') as f: while True: data= f.read(read_data) if not data: break elif searchtext in data: print "Found" try: offset=hex(data.index(searchtext)) print offset except ValueError: print 'Not Found' else: continue The address I am getting is #0x2c0900 #0xb62300 But the actual positioning is # 652c0900 # 652c0950 From rosuav at gmail.com Mon Apr 23 13:31:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Apr 2018 03:31:14 +1000 Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: Message-ID: On Tue, Apr 24, 2018 at 3:24 AM, Hac4u wrote: > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. > > This is my code > > import os > import re > filename="filename.dmp" > read_data=2**24 > searchtext="bd:mongo:" > he=searchtext.encode('hex') Why encode it as hex? > with open(filename, 'rb') as f: > while True: > data= f.read(read_data) > if not data: > break > elif searchtext in data: > print "Found" > try: > offset=hex(data.index(searchtext)) > print offset > except ValueError: > print 'Not Found' > else: > continue You have a loop that reads a slab of data from a file, then searches the current data only. Then you search that again for the actual index, and print it - but you're printing the offset within the current chunk only. You'll need to maintain a chunk position in order to get the actual offset. Also, you're not going to find this if it spans across a chunk boundary. May need to cope with that. ChrisA From samakshkaushik at gmail.com Mon Apr 23 13:57:06 2018 From: samakshkaushik at gmail.com (Hac4u) Date: Mon, 23 Apr 2018 10:57:06 -0700 (PDT) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: Message-ID: <4b757560-fbdc-4ae7-af40-c1a564f0dfa1@googlegroups.com> On Monday, April 23, 2018 at 11:01:39 PM UTC+5:30, Chris Angelico wrote: > On Tue, Apr 24, 2018 at 3:24 AM, Hac4u wrote: > > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. > > > > This is my code > > > > import os > > import re > > filename="filename.dmp" > > read_data=2**24 > > searchtext="bd:mongo:" > > he=searchtext.encode('hex') > > Why encode it as hex? > > > with open(filename, 'rb') as f: > > while True: > > data= f.read(read_data) > > if not data: > > break > > elif searchtext in data: > > print "Found" > > try: > > offset=hex(data.index(searchtext)) > > print offset > > except ValueError: > > print 'Not Found' > > else: > > continue > > You have a loop that reads a slab of data from a file, then searches > the current data only. Then you search that again for the actual > index, and print it - but you're printing the offset within the > current chunk only. You'll need to maintain a chunk position in order > to get the actual offset. > > Also, you're not going to find this if it spans across a chunk > boundary. May need to cope with that. > > ChrisA I was encoding to try something.You can ignore that line.. Yea i was not maitaing the chunk position..Can u help me out with any link..I am out of ideas and this is my first time dealing with memory codes. Regards Samaksh From python at mrabarnett.plus.com Mon Apr 23 15:24:21 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Apr 2018 20:24:21 +0100 Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: Message-ID: On 2018-04-23 18:24, Hac4u wrote: > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. > > This is my code > > import os > import re > filename="filename.dmp" > read_data=2**24 > searchtext="bd:mongo:" > he=searchtext.encode('hex') > with open(filename, 'rb') as f: > while True: > data= f.read(read_data) > if not data: > break > elif searchtext in data: > print "Found" > try: > offset=hex(data.index(searchtext)) > print offset > except ValueError: > print 'Not Found' > else: > continue > > > The address I am getting is > #0x2c0900 > #0xb62300 > > But the actual positioning is > # 652c0900 > # 652c0950 > Here's a version that handles overlaps. Try to keep in mind the distinction between bytestrings and text strings. It doesn't matter as much in Python 2, but it does in Python 3. filename = "filename.dmp" chunk_size = 2**24 search_text = b"bd:mongo:" chunk_start = 0 offset = 0 search_length = len(search_text) overlap_length = search_length - 1 data = b'' with open(filename, 'rb') as f: while True: # Read in more data. data += f.read(chunk_size) if not data: break # Search this chunk. while True: offset = data.find(search_text, offset) if offset < 0: break print "Found at", hex(chunk_start + offset) offset += search_length # We've searched this chunk. Discard all but a portion of overlap. chunk_start += len(data) - overlap_length if overlap_length > 0: data = data[-overlap_length : ] else: data = b'' offset = 0 From grant.b.edwards at gmail.com Mon Apr 23 16:10:12 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 23 Apr 2018 20:10:12 +0000 (UTC) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python References: Message-ID: On 2018-04-23, Hac4u wrote: > I have a raw data of size nearly 10GB. I would like to find a text > string and print the memory address at which it is stored. The first thing I would try is to map the file into memory as a string (Pythonb 2) or bytearray (Python 3), and then search it using the find() method to search it. My theory is you let the OS worry about shuffling blocks between RAM and disk -- it's pretty good at that (well, Linux is anyway). #!/usr/bin/python3 import sys,mmap,os fn = os.open(sys.argv[1],os.O_RDONLY) mm = mmap.mmap(fn,0,prot=mmap.PROT_READ) i = mm.find(bytes(sys.argv[2],encoding='UTF-8')) print(i) The above code works for me, but I don't know how perfomance compares with other methods. I think the mmap() signature is slightly different on Windows. -- Grant Edwards grant.b.edwards Yow! Not SENSUOUS ... only at "FROLICSOME" ... and in gmail.com need of DENTAL WORK ... in PAIN!!! From bc at freeuk.com Mon Apr 23 16:52:18 2018 From: bc at freeuk.com (bartc) Date: Mon, 23 Apr 2018 21:52:18 +0100 Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: Message-ID: <0IrDC.8218$Vm6.2993@fx45.am4> On 23/04/2018 21:45, Stefan Ram wrote: > MRAB writes: >> offset += search_length > > Or, offset += 1, to also find overlaps of that kind: > > file = "eee" > word = "ee" > > . The above word "ee" occurs at position 0 and 1 in the file. > > My attempt: > > #include > #include > int main( void ) > { FILE * const haystack = fopen( "filename.dmp", "r" ); > if( !haystack )goto end; > char const * const needle = "bd:mongo:"; > int offset = 0; > int const l =( int )strlen( needle ); > { int o[ l ]; /* VLA */ > for( int i=0; i < l; ++i )o[ i ]= -1; > o[ 0 ]= 0; > next: ; > int const x = fgetc( haystack ); > if( x == EOF )goto out; > ++offset; > for( int i=0; i < l; ++ i ) > if( o[ i ]>= 0 ) > { char const ch = needle[ o[ i ] ]; > if( ch == x )++o[ i ]; > if( o[ i ]==( int )strlen( needle )) > { printf( "found at %d\n", offset -( int )strlen( needle )); }} > for( int i = l; i; --i )o[ i ]= o[ i - 1 ]; > o[ 0 ]= 0; > goto next; > out: fclose( haystack ); } > end: ; } > Did you say that you teach programming? -- bartc From samakshkaushik at gmail.com Mon Apr 23 17:07:19 2018 From: samakshkaushik at gmail.com (Hac4u) Date: Mon, 23 Apr 2018 14:07:19 -0700 (PDT) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: <87sh7ln1a5.fsf@nightsong.com> References: <87sh7ln1a5.fsf@nightsong.com> Message-ID: On Tuesday, April 24, 2018 at 1:28:07 AM UTC+5:30, Paul Rubin wrote: > Hac4u writes: > > I have a raw data of size nearly 10GB. I would like to find a text > > string and print the memory address at which it is stored. > > The simplest way is probably to mmap the file and use mmap.find: > > https://docs.python.org/2/library/mmap.html#mmap.mmap.find Thanks alot Buddy, And yea I will try to convert it in mmap.. Ur code helped alot. But I have few doubts 1. What is the use of overlap. 2. Ur code does not end..Like it does break even after searching through the entire file. Bdw, I modified your code.. import os import re filename="E:/bitdefender/test.vmem" read_data=2**24 offset=0 chunk_start=0 searchtext=b"bd:mongo:" search_length=len(searchtext) overlap_length = search_length - 1 he=searchtext.encode('hex') with open(filename, 'rb') as f: while True: data= f.read(read_data) if not data: break while True: offset=data.find(searchtext,offset) # print offset if offset < 0: break print "Found at",hex(chunk_start+offset) offset+=search_length chunk_start += len(data) data=data[read_data:] offset=0 From samakshkaushik at gmail.com Mon Apr 23 17:11:16 2018 From: samakshkaushik at gmail.com (Hac4u) Date: Mon, 23 Apr 2018 14:11:16 -0700 (PDT) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: Message-ID: <92719182-18cb-423c-a25a-a78ac039251e@googlegroups.com> On Tuesday, April 24, 2018 at 12:54:43 AM UTC+5:30, MRAB wrote: > On 2018-04-23 18:24, Hac4u wrote: > > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. > > > > This is my code > > > > import os > > import re > > filename="filename.dmp" > > read_data=2**24 > > searchtext="bd:mongo:" > > he=searchtext.encode('hex') > > with open(filename, 'rb') as f: > > while True: > > data= f.read(read_data) > > if not data: > > break > > elif searchtext in data: > > print "Found" > > try: > > offset=hex(data.index(searchtext)) > > print offset > > except ValueError: > > print 'Not Found' > > else: > > continue > > > > > > The address I am getting is > > #0x2c0900 > > #0xb62300 > > > > But the actual positioning is > > # 652c0900 > > # 652c0950 > > > Here's a version that handles overlaps. > > Try to keep in mind the distinction between bytestrings and text > strings. It doesn't matter as much in Python 2, but it does in Python 3. > > > filename = "filename.dmp" > chunk_size = 2**24 > search_text = b"bd:mongo:" > chunk_start = 0 > offset = 0 > search_length = len(search_text) > overlap_length = search_length - 1 > data = b'' > > with open(filename, 'rb') as f: > while True: > # Read in more data. > data += f.read(chunk_size) > if not data: > break > > # Search this chunk. > while True: > offset = data.find(search_text, offset) > if offset < 0: > break > > print "Found at", hex(chunk_start + offset) > offset += search_length > > # We've searched this chunk. Discard all but a portion of overlap. > chunk_start += len(data) - overlap_length > > if overlap_length > 0: > data = data[-overlap_length : ] > else: > data = b'' > > offset = 0 Thanks alot for the code. I have two questions 1. Why did u use overlap. And, In what condition it can be counted on? 2. Your code does not end. It keep on looking for sth ..Though it worked well. So, Thanks alot for the code. Here is my modified code(taken help from your code) import os import re filename="filename.dmp" read_data=2**24 offset=0 chunk_start=0 searchtext=b"bd:mongo:" search_length=len(searchtext) overlap_length = search_length - 1 he=searchtext.encode('hex') with open(filename, 'rb') as f: while True: data= f.read(read_data) if not data: break while True: offset=data.find(searchtext,offset) # print offset if offset < 0: break print "Found at",hex(chunk_start+offset) offset+=search_length chunk_start += len(data) data=data[read_data:] offset=0 From bgibbeme at us.ibm.com Mon Apr 23 17:38:30 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Mon, 23 Apr 2018 21:38:30 +0000 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: From: Brian Gibbemeyer/Detroit/IBM To: python-list at python.org, docs at python.org Date: 04/23/2018 03:35 PM Subject: Issue with python365.chm on window 7 Not sure which email this should go to. But I downloaded .chm version of the Python guide and found that it is not working in windows 7 Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care Phone: 1-7349133594 | Mobile: 1-7347258319 E-mail: bgibbeme at us.ibm.com 100 Phoenix Dr Ann Arbor, MI 48108-2202 United States From tjreedy at udel.edu Mon Apr 23 18:37:39 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Apr 2018 18:37:39 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: On 4/23/2018 5:38 PM, Brian Gibbemeyer wrote: > From: Brian Gibbemeyer/Detroit/IBM > Not sure which email this should go to. This is a good place to start. > But I downloaded .chm version of the Python guide and found that it is not > working in windows 7 How did you download it? How did you try to make it 'work'? What did it do instead? Have you successfully run Python Windows Help before? I installed python.org 64-bit 3.6.5 on Win 10 with the .exe installer. I run it by clicking on Python 3.6 => Python 3.6 Manuals in the Win10 version of what was Start Menu. The icon is a notebook page with question mark. Window like it has for over a decade, with sidebar on left. If anyone else has 3.6.5 (the latest 3.6) on Win 7, what to you see? -- Terry Jan Reedy From python at mrabarnett.plus.com Mon Apr 23 18:43:01 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Apr 2018 23:43:01 +0100 Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: <92719182-18cb-423c-a25a-a78ac039251e@googlegroups.com> References: <92719182-18cb-423c-a25a-a78ac039251e@googlegroups.com> Message-ID: <2c173c08-fd29-f611-c144-4c981982f1d1@mrabarnett.plus.com> On 2018-04-23 22:11, Hac4u wrote: > On Tuesday, April 24, 2018 at 12:54:43 AM UTC+5:30, MRAB wrote: >> On 2018-04-23 18:24, Hac4u wrote: >> > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. >> > >> > This is my code >> > >> > import os >> > import re >> > filename="filename.dmp" >> > read_data=2**24 >> > searchtext="bd:mongo:" >> > he=searchtext.encode('hex') >> > with open(filename, 'rb') as f: >> > while True: >> > data= f.read(read_data) >> > if not data: >> > break >> > elif searchtext in data: >> > print "Found" >> > try: >> > offset=hex(data.index(searchtext)) >> > print offset >> > except ValueError: >> > print 'Not Found' >> > else: >> > continue >> > >> > >> > The address I am getting is >> > #0x2c0900 >> > #0xb62300 >> > >> > But the actual positioning is >> > # 652c0900 >> > # 652c0950 >> > >> Here's a version that handles overlaps. >> >> Try to keep in mind the distinction between bytestrings and text >> strings. It doesn't matter as much in Python 2, but it does in Python 3. >> >> >> filename = "filename.dmp" >> chunk_size = 2**24 >> search_text = b"bd:mongo:" >> chunk_start = 0 >> offset = 0 >> search_length = len(search_text) >> overlap_length = search_length - 1 >> data = b'' >> >> with open(filename, 'rb') as f: >> while True: >> # Read in more data. >> data += f.read(chunk_size) >> if not data: >> break >> >> # Search this chunk. >> while True: >> offset = data.find(search_text, offset) >> if offset < 0: >> break >> >> print "Found at", hex(chunk_start + offset) >> offset += search_length >> >> # We've searched this chunk. Discard all but a portion of overlap. >> chunk_start += len(data) - overlap_length >> >> if overlap_length > 0: >> data = data[-overlap_length : ] >> else: >> data = b'' >> >> offset = 0 > > > > Thanks alot for the code. > > I have two questions > > 1. Why did u use overlap. And, In what condition it can be counted on? Suppose you're searching for b"bd:mongo:". What happens if a chunk ends with b"b" and the next chunk starts with b"d:mongo:"? Or b"bd:m" and b"ongo:"? Or b"bd:mongo" and b":"? It wouldn't find a match that's split across chunks. > 2. Your code does not end. It keep on looking for sth ..Though it worked well. > > So, Thanks alot for the code. > Here's my code with a bug fix: filename = "filename.dmp" chunk_size = 2**24 search_text = b"bd:mongo:" chunk_start = 0 offset = 0 search_length = len(search_text) overlap_length = search_length - 1 data = b'' with open(filename, 'rb') as f: while True: # Read in more data. data += f.read(chunk_size) if len(data) < search_length: break # Search this chunk. while True: offset = data.find(search_text, offset) if offset < 0: break print "Found at", hex(chunk_start + offset) offset += search_length # We've searched this chunk. Discard all but a portion of overlap. chunk_start += len(data) - overlap_length if overlap_length > 0: data = data[-overlap_length : ] else: data = b'' offset = 0 From samakshkaushik at gmail.com Mon Apr 23 19:12:01 2018 From: samakshkaushik at gmail.com (Hac4u) Date: Mon, 23 Apr 2018 16:12:01 -0700 (PDT) Subject: Finding a text in raw data(size nearly 10GB) and Printing its memory address using python In-Reply-To: References: <92719182-18cb-423c-a25a-a78ac039251e@googlegroups.com> <2c173c08-fd29-f611-c144-4c981982f1d1@mrabarnett.plus.com> Message-ID: <48dcb784-1dd3-425b-bbd1-252a3de660e4@googlegroups.com> On Tuesday, April 24, 2018 at 4:13:17 AM UTC+5:30, MRAB wrote: > On 2018-04-23 22:11, Hac4u wrote: > > On Tuesday, April 24, 2018 at 12:54:43 AM UTC+5:30, MRAB wrote: > >> On 2018-04-23 18:24, Hac4u wrote: > >> > I have a raw data of size nearly 10GB. I would like to find a text string and print the memory address at which it is stored. > >> > > >> > This is my code > >> > > >> > import os > >> > import re > >> > filename="filename.dmp" > >> > read_data=2**24 > >> > searchtext="bd:mongo:" > >> > he=searchtext.encode('hex') > >> > with open(filename, 'rb') as f: > >> > while True: > >> > data= f.read(read_data) > >> > if not data: > >> > break > >> > elif searchtext in data: > >> > print "Found" > >> > try: > >> > offset=hex(data.index(searchtext)) > >> > print offset > >> > except ValueError: > >> > print 'Not Found' > >> > else: > >> > continue > >> > > >> > > >> > The address I am getting is > >> > #0x2c0900 > >> > #0xb62300 > >> > > >> > But the actual positioning is > >> > # 652c0900 > >> > # 652c0950 > >> > > >> Here's a version that handles overlaps. > >> > >> Try to keep in mind the distinction between bytestrings and text > >> strings. It doesn't matter as much in Python 2, but it does in Python 3. > >> > >> > >> filename = "filename.dmp" > >> chunk_size = 2**24 > >> search_text = b"bd:mongo:" > >> chunk_start = 0 > >> offset = 0 > >> search_length = len(search_text) > >> overlap_length = search_length - 1 > >> data = b'' > >> > >> with open(filename, 'rb') as f: > >> while True: > >> # Read in more data. > >> data += f.read(chunk_size) > >> if not data: > >> break > >> > >> # Search this chunk. > >> while True: > >> offset = data.find(search_text, offset) > >> if offset < 0: > >> break > >> > >> print "Found at", hex(chunk_start + offset) > >> offset += search_length > >> > >> # We've searched this chunk. Discard all but a portion of overlap. > >> chunk_start += len(data) - overlap_length > >> > >> if overlap_length > 0: > >> data = data[-overlap_length : ] > >> else: > >> data = b'' > >> > >> offset = 0 > > > > > > > > Thanks alot for the code. > > > > I have two questions > > > > 1. Why did u use overlap. And, In what condition it can be counted on? > > Suppose you're searching for b"bd:mongo:". > > What happens if a chunk ends with b"b" and the next chunk starts with > b"d:mongo:"? Or b"bd:m" and b"ongo:"? Or b"bd:mongo" and b":"? > > It wouldn't find a match that's split across chunks. > > > 2. Your code does not end. It keep on looking for sth ..Though it worked well. > > > > So, Thanks alot for the code. > > > Here's my code with a bug fix: > > filename = "filename.dmp" > chunk_size = 2**24 > search_text = b"bd:mongo:" > chunk_start = 0 > offset = 0 > search_length = len(search_text) > overlap_length = search_length - 1 > data = b'' > > with open(filename, 'rb') as f: > while True: > # Read in more data. > data += f.read(chunk_size) > if len(data) < search_length: > break > > # Search this chunk. > while True: > offset = data.find(search_text, offset) > if offset < 0: > break > > print "Found at", hex(chunk_start + offset) > offset += search_length > > # We've searched this chunk. Discard all but a portion of overlap. > chunk_start += len(data) - overlap_length > > if overlap_length > 0: > data = data[-overlap_length : ] > else: > data = b'' > > offset = 0 Got it.. Thanks aton for the explaination.. From bob.martin at excite.com Tue Apr 24 07:10:21 2018 From: bob.martin at excite.com (Bob Martin) Date: Tue, 24 Apr 2018 07:10:21 BST Subject: Issue with python365.chm on window 7 References: Message-ID: in 793268 20180423 223830 "Brian Gibbemeyer" wrote: >From: Brian Gibbemeyer/Detroit/IBM >To: python-list at python.org, docs at python.org >Date: 04/23/2018 03:35 PM >Subject: Issue with python365.chm on window 7 > > >Not sure which email this should go to. > >But I downloaded .chm version of the Python guide and found that it is not = > >working in windows 7 > > > > > > >Thank you, > >Brian Gibbemeyer >Sr Software Engineer >Watson Health - Value Based Care > > >Phone: 1-7349133594 | Mobile: 1-7347258319 >E-mail: bgibbeme at us.ibm.com > > >100 Phoenix Dr >Ann Arbor, MI 48108-2202 >United States Senior Software Engineer? Seriously? From mathsolutiondeveloper at gmail.com Tue Apr 24 05:19:24 2018 From: mathsolutiondeveloper at gmail.com (Musa Mohamma) Date: Tue, 24 Apr 2018 10:19:24 +0100 Subject: Scripts folder empty in a repaired python install Message-ID: Hi, Yesterday I installed python 3.6.5 64 bit in the same directory as my existing python 3.6.5 32 bit hoping that the former will replace the later. After the installation, it was the 32 bit python that was still active on my windows 10 machine. So I uninstalled python using the control panel and manually removed other left over folder from c-drive. I now re-installed the 64 bit version again using option 'repair'. The install was successful but the 'Scripts' folder was empty so I couldn't use pip. Please what is the best way of getting pip back? Kind regards, Musa Mohamma From ned at nedbatchelder.com Tue Apr 24 07:17:02 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Apr 2018 07:17:02 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: On 4/24/18 2:10 AM, Bob Martin wrote: > Senior Software Engineer? > Seriously? What is the point of this comment?? We can be more respectful than this. --Ned. From sjmsoft at gmail.com Tue Apr 24 08:05:46 2018 From: sjmsoft at gmail.com (sjmsoft at gmail.com) Date: Tue, 24 Apr 2018 05:05:46 -0700 (PDT) Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: <7165d906-4fa8-4790-b604-d3f24b739396@googlegroups.com> On Monday, April 23, 2018 at 7:38:04 PM UTC-3, Terry Reedy wrote: > I installed python.org 64-bit 3.6.5 on Win 10 with the .exe installer. > I run it by clicking on Python 3.6 => Python 3.6 Manuals in the Win10 > version of what was Start Menu. The icon is a notebook page with > question mark. Window like it has for over a decade, with sidebar on left. > > If anyone else has 3.6.5 (the latest 3.6) on Win 7, what to you see? I did the same, and see the same, as Terry. I'm using Windows 7 Enterprise. HTH, Steve J. Martin From bgibbeme at us.ibm.com Tue Apr 24 08:15:50 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 08:15:50 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: see my comments below denoted by +++++ From: Terry Reedy To: python-list at python.org Date: 04/23/2018 06:45 PM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" This is a good place to start. > But I downloaded .chm version of the Python guide and found that it is not > working in windows 7 How did you download it? ++++I downloaded it from the https://www.python.org/downloads/release/python-364/ site How did you try to make it 'work'? ++++Nothing yet What did it do instead? ++++Used the web resources... but I am looking for an offline resources. I anticipate I will be in an area that I will not have access to the internet soon. Have you successfully run Python Windows Help before? ++++I have used windows help files before and they work fine. In fact I can user the windows help file that came installed with version of python. the one that I download of the web site is the problem. I installed python.org 64-bit 3.6.5 on Win 10 with the .exe installer. I run it by clicking on Python 3.6 => Python 3.6 Manuals in the Win10 version of what was Start Menu. The icon is a notebook page with question mark. Window like it has for over a decade, with sidebar on left. If anyone else has 3.6.5 (the latest 3.6) on Win 7, what to you see? ++++ if I go that route above I can see a working help file on windows which is a successful workround for me. the one you download from the website by itself I still cannot open. -- Terry Jan Reedy -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=9cqQ_q_K0jhhqy_GlOHSaApBxOjA_KliaKwffBFsna4&s=P2PPb7UlduE9v_e41k2s_qBM2WRlzEzIv2nNRSGuZzQ&e= From bgibbeme at us.ibm.com Tue Apr 24 08:18:16 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 08:18:16 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: <7165d906-4fa8-4790-b604-d3f24b739396@googlegroups.com> References: <7165d906-4fa8-4790-b604-d3f24b739396@googlegroups.com> Message-ID: Did you download it form the web? https://www.python.org/downloads/release/python-364/ That is the one not working. I id not know about the .chm that was installed with the product until this morning. Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care Phone: 1-7349133594 | Mobile: 1-7347258319 E-mail: bgibbeme at us.ibm.com 100 Phoenix Dr Ann Arbor, MI 48108-2202 United States From: sjmsoft at gmail.com To: python-list at python.org Date: 04/24/2018 08:15 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" On Monday, April 23, 2018 at 7:38:04 PM UTC-3, Terry Reedy wrote: > I installed python.org 64-bit 3.6.5 on Win 10 with the .exe installer. > I run it by clicking on Python 3.6 => Python 3.6 Manuals in the Win10 > version of what was Start Menu. The icon is a notebook page with > question mark. Window like it has for over a decade, with sidebar on left. > > If anyone else has 3.6.5 (the latest 3.6) on Win 7, what to you see? I did the same, and see the same, as Terry. I'm using Windows 7 Enterprise. HTH, Steve J. Martin -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=fQCIrR9hVbtFYIQQdyKKK0s2VSUhYApkQlWdS_IEWbU&s=gHJgISCYbxPc2pymQnkJUNqNFHdbl9ZxFslMhaBZQfo&e= From bgibbeme at us.ibm.com Tue Apr 24 10:15:30 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 14:15:30 +0000 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: Yes actually I am a Sr Software Engineer. I am not an expert in one language. I am pretty handy in picking up new concepts and applying the concepts to meet business demands.. I am just reporting a valid issue. I don't ever get to code in python, but I really respect the language. In this case. I need to automate the porting of tableau reports to different environments. I found that Python speaks to the rest api....therefore I get to code with python. I haven't touched python in 14 years. Normally I do not respond to these types of responses. Due to the power of relative anonymity on the internet, it just escalates out of control quickly and is usually not constructive. I type this up, not with the intent of embarrassing anyone or aggravating consummate professionals. However I can see this goes out to several people and possibly people who are new to the language. I do not want those new to the language or new to using forums to feel intimidated by jokes or negativity. This response is based on conversations I have had with new IT professionals on why they do not reach out to public forums. I am a proponent for using public forums, I would like to see more people use them, even those that do not have thick skins. Hence I responded. Perhaps I should have fully explained where I got the windows help file that would have been less confusing. But if the list would have posted the graphic that I attached to the original email it would have more self explanatory Bob if you can go to https://www.python.org/downloads/release/python-364/ And download the help file I have link below. https://www.python.org/ftp/python/3.6.4/python364.chm See if you can open that up and report back. I am not able however I can open the chm file that comes with python install. This is the graphic I sent. Bob Should be able to see it but the list will not Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care From: Bob Martin To: python-list at python.org Date: 04/24/2018 02:18 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" in 793268 20180423 223830 "Brian Gibbemeyer" wrote: >From: Brian Gibbemeyer/Detroit/IBM >To: python-list at python.org, docs at python.org >Date: 04/23/2018 03:35 PM >Subject: Issue with python365.chm on window 7 > > >Not sure which email this should go to. > >But I downloaded .chm version of the Python guide and found that it is not = > >working in windows 7 > > > > > > >Thank you, > >Brian Gibbemeyer >Sr Software Engineer >Watson Health - Value Based Care > > > >100 Phoenix Dr >Ann Arbor, MI 48108-2202 >United States Senior Software Engineer? Seriously? -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=yS6loF1Uy_1ajZRgtVlMN0F-X324M9-f8bd8FKvGcuA&s=8Ypfxosghco_KKiWJ6qJIuNmErlEG9xSIoV2rveHQvA&e= From bgibbeme at us.ibm.com Tue Apr 24 10:49:48 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 10:49:48 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: The links without the url defense wrappers https://www.python.org/downloads/release/python-365/ https://www.python.org/ftp/python/3.6.5/python365.chm Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care From: "Brian Gibbemeyer" To: Bob Martin Cc: python-list at python.org Date: 04/24/2018 10:26 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" Yes actually I am a Sr Software Engineer. I am not an expert in one language. I am pretty handy in picking up new concepts and applying the concepts to meet business demands.. I am just reporting a valid issue. I don't ever get to code in python, but I really respect the language. In this case. I need to automate the porting of tableau reports to different environments. I found that Python speaks to the rest api....therefore I get to code with python. I haven't touched python in 14 years. Normally I do not respond to these types of responses. Due to the power of relative anonymity on the internet, it just escalates out of control quickly and is usually not constructive. I type this up, not with the intent of embarrassing anyone or aggravating consummate professionals. However I can see this goes out to several people and possibly people who are new to the language. I do not want those new to the language or new to using forums to feel intimidated by jokes or negativity. This response is based on conversations I have had with new IT professionals on why they do not reach out to public forums. I am a proponent for using public forums, I would like to see more people use them, even those that do not have thick skins. Hence I responded. Perhaps I should have fully explained where I got the windows help file that would have been less confusing. But if the list would have posted the graphic that I attached to the original email it would have more self explanatory Bob if you can go to https://urldefense.proofpoint.com/v2/url?u=https-3A__www.python.org_downloads_release_python-2D364_&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=6QKvk2OAsvUYyrRzkwK4FSHqREtMQevyi9D6dMGPG0c&s=zpwTrS4mGqnpszzsNnYgQ_ydH8y3Q4d9Lz0CPLuwa6E&e= And download the help file I have link below. https://urldefense.proofpoint.com/v2/url?u=https-3A__www.python.org_ftp_python_3.6.4_python364.chm&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=6QKvk2OAsvUYyrRzkwK4FSHqREtMQevyi9D6dMGPG0c&s=RWWyXltMIErykj4fbUCCarJlmazo7AR1Xt6BP7wZHBk&e= See if you can open that up and report back. I am not able however I can open the chm file that comes with python install. This is the graphic I sent. Bob Should be able to see it but the list will not Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care From: Bob Martin To: python-list at python.org Date: 04/24/2018 02:18 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" in 793268 20180423 223830 "Brian Gibbemeyer" wrote: >From: Brian Gibbemeyer/Detroit/IBM >To: python-list at python.org, docs at python.org >Date: 04/23/2018 03:35 PM >Subject: Issue with python365.chm on window 7 > > >Not sure which email this should go to. > >But I downloaded .chm version of the Python guide and found that it is not = > >working in windows 7 > > > > > > >Thank you, > >Brian Gibbemeyer >Sr Software Engineer >Watson Health - Value Based Care > > > >100 Phoenix Dr >Ann Arbor, MI 48108-2202 >United States Senior Software Engineer? Seriously? -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=yS6loF1Uy_1ajZRgtVlMN0F-X324M9-f8bd8FKvGcuA&s=8Ypfxosghco_KKiWJ6qJIuNmErlEG9xSIoV2rveHQvA&e= -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=6QKvk2OAsvUYyrRzkwK4FSHqREtMQevyi9D6dMGPG0c&s=2M9mlm3p8rexnbkiCWbOCuddNnYDP-ZOweXtmrHsgKg&e= From rosuav at gmail.com Tue Apr 24 10:51:36 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Apr 2018 00:51:36 +1000 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: On Wed, Apr 25, 2018 at 12:15 AM, Brian Gibbemeyer wrote: > Yes actually I am a Sr Software Engineer. I am not an expert in one > language. I am pretty handy in picking up new concepts and applying the > concepts to meet business demands.. > I am just reporting a valid issue. > I don't ever get to code in python, but I really respect the language. > People will insult you for anything and everything. Sometimes with good cause... sometimes without. Personally, I respect someone for being willing to ask for help, rather than thinking "I'm such an amazing person, I shouldn't need help". None of us is perfect, all of us are learning. Though if you want to win favour with the Python community, there are a few easy things you can do. One is to avoid top-posting: take the quoted text from the message you're replying to, trim it down to just the parts you need, and then put your responses underneath. Top-posting (leaving all the quoted text underneath, and then putting your response above) tends to be frowned upon in most tech newsgroups/mailing lists. Regarding your original query - the .CHM file is a downloadable version of the same documentation that can be viewed on the web. Do you have a particular need for offline viewing? If not, I would definitely recommend using the web version; that way, if it gets updated (eg to clarify some wording or improve an example), you'll get the update. ChrisA From ethan at stoneleaf.us Tue Apr 24 11:21:51 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 24 Apr 2018 08:21:51 -0700 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: <5ADF4B8F.6020502@stoneleaf.us> On 04/24/2018 07:15 AM, Brian Gibbemeyer wrote: > I found that Python speaks to the rest api....therefore I get to code with > python. I haven't touched python in 14 years. Welcome back! :) > Normally I do not respond to these types of responses. Due to the power of > relative anonymity on the internet, it just escalates out of control > quickly and is usually not constructive. Hopefully Bob was just having a bad day. I know it's happened to me. Thank you for your respectful reply. > But if the list would have posted the graphic that I attached to the > original email it would have more self explanatory This is a text-only mailing list, not a web forum. Graphics are stripped. > Bob if you can go to > https://www.python.org/downloads/release/python-364/ > > > And download the help file > > I have link below. > > https://www.python.org/ftp/python/3.6.4/python364.chm > > See if you can open that up and report back. Downloaded, opened: I see the topics on the left, but the main frame is empty; it stays empty no matter which topic I click on. Windows 7 Pro, Service Pack 1 Windows 10 Pro -- ~Ethan~ From bgibbeme at us.ibm.com Tue Apr 24 11:23:25 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 11:23:25 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: References: Message-ID: I understand that. I have seen great repositories of information dry up because of this. Folks got tired of infighting and brought the servers down. I do realize that responding to this adds to the problem. Thanks for the advice on top posting, I will follow it from now on. Yes I have a need for offline. I frequently visit spots without access to internet or even cell reception (Farm Country) I am actually all set with the version of the file in the installed version of python. From: Chris Angelico To: Python Date: 04/24/2018 11:01 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" On Wed, Apr 25, 2018 at 12:15 AM, Brian Gibbemeyer wrote: > Yes actually I am a Sr Software Engineer. I am not an expert in one > language. I am pretty handy in picking up new concepts and applying the > concepts to meet business demands.. > I am just reporting a valid issue. > I don't ever get to code in python, but I really respect the language. > People will insult you for anything and everything. Sometimes with good cause... sometimes without. Personally, I respect someone for being willing to ask for help, rather than thinking "I'm such an amazing person, I shouldn't need help". None of us is perfect, all of us are learning. Though if you want to win favour with the Python community, there are a few easy things you can do. One is to avoid top-posting: take the quoted text from the message you're replying to, trim it down to just the parts you need, and then put your responses underneath. Top-posting (leaving all the quoted text underneath, and then putting your response above) tends to be frowned upon in most tech newsgroups/mailing lists. Regarding your original query - the .CHM file is a downloadable version of the same documentation that can be viewed on the web. Do you have a particular need for offline viewing? If not, I would definitely recommend using the web version; that way, if it gets updated (eg to clarify some wording or improve an example), you'll get the update. ChrisA -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=JCWLvv93inkrQynzX75G7yAOVQfIOWDmQk50w80T578&s=mAW2RoRLPaTGs7Fez49IhLvRTSy3I1FPfHsuoJ2sXCA&e= From bgibbeme at us.ibm.com Tue Apr 24 13:00:39 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 13:00:39 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: <5ADF4B8F.6020502@stoneleaf.us> References: <5ADF4B8F.6020502@stoneleaf.us> Message-ID: Thank you, feels good to be back. Since the picture won't go through let me explain the I see The file at https://www.python.org/ftp/python/3.6.4/python364.chm Loads up into a window help container. Looks normal but if if I try to click on one of the index branches on the left hand side, nothing appears in the right pane. From: Ethan Furman To: python-list at python.org Date: 04/24/2018 11:31 AM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" On 04/24/2018 07:15 AM, Brian Gibbemeyer wrote: > I found that Python speaks to the rest api....therefore I get to code with > python. I haven't touched python in 14 years. Welcome back! :) > Normally I do not respond to these types of responses. Due to the power of > relative anonymity on the internet, it just escalates out of control > quickly and is usually not constructive. Hopefully Bob was just having a bad day. I know it's happened to me. Thank you for your respectful reply. > But if the list would have posted the graphic that I attached to the > original email it would have more self explanatory This is a text-only mailing list, not a web forum. Graphics are stripped. > Bob if you can go to > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.python.org_downloads_release_python-2D364_&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=Lqd4Q1H0B7dhLZtfdHwoEFQFJkgaTXOYH0axA4T1p44&s=cy3Qx7XVml3FlwR_r5FAGCQdNxr79tEaVb7-SRHfjpY&e= > > > And download the help file > > I have link below. > > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.python.org_ftp_python_3.6.4_python364.chm&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=Lqd4Q1H0B7dhLZtfdHwoEFQFJkgaTXOYH0axA4T1p44&s=XwGHjV37PtHSTaAeJPWmYskbS2tNxY7Pw7mAbPtPd0g&e= > > See if you can open that up and report back. Downloaded, opened: I see the topics on the left, but the main frame is empty; it stays empty no matter which topic I click on. Windows 7 Pro, Service Pack 1 Windows 10 Pro -- ~Ethan~ -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=Lqd4Q1H0B7dhLZtfdHwoEFQFJkgaTXOYH0axA4T1p44&s=oTm1nyiNb9GAzW-chAlciPWZTx9ZTPAUCssQ-jA5EI8&e= From jcasale at activenetwerx.com Tue Apr 24 14:16:12 2018 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 24 Apr 2018 18:16:12 +0000 Subject: Issue with python365.chm on window 7 In-Reply-To: References: <5ADF4B8F.6020502@stoneleaf.us> Message-ID: <71e6ec3a47f849b79c2083a01a5d5bfe@activenetwerx.com> -----Original Message----- From: Python-list On Behalf Of Brian Gibbemeyer Sent: Tuesday, April 24, 2018 11:01 AM To: Ethan Furman Cc: python-list at python.org Subject: Re: Issue with python365.chm on window 7 > The file at > https://www.python.org/ftp/python/3.6.4/python364.chm > > Loads up into a window help container. Looks normal > but if if I try to click on one of the index branches on the left hand > side, nothing appears in the right pane. Right click it, choose unblock then click ok. From nbt22 at cam.ac.uk Tue Apr 24 14:22:14 2018 From: nbt22 at cam.ac.uk (Nagendra Babu Thillaiappan) Date: Tue, 24 Apr 2018 19:22:14 +0100 Subject: Python installation - fatal error Message-ID: <6ff6ea2d152cfb28135f20001e0c28c3@cam.ac.uk> Hi, I am a new user to Python and was trying to install version 3.6.5 (on a Windows 7 64-bit machine). However, I installed a different version by mistake and had to uninstall it. Then I tried installing version 3.6.5 using the .exe file, and it returns a fatal error (log in attachment). Can I request your help in sorting this out? Thank you. Best Babu -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Error log.txt URL: From bgibbeme at us.ibm.com Tue Apr 24 14:36:15 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 14:36:15 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: <71e6ec3a47f849b79c2083a01a5d5bfe@activenetwerx.com> References: <5ADF4B8F.6020502@stoneleaf.us> <71e6ec3a47f849b79c2083a01a5d5bfe@activenetwerx.com> Message-ID: I right clicked on the file, no option to unblock. I right clicked on the right pane: no right click menu. I tried clicking on internet options within help menu under the options icon in the ribbon and that leads to nowhere. I can open the one that came with the python installation... no issue. The stand alone .chm one downloaded from the web on other hand I get this issue. From: "Joseph L. Casale" To: "python-list at python.org" Date: 04/24/2018 02:22 PM Subject: RE: Issue with python365.chm on window 7 Sent by: "Python-list" -----Original Message----- From: Python-list On Behalf Of Brian Gibbemeyer Sent: Tuesday, April 24, 2018 11:01 AM To: Ethan Furman Cc: python-list at python.org Subject: Re: Issue with python365.chm on window 7 > The file at > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.python.org_ftp_python_3.6.4_python364.chm&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=LcE1CA9huFP5ZyzN1wDusn8136RgALyZLGZWaTeuojE&s=MqkO6BqWXLOSzDtJ-jE-0n2tbixWRnTZciwI0OqrZHI&e= > > Loads up into a window help container. Looks normal > but if if I try to click on one of the index branches on the left hand > side, nothing appears in the right pane. Right click it, choose unblock then click ok. -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=LcE1CA9huFP5ZyzN1wDusn8136RgALyZLGZWaTeuojE&s=pvJcd9T8TeyuwTC4E7yqdttb1ld6UUj7s9mJSCfHmZo&e= From ethan at stoneleaf.us Tue Apr 24 15:03:47 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 24 Apr 2018 12:03:47 -0700 Subject: Issue with python365.chm on window 7 In-Reply-To: <1142878159.334079.1524588155972@mail.yahoo.com> References: <5ADF4B8F.6020502@stoneleaf.us> <1142878159.334079.1524588155972@mail.yahoo.com> Message-ID: <5ADF7F93.4090303@stoneleaf.us> [redirecting to list] On 04/24/2018 09:42 AM, Erik Martinson wrote: > CHM files have a long history of security issues. Windows blocks them by default. To fix, right-click on the file and go > to properties. In the security section, click the box that says Unblock. > > - Erik From jcasale at activenetwerx.com Tue Apr 24 15:04:02 2018 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 24 Apr 2018 19:04:02 +0000 Subject: Issue with python365.chm on window 7 In-Reply-To: References: <5ADF4B8F.6020502@stoneleaf.us> <71e6ec3a47f849b79c2083a01a5d5bfe@activenetwerx.com> Message-ID: <9b4854e37767459ba52e72011841a313@activenetwerx.com> From: Brian Gibbemeyer Sent: Tuesday, April 24, 2018 12:36 PM To: Joseph L. Casale Cc: python-list at python.org Subject: RE: Issue with python365.chm on window 7 > I right clicked on the file, no option to unblock. Sorry, choose properties, then unblock. From bc at freeuk.com Tue Apr 24 15:21:14 2018 From: bc at freeuk.com (bartc) Date: Tue, 24 Apr 2018 20:21:14 +0100 Subject: Issue with python365.chm on window 7 In-Reply-To: References: <5ADF4B8F.6020502@stoneleaf.us> <1142878159.334079.1524588155972@mail.yahoo.com> <5ADF7F93.4090303@stoneleaf.us> Message-ID: On 24/04/2018 20:03, Ethan Furman wrote: > [redirecting to list] > > On 04/24/2018 09:42 AM, Erik Martinson wrote: > >> CHM files have a long history of security issues. Windows blocks them >> by default. To fix, right-click on the file and go >> to properties. In the security section, click the box that says Unblock. >> >> - Erik > I've long had issues with .chm files not working including this one. Your fix worked (on Windows 7, you have to look at the General Properties tab, and the Unblock option is at the bottom. Clicking Unblock greys it out, then it's Apply or OK). But it seems unfriendly to say the least for a HELP file of all things to just flatly not work like without a word of explanation (or even This file is blocked; do you want to unblock it?) -- bartc From bgibbeme at us.ibm.com Tue Apr 24 15:38:57 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 15:38:57 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: <5ADF7F93.4090303@stoneleaf.us> References: <5ADF4B8F.6020502@stoneleaf.us> <1142878159.334079.1524588155972@mail.yahoo.com> <5ADF7F93.4090303@stoneleaf.us> Message-ID: Thank you Ethan,,, that worked. Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care Phone: 1-7349133594 | Mobile: 1-7347258319 E-mail: bgibbeme at us.ibm.com 100 Phoenix Dr Ann Arbor, MI 48108-2202 United States From: Ethan Furman To: Python Date: 04/24/2018 03:07 PM Subject: Re: Issue with python365.chm on window 7 Sent by: "Python-list" [redirecting to list] On 04/24/2018 09:42 AM, Erik Martinson wrote: > CHM files have a long history of security issues. Windows blocks them by default. To fix, right-click on the file and go > to properties. In the security section, click the box that says Unblock. > > - Erik -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=gOy942YE0_GEt6R4tBR7vb8LOg2jMs2HyIxsPnSzXJA&s=v4JBVQidjl0E0IJXHgOlwosJo3Sn0HlmyQanu_oaKYE&e= From bgibbeme at us.ibm.com Tue Apr 24 15:47:48 2018 From: bgibbeme at us.ibm.com (Brian Gibbemeyer) Date: Tue, 24 Apr 2018 15:47:48 -0400 Subject: Issue with python365.chm on window 7 In-Reply-To: <9b4854e37767459ba52e72011841a313@activenetwerx.com> References: <5ADF4B8F.6020502@stoneleaf.us> <71e6ec3a47f849b79c2083a01a5d5bfe@activenetwerx.com> <9b4854e37767459ba52e72011841a313@activenetwerx.com> Message-ID: And thank you Joseph as well. Thank you, Brian Gibbemeyer Sr Software Engineer Watson Health - Value Based Care Phone: 1-7349133594 | Mobile: 1-7347258319 E-mail: bgibbeme at us.ibm.com 100 Phoenix Dr Ann Arbor, MI 48108-2202 United States From: "Joseph L. Casale" To: "python-list at python.org" Date: 04/24/2018 03:10 PM Subject: RE: Issue with python365.chm on window 7 Sent by: "Python-list" From: Brian Gibbemeyer Sent: Tuesday, April 24, 2018 12:36 PM To: Joseph L. Casale Cc: python-list at python.org Subject: RE: Issue with python365.chm on window 7 > I right clicked on the file, no option to unblock. Sorry, choose properties, then unblock. -- https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dlist&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=3-xCv_9fHD4qEMBICdrDmpWXQjchU-G2EWkEPa84asc&m=wkVrh9lWm4PAn2tGJLdSc8WoVEYoujGhSqN0zu_UJTE&s=leGl4avLKj-zRfVJg2J2mH48zAHfD1jFACTKmC_AIoY&e= From ethan at stoneleaf.us Tue Apr 24 15:48:54 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 24 Apr 2018 12:48:54 -0700 Subject: Issue with python365.chm on window 7 In-Reply-To: References: <5ADF4B8F.6020502@stoneleaf.us> <1142878159.334079.1524588155972@mail.yahoo.com> <5ADF7F93.4090303@stoneleaf.us> Message-ID: <5ADF8A26.5030904@stoneleaf.us> On 04/24/2018 12:38 PM, Brian Gibbemeyer wrote: > Thank you Ethan,,, that worked. [redirecting thanks to Erik] Thanks, Erik! ;) -- ~Ethan~ From suabiut at gmail.com Tue Apr 24 18:37:25 2018 From: suabiut at gmail.com (sum abiut) Date: Wed, 25 Apr 2018 09:37:25 +1100 Subject: jilian to Gregorian date conversion error Message-ID: Hi, i get the error message: an integer is required when i am try to convert from julian date to Gregorian date in my view.py, after i have query the db i want to convert the applied date from julian date to Gregorian date but i got the above error, convert_date=(datetime.date.fromordinal(rate.columns.date_applied)) sum, From fifii.geral at gmail.com Tue Apr 24 18:57:53 2018 From: fifii.geral at gmail.com (fifii.geral at gmail.com) Date: Tue, 24 Apr 2018 15:57:53 -0700 (PDT) Subject: Minmax tictactoe :c Cannot understand why this does not work Message-ID: <7735ebc7-fc63-40e9-96a9-c7585adea3b7@googlegroups.com> class AiMove: def __init__(self): self.x = -1 self.y=-1 self.score = 0 def Imprimir(Matriz,n): for i in range(n): linea ="|" for j in range(n): if (Matriz[i][j] == 0): linea+=" " elif (Matriz[i][j]==- 1): linea+="X" elif (Matriz[i][j]== 1): linea+="O" linea+="|" print linea print "---------" def Gameover(Matriz,n): #Condicion tablero lleno blancos=0; for i in range(n): contJfilas = 0 contCfilas = 0 contJcol = 0 contCcol = 0 for j in range(n): if(Matriz[i][j]==0): blancos = blancos + 1 if (Matriz[i][j]==1): contCfilas= contCfilas+1 elif(Matriz[i][j]==-1): contJfilas = contJfilas +1 if (Matriz[j][i]==1): contCcol= contCcol +1 elif (Matriz[j][i]==-1): contJcol= contJcol +1 #Condicion 3 en raya en fila o 3 en raya columna if (contJcol==3 or contJfilas ==3): return -1 elif (contCfilas==3 or contCcol ==3): return 1 if blancos == 16: return 2 else: return 0 def getMejorM(Matriz, player,n): rv = Gameover(Matriz,n) if(rv== 1): a = AiMove() a.score = 10 return a elif rv==-1: a = AiMove() a.score = -10 return a elif rv ==2: #Si es empate a = AiMove() return a movimientos = [] for i in range (n): for j in range (n): if(Matriz[i][j] == 0): movimiento = AiMove() movimiento.x = i movimiento.y = j Matriz[i][j] = player if (player == 1): movimiento.score = getMejorM(Matriz, -1,n).score else: movimiento.score = getMejorM(Matriz, 1,n).score movimientos.append(movimiento) Matriz[i][j] = 0 #Escoger auxb = 0 if player==1: mejorscore = -100000 for i in range (len(movimientos)): if movimientos[i].score > mejorscore: auxb= i mejorscore = movimientos[i].score elif player==-1: peorscore = 100000 for i in range (len(movimientos)): if movimientos[i].score < peorscore: auxb= i peorscore = movimientos[i].score #Retornar el mejor movimiento return movimientos[auxb] n=4 Matriz = [[0 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): Matriz[i][j] = 0 Imprimir(Matriz,n) while True: fila = int(raw_input("Ingresa casilla x: "))-1 columna = int(raw_input("Ingresa casilla y: "))-1 if (Matriz[fila][columna] == 0): Matriz[fila][columna] = -1 #Mover(Matriz,n) Imprimir(Matriz,n) bestM = AiMove() bestM = getMejorM(Matriz, 1, n) Matriz[bestM.x][bestM.y] = 1 Imprimir(Matriz,n) if Gameover(Matriz,n) != 0: break print "FIN" From python at mrabarnett.plus.com Tue Apr 24 19:55:39 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 Apr 2018 00:55:39 +0100 Subject: jilian to Gregorian date conversion error In-Reply-To: References: Message-ID: <092a5b37-d6d5-d9a7-879c-0ebba5675eb9@mrabarnett.plus.com> On 2018-04-24 23:37, sum abiut wrote: > Hi, > > i get the error message: > > an integer is required > > when i am try to convert from julian date to Gregorian date > > in my view.py, after i have query the db i want to convert the applied date > from julian date to Gregorian date but i got the above error, > > convert_date=(datetime.date.fromordinal(rate.columns.date_applied)) > > > sum, > datetime.date.fromordinal expects an integer, but the value of rate.columns.date_applied is not an integer. Also, the integer is interpreted as a "proleptic Gregorian ordinal", not a Julian date. From WhoKnows at newsguy.com Tue Apr 24 20:30:17 2018 From: WhoKnows at newsguy.com (Bill) Date: Tue, 24 Apr 2018 20:30:17 -0400 Subject: Minmax tictactoe :c Cannot understand why this does not work In-Reply-To: <7735ebc7-fc63-40e9-96a9-c7585adea3b7@googlegroups.com> References: <7735ebc7-fc63-40e9-96a9-c7585adea3b7@googlegroups.com> Message-ID: You need a good lesson in "program documentation". Your code looks terrible--really! fifii.geral at gmail.com wrote: > class AiMove: > def __init__(self): > self.x = -1 > self.y=-1 > self.score = 0 > > > def Imprimir(Matriz,n): > for i in range(n): > linea ="|" > for j in range(n): > if (Matriz[i][j] == 0): > linea+=" " > elif (Matriz[i][j]==- 1): > linea+="X" > elif (Matriz[i][j]== 1): > linea+="O" > linea+="|" > print linea > > print "---------" > > def Gameover(Matriz,n): > #Condicion tablero lleno > blancos=0; > for i in range(n): > contJfilas = 0 > contCfilas = 0 > contJcol = 0 > contCcol = 0 > for j in range(n): > if(Matriz[i][j]==0): > blancos = blancos + 1 > if (Matriz[i][j]==1): > contCfilas= contCfilas+1 > elif(Matriz[i][j]==-1): > contJfilas = contJfilas +1 > if (Matriz[j][i]==1): > contCcol= contCcol +1 > elif (Matriz[j][i]==-1): > contJcol= contJcol +1 > #Condicion 3 en raya en fila o 3 en raya columna > if (contJcol==3 or contJfilas ==3): > return -1 > elif (contCfilas==3 or contCcol ==3): > return 1 > if blancos == 16: > return 2 > else: > return 0 > > def getMejorM(Matriz, player,n): > rv = Gameover(Matriz,n) > if(rv== 1): > a = AiMove() > a.score = 10 > return a > elif rv==-1: > a = AiMove() > a.score = -10 > return a > > elif rv ==2: #Si es empate > a = AiMove() > return a > > movimientos = [] > for i in range (n): > for j in range (n): > if(Matriz[i][j] == 0): > movimiento = AiMove() > movimiento.x = i > movimiento.y = j > Matriz[i][j] = player > if (player == 1): > movimiento.score = getMejorM(Matriz, -1,n).score > else: > movimiento.score = getMejorM(Matriz, 1,n).score > movimientos.append(movimiento) > Matriz[i][j] = 0 > > #Escoger > auxb = 0 > if player==1: > mejorscore = -100000 > for i in range (len(movimientos)): > if movimientos[i].score > mejorscore: > auxb= i > mejorscore = movimientos[i].score > > elif player==-1: > peorscore = 100000 > for i in range (len(movimientos)): > if movimientos[i].score < peorscore: > auxb= i > peorscore = movimientos[i].score > > #Retornar el mejor movimiento > return movimientos[auxb] > > > > n=4 > Matriz = [[0 for i in range(n)] for j in range(n)] > for i in range(n): > for j in range(n): > Matriz[i][j] = 0 > Imprimir(Matriz,n) > while True: > fila = int(raw_input("Ingresa casilla x: "))-1 > columna = int(raw_input("Ingresa casilla y: "))-1 > if (Matriz[fila][columna] == 0): > Matriz[fila][columna] = -1 > #Mover(Matriz,n) > Imprimir(Matriz,n) > bestM = AiMove() > bestM = getMejorM(Matriz, 1, n) > Matriz[bestM.x][bestM.y] = 1 > Imprimir(Matriz,n) > if Gameover(Matriz,n) != 0: > break > > print "FIN" > > > > > > > > > > > > > > > > > > From suabiut at gmail.com Tue Apr 24 22:43:15 2018 From: suabiut at gmail.com (sum abiut) Date: Wed, 25 Apr 2018 13:43:15 +1100 Subject: jilian to Gregorian date conversion error In-Reply-To: References: <092a5b37-d6d5-d9a7-879c-0ebba5675eb9@mrabarnett.plus.com> Message-ID: Thanks date example is 736788 in julian On Wed, Apr 25, 2018 at 12:34 PM, Dennis Lee Bieber wrote: > On Wed, 25 Apr 2018 00:55:39 +0100, MRAB > declaimed the following: > > > >Also, the integer is interpreted as a "proleptic Gregorian ordinal", not > >a Julian date. > > You didn't provide examples of the dates in question. > > https://en.wikipedia.org/wiki/Conversion_between_Julian_and_ > Gregorian_calendars > > Any date before 1582-10-15 is a "proleptic", since the Gregorian > calendar did not exist in those years. > > https://planetcalc.com/505/ > > https://www.amazon.com/Practical-Astronomy-Calculator-Peter-Duffett- > Smith/dp/0521356997/ref=sr_1_4?ie=UTF8&qid=1524619974&sr=8- > 4&keywords=astronomy+calculator > Has programs for converting between Julian and Gregorian (astronomical > definitions). > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From viakondratiuk at gmail.com Wed Apr 25 01:17:30 2018 From: viakondratiuk at gmail.com (Viacheslav Kondratiuk) Date: Wed, 25 Apr 2018 08:17:30 +0300 Subject: How would you split project into 2 parts? Message-ID: I need to split a project into 2 parts. To have one part as the main project and include the second one as a submodule. Those parts located at different parts of a project. I can see 2 ways how I can do that: 1. Use PyCharm Refactor->Move functionality. It works fine. It takes a module or a package, changes all project imports to a new namespace, sorts those imports according to pep8 (which is not necessary and seems there is no way to disable it). There are 2 problems with this approach: a. If I want to move a module to a new package I have to recreate manually whole dir tree. b. It's too slow. It takes nearly 1 hour to move a package with 11 modules into a new namespace. 2. I wrote a script. It has a mapping from an old_path to a new_path. I extract all namespaces from old_path and replace those with new_path namespaces by iterating over all *.py files from a project. I can use fileinput module to replace namespaces in inplace. And when it's done apply git mv for all specified path. I wonder if there any tool to do that about which I don't know? Do you see any problems with my approach? How would you do that? - Slava From bc at freeuk.com Wed Apr 25 07:12:30 2018 From: bc at freeuk.com (bartc) Date: Wed, 25 Apr 2018 12:12:30 +0100 Subject: Minmax tictactoe :c Cannot understand why this does not work In-Reply-To: <7735ebc7-fc63-40e9-96a9-c7585adea3b7@googlegroups.com> References: <7735ebc7-fc63-40e9-96a9-c7585adea3b7@googlegroups.com> Message-ID: On 24/04/2018 23:57, fifii.geral at gmail.com wrote: > movimientos = [] > for i in range (n): > for j in range (n): ..... > auxb = 0 .... > return movimientos[auxb] What do you mean by 'does not work'? With input of fila=1, and columna=1, I get an error in the last line above. Because movimientos is an empty list, but you are accessing the first element as movimientos[0], because auxb is zero. I don't understand your program (the layout is fine BTW), but you need to debug the logic of it. (Being recursive doesn't help.) Is an empty movimientos allowed at this point or not? Is auxb==0 a legal index here or not? (Tip: I used these lines in the input loop to simply testing rather than having to type them in (as 2 and 2) each time: fila = 1 columna = 1 ) -- bartc From rodacoram8 at gmail.com Wed Apr 25 11:32:42 2018 From: rodacoram8 at gmail.com (Rodrigo Acosta) Date: Wed, 25 Apr 2018 08:32:42 -0700 (PDT) Subject: Determining whether a package or module should be installed globally using pip Message-ID: Is there a rule of thumb in deciding where to install a package? What makes a package, other than security vulnerabilities, better to install globally e.g. using sudo pip install, or by changing directory to tmp folder, or by using virtualenv? Thank you python users, you're my only hope, RAR From p.f.moore at gmail.com Wed Apr 25 12:22:19 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 25 Apr 2018 17:22:19 +0100 Subject: Determining whether a package or module should be installed globally using pip In-Reply-To: References: Message-ID: On 25 April 2018 at 16:32, Rodrigo Acosta wrote: > Is there a rule of thumb in deciding where to install a package? What makes a package, other than security vulnerabilities, better to install globally e.g. using sudo pip install, or by changing directory to tmp folder, or by using virtualenv? Generally, I would say you should *never* use "sudo pip install". The system installed Python is managed by your distribution package manager, and you should only ever make changes to that using vendor supplied packages ("apt-get install python-requests" or whatever the incantation might be). If you're installing packages for a project, virtualenvs are a very good idea. (You can also use higher level tools like pew or pipenv to make management of virtual environments easier). Or if you just want to install packages for your own use in adhoc scripts, etc, then you can install them using "pip install --user" - this will make them available in the system Python without altering system-managed files or directories (note that I *didn't* use sudo!) Hope this helps, Paul From rosuav at gmail.com Wed Apr 25 12:50:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Apr 2018 02:50:25 +1000 Subject: Determining whether a package or module should be installed globally using pip In-Reply-To: References: Message-ID: On Thu, Apr 26, 2018 at 2:22 AM, Paul Moore wrote: > On 25 April 2018 at 16:32, Rodrigo Acosta wrote: >> Is there a rule of thumb in deciding where to install a package? What makes a package, other than security vulnerabilities, better to install globally e.g. using sudo pip install, or by changing directory to tmp folder, or by using virtualenv? > > Generally, I would say you should *never* use "sudo pip install". The > system installed Python is managed by your distribution package > manager, and you should only ever make changes to that using vendor > supplied packages ("apt-get install python-requests" or whatever the > incantation might be). This is the case if your Python was managed by your distribution. If you've installed a different Python (maybe one you built from source), then 'sudo python3 -m pip install' may be appropriate. But yes, for the system Python, use the system package manager. ChrisA From tkadm30 at yandex.com Wed Apr 25 13:21:02 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 25 Apr 2018 13:21:02 -0400 Subject: [ZODB] Multithreaded connection pooling support for ZODB databases? In-Reply-To: <85938779-9d7c-481b-bcbc-cb15c414952a@yandex.com> References: <2d24615f-0fb8-a8a4-2c53-1112d6f82a26@yandex.com> <19a832b9-f926-ffb4-931e-0db639a88026@yandex.com> <85938779-9d7c-481b-bcbc-cb15c414952a@yandex.com> Message-ID: Hi, I would like to know if you could please share some input about this ThreadConnectionPool class for libschevo/ZODB. :) Thanks! Etienne Le 2018-04-20 ? 04:49, Etienne Robillard a ?crit?: > Heads up people! > > I've finally managed to make a working `ThreadedConnectionPool` class > for supporting multiple ZODB databases connections on top of libschevo > API! :) > > Technically, I decided to use gevent.Greenlet under the hood to spawn > multiple cooperative ClientStorage client/server connections. > > I'm also making all my testing and development under PyPy 5.9. > > You can check out the code here: > https://bitbucket.org/tkadm30/libschevo/commits/37feb029615d76f3d81233990e509b6eb6ffb5d7 > > Comments are welcome! :) > > Etienne > > > Le 2018-04-16 ? 18:27, Etienne Robillard a ?crit?: >> Hi Jason, >> >> I just made some more changes to my ThreadedConnectionPool class >> here: >> https://bitbucket.org/tkadm30/django-hotsauce/commits/81d2e8f30019840d9c8bbdf7f82df6de2be024fc >> >> In summary, the `ThreadedConnectionPool` class is now a subclass of >> `threading.Thread` and is extending the `run` method to populate a >> thread local dictionary with ClientStorage connections. >> >> Kind regards, >> >> Etienne >> Le 2018-04-16 ? 09:14, Jason Madden a ?crit?: >>>>>> On Apr 15, 2018, at 8:17 PM, Etienne Robillard >>>>>> wrote: >>>>>> >>>>>> I would like to define a `ThreadedConnectionPoll` class to allow >>>>>> multithreaded caching of ZODB databases into memory. >>> >>> The ZODB.DB object is *already* thread safe for connection >>> management. You shouldn't need to do anything other than use >>> ZODB.DB().open() and conn.close() from all the threads you're using. >>> (That is, create exactly one ZODB.DB object for each database you >>> are using and share that object amongst your threads, using >>> db.open()/conn.close() as needed. For storages like RelStorage that >>> have caches at the ZODB.DB level---which are also thread safe---this >>> is important.) >>> >>> If you are managing multiple databases and want to be able to make >>> references between them (a multiple-database) it is critical that >>> they share the same `databases` object. But that is an advanced usage. >>> >>> >>>> Here's a updated version of my code so far using threading.local : >>>> >>>> from threading import local >>>> from notmm.dbapi.orm import ClientStorageProxy >>>> >>>> class ThreadedConnectionPool(object): >>>> >>>> ???? def __init__(self, d, debug=True): >>>> ???????? if debug: >>>> ???????????? assert isinstance(d, dict) == True >>>> ???????? local.pool = d >>>> ???????? for key,value in local.pool.iteritems(): >>> Unless you left out part of the code, it appears that you're trying >>> to set (and read) a class attribute on the threading.local class. >>> This does not create thread-local state. It is also not portable and >>> doesn't work when local is an extension type: >>> >>> py> from threading import local >>> py> import sys >>> py> sys.version_info # CPython 3.7; same result in 2.7 >>> sys.version_info(major=3, minor=7, micro=0, releaselevel='beta', >>> serial=3) >>> py> local >>> >>> py> local.foo = 1 >>> Traceback (most recent call last): >>> ?? File "", line 1, in >>> TypeError: can't set attributes of built-in/extension type >>> '_thread._local' >>> >>> pypy> sys.version_info # pypy 2 >>> (major=2, minor=7, micro=13, releaselevel='final', serial=42) >>> pypy> from threading import local >>> pypy> local.foo = 1 >>> Traceback (most recent call last): >>> ?? File "", line 1, in >>> TypeError: can't set attributes on type object '_local' >>> >>> It generally also shouldn't be necessary as the parameters to >>> __init__ are preserved and used again in each thread; you can use >>> this to share information if those parameters are mutable: >>> >>> py> from threading import get_ident >>> py> from threading import Thread >>> py> class MyLocal(local): >>> ...???? def __init__(self, l): >>> ...???????? print("Creating in thread", get_ident(), "param", l) >>> ...???????? l.append(get_ident()) >>> ... >>> py> l = [] >>> py> mylocal = MyLocal(l) >>> Creating in thread 140736147411840 param [] >>> py> l >>> [140736147411840] >>> py> def target(): >>> ...???? mylocal.foo = 1 >>> ... >>> py> t = Thread(target=target) >>> py> t.start() >>> Creating in thread 123145538318336 param [140736147411840] >>> None >>> py> l >>> [140736147411840, 123145538318336] >>> >>> Jason >>> >> > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From suabiut at gmail.com Thu Apr 26 00:43:43 2018 From: suabiut at gmail.com (sum abiut) Date: Thu, 26 Apr 2018 15:43:43 +1100 Subject: jilian to Gregorian date conversion error In-Reply-To: References: <092a5b37-d6d5-d9a7-879c-0ebba5675eb9@mrabarnett.plus.com> Message-ID: ok so i have fixed that using the for loop result_proxy=connection.execute(stmt).fetchall() for a in result_proxy: test=datetime.date.fromordinal(int(a.date_applied)) Now if i want to pass a range of date to date_applied above. How to i do that? I know in sql i did did it like this rate.columns.date_applied.between(covert,convert1) where convert and convert1 are the range of date cheers, On Thu, Apr 26, 2018 at 4:47 AM, Dennis Lee Bieber wrote: > On Wed, 25 Apr 2018 13:43:15 +1100, sum abiut > declaimed > the following: > > >Thanks date example is 736788 in julian > > > > Okay... > https://en.wikipedia.org/wiki/Julian_day#Julian_or_ > Gregorian_calendar_from_Julian_day_number > > Using a calculator program based upon Duffett that converts to > > -2695.03205 > > or > midnight, Mar 20, 2696BC > (there is no year 0, so BC dates convert with a 1 year delta... 1BC is > 0.xxx) > > Note that datetime.date.fromordinal() is counting from > Jan 1, 1AD; it > is NOT Julian Day which counts from noon Jan 1, 4713BC > > Treating your number as an ordinal gives > > >>> import datetime > >>> datetime.date.fromordinal(736788) > datetime.date(2018, 4, 4) > >>> > > ... So your original problem is not with the number, per se, but perhaps in > the format it has in > > rate.columns.date_applied > > is there a possibility that is a string field and not numeric? > > >>> st = "736788" > >>> datetime.date.fromordinal(st) > Traceback (most recent call last): > File "", line 1, in > TypeError: an integer is required > >>> datetime.date.fromordinal(736788.0) > Traceback (most recent call last): > File "", line 1, in > TypeError: integer argument expected, got float > >>> import decimal > >>> dc = decimal.Decimal(st) > >>> dc > Decimal('736788') > >>> datetime.date.fromordinal(dc) > datetime.date(2018, 4, 4) > >>> > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > -- > https://mail.python.org/mailman/listinfo/python-list > From flebber.crue at gmail.com Thu Apr 26 01:29:21 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 25 Apr 2018 22:29:21 -0700 (PDT) Subject: Data Integrity Parsing json In-Reply-To: <87vacf6jb8.fsf@nightsong.com> References: <722d0126-4002-4a69-88f6-eacbc55c21aa@googlegroups.com> <87vacf6jb8.fsf@nightsong.com> Message-ID: <12a0a1c1-b098-43aa-8099-8431f71a0039@googlegroups.com> On Thursday, 26 April 2018 07:57:28 UTC+10, Paul Rubin wrote: > Sayth Renshaw writes: > > What I am trying to figure out is how I give myself surety that the > > data I parse out is correct or will fail in an expected way. > > JSON is messier than people think. Here's an article with some > explanation and test code: > > http://seriot.ch/parsing_json.php Thanks Paul there is a lot of good information in that article. Sayth From tartley at gmail.com Thu Apr 26 10:00:54 2018 From: tartley at gmail.com (tartley at gmail.com) Date: Thu, 26 Apr 2018 07:00:54 -0700 (PDT) Subject: After update to pip 10 I get: Cache entry deserialization failed, entry ignored In-Reply-To: <87604pdn9f.fsf@munus.decebal.nl> References: <87604pdn9f.fsf@munus.decebal.nl> Message-ID: <53bd27d9-7ee6-4c21-8401-6066d61feb70@googlegroups.com> On Wednesday, April 18, 2018 at 1:59:14 AM UTC-5, Cecil Westerhof wrote: > After I updated pip2/3 to 10 from 9 I sometimes get: > Cache entry deserialization failed, entry ignored > > For example when I execute: > pip3 list --outdated > > But not always. > > What could be happening here? And how would I solve this? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof It sounds like there's a bug in pip10 that makes the cache entries use a different format for Python2 versus Python3. https://github.com/pypa/pip/issues/5250 So either: * erase your cache directory. On *nix it's ~/.cache/pip. or * run pip with --no-cache-dir or * run pip with --cache-dir=X to set a different cache dir for Python2 vs Python3. or * await a pip10 bugfix? From Cecil at decebal.nl Thu Apr 26 11:25:24 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 26 Apr 2018 17:25:24 +0200 Subject: After update to pip 10 I get: Cache entry deserialization failed, entry ignored References: <87604pdn9f.fsf@munus.decebal.nl> <53bd27d9-7ee6-4c21-8401-6066d61feb70@googlegroups.com> Message-ID: <87efj2j8gr.fsf@munus.decebal.nl> tartley at gmail.com writes: > On Wednesday, April 18, 2018 at 1:59:14 AM UTC-5, Cecil Westerhof wrote: >> After I updated pip2/3 to 10 from 9 I sometimes get: >> Cache entry deserialization failed, entry ignored >> >> For example when I execute: >> pip3 list --outdated >> >> But not always. >> >> What could be happening here? And how would I solve this? >> >> -- >> Cecil Westerhof >> Senior Software Engineer >> LinkedIn: http://www.linkedin.com/in/cecilwesterhof > > It sounds like there's a bug in pip10 that makes the cache entries use a different format for Python2 versus Python3. > https://github.com/pypa/pip/issues/5250 I have seen that, but that did not work in my case. > So either: > > * erase your cache directory. On *nix it's ~/.cache/pip. That would make the usage of cache superfluous and I am wondering if that is really the issue. See reply below. > or > > * run pip with --no-cache-dir Tried this, but it did not work. > or > > * run pip with --cache-dir=X to set a different cache dir for Python2 vs Python3. > > or > > * await a pip10 bugfix? For the moment I do in my (tcl) script: while {[catch ${command} errorStr opts]} { incr errors if {${debug}} { puts ------------------------------------------------------------ puts ${opts} puts ------------------------------------------------------------ } if {${errors} >= ${maxTries}} { error "Could not get ${pip} information with ${errors} tries" } } There is not always a problem and if there is a problem it is never more as once. (Till now.) I use command because I do it for pip2 and pip3. It is filled with: # First 2 lines are a header set command {set outdated \ [lrange \ [split [exec ${pip} list --outdated] \n] \ 2 end]} And pip is pip2 or pip3. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From skip.montanaro at gmail.com Thu Apr 26 11:37:50 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 26 Apr 2018 10:37:50 -0500 Subject: detect laptop open/close from within Python? Message-ID: I'm going through a bout of RSI problems with my wrists, so klst night I refreshed an old typing watcher program I wrote a couple decades ago (there's a comment about Python 1.4 in the code!): https://github.com/smontanaro/python-bits/blob/master/watch.py It's far from perfect and I'm sure miles behind more modern stuff, but it does the trick for me. I noticed a feww minutes ago that when I opened my laptop it immediately locked the screen. It would be nice to get notified of open/close events on the laptop. Any idea if there is a signal I can catch (Ubuntu 17.10) or a Tk event I can respond to? Thx, Skip From rosuav at gmail.com Thu Apr 26 11:49:23 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Apr 2018 01:49:23 +1000 Subject: detect laptop open/close from within Python? In-Reply-To: References: Message-ID: On Fri, Apr 27, 2018 at 1:37 AM, Skip Montanaro wrote: > I'm going through a bout of RSI problems with my wrists, so klst night > I refreshed an old typing watcher program I wrote a couple decades ago > (there's a comment about Python 1.4 in the code!): > > https://github.com/smontanaro/python-bits/blob/master/watch.py > > It's far from perfect and I'm sure miles behind more modern stuff, but > it does the trick for me. > > I noticed a feww minutes ago that when I opened my laptop it > immediately locked the screen. It would be nice to get notified of > open/close events on the laptop. Any idea if there is a signal I can > catch (Ubuntu 17.10) or a Tk event I can respond to? > No idea if it'll work on your system, but on my laptop, there's a pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid is open or closed. ChrisA From alister.ware at ntlworld.com Thu Apr 26 12:08:25 2018 From: alister.ware at ntlworld.com (Alister) Date: Thu, 26 Apr 2018 16:08:25 GMT Subject: Data Integrity Parsing json References: <722d0126-4002-4a69-88f6-eacbc55c21aa@googlegroups.com> Message-ID: On Wed, 25 Apr 2018 14:32:01 -0700, Sayth Renshaw wrote: > Hi > > Hoping for guidance trying to find some advanced articles or guides or > topics for json parsing. > > I can parse and extract json just dandy. > > What I am trying to figure out is how I give myself surety that the data > I parse out is correct or will fail in an expected way. > > All the articles I search are just basic parsing tutorials. > > Can you help with some advice or perhaps some saved away bookmarks you > have that could be useful. > > Cheers > > Sayth is there any reason you appear to be re-inventing the wheel rather than using the existing json module from the std library? -- "Well, if you can't believe what you read in a comic book, what *___can* you believe?!" -- Bullwinkle J. Moose [Jay Ward] From skip.montanaro at gmail.com Thu Apr 26 12:22:56 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 26 Apr 2018 11:22:56 -0500 Subject: detect laptop open/close from within Python? In-Reply-To: References: Message-ID: > No idea if it'll work on your system, but on my laptop, there's a > pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid > is open or closed. Thanks, I do have that. Now to figure out when it changes state... Unfortunately, the timestamp on the file seems to update continuously, not just on state changes. Maybe /proc/acpi/wakeup will be of some use. Skip From skip.montanaro at gmail.com Thu Apr 26 13:03:17 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 26 Apr 2018 12:03:17 -0500 Subject: detect laptop open/close from within Python? In-Reply-To: References: Message-ID: > Thanks, I do have that. Now to figure out when it changes state... > Unfortunately, the timestamp on the file seems to update continuously, > not just on state changes. Maybe /proc/acpi/wakeup will be of some > use. It appears that I can, at least some of the time. Might need to check it more frequently than I check for human input, but that will likely be good enough for my needs. Thanks again for the pointer. Skip From tjol at tjol.eu Thu Apr 26 13:06:24 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 26 Apr 2018 19:06:24 +0200 Subject: detect laptop open/close from within Python? In-Reply-To: References: Message-ID: <1e21e19a-eec5-9860-5d57-4d0767c50d2c@tjol.eu> On 26/04/18 17:37, Skip Montanaro wrote: > I'm going through a bout of RSI problems with my wrists, so klst night > I refreshed an old typing watcher program I wrote a couple decades ago > (there's a comment about Python 1.4 in the code!): > > https://github.com/smontanaro/python-bits/blob/master/watch.py > > It's far from perfect and I'm sure miles behind more modern stuff, but > it does the trick for me. > > I noticed a feww minutes ago that when I opened my laptop it > immediately locked the screen. It would be nice to get notified of > open/close events on the laptop. Any idea if there is a signal I can > catch (Ubuntu 17.10) or a Tk event I can respond to? I think there's a dbus event that you should be able to listen for (but I'll let you do the googling as to what that event is, exactly) From vs at it.uu.se Thu Apr 26 14:33:17 2018 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 26 Apr 2018 20:33:17 +0200 Subject: Installation of tensorflow via pip -- messages? Message-ID: First I upgraded my pip *C:\Python36>python -m pip install --upgrade pip* Collecting pip ? Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB) ??? 100% |????????????????????????????????| 1.3MB 685kB/s Installing collected packages: pip ? Found existing installation: pip 9.0.3 ??? Uninstalling pip-9.0.3: ????? Successfully uninstalled pip-9.0.3 Successfully installed pip-10.0.1 Then I upgraded tensorflow *C:\Python36>python -m pip install --upgrade tensorflow* ... ... ... The script tensorboard.exe is installed in 'C:\Python36\Scripts' which is not on PATH. ? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. ... ... The scripts freeze_graph.exe, saved_model_cli.exe, tensorboard.exe, toco.exe and toco_from_protos.exe are installed in 'C:\Python36\Scripts' which is not on PATH. ? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. However, this directory is in my PATH *C:\Python36>path* PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Python36\Scripts\;C:\Python36\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\; ... ... Why am I getting this message, that I need to consider adding this directory to PATH when it is already in PATH? Note, all of these *.exe files are in C:\Python36\Scripts. From p.f.moore at gmail.com Thu Apr 26 14:52:08 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 26 Apr 2018 19:52:08 +0100 Subject: Installation of tensorflow via pip -- messages? In-Reply-To: References: Message-ID: On 26 April 2018 at 19:33, Virgil Stokes wrote: > Why am I getting this message, that I need to consider adding this directory > to PATH when it is already in PATH? > Note, all of these *.exe files are in C:\Python36\Scripts. The PATH entry ends with a backslash, which is confusing the check done by pip. It's a known issue and has been fixed in the development version of pip, so it'll be resolved in the next release. In the meantime, you can either remove the redundant trailing backslash from your PATH, or just ignore the warning. Paul From vs at it.uu.se Thu Apr 26 15:04:09 2018 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 26 Apr 2018 21:04:09 +0200 Subject: Installation of tensorflow via pip -- messages? In-Reply-To: References: Message-ID: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> Thanks Paul for the prompt reply, However, each entry in this Windows 10 path has a trailing backslash. If my memory is correct, this is the default for path directories. IMHO it would have been useful to have "warning" somewhere in these messages. On 2018-04-26 20:52, Paul Moore wrote: > On 26 April 2018 at 19:33, Virgil Stokes wrote: >> Why am I getting this message, that I need to consider adding this directory >> to PATH when it is already in PATH? >> Note, all of these *.exe files are in C:\Python36\Scripts. > The PATH entry ends with a backslash, which is confusing the check > done by pip. It's a known issue and has been fixed in the development > version of pip, so it'll be resolved in the next release. In the > meantime, you can either remove the redundant trailing backslash from > your PATH, or just ignore the warning. > > Paul From p.f.moore at gmail.com Thu Apr 26 15:31:33 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 26 Apr 2018 20:31:33 +0100 Subject: Installation of tensorflow via pip -- messages? In-Reply-To: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> References: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> Message-ID: On 26 April 2018 at 20:04, Virgil Stokes wrote: > IMHO it would have been useful to have "warning" somewhere in these > messages. Ha, I'd never even noticed that it didn't... I think it's in a different colour, FWIW, but your point is good. Paul From tjreedy at udel.edu Thu Apr 26 16:18:13 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Apr 2018 16:18:13 -0400 Subject: Installation of tensorflow via pip -- messages? In-Reply-To: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> References: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> Message-ID: On 4/26/2018 3:04 PM, Virgil Stokes wrote: > However, each entry in this Windows 10 path has a trailing backslash. Some do, and some don't, which is the same on my Win10 > If my memory is correct, this is the default for path directories. The Python entries do, as added by the Windows Installer written by a Microsoft engineer, so this must at least be a correct alternative. -- Terry Jan Reedy From storchaka at gmail.com Thu Apr 26 16:22:06 2018 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 26 Apr 2018 23:22:06 +0300 Subject: Improving syntax error messages Message-ID: What syntax errors did you see most often? Which of them looks the most weird? How would you like to improve their messages. From p.f.moore at gmail.com Thu Apr 26 17:23:42 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 26 Apr 2018 22:23:42 +0100 Subject: Installation of tensorflow via pip -- messages? In-Reply-To: References: <226cfa2e-5193-ed36-cfce-cce34d57fa1e@it.uu.se> Message-ID: On 26 April 2018 at 21:18, Terry Reedy wrote: >> If my memory is correct, this is the default for path directories. > > The Python entries do, as added by the Windows Installer written by a > Microsoft engineer, so this must at least be a correct alternative. It's definitely acceptable - there's no doubt the pip 10.0.1 behaviour is a bug (that's been fixed). No-one is arguing otherwise. The suggestion to remove the backslashes was nothing more than a workaround that can be used until the next release of pip. Paul From tjreedy at udel.edu Thu Apr 26 20:56:14 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Apr 2018 20:56:14 -0400 Subject: Improving syntax error messages In-Reply-To: References: Message-ID: On 4/26/2018 4:22 PM, Serhiy Storchaka wrote: > What syntax errors did you see most often? Which of them looks the most > weird? How would you like to improve their messages. One way to research this would be to search stackoverflow.com for "[python] SyntaxError". There are currently 8142 results, and they can be sorted newest first. The general 'invalid syntax' message must be most common, and perhaps is the most puzzling. -- Terry Jan Reedy From jimbo1qaz at gmail.com Fri Apr 27 00:06:23 2018 From: jimbo1qaz at gmail.com (jimbo1qaz) Date: Thu, 26 Apr 2018 21:06:23 -0700 Subject: setuptools setup.py commands are unintuitive and undiscoverable (--help-commands should replace --help) Message-ID: Frequently I have encountered projects packaged using setuptools, with a setup.py. To find out how to install it, I usually turned to Stack Overflow (https://stackoverflow.com/a/1472014) which doesn't explain what options exist or do. Surprisingly, neither "setup.py" nor "setup.py --help" doesn't provide a list of options either, instead telling you how to show various metadata options which are not useful to end users of the software project, trying to build/install it. Instead, to show a list of useful actions a user can perform, you need to use "setup.py --help-commands", which I only discovered several years after starting to use Python. Why isn't this command enabled by default (called without arguments, or with --help). https://imgur.com/a/HF4Iw6D From sjsumitj at gmail.com Fri Apr 27 03:47:45 2018 From: sjsumitj at gmail.com (Sum) Date: Fri, 27 Apr 2018 13:17:45 +0530 Subject: How to add values from test steps in pytest excel report Message-ID: Hi, I am using python 2.7 and pytest version 3.2.1 I am using pytest excel plugin to run the pytest and generate test report in excel format. Step to install pytest excel : pip install pytest-excel I am running my pytest test using below : py.test --excelreport=report.xls e_test.py Output Test report excel format : SUITE NAME TEST NAME DESCRIPTION RESULT DURATION MESSAGE FILE NAME MARKERSTestSumFlow test_step1 PASSED 15.24737811 e_test.py My query is that I want to display the values from my corresponding test steps in pytest. e.g. if my test step is following, then how do I display the output of test_step1 "newNum" in the excel report. def test_step1(fNum, sNum): newNum = fNum - sNum print newNum Regards, Sumit From vijithmp87 at gmail.com Fri Apr 27 04:02:59 2018 From: vijithmp87 at gmail.com (VijithNambiar) Date: Fri, 27 Apr 2018 13:32:59 +0530 Subject: =?UTF-8?Q?Fwd=3A_Reporting_Documentation_Bug_in_Documentation_=C2=BB?= =?UTF-8?Q?_The_Python_Tutorial_=C2=BB6=2EModules?= In-Reply-To: References: Message-ID: Hi I think there is a bug in the section https://docs.python.org/3/ tutorial/modules.html#more-on-modules where the outputs of the statements below is given as wrong as it is starting with a '0' >>> import fibo as fib>>> fib.fib(500)0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 >>> import fibo as fib>>> fib.fib(500)0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 From frank at chagford.com Fri Apr 27 04:21:24 2018 From: frank at chagford.com (Frank Millman) Date: Fri, 27 Apr 2018 10:21:24 +0200 Subject: Question about Decimal and rounding Message-ID: Hi all I have an object which represents a Decimal type. It can receive input from various sources. It has to round the value to a particular scale factor before storing it. The scale factor can vary, so it has to be looked up every time, which is a slight overhead. I thought I could speed it up a bit by checking first to see if the value has any decimal places. If not, I can skip the scaling routine. This is how I do it - s = str(value) if '.' in s: int_portion, dec_portion = s.split('.') is_integer = (int(int_portion) == value) else: is_integer = True It assumes that the value is in the form iii.ddd or just iii. Today I found the following value - -1.4210854715202004e-14 which does not match my assumption. It happens to work, but I don't understand enough about the notation to know if this is reliable, or if there are any corner cases where my test would fail. I suspect that my test is a case of premature optimisation, and that I might as well just scale the value every time. Still, I would be interested to know if this could be a problem, or if there is a better way to do what I want. Thinking aloud, maybe this is a better test - is_integer = (value == value.quantize(0)) Thanks Frank Millman From tjol at tjol.eu Fri Apr 27 05:26:35 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 27 Apr 2018 11:26:35 +0200 Subject: setuptools setup.py commands are unintuitive and undiscoverable (--help-commands should replace --help) In-Reply-To: References: Message-ID: <897a4971-61e5-a980-3c26-92702bb7f0e3@tjol.eu> On 27/04/18 06:06, jimbo1qaz wrote: > Frequently I have encountered projects packaged using setuptools, with a > setup.py. To find out how to install it, I usually turned to Stack Overflow > (https://stackoverflow.com/a/1472014) which doesn't explain what options > exist or do. > > Surprisingly, neither "setup.py" nor "setup.py --help" doesn't provide a > list of options either, instead telling you how to show various metadata > options which are not useful to end users of the software project, trying > to build/install it. > > Instead, to show a list of useful actions a user can perform, you need to > use "setup.py --help-commands", which I only discovered several years after > starting to use Python. Why isn't this command enabled by default (called > without arguments, or with --help). > > https://imgur.com/a/HF4Iw6D > Sure, setuptools has a lot of weird historical quirks, but the help message? That looks fine to me. It *starts* by telling you about setup.py install and setup.py build. The only command most users will ever need is listed clearly in the *third* line of the --help message. How do you get any more discoverable than that? There are other specialised commands, but those are mostly useful for maintainers and some sysadmins. (and --help-commands is referenced in the *first* line of the --help message) Most of the time, you should just be installing things with pip anyway. Most packages are on the PyPI, and even where they're not, pip can install directly from source tarballs and git repositories. -- Thomas From tjol at tjol.eu Fri Apr 27 05:49:57 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 27 Apr 2018 11:49:57 +0200 Subject: Question about Decimal and rounding In-Reply-To: References: Message-ID: <19223891-2006-d496-bdfe-32776834e318@tjol.eu> On 27/04/18 10:21, Frank Millman wrote: > Hi all > > I have an object which represents a Decimal type. > > It can receive input from various sources. It has to round the value to > a particular scale factor before storing it. The scale factor can vary, > so it has to be looked up every time, which is a slight overhead. I > thought I could speed it up a bit by checking first to see if the value > has any decimal places. If not, I can skip the scaling routine. > > This is how I do it - > > ?? s = str(value) > ?? if '.' in s: > ?????? int_portion, dec_portion = s.split('.') > ?????? is_integer = (int(int_portion) == value) > ?? else: > ?????? is_integer = True > > It assumes that the value is in the form iii.ddd or just iii. Today I > found the following value - > > ?? -1.4210854715202004e-14 > > which does not match my assumption. > > It happens to work, but I don't understand enough about the notation to > know if this is reliable, or if there are any corner cases where my test > would fail. This is not reliable. Decimal is happy to give you integers in scientific notation if this is needed to keep track of the number of significant digits. >>> str(Decimal('13.89e2')) '1389' >>> str(Decimal('13.89e3')) '1.389E+4' >>> Decimal('13.89e3') == 13890 True It appears to me that the "obvious" way to check whether a Decimal number is an integer is simply: >>> d1 = Decimal('1.1') >>> d2 = Decimal('3') >>> int(d1) == d1 False >>> int(d2) == d2 True Final thoughts: * Beware of spending too much time on premature optimisations that you might not need. * Are you *absolutely* sure that you can *always* skip your rounding step for all integers? There's *no* risk of this optimisation ruining some future dataset? -- Thomas From zljubisic at gmail.com Fri Apr 27 09:50:41 2018 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Fri, 27 Apr 2018 06:50:41 -0700 (PDT) Subject: Passing all pandas DataFrame columns to function as separate parameters Message-ID: <477a8f26-fbcb-449b-bdd5-1a54573ba1de@googlegroups.com> Hi, I have pandas DataFrame with several columns. I have to pass all columns as separate parameter to a function. Something like this if I have 4 columns. f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 2], df_piv.iloc[:, 3]) As number of columns varies, how to do it in the most efficient way? Regards. From frank at chagford.com Fri Apr 27 09:51:14 2018 From: frank at chagford.com (Frank Millman) Date: Fri, 27 Apr 2018 15:51:14 +0200 Subject: Question about Decimal and rounding In-Reply-To: <19223891-2006-d496-bdfe-32776834e318@tjol.eu> References: <19223891-2006-d496-bdfe-32776834e318@tjol.eu> Message-ID: "Thomas Jollans" wrote in message news:19223891-2006-d496-bdfe-32776834e318 at tjol.eu... > On 27/04/18 10:21, Frank Millman wrote: > > > I have an object which represents a Decimal type. > > > > It can receive input from various sources. It has to round the value to > > a particular scale factor before storing it. The scale factor can vary, > > so it has to be looked up every time, which is a slight overhead. I > > thought I could speed it up a bit by checking first to see if the value > > has any decimal places. If not, I can skip the scaling routine. > > > > This is how I do it - > > > > s = str(value) > > if '.' in s: > > int_portion, dec_portion = s.split('.') > > is_integer = (int(int_portion) == value) > > else: > > is_integer = True > > > > It assumes that the value is in the form iii.ddd or just iii. Today I > > found the following value - > > > > -1.4210854715202004e-14 > > > > which does not match my assumption. > > > > It happens to work, but I don't understand enough about the notation to > > know if this is reliable, or if there are any corner cases where my test > > would fail. > > This is not reliable. Decimal is happy to give you integers in > scientific notation if this is needed to keep track of the number of > significant digits. > > >>> str(Decimal('13.89e2')) > '1389' > >>> str(Decimal('13.89e3')) > '1.389E+4' > >>> Decimal('13.89e3') == 13890 > True > > It appears to me that the "obvious" way to check whether a Decimal > number is an integer is simply: > > >>> d1 = Decimal('1.1') > >>> d2 = Decimal('3') > >>> int(d1) == d1 > False > >>> int(d2) == d2 > True > Thanks, Thomas - makes perfect sense. I have been burned before by - >>> int('1.1') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1.1' so I did not think of trying - >>> int(Decimal('1.1')) 1 but it works just fine. Frank From tjol at tjol.eu Fri Apr 27 10:18:24 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 27 Apr 2018 16:18:24 +0200 Subject: Passing all pandas DataFrame columns to function as separate parameters In-Reply-To: <477a8f26-fbcb-449b-bdd5-1a54573ba1de@googlegroups.com> References: <477a8f26-fbcb-449b-bdd5-1a54573ba1de@googlegroups.com> Message-ID: <3ed51a3f-d90f-a16d-aca1-d8bf682aa1cf@tjol.eu> On 27/04/18 15:50, zljubisic at gmail.com wrote: > Hi, > > I have pandas DataFrame with several columns. I have to pass all columns as separate parameter to a function. > > Something like this if I have 4 columns. > > f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 2], df_piv.iloc[:, 3]) > > As number of columns varies, how to do it in the most efficient way? You could get the DataFrame as a 2d array (df.values) and work from there: func(*df.values.T) Of course, this is completely unreadable, and it has another problem: if your columns have different types, this will cast some or all of your columns to a different type. It's probably clearer if you start with the column labels: func(*(df.loc[:,col] for col in df.columns)) or use df.items(): func(*(values for col, values in df.items())) -- Thomas From rshepard at appl-ecosys.com Fri Apr 27 13:34:27 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 27 Apr 2018 10:34:27 -0700 (PDT) Subject: Understanding pdb result Message-ID: Running python3-3.6.5 and wxPython-4.0.1 on Slackware-14.2. The module begins this way: #!/usr/bin/env python3 import sys, os import pdb import wx When pdb is invoked and I step through the code I get these results: $ python3 -m pdb openEDMS.py > /home/rshepard/development/openEDMS/openEDMS.py(8)() -> """ (Pdb) s > /home/rshepard/development/openEDMS/openEDMS.py(10)() -> import sys, os (Pdb) s > /home/rshepard/development/openEDMS/openEDMS.py(11)() -> import pdb (Pdb) > /home/rshepard/development/openEDMS/openEDMS.py(12)() -> import wx (Pdb) --Call-- > (966)_find_and_load() (Pdb) My web search suggests that I need to import importlib, but doing so does not change the results. Please pass me a pointer to a resource that teaches me how to avoid this error. TIA, Rich From steve+comp.lang.python at pearwood.info Fri Apr 27 19:58:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 27 Apr 2018 23:58:19 +0000 (UTC) Subject: Understanding pdb result References: Message-ID: On Fri, 27 Apr 2018 10:34:27 -0700, Rich Shepard wrote: > Running python3-3.6.5 and wxPython-4.0.1 on Slackware-14.2. > > The module begins this way: > > #!/usr/bin/env python3 > > import sys, os > import pdb > import wx [...] > Please pass me a pointer to a resource that teaches me how to avoid > this error. What error are you referring to? Why are you using pdb in the first place? If you're getting an error, the first thing to do is read the traceback. If you're getting a traceback, tell us what it is. Don't paraphrase it, copy and paste it. If you're not getting a traceback, please explain why you think you need to use pdb and what error you think you are getting, because I have no clue. -- Steve From ejmmanning at gmail.com Sat Apr 28 00:04:49 2018 From: ejmmanning at gmail.com (Ed Manning) Date: Fri, 27 Apr 2018 21:04:49 -0700 (PDT) Subject: I need help with this python regex Message-ID: <7981efb5-6705-4042-a70d-831c5570c524@googlegroups.com> Here is the source code. import re log = open("csg.txt", "r") # Opens a file call session.txt regex = re.compile(r'policy id \d+') # search for the policy ID regex1 = re.compile(r'log count \d+') # search for the policy ID for match in log: x = regex.findall(match) y = regex1.findall(match) q = x + y print(q) The problem I am having i when it print out ti looks like this L'Policy ID 243"| [] [] [] [] [] [] [] [] {'log count 777,"] How so I fix the code sone that it does not print empty [] Here so to the test file get policy id 243 name:"csg to wes" (id 243), zone csg -> fwc,action Permit, status "enabled" 10 sources: "206.221.59.229", "206.221.59.246/32", "csg_205.144.151.107/32", "csg_205.144.151.177/32", "csg_205.144.151.24/32", "csg_205.144.152.50/32", "csg_205.144.153.55/32", "csg_206.221.59.244/32", "csg_206.221.59.250/32", "csg_206.221.61.29/32" 19 destinations: "MIP(204.235.119.135)", "MIP(204.235.119.136)", "MIP(204.235.119.243)", "MIP(204.235.119.34)", "MIP(204.235.119.39)", "MIP(204.235.119.40)", "MIP(204.235.119.41)", "MIP(204.235.119.42)", "MIP(204.235.119.43)", "MIP(204.235.119.44)", "MIP(204.235.119.45)", "MIP(204.235.119.46)", "MIP(204.235.119.47)", "MIP(204.235.119.50)", "MIP(204.235.119.51)", "MIP(204.235.119.52)", "MIP(204.235.119.79)", "MIP(204.235.119.82)", "MIP(204.235.119.83)" 1 service: "ANY" Rules on this VPN policy: 0 nat off, Web filtering : disabled vpn unknown vpn, policy flag 00010000, session backup: on traffic shaping off, scheduler n/a, serv flag 00 log close, log count 777, alert no, counter yes(79) byte rate(sec/min) 0/0 total octets 0, counter(session/packet/octet) 0/0/79 priority 7, diffserv marking Off tadapter: state off, gbw/mbw 0/0 policing (no) No Authentication No User, User Group or Group expression se get policy id 602 name:"ID 36129" (id 602), zone csg -> fwc,action Permit, status "enabled" src "csg_205.144.151.107/32", dst "MIP(204.235.119.191)", serv "ANY" Rules on this VPN policy: 0 nat off, Web filtering : disabled vpn unknown vpn, policy flag 00010000, session backup: on traffic shaping off, scheduler n/a, serv flag 00 log close, log count 0, alert no, counter yes(80) byte rate(sec/min) 0/0 total octets 0, counter(session/packet/octet) 0/0/80 priority 7, diffserv marking Off tadapter: state off, gbw/mbw 0/0 policing (no) No Authentication No User, User Group or Group expression set csg-vx-fw-n-12:csg-vx-fw-n-01(M)-> get policy id 420 name:"ID 12637" (id 420), zone csg -> fwc,action Permit, status "enabled" 1 source: "csg_204.235.119.78/32" 1 destination: "eg_csg" 6 services: "PING", "tcp_30001-30100", "tcp_6051-6055", "tcp_7041-7091", "TELNET", "TRACEROUTE" Rules on this VPN policy: 0 nat off, Web filtering : disabled vpn unknown vpn, policy flag 00010000, session backup: on traffic shaping off, scheduler n/a, serv flag 00 log close, log count 0, alert no, counter yes(81) byte rate(sec/min) 0/0 total octets 0, counter(session/packet/octet) 0/0/81 priority 7, diffserv marking Off tadapter: state off, gbw/mbw 0/0 policing (no) No Authentication No User, User Group or Group expression set From hjp-python at hjp.at Sat Apr 28 02:55:28 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 28 Apr 2018 08:55:28 +0200 Subject: I need help with this python regex In-Reply-To: <7981efb5-6705-4042-a70d-831c5570c524@googlegroups.com> References: <7981efb5-6705-4042-a70d-831c5570c524@googlegroups.com> Message-ID: <20180428065528.arw45snagskzhp3t@hjp.at> On 2018-04-27 21:04:49 -0700, Ed Manning wrote: > Here is the source code. > > > import re > > > log = open("csg.txt", "r") # Opens a file call session.txt > regex = re.compile(r'policy id \d+') # search for the policy ID > regex1 = re.compile(r'log count \d+') # search for the policy ID > > for match in log: > x = regex.findall(match) > y = regex1.findall(match) > > q = x + y > print(q) > > > The problem I am having i when it print out ti looks like this > > > L'Policy ID 243"| > [] > [] > [] > [] > [] > [] > [] > [] > {'log count 777,"] > > > > How so I fix the code sone that it does not print empty [] Print the result only if findall actually found something. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From rshepard at appl-ecosys.com Sat Apr 28 10:40:12 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 28 Apr 2018 07:40:12 -0700 (PDT) Subject: Understanding pdb result In-Reply-To: References: Message-ID: On Fri, 27 Apr 2018, Steven D'Aprano wrote: > What error are you referring to? Steven, The menu does not display, only the frame and status bar. > Why are you using pdb in the first place? Because it is a debugger that allows me to process code line-by-line and works with Python3. > If you're getting an error, the first thing to do is read the traceback. > If you're getting a traceback, tell us what it is. Don't paraphrase it, > copy and paste it. There is no traceback. Had there been I would have been able to find the problem. > If you're not getting a traceback, please explain why you think you need > to use pdb and what error you think you are getting, because I have no > clue. See attached test.py. Rich -------------- next part -------------- #!/usr/bin/env python3 import wx #!/usr/bin/env python3 import sys, os, importlib import pdb import wx import wx.grid import sqlalchemy class MainFrame(wx.Frame): def __init__(self, parent, title='test'): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title = title, size=wx.Size(800,600), style=wx.DEFAULT_FRAME_STYLE) self.SetSizeHints(minSize=wx.Size(300,200), maxSize=wx.Size(900,700), incSize=wx.Size(50,50)) # Create status bar self.CreateStatusBar() self.SetStatusText("This is where you'll see helpful messages") # Prepare the menu bar menuBar = wx.MenuBar() # 1st menu from left (File) fileMenu = wx.Menu() fileMenu.Append(wx.ID_NEW, '&New', 'Create new file') fileMenu.Append(wx.ID_OPEN, '&Open', 'Open existing file') fileMenu.Append(wx.ID_SAVE, '&Save', 'Save this file') fileMenu.Append(wx.ID_SAVEAS, 'S&ave as ...', 'Save file with different name') fileMenu.Append(105, '&Import', 'Import a file') fileMenu.Append(106, '&Export', 'Export this file') fileMenu.Append(wx.ID_CLOSE, '&Quit', 'Quit') # Add menu to menu bar menuBar.Append(fileMenu, '&File') if __name__ == '__main__': edms = wx.App() top = MainFrame(None, 'test') top.Show() edms.MainLoop() From rshepard at appl-ecosys.com Sat Apr 28 11:33:46 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 28 Apr 2018 08:33:46 -0700 (PDT) Subject: Understanding pdb result [RESOLVED] In-Reply-To: References: Message-ID: On Sat, 28 Apr 2018, Rich Shepard wrote: > The menu does not display, only the frame and status bar. Fixed the problem: I had neglected to attach the menu bar to the frame. Mea culpa! Rich From mal at europython.eu Sun Apr 29 05:02:59 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 29 Apr 2018 11:02:59 +0200 Subject: EuroPython 2018: Website Launched Message-ID: We are excited to announce the launch of the EuroPython 2018 website: * https://ep2018.europython.eu/ * The EuroPython conference will take place in Edinburgh, UK, this year, from July 23 - 29. EuroPython 2018 - The European Python Conference ------------------------------------------------ Here?s an overview of what you can expect in Edinburgh: * We will start with the Workshops and the Trainings on Monday and Tuesday, July 23-24. * The main 3 conference day follow, packed with keynotes, talks, helpdesks, panels and open space sessions. * A complete PyData EuroPython 2018 will be included as well. * The two weekend days after the conference, July 28 and 29, are reserved for sprints. Overall, we will again have 7 days worth of great Python content, arranged in over 120 sessions, waiting for you. In short: * Monday, Tuesday, July 23-24: Workshops and Trainings and Beginners? Day * Wednesday - Friday, July 25-27: Main Conference with talks, keynotes, exhibit, panels, posters, helpdesks and open sessions. * Saturday, Sunday, July 28-29: Sprints. Meet our launch sponsors ------------------------ All this would not be possible without the generous help of our launch sponsors: * Smarkets * Datadog * Intel * Jetbrains * numberly / 1000mercis In the coming days, we will provide you with more information and announce the start of the Call for Proposals and Early Bird Ticket sales. Please watch our EuroPython blog for updates. Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/990509930426880005 Thanks. From suabiut at gmail.com Sun Apr 29 19:05:43 2018 From: suabiut at gmail.com (sum abiut) Date: Mon, 30 Apr 2018 10:05:43 +1100 Subject: jilian to Gregorian date conversion error In-Reply-To: <4659edt2o9g3fkgrvajgjlkrlv7kgt7cqv@4ax.com> References: <092a5b37-d6d5-d9a7-879c-0ebba5675eb9@mrabarnett.plus.com> <4659edt2o9g3fkgrvajgjlkrlv7kgt7cqv@4ax.com> Message-ID: Hi Dennnis, Thank you for your email. My issue is i what to be able to display the rage of date base on the start and end date that was selected but i don't know how to do that. when i did a for look from my template for example. {%for a in result_proxy%} {{a.date_applied}} {%endfor%} i was able to display the range of dates but its is julian date but i don't want the dates to be in julian dates. I want the dates to be in a gregorian date where by the end users can understand it. Which is why i was trying to convert that from my view.py before passing the the parameter to the template. appreciate any assistances. cheers, On Sun, Apr 29, 2018 at 2:39 AM, Dennis Lee Bieber wrote: > On Thu, 26 Apr 2018 15:43:43 +1100, sum abiut > declaimed > the following: > > >ok so i have fixed that using the for loop > > > >result_proxy=connection.execute(stmt).fetchall() > > for a in result_proxy: > > test=datetime.date.fromordinal(int(a.date_applied)) > > > > > >Now if i want to pass a range of date to date_applied above. How to i do > that? > > > >I know in sql i did did it like this > >rate.columns.date_applied.between(covert,convert1) > > > >where convert and convert1 are the range of date > > You are now getting into basic logic and algorithm design -- which > is > not something specific to Python. > > Since I don't have access to the database schema, nor most of the > surrounding code, I can only brute force a solution... It would probably be > better to modify the SQL "stmt" to only return the desired entries but... > > > ... > for a in r_p: > ada = int(a.date_applied) > if convert <= ada <= convert1: > ... > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From george at fischhof.hu Mon Apr 30 05:09:45 2018 From: george at fischhof.hu (George Fischhof) Date: Mon, 30 Apr 2018 11:09:45 +0200 Subject: How to add values from test steps in pytest excel report In-Reply-To: References: Message-ID: On 27 Apr 2018 9:49 am, "Sum" wrote: Hi, I am using python 2.7 and pytest version 3.2.1 I am using pytest excel plugin to run the pytest and generate test report in excel format. Step to install pytest excel : pip install pytest-excel I am running my pytest test using below : py.test --excelreport=report.xls e_test.py Output Test report excel format : SUITE NAME TEST NAME DESCRIPTION RESULT DURATION MESSAGE FILE NAME MARKERSTestSumFlow test_step1 PASSED 15.24737811 e_test.py My query is that I want to display the values from my corresponding test steps in pytest. e.g. if my test step is following, then how do I display the output of test_step1 "newNum" in the excel report. def test_step1(fNum, sNum): newNum = fNum - sNum print newNum Regards, Sumit -- https://mail.python.org/mailman/listinfo/python-list Hi Sumit, You should use assert for testing: assert new_num == f_num - s_num, "Message if assert is false" or if you want to use more checking, you should use pytest.assume plugin. If you just want to write something to output, you should use logging, here are some info about logging in pytest: https://docs.pytest.org/en/latest/logging.html BR, George From joepareti54 at gmail.com Mon Apr 30 05:25:17 2018 From: joepareti54 at gmail.com (joseph pareti) Date: Mon, 30 Apr 2018 11:25:17 +0200 Subject: permission denied when installing tensorflow on centos 7 Message-ID: here are details on my attempt: tensorflow for centos 7 installation guidelines are in: https://gist.github.com/thoolihan/28679cd8156744a62f88 sudo yum -y install epel-release sudo yum -y install gcc gcc-c++ python-pip python-devel atlas atlas-devel gcc- gfortran openssl-devel libffi-devel # use pip or pip3 as you prefer for python or python3 pip install --upgrade virtualenv virtualenv --system-site-packages ~/venvs/tensorflow source ~/venvs/tensorflow/bin/activate pip install --upgrade numpy scipy wheel cryptography #optional pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp35- cp35m-linux_x86_64.whl # or below if you want gpu, support, but cuda and cudnn are required, see docs for more install instructions pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0rc0-cp35- cp35m-linux_x86_64.whl EXECUTION /STEP 1 OK EXECUTION /STEP 2 OK EXECUTION /STEP 3 [joepareti54 at xxx tensorflow_tmpdir]$ pip3 install --upgrade virtualenv >> step3.txt 2>&1 [joepareti54 at xxx tensorflow_tmpdir]$ cat step3.txt Collecting virtualenv Downloading https://files.pythonhosted.org/packages/ed/ea/e20b5cbebf45d3096e8138ab74eda139595d827677f38e9dd543e6015bdf/virtualenv-15.2.0-py2.py3-none-any.whl (2.6MB) Installing collected packages: virtualenv Exception: Traceback (most recent call last): File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install **kwargs File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files isolated=self.isolated, File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/wheel.py", line 345, in move_wheel_files clobber(source, lib_dir, True) File "/anaconda/envs/py35/lib/python3.5/site-packages/pip/wheel.py", line 323, in clobber shutil.copyfile(srcfile, destfile) File "/anaconda/envs/py35/lib/python3.5/shutil.py", line 115, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: '/anaconda/envs/py35/lib/python3.5/site-packages/virtualenv.py' You are using pip version 9.0.1, however version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. [joepareti54 at xxx tensorflow_tmpdir]$ From george at fischhof.hu Mon Apr 30 05:30:29 2018 From: george at fischhof.hu (George Fischhof) Date: Mon, 30 Apr 2018 11:30:29 +0200 Subject: unittest.Testsuite and execution order In-Reply-To: References: <232eb1c7-0233-f71c-84f5-344399993e46@gmail.com> Message-ID: On 20 Apr 2018 8:39 am, "Chris Angelico" wrote: On Fri, Apr 20, 2018 at 3:01 PM, Francesco Russo wrote: > On 18/04/18 20:26, Chris Angelico wrote: >> This is a bad idea. Each function that starts test_ should be >> completely independent. You should be able to run any one of them on >> its own (say, if you're trying to figure out why your latest change >> caused a test failure), and it should have the same result. >> >> Make it so that test_func_1 and test_func_2 are completely >> independent, and then, if you need a single test that uses both, have >> a test that calls on each function. > > I'm not sure I understand you here. > I understood that (besides, or instead of, making an integration test by > making those tests into one test, as you wrote above) I could make a > test for func_2 making it independent from func_1, for example this way: > > class MyTestFunc2(unittest.TestCase): > def setUp(self): > # Prepare preconditions for func_2 > > def test_func_2(self): > sut.func_2() > self.assert(...) > > Such a test case wouldn't even need a test suite. > Is this what you meant? What I mean is that test_func_1 and test_func_2 should be able to pass or fail regardless of whether the other has been run or not. That kind of independence. If you then want to write an integration test that verifies that data created by func_1 can be read by func_2, that is a separate test. > The official "unittest" web pages for Python 2 and 3 say this, for the > TestSuite class: > *This class represents an aggregation of individual tests cases and test > suites* > saying nothing about the order. But the docstring of the TestSuite class > says: > *It will run the individual test cases in the order in which they were > added, aggregating the results* > Can I consider the docstring an official documentation as well? > That's something for other people to answer; I don't know whether TestSuite is a replaceable class. I'm not sure what the mechanics are for test randomization, but it is most definitely a thing. ChrisA -- https://mail.python.org/mailman/listinfo/python-list Hi, If you want to use more asserts in a test case, you should use pytest-assume plugin. George From george at fischhof.hu Mon Apr 30 09:48:53 2018 From: george at fischhof.hu (George Fischhof) Date: Mon, 30 Apr 2018 15:48:53 +0200 Subject: Flask test generator code review? In-Reply-To: References: Message-ID: 2018-04-18 12:41 GMT+02:00 Albert-Jan Roskam : > Hi, > > I am writing my first unittests for a Flask app. First modest goal is to > test whether a selected subset of the templates return the expected status > 200. > I am using a nose test generator in a class for this. Is the code below > the correct way to do this? And is there a way to dynamically set the > docstring of test_generator? This would make the nosetests output a bit > more understandable. > > Thanks! > Albert-Jan > > import os > import sys > from os.path import splitext > from http import HTTPStatus as status > > import nose > > from MyFabulousApp import app > > app.testing = True > template_folder = app.config['TEMPLATE_FOLDER'] > > > class Test_MyFabulousApp_HTTP_Status_OK: > > def __init__(self): > self.setup() # with unittest, setUp is called automatically, but > not with nose > > def setup(self): > self.client = app.test_client() > self.client.post('/login', follow_redirects=True) > > def teardown(self): > self.client.post('/logout', follow_redirects=True) > > def test_generator(self): > """Does template return HTTP Status 200?""" > def the_test(self, template): > # the following line throws an error: AttributeError: > attribute '__doc__' of 'method' objects is not writable > #self.test_generator.__doc__ = 'Does template "%s" return HTTP > Status 200?' % template > respons = self.client.get('/' + template) > actual = respons.status_code > desired = status.OK.value > assert actual == desired, \ > 'Template "%s" returns status code %d' % (template, actual) > templates = [splitext(item)[0] for item in > os.listdir(template_folder)] > for template in templates: > yield the_test, self, template > > > if __name__ == '__main__': > nose.run(defaultTest=__name__, argv=[sys.argv[0], '__main__', > '--verbosity=2']) > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, maybe you should check PyTest https://docs.pytest.org/en/latest/ and Flas testing turorial: http://flask.pocoo.org/docs/1.0/testing/ BR, George From demianbrecht at gmail.com Mon Apr 30 13:06:33 2018 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 30 Apr 2018 10:06:33 -0700 Subject: Inconsistent site.py behavior between venv and system Message-ID: I recently ran into an issue using the site package and I wanted to confirm that I'm not doing something wrong here before creating an issue: I have a need to `git subtree` modules into a Django project and then add the dependencies such that they're discoverable in code. I also need to have consistent behavior between `python setup.py (develop|install)` and `pip install -r requirements.txt` (the latter is used by Heroku for project installation). An example project that demonstrates the issue is here: https://github.com/demianbrecht/python-sitehooks-example. In the example, I've subtree'd requests into _vendor and forced site hooks to fire using `site.main()` in testme/settings.py: https://github.com/demianbrecht/python-sitehooks-example/commit/1b81e15c6f28bc80a4f984cffa78eb2ced80a320. Forcing the execution is not needed when the package is actually installed using setup.py, but is needed when using `pip install -r requirements.txt`. This works great when running within a virtualenv, but I get the following on system python: $ python3.6 ./manage.py test Traceback (most recent call last): File "./manage.py", line 22, in execute_from_command_line(sys.argv) File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute settings.INSTALLED_APPS File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 978, in _gcd_import File "", line 961, in _find_and_load File "", line 950, in _find_and_load_unlocked File "", line 655, in _load_unlocked File "", line 678, in exec_module File "", line 205, in _call_with_frames_removed File "///testme/testme/settings.py", line 13, in site.main() File "/usr/local/lib/python3.6/site.py", line 525, in main abs_paths() File "/usr/local/lib/python3.6/site.py", line 110, in abs_paths m.__cached__ = os.path.abspath(m.__cached__) File "/usr/local/lib/python3.6/posixpath.py", line 369, in abspath path = os.fspath(path) TypeError: expected str, bytes or os.PathLike object, not NoneType Using venv and system comparisons for debugging doesn't help much as site.py is different in the two environments. Any insight into what may be going on here or what I'm doing wrong would be much appreciated. I realize that I could just muck with PYTHONPATH, but I thought this approach would be a little nicer as it's transparent to the user. ------- GPG Fingerprint: 9ACFB014BA1E5B4939ACA3B214E4E96742F22903 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From rosuav at gmail.com Mon Apr 30 13:15:20 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 May 2018 03:15:20 +1000 Subject: The perils of multiple Pythons Message-ID: https://xkcd.com/1987/ So.... take-away is: On a Mac, just use Homebrew. (Cue the angry hordes telling me how wrong I am.) ChrisA From ned at nedbatchelder.com Mon Apr 30 13:30:21 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Apr 2018 13:30:21 -0400 Subject: The perils of multiple Pythons In-Reply-To: References: Message-ID: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> On 4/30/18 1:15 PM, Chris Angelico wrote: > https://xkcd.com/1987/ > > So.... take-away is: On a Mac, just use Homebrew. > > (Cue the angry hordes telling me how wrong I am.) > My take-away (though not really, since I held this view before this morning): pick a way and stick to it. --Ned. From rosuav at gmail.com Mon Apr 30 13:32:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 May 2018 03:32:51 +1000 Subject: The perils of multiple Pythons In-Reply-To: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder wrote: > On 4/30/18 1:15 PM, Chris Angelico wrote: >> >> https://xkcd.com/1987/ >> >> So.... take-away is: On a Mac, just use Homebrew. >> >> (Cue the angry hordes telling me how wrong I am.) >> > > My take-away (though not really, since I held this view before this > morning): pick a way and stick to it. Well, yes. Until that way stops working, in which case you have to try another way. And that's when the problems start... ChrisA From jlgimeno71 at gmail.com Mon Apr 30 13:38:54 2018 From: jlgimeno71 at gmail.com (Jorge Gimeno) Date: Mon, 30 Apr 2018 10:38:54 -0700 Subject: www.python.org down Message-ID: Not sure who to report to, but the site comes back with a 503. Anyone know where I can direct this to? -Jorge L. Gimeno From bill at baddogconsulting.com Mon Apr 30 14:10:50 2018 From: bill at baddogconsulting.com (Bill Deegan) Date: Mon, 30 Apr 2018 14:10:50 -0400 Subject: www.python.org down In-Reply-To: References: Message-ID: Ditto. I see a 502. On Mon, Apr 30, 2018 at 1:38 PM, Jorge Gimeno wrote: > Not sure who to report to, but the site comes back with a 503. Anyone know > where I can direct this to? > > -Jorge L. Gimeno > -- > https://mail.python.org/mailman/listinfo/python-list > From p.f.moore at gmail.com Mon Apr 30 14:17:21 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 30 Apr 2018 19:17:21 +0100 Subject: www.python.org down In-Reply-To: References: Message-ID: It's working for me now. Paul On 30 April 2018 at 18:38, Jorge Gimeno wrote: > Not sure who to report to, but the site comes back with a 503. Anyone know > where I can direct this to? > > -Jorge L. Gimeno > -- > https://mail.python.org/mailman/listinfo/python-list From breamoreboy at gmail.com Mon Apr 30 14:26:40 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 30 Apr 2018 19:26:40 +0100 Subject: www.python.org down In-Reply-To: References: Message-ID: On 30/04/18 19:17, Paul Moore wrote: > It's working for me now. > Paul > > On 30 April 2018 at 18:38, Jorge Gimeno wrote: >> Not sure who to report to, but the site comes back with a 503. Anyone know >> where I can direct this to? >> >> -Jorge L. Gimeno >> -- >> https://mail.python.org/mailman/listinfo/python-list When originally reported I was getting, and am still getting, 502. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bill at baddogconsulting.com Mon Apr 30 14:26:53 2018 From: bill at baddogconsulting.com (Bill Deegan) Date: Mon, 30 Apr 2018 14:26:53 -0400 Subject: www.python.org down In-Reply-To: References: Message-ID: Still 502 for me. On Mon, Apr 30, 2018 at 2:17 PM, Paul Moore wrote: > It's working for me now. > Paul > > On 30 April 2018 at 18:38, Jorge Gimeno wrote: > > Not sure who to report to, but the site comes back with a 503. Anyone > know > > where I can direct this to? > > > > -Jorge L. Gimeno > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- > https://mail.python.org/mailman/listinfo/python-list > From bill at baddogconsulting.com Mon Apr 30 14:41:05 2018 From: bill at baddogconsulting.com (Bill Deegan) Date: Mon, 30 Apr 2018 14:41:05 -0400 Subject: www.python.org down In-Reply-To: References: Message-ID: back up for me. On Mon, Apr 30, 2018 at 2:26 PM, Mark Lawrence wrote: > On 30/04/18 19:17, Paul Moore wrote: > >> It's working for me now. >> Paul >> >> On 30 April 2018 at 18:38, Jorge Gimeno wrote: >> >>> Not sure who to report to, but the site comes back with a 503. Anyone >>> know >>> where I can direct this to? >>> >>> -Jorge L. Gimeno >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> > When originally reported I was getting, and am still getting, 502. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > From breamoreboy at gmail.com Mon Apr 30 14:46:22 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 30 Apr 2018 19:46:22 +0100 Subject: www.python.org down In-Reply-To: References: Message-ID: On 30/04/18 19:41, Bill Deegan wrote: > back up for me. > Ditto :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From walters.justin01 at gmail.com Mon Apr 30 16:22:11 2018 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 30 Apr 2018 13:22:11 -0700 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico wrote: > On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder > wrote: > > On 4/30/18 1:15 PM, Chris Angelico wrote: > >> > >> https://xkcd.com/1987/ > >> > >> So.... take-away is: On a Mac, just use Homebrew. > >> > >> (Cue the angry hordes telling me how wrong I am.) > >> > > > > My take-away (though not really, since I held this view before this > > morning): pick a way and stick to it. > > Well, yes. Until that way stops working, in which case you have to try > another way. And that's when the problems start... > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > I feel like this problem is pretty handily solved by virtual environments. Also, if a single project requires all of this, perhaps Python isn't the best choice for the project. From rosuav at gmail.com Mon Apr 30 16:40:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 May 2018 06:40:49 +1000 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Tue, May 1, 2018 at 6:22 AM, justin walters wrote: > On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico wrote: > >> On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder >> wrote: >> > On 4/30/18 1:15 PM, Chris Angelico wrote: >> >> >> >> https://xkcd.com/1987/ >> >> >> >> So.... take-away is: On a Mac, just use Homebrew. >> >> >> >> (Cue the angry hordes telling me how wrong I am.) >> >> >> > >> > My take-away (though not really, since I held this view before this >> > morning): pick a way and stick to it. >> >> Well, yes. Until that way stops working, in which case you have to try >> another way. And that's when the problems start... >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > I feel like this problem is pretty handily solved by virtual environments. > Also, if a single project requires all of this, > perhaps Python isn't the best choice for the project. Some of it is definitely solved by venvs. But which Python binary do you use? And is venv installed? Do you need to install virtualenv first? How do you... etc, etc, etc, etc, etc. Endless fun! ChrisA From walters.justin01 at gmail.com Mon Apr 30 16:59:23 2018 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 30 Apr 2018 13:59:23 -0700 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Mon, Apr 30, 2018 at 1:40 PM, Chris Angelico wrote: > On Tue, May 1, 2018 at 6:22 AM, justin walters > wrote: > > On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico > wrote: > > > >> On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder > >> wrote: > >> > On 4/30/18 1:15 PM, Chris Angelico wrote: > >> >> > >> >> https://xkcd.com/1987/ > >> >> > >> >> So.... take-away is: On a Mac, just use Homebrew. > >> >> > >> >> (Cue the angry hordes telling me how wrong I am.) > >> >> > >> > > >> > My take-away (though not really, since I held this view before this > >> > morning): pick a way and stick to it. > >> > >> Well, yes. Until that way stops working, in which case you have to try > >> another way. And that's when the problems start... > >> > >> ChrisA > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > > I feel like this problem is pretty handily solved by virtual > environments. > > Also, if a single project requires all of this, > > perhaps Python isn't the best choice for the project. > > Some of it is definitely solved by venvs. But which Python binary do > you use? And is venv installed? Do you need to install virtualenv > first? How do you... etc, etc, etc, etc, etc. Endless fun! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > With Python 3.5+, venv is a built in module. If using a venv, default to using the binary in the venv. That's what I do anyways. From rosuav at gmail.com Mon Apr 30 17:03:29 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 May 2018 07:03:29 +1000 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Tue, May 1, 2018 at 6:59 AM, justin walters wrote: > With Python 3.5+, venv is a built in module. If using a venv, default to > using the binary in the venv. > > That's what I do anyways. Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and Macs don't ship with Python 3.5+. So there's a bootstrapping problem: how do you install a newer Python? There are about half a dozen options. ChrisA From python.list at tim.thechases.com Mon Apr 30 17:16:25 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Apr 2018 16:16:25 -0500 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: <20180430161625.5b996b8a@bigbox.christie.dr> On 2018-05-01 06:40, Chris Angelico wrote: >>> >> https://xkcd.com/1987/ >> >> I feel like this problem is pretty handily solved by virtual >> environments. Also, if a single project requires all of this, >> perhaps Python isn't the best choice for the project. > > Some of it is definitely solved by venvs. But which Python binary do > you use? Pretty sure that all venvs I've used know their corresponding binary. But... > And is venv installed? Do you need to install virtualenv > first? How do you... Is it virtualenv? Or are you using virtualenvwrapper which, last I checked doesn't work in ksh (OpenBSD's default shell) without jumping through hoops and getting external ksh-specific files? Or are you using pipenv? Or `python -m venv`? So many different flavors. :-( -tkc From rosuav at gmail.com Mon Apr 30 17:22:13 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 May 2018 07:22:13 +1000 Subject: The perils of multiple Pythons In-Reply-To: <20180430161625.5b996b8a@bigbox.christie.dr> References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> <20180430161625.5b996b8a@bigbox.christie.dr> Message-ID: On Tue, May 1, 2018 at 7:16 AM, Tim Chase wrote: > On 2018-05-01 06:40, Chris Angelico wrote: >>>> >> https://xkcd.com/1987/ >>> >>> I feel like this problem is pretty handily solved by virtual >>> environments. Also, if a single project requires all of this, >>> perhaps Python isn't the best choice for the project. >> >> Some of it is definitely solved by venvs. But which Python binary do >> you use? > > Pretty sure that all venvs I've used know their corresponding binary. > But... Right. It's locked in when you create it. But you still have to pick. >> And is venv installed? Do you need to install virtualenv >> first? How do you... > > Is it virtualenv? Or are you using virtualenvwrapper which, last I > checked doesn't work in ksh (OpenBSD's default shell) without jumping > through hoops and getting external ksh-specific files? Or are you > using pipenv? Or `python -m venv`? So many different flavors. :-( > Exactly! Personally, I don't use any of them except "python3 -m venv", but I also have some custom bash scripting to make the activation and deactivation happen automatically. ChrisA From rshepard at appl-ecosys.com Mon Apr 30 18:24:45 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 30 Apr 2018 15:24:45 -0700 (PDT) Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Mon, 30 Apr 2018, justin walters wrote: > With Python 3.5+, venv is a built in module. If using a venv, default to > using the binary in the venv. That's what I do anyways. I'm running Python3-3.6.5 and have a developing application in ~/development/project/. Can I run 'python3 -m venv ~/development/project/' to install it in a directory with existing modules? Rich From walters.justin01 at gmail.com Mon Apr 30 19:29:28 2018 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 30 Apr 2018 16:29:28 -0700 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Mon, Apr 30, 2018 at 3:24 PM, Rich Shepard wrote: > On Mon, 30 Apr 2018, justin walters wrote: > > With Python 3.5+, venv is a built in module. If using a venv, default to >> using the binary in the venv. That's what I do anyways. >> > > I'm running Python3-3.6.5 and have a developing application in > ~/development/project/. Can I run 'python3 -m venv ~/development/project/' > to install it in a directory with existing modules? > > Rich > -- > https://mail.python.org/mailman/listinfo/python-list > Yes, you can create a virtual env with all of the global packages. Though, you would probably want to run: `python3 -m venv ~/development/project/venv` to put the virtualenv files in their own directory. Then you just need to activate it with: `source venv/bin/activate`. As long as the virtualenv is activated, you can interact with it in the same way you would with the system/global environment. i.e. running the interpreter will use the binary from the virtualenv, pip install will install in the virtualenv only, etc. From rshepard at appl-ecosys.com Mon Apr 30 19:56:55 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 30 Apr 2018 16:56:55 -0700 (PDT) Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On Mon, 30 Apr 2018, justin walters wrote: > Yes, you can create a virtual env with all of the global packages. Though, > you would probably want to run: `python3 -m venv > ~/development/project/venv` to put the virtualenv files in their own > directory. Justin, That's what I thought to be the case after reading the python docs about the venv module. Thanks! Rich From tjreedy at udel.edu Mon Apr 30 21:27:46 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Apr 2018 21:27:46 -0400 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On 4/30/2018 5:03 PM, Chris Angelico wrote: > On Tue, May 1, 2018 at 6:59 AM, justin walters > wrote: >> With Python 3.5+, venv is a built in module. If using a venv, default to >> using the binary in the venv. >> >> That's what I do anyways. > > Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and > Macs don't ship with Python 3.5+. So there's a bootstrapping problem: > how do you install a newer Python? There are about half a dozen > options. > > ChrisA > -- Terry Jan Reedy From tjreedy at udel.edu Mon Apr 30 21:31:55 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Apr 2018 21:31:55 -0400 Subject: The perils of multiple Pythons In-Reply-To: References: <896cfef9-0513-15de-8b24-b2da60bf0551@nedbatchelder.com> Message-ID: On 4/30/2018 5:03 PM, Chris Angelico wrote: > Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and > Macs don't ship with Python 3.5+. So there's a bootstrapping problem: > how do you install a newer Python? There are about half a dozen > options. I think the situation is improved with 3.7 Mac installer, which includes and installs an up-to-date tcl/tk, instead of telling people, on a separate page that many do not go to, to separately install a less ancient tcl/tk from ActiveState, which some have trouble doing, or switch to another distribution, which has its own issues. -- Terry Jan Reedy