From tjreedy at udel.edu Thu Aug 1 02:32:39 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 1 Aug 2019 02:32:39 -0400 Subject: Why won't the run-time error reporter point to the error position with a caret like the syntax error reporter does? It knows exactly where the error is. In-Reply-To: <1d65ba31-842b-40cb-9100-0b719207938b@googlegroups.com> References: <1d65ba31-842b-40cb-9100-0b719207938b@googlegroups.com> Message-ID: On 7/31/2019 11:19 PM, jsalsman at gmail.com wrote: > Honestly this is the only thing in over half a decade of daily python use which has disappointed me enough to want to ask the devs: > >>>> print(1/) > File "", line 1 > print(1/) > ^ > SyntaxError: invalid syntax SyntaxErrors mostly come from the parser, occasionally from the compiler, both of which have access to line and column. >>>> print(1/1, 1/0, 1/1) > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero This comes from the runtime engine, which only has access to line numbers, and even line numbers lie when a statement spans multiple lines. In CPython, the runtime engine is executing bytecodes, and bytecode do not correspond to column numbers. In something like "a + b / (2 * c + d//3)", if the denominator (which could be on multiple lines) is 0, where should a caret point? -- Terry Jan Reedy From rosuav at gmail.com Thu Aug 1 03:18:54 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Aug 2019 17:18:54 +1000 Subject: Why won't the run-time error reporter point to the error position with a caret like the syntax error reporter does? It knows exactly where the error is. In-Reply-To: References: <1d65ba31-842b-40cb-9100-0b719207938b@googlegroups.com> Message-ID: On Thu, Aug 1, 2019 at 4:34 PM Terry Reedy wrote: > > On 7/31/2019 11:19 PM, jsalsman at gmail.com wrote: > > Honestly this is the only thing in over half a decade of daily python use which has disappointed me enough to want to ask the devs: > > > >>>> print(1/) > > File "", line 1 > > print(1/) > > ^ > > SyntaxError: invalid syntax > > SyntaxErrors mostly come from the parser, occasionally from the > compiler, both of which have access to line and column. > > >>>> print(1/1, 1/0, 1/1) > > Traceback (most recent call last): > > File "", line 1, in > > ZeroDivisionError: division by zero > > This comes from the runtime engine, which only has access to line > numbers, and even line numbers lie when a statement spans multiple > lines. In CPython, the runtime engine is executing bytecodes, and > bytecode do not correspond to column numbers. In something like > "a + b / (2 * c + d//3)", if the denominator (which could be on multiple > lines) is 0, where should a caret point? > Probably to the slash, since it's the division operation that threw the error. I don't think it would be all that useful, but it would at least be sane and logical. ChrisA From sidneylangweil at gmail.com Thu Aug 1 10:26:13 2019 From: sidneylangweil at gmail.com (Sidney Langweil) Date: Thu, 1 Aug 2019 07:26:13 -0700 (PDT) Subject: newbie question Message-ID: <0453a7e5-f0ce-4eeb-80dc-85615421e77c@googlegroups.com> A Python script invokes a function in another file in the same directory. I would like to invoke that function without the need for an import. I think I read that having an empty __init__.py is sufficient. But it does not seem to work for me. I'm sure this is obvious to many of you. Thanks in advance for your help. Sid From cspealma at redhat.com Thu Aug 1 10:57:05 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 1 Aug 2019 10:57:05 -0400 Subject: newbie question In-Reply-To: <0453a7e5-f0ce-4eeb-80dc-85615421e77c@googlegroups.com> References: <0453a7e5-f0ce-4eeb-80dc-85615421e77c@googlegroups.com> Message-ID: Sorry, but you can't. If you have two python modules, neither has access to things in the other without an import. That's the whole point of an import. On Thu, Aug 1, 2019 at 10:30 AM Sidney Langweil wrote: > A Python script invokes a function in another file in the same directory. > > I would like to invoke that function without the need for an import. > > I think I read that having an empty __init__.py is sufficient. But it > does not seem to work for me. > > I'm sure this is obvious to many of you. Thanks in advance for your help. > > Sid > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From sidneylangweil at gmail.com Thu Aug 1 11:31:58 2019 From: sidneylangweil at gmail.com (Sidney Langweil) Date: Thu, 1 Aug 2019 08:31:58 -0700 (PDT) Subject: newbie question In-Reply-To: References: <0453a7e5-f0ce-4eeb-80dc-85615421e77c@googlegroups.com> Message-ID: <3653d807-bdba-40a2-b6d1-7632e6816192@googlegroups.com> On Thursday, August 1, 2019 at 7:57:31 AM UTC-7, Calvin Spealman wrote: > Sorry, but you can't. If you have two python modules, neither has access to > things in the other without an import. > > That's the whole point of an import. > > On Thu, Aug 1, 2019 at 10:30 AM Sidney Langweil > wrote: > > > A Python script invokes a function in another file in the same directory. > > > > I would like to invoke that function without the need for an import. > > > > I think I read that having an empty __init__.py is sufficient. But it > > does not seem to work for me. > > > > I'm sure this is obvious to many of you. Thanks in advance for your help. > > > > Sid > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > [image: https://red.ht/sig] > TRIED. TESTED. TRUSTED. Thank you. As long as using 'import' is correct in this case, I do not mind inserting the extra line(s). Side From sinardyxing at gmail.com Thu Aug 1 05:08:51 2019 From: sinardyxing at gmail.com (Sinardy Xing) Date: Thu, 1 Aug 2019 17:08:51 +0800 Subject: Create Logging module Message-ID: Hi, I am learning to create python logging. My goal is to create a logging module where I can use as decorator in my main app following is the logging code ---- start here--- import logging #DEBUG : Detailed information, typically of interest only when diagnosing problems. #INFO : Confirmation that things are working as expected. #WARNING (default): An indication that something unexpected happened, or indicative of some problem in the near future # (e.g. 'disk space low'). The software is still working as expected. #ERROR : Due to a more serious problem, the software has not been able to perform some function. #CRITICAL :A serious error, indicating that the program itself may be unable to continue running. from functools import wraps def logme(func_to_log): import logging #Without getLogger name it will log all in root logger = logging.getLogger(__name__) #Check log level within understanable parameter, set to INFO if is not permitable value def check_log_level(logleveltocheck): if any(logleveltocheck.upper() in lf for lf in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']): return logleveltocheck.upper() else: return 'INFO' log_file_level='INFO' #check_log_level('info') log_console_level='INFO' #check_log_level('info') #root level logger.setLevel('INFO') formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s') #Read log file from parameter logfile='mylogfile.log' file_handler = logging.FileHandler(logfile) file_handler.setLevel(log_file_level) file_handler.setFormatter(formatter) stream_handler = logging.StreamHandler() stream_handler.setLevel(log_console_level) stream_handler.setFormatter(formatter) logger.addHandler() logger.addHandler(stream_handler) #this wraps is to make sure we are returning func_to_log instead of wrapper @wraps(func_to_log) def wrapper(*args, **kwargs): logger.info('Ran with args: {}, and kwargs: {}'.format(args, kwargs)) return func_to_log(*args, **kwargs) return wrapper def timer(func_to_log): import time #this wraps is to make sure we are returning func_to_log instead of wrapper @wraps(func_to_log) def wrapper(*args, **kwargs): t1 = time.time() result = func_to_log(*args, **kwargs) t2 = time.time() - t1 print('{} ran in {} sec'.format(func_to_log.__name__, t2)) return result --- end here--- following is my main app -- start here-- from loggingme import logme def say_hello(name, age): print('Hello {}, I am {}'.format(name, age)) #say_hello=logme(say_hello('Sinardy')) @logme say_hello('Tonny', 8) --- end here--- I have error look like in the wrapper. Can someone point to me where is the issue or is this the correct way to create logging module? PS: above code with python 3.7.4 Thank you. regards, C From sinardyxing at gmail.com Thu Aug 1 05:13:04 2019 From: sinardyxing at gmail.com (Sinardy Xing) Date: Thu, 1 Aug 2019 17:13:04 +0800 Subject: Create Logging module In-Reply-To: References: Message-ID: Sorry for spamming this is suppose send to tutor-owner at python.org On Thu, Aug 1, 2019 at 5:08 PM Sinardy Xing wrote: > Hi, > > I am learning to create python logging. > > My goal is to create a logging module where I can use as decorator in my > main app > > following is the logging code > > ---- start here--- > > import logging > > #DEBUG : Detailed information, typically of interest only when > diagnosing problems. > #INFO : Confirmation that things are working as expected. > #WARNING (default): An indication that something unexpected happened, or > indicative of some problem in the near future > # (e.g. 'disk space low'). The software is still working as > expected. > #ERROR : Due to a more serious problem, the software has not been able > to perform some function. > #CRITICAL :A serious error, indicating that the program itself may be > unable to continue running. > > from functools import wraps > > def logme(func_to_log): > import logging > > #Without getLogger name it will log all in root > logger = logging.getLogger(__name__) > > #Check log level within understanable parameter, set to INFO if is not > permitable value > def check_log_level(logleveltocheck): > if any(logleveltocheck.upper() in lf for lf in ['DEBUG', > 'INFO', 'WARNING', 'ERROR', 'CRITICAL']): > return logleveltocheck.upper() > else: > return 'INFO' > > log_file_level='INFO' #check_log_level('info') > log_console_level='INFO' #check_log_level('info') > > #root level > logger.setLevel('INFO') > > formatter = logging.Formatter('%(asctime)s :: %(name)s :: > %(levelname)s :: %(message)s') > > #Read log file from parameter > logfile='mylogfile.log' > file_handler = logging.FileHandler(logfile) > file_handler.setLevel(log_file_level) > file_handler.setFormatter(formatter) > > stream_handler = logging.StreamHandler() > stream_handler.setLevel(log_console_level) > stream_handler.setFormatter(formatter) > > logger.addHandler() > logger.addHandler(stream_handler) > > #this wraps is to make sure we are returning func_to_log instead of > wrapper > @wraps(func_to_log) > def wrapper(*args, **kwargs): > logger.info('Ran with args: {}, and kwargs: {}'.format(args, > kwargs)) > return func_to_log(*args, **kwargs) > > return wrapper > > > def timer(func_to_log): > import time > > #this wraps is to make sure we are returning func_to_log instead of > wrapper > @wraps(func_to_log) > def wrapper(*args, **kwargs): > t1 = time.time() > result = func_to_log(*args, **kwargs) > t2 = time.time() - t1 > print('{} ran in {} sec'.format(func_to_log.__name__, t2)) > return result > > --- end here--- > > > following is my main app > > -- start here-- > from loggingme import logme > > def say_hello(name, age): > print('Hello {}, I am {}'.format(name, age)) > > #say_hello=logme(say_hello('Sinardy')) > @logme > say_hello('Tonny', 8) > > --- end here--- > > > I have error look like in the wrapper. > > Can someone point to me where is the issue or is this the correct way to > create logging module? > > PS: above code with python 3.7.4 > > Thank you. > > regards, > C > From kabbaraahmadadam at gmail.com Thu Aug 1 09:31:02 2019 From: kabbaraahmadadam at gmail.com (adam kabbara) Date: Thu, 1 Aug 2019 16:31:02 +0300 Subject: help with tkinter Message-ID: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message Sent from Mail for Windows 10 From rhodri at kynesim.co.uk Thu Aug 1 12:28:36 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 1 Aug 2019 17:28:36 +0100 Subject: help with tkinter In-Reply-To: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: Hi there, Adam! On 01/08/2019 14:31, adam kabbara wrote: > Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message What *exactly* did you type? Please cut-and-paste from your console/editor into the email, don't just retype it. If you did literally type "from tkinter import*" then Python is probably complaining that it doesn't know what "import*" means because you missed out a space! Also, what *exactly* was the error message? Again, please cut-and-paste. Python usually gives you a pretty good indication of what you did wrong; if you show us, we can help you get used to interpreting it for yourself. Happy coding! -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Thu Aug 1 14:06:28 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Aug 2019 04:06:28 +1000 Subject: help with tkinter In-Reply-To: References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: On Fri, Aug 2, 2019 at 2:30 AM Rhodri James wrote: > > Hi there, Adam! > > On 01/08/2019 14:31, adam kabbara wrote: > > Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message > > What *exactly* did you type? Please cut-and-paste from your > console/editor into the email, don't just retype it. If you did > literally type "from tkinter import*" then Python is probably > complaining that it doesn't know what "import*" means because you missed > out a space! Actually, Python's fine with that, but the principle is still valid: be specific about what you entered and what Python replied. ChrisA From rhodri at kynesim.co.uk Thu Aug 1 14:15:19 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 1 Aug 2019 19:15:19 +0100 Subject: help with tkinter In-Reply-To: References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: <73acb02e-fae5-35e6-5b39-b65f8a8907fc@kynesim.co.uk> On 01/08/2019 19:06, Chris Angelico wrote: > On Fri, Aug 2, 2019 at 2:30 AM Rhodri James wrote: >> >> Hi there, Adam! >> >> On 01/08/2019 14:31, adam kabbara wrote: >>> Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message >> >> What *exactly* did you type? Please cut-and-paste from your >> console/editor into the email, don't just retype it. If you did >> literally type "from tkinter import*" then Python is probably >> complaining that it doesn't know what "import*" means because you missed >> out a space! > > Actually, Python's fine with that, but the principle is still valid: > be specific about what you entered and what Python replied. Fair enough. I should try out "obvious syntax errors" before I declare them as such. -- Rhodri James *-* Kynesim Ltd From danielokeyokoro at gmail.com Thu Aug 1 16:06:14 2019 From: danielokeyokoro at gmail.com (Daniel Okey-Okoro) Date: Thu, 1 Aug 2019 13:06:14 -0700 Subject: PEP: add a `no` keyword as an alias for `not` Message-ID: I think that adding a `no` keyword as an alias for `not` would make for more readable, simple, pythonic code. Take the below: ``` if not val: do_thing_because_value_is_falsy() ``` could be (is actually understood as): ``` if no val: do_thing_because_value_is_falsy() ``` I think this PEP is a work-around for an underlying subtle issue with how the `not` operator is used. It has two use-cases: 1. as a NOT gate for producing opposite boolean values ``` opposite = not regular ``` 2. as a sort of ".is_falsy()" checker; when used with an if statement. like the first example. This PEP would make the difference between the two usecases explicit. Thoughts? Best Intentions, Daniel Okey-Okoro. From cspealma at redhat.com Thu Aug 1 16:10:24 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 1 Aug 2019 16:10:24 -0400 Subject: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: I think they actually read like they would mean slightly different things, which would make them existing as aliases confusing. I read `if not val` as "If val isn't true" but i would read `if no val` as "if val does not exist" On Thu, Aug 1, 2019 at 4:07 PM Daniel Okey-Okoro wrote: > I think that adding a `no` keyword as an alias for `not` would make for > more readable, simple, pythonic code. > > Take the below: > > ``` > if not val: > do_thing_because_value_is_falsy() > ``` > > could be (is actually understood as): > > ``` > if no val: > do_thing_because_value_is_falsy() > ``` > > I think this PEP is a work-around for an underlying subtle issue with how > the `not` operator is used. > > It has two use-cases: > > 1. as a NOT gate for producing opposite boolean values > > ``` > opposite = not regular > ``` > > 2. as a sort of ".is_falsy()" checker; when used with an if statement. > > like the first example. > > > This PEP would make the difference between the two usecases explicit. > > Thoughts? > > Best Intentions, > Daniel Okey-Okoro. > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From danielokeyokoro at gmail.com Thu Aug 1 16:25:21 2019 From: danielokeyokoro at gmail.com (Daniel Okey-Okoro) Date: Thu, 1 Aug 2019 13:25:21 -0700 Subject: Fwd: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Daniel Okey-Okoro Date: Thu, Aug 1, 2019 at 1:24 PM Subject: Re: PEP: add a `no` keyword as an alias for `not` To: Calvin Spealman Good point Calvin, ------------------------------------------------------------ But in many cases, when people write `if not val` they're checking if the val is `None` i.e. `if val is None`, `if val == None` (so in effect it's kind of like they're checking if "something isn't there") I just did a code review. The idea popped in my head after reading code that behaved this way. ------------------------------------------------------------------- Plus, I'm suggesting an alias. In some usecases it would be better to just use `if not val`. i.e. in cases where you are strictly doing True/False assessments not Falsey ( is_empty() ) assessments e.g. None, [], "", 0 ``` Best Intentions, Daniel Okey-Okoro On Thu, Aug 1, 2019, 1:10 PM Calvin Spealman wrote: > I think they actually read like they would mean slightly different things, > which would make them existing as aliases confusing. > > I read `if not val` as "If val isn't true" but i would read `if no val` as > "if val does not exist" > > On Thu, Aug 1, 2019 at 4:07 PM Daniel Okey-Okoro < > danielokeyokoro at gmail.com> wrote: > >> I think that adding a `no` keyword as an alias for `not` would make for >> more readable, simple, pythonic code. >> >> Take the below: >> >> ``` >> if not val: >> do_thing_because_value_is_falsy() >> ``` >> >> could be (is actually understood as): >> >> ``` >> if no val: >> do_thing_because_value_is_falsy() >> ``` >> >> I think this PEP is a work-around for an underlying subtle issue with how >> the `not` operator is used. >> >> It has two use-cases: >> >> 1. as a NOT gate for producing opposite boolean values >> >> ``` >> opposite = not regular >> ``` >> >> 2. as a sort of ".is_falsy()" checker; when used with an if statement. >> >> like the first example. >> >> >> This PEP would make the difference between the two usecases explicit. >> >> Thoughts? >> >> Best Intentions, >> Daniel Okey-Okoro. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > [image: https://red.ht/sig] > TRIED. TESTED. TRUSTED. > -- Best Intentions, Daniel Okey-Okoro. From danielokeyokoro at gmail.com Thu Aug 1 16:38:02 2019 From: danielokeyokoro at gmail.com (Daniel Okey-Okoro) Date: Thu, 1 Aug 2019 13:38:02 -0700 Subject: Fwd: [Python-ideas] Re: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Daniel Okey-Okoro Date: Thu, Aug 1, 2019 at 1:37 PM Subject: Re: [Python-ideas] Re: PEP: add a `no` keyword as an alias for `not` To: Chris Angelico > not a strong enough justification for breaking any code that uses "no" in any other way. This is a very crucial point I didn't consider. ------------------------------------------------------------ What if we could lexically limit it to `if no {{everything else in the if block}}`? I think that would sufficiently protect us from unintentionally breaking people's code. ----------------------------------------------------------- > The bar for creating new keywords is extremely high I'm grateful that it is. I think python is awesome. And I trust the community/council to keep it awesome. If the idea doesn't make sense to most people then I'm happy with it never getting picked up. Just sharing an idea. On Thu, Aug 1, 2019 at 1:12 PM Chris Angelico wrote: > On Fri, Aug 2, 2019 at 6:09 AM Daniel Okey-Okoro > wrote: > > > > I think that adding a `no` keyword as an alias for `not` would make for > > more readable, simple, pythonic code. > > The bar for creating new keywords is extremely high. Simply making > your code slightly more like English is not a strong enough > justification for breaking any code that uses "no" in any other way. > > ChrisA > _______________________________________________ > Python-ideas mailing list -- python-ideas at python.org > To unsubscribe send an email to python-ideas-leave at python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas at python.org/message/DJUKCQH3RA6HKCYUHOXBKDRCULJKB6LT/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Best Intentions, Daniel Okey-Okoro. -- Best Intentions, Daniel Okey-Okoro. From best_lay at yahoo.com Thu Aug 1 17:06:51 2019 From: best_lay at yahoo.com (Wildman) Date: Thu, 01 Aug 2019 16:06:51 -0500 Subject: help with tkinter References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: On Thu, 01 Aug 2019 16:31:02 +0300, adam kabbara wrote: > Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message > What was the error and what version of Python are you using? For Python 2 you need... from Tkinter import* -- GNU/Linux user #557453 "There are only 10 types of people in the world... those who understand Binary and those who don't." -Spike From Karsten.Hilbert at gmx.net Thu Aug 1 17:19:25 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 1 Aug 2019 23:19:25 +0200 Subject: Fwd: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: <20190801211925.GA2649@hermes.hilbert.loc> On Thu, Aug 01, 2019 at 01:25:21PM -0700, Daniel Okey-Okoro wrote: > Good point Calvin, > ------------------------------------------------------------ > But in many cases, when people write `if not val` they're checking if the > val is `None` > > i.e. `if val is None`, `if val == None` > > (so in effect it's kind of like they're checking if "something isn't there") No. Something being None does not mean something isn't there. Something isn't there if something isn't there: hasattr(object_or_scope_to_check, 'name_of_attribute') Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From grant.b.edwards at gmail.com Thu Aug 1 17:41:16 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 1 Aug 2019 21:41:16 -0000 (UTC) Subject: Fwd: PEP: add a `no` keyword as an alias for `not` References: Message-ID: On 2019-08-01, Daniel Okey-Okoro wrote: > But in many cases, when people write `if not val` they're checking if the > val is `None` > > i.e. `if val is None`, `if val == None` If they want to know if val is None, then they should be typing 'val is None'. IMO, it's not an improvement to let them type 'no val' instead of 'not val' when what they really mean is 'val is None'. > (so in effect it's kind of like they're checking if "something isn't > there") Except there _is_ something there. It just has a 'false' value in the case of 'not val' or it's the None singleton object in the 'val is None'. Something not being there is a whole different thing... -- Grant Edwards grant.b.edwards Yow! My mind is making at ashtrays in Dayton ... gmail.com From ethan at stoneleaf.us Thu Aug 1 17:46:05 2019 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 1 Aug 2019 14:46:05 -0700 Subject: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: <55b11f2b-093b-171a-9f93-e1167e8b4d85@stoneleaf.us> On 08/01/2019 01:06 PM, Daniel Okey-Okoro wrote: > [an idea] Two things: 1) please do not cross-post. 2) a PEP is a very particular thing* -- please do not say you have one unless you do. ;) -- ~Ethan~ * https://www.python.org/dev/peps/pep-0001/ From cs at cskk.id.au Thu Aug 1 18:24:41 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 2 Aug 2019 08:24:41 +1000 Subject: Is there a simple way to wrap a built-in function for the whole package? In-Reply-To: <188ce0c3-ff6c-4f57-864d-b807da37e186@googlegroups.com> References: <188ce0c3-ff6c-4f57-864d-b807da37e186@googlegroups.com> Message-ID: <20190801222441.GA54533@cskk.homeip.net> On 31Jul2019 19:16, Jach Fong wrote: >I get a package from Pypi. The package has many modules using built-in open() function. I like to redefine all the open() there with the default encoding 'utf-8', but not for code outside the package. Maybe I can put my def statement at the beginning of every module of this package, but just wondering is there a simple way of doing it? I would define something like this in the __init__.py file of the package (or in some utils.py file in the package): def open8(path): return open(path, encoding='utf-8') and just: from . import open8 and use "open8" throughout the code instead of "open"? What not alias "open"? Because I would want it evident that in this code we're doing a slightly special flavour of open. By using a distinct name I avoid confusion about the unusual semantics. Cheers, Cameron Simpson From jfong at ms4.hinet.net Thu Aug 1 21:18:10 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 1 Aug 2019 18:18:10 -0700 (PDT) Subject: Is there a simple way to wrap a built-in function for the whole package? In-Reply-To: References: <188ce0c3-ff6c-4f57-864d-b807da37e186@googlegroups.com> <20190801222441.GA54533@cskk.homeip.net> Message-ID: <4cfaca9a-8067-47b6-9e52-e090e31dfef8@googlegroups.com> Cameron Simpson? 2019?8?2???? UTC+8??6?25?00???? > On 31Jul2019 19:16, Jach Fong wrote: > >I get a package from Pypi. The package has many modules using built-in open() function. I like to redefine all the open() there with the default encoding 'utf-8', but not for code outside the package. Maybe I can put my def statement at the beginning of every module of this package, but just wondering is there a simple way of doing it? > > I would define something like this in the __init__.py file of the > package (or in some utils.py file in the package): > > def open8(path): > return open(path, encoding='utf-8') > > and just: > > from . import open8 > > and use "open8" throughout the code instead of "open"? > > What not alias "open"? Because I would want it evident that in this code > we're doing a slightly special flavour of open. By using a distinct name > I avoid confusion about the unusual semantics. > > Cheers, > Cameron Simpson Instead of changing open() to open8() throughout the code, I prefer change it directly to open(encoding='utf-8'). Anyway, using "from . import open" is a good idea, thank you. --Jach From hongyi.zhao at gmail.com Fri Aug 2 03:37:51 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 2 Aug 2019 07:37:51 -0000 (UTC) Subject: Using pycurl to obtain the download speed in real-time for a huge file. Message-ID: Hi, I want to use pycurl to obtain the download speed in real-time for a huge file. Is this possible or not? Any hints on this issue? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From PythonList at DancesWithMice.info Fri Aug 2 05:10:32 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 2 Aug 2019 21:10:32 +1200 Subject: Remote/Pair-Programming in-the-cloud Message-ID: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Please recommend a Python-friendly, bandwidth-respectful, (but effective) system for pair-programming; where the 'pair' are geographically separate. Next week is the local PUG's next meeting (details below) billed as a "Python Hands-On Coding night". I shall be travelling, so can't attend in-person. The meeting organiser and I are investigating the possibility of offering remote 'support', enthusiastic at developing the prospect such extra flexibility may offer... The PUG will be meeting at the university. I will gain Internet access from another uni or through a caf?'s wi-fi service. [I don't mind putting a bit of money into a good service, but $free for preference and F/LOSS for principle] I have surveyed various cloud-based services: - PythonAnywhere: Py3.6, used them in London (UK) perhaps one decade ago, team/"education" facility appears to work. Am checking with them... - PythonFiddle: doesn't seem to share - ShiftEdit: have been awaiting promised credentials-email all day... - CodeEnvy: Py3.5.1, doesn't seem to allow 'team' - IdeaOne: doesn't seem to share - UseTogether: off the air. - CodeAnywhere: 7-day trial free and tomorrow will be experimenting with: - AWS Cloud9: (apparently will run on a small, free, cloud-server) Then there is the possibility of installing a multi-user editor on my VPS or in an OpenStack PublicCloud instance: - Codiad: its need for PHP puts me off (haven't used/configured that language for >10yrs) and tomorrow will be reviewing: - Koding: (no longer offer their own server/services so looks-like I'll have to dredge-up my inner-SysAdmin - small children should look away now!) Do you have experience of such remote/shared/pair-programming facilities? Are you able to recommend software/a platform, please? *** Meeting ANN email/briefing: During these meetups, we pull out our own laptops and dig into coding something meaningful that works. We'll do a quick "round" at the start, where you can introduce yourself, your project, and any need for expertise you may have. People tend to wander around, checking out what others are using Python for, and giving ideas and tips where appropriate. Get ready to spend quality time on your own projects, on your own laptop, and catch up on what everyone else is doing. I'm going to be working on standing up a Python-based Solid Identity Platform (see https://www.infoq.com/news/2018/10/solid-identity-platform/) and you can work with us on your flashiest apps - which we will help you make perfect. *** (NB within the above quote, the "I" is the mtg organiser, not myself - although it does sound like an interesting topic...) -- Regards, =dn From barry at barrys-emacs.org Fri Aug 2 14:36:00 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 2 Aug 2019 19:36:00 +0100 Subject: Using pycurl to obtain the download speed in real-time for a huge file. In-Reply-To: References: Message-ID: > On 2 Aug 2019, at 08:37, Hongyi Zhao wrote: > > Hi, > > I want to use pycurl to obtain the download speed in real-time for a huge > file. Is this possible or not? Yes > Any hints on this issue? Google for python pycurl progress Barry > > Regards > -- > .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Fri Aug 2 16:32:38 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 2 Aug 2019 16:32:38 -0400 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On 8/2/2019 5:10 AM, DL Neil wrote: > Please recommend a Python-friendly, bandwidth-respectful, (but > effective) system for pair-programming; where the 'pair' are > geographically separate. 'geographically separate' could range from in the same room to a continent away, as long as two people have separate keyboards and screens. > [I don't mind putting a bit of money into a good service, but $free for > preference and F/LOSS for principle] IDLE is Python-friendly, free, and FOSS. I wonder how hard it would be to pair programming connectivity as an extension. A couple of questions: 1. Do the systems you have considered operate as an editor + satellite terminal or as synchronized peer editors. 2. Do two systems connect directly peer-to-peer or through a server? -- Terry Jan Reedy From rosuav at gmail.com Fri Aug 2 16:44:02 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Aug 2019 06:44:02 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On Sat, Aug 3, 2019 at 6:34 AM Terry Reedy wrote: > > On 8/2/2019 5:10 AM, DL Neil wrote: > > Please recommend a Python-friendly, bandwidth-respectful, (but > > effective) system for pair-programming; where the 'pair' are > > geographically separate. > > 'geographically separate' could range from in the same room to a > continent away, as long as two people have separate keyboards and screens. Though there may be differences between LAN-optimized tools and internet-optimized ones. > > [I don't mind putting a bit of money into a good service, but $free for > > preference and F/LOSS for principle] > > > > IDLE is Python-friendly, free, and FOSS. I wonder how hard it would be > to pair programming connectivity as an extension. A couple of questions: > > 1. Do the systems you have considered operate as an editor + satellite > terminal or as synchronized peer editors. > > 2. Do two systems connect directly peer-to-peer or through a server? > Not the OP, but weighing in from personal experience: I've often pair programmed using just a video call service (with screen share). The biggest downside is that it has to share the full image of the screen, which means it has to aggressively compress the video in order to handle home-grade internet connections. (OTOH, that does mean that it's IDE-independent, and can showcase literally anything.) If IDLE were to grow a peer-to-peer pair programming feature, I could imagine it being a text-only connection with a single master and any number of slaves, where the slaves are showing a replica of the master's screen. IMO the slaves should not need any way to directly manipulate anything, though it may be of value to be able to highlight a block of text and have the master see that highlight (independently of the master's own text selection). Having everyone able to edit simultaneously creates technological problems, and then a social problem (when you start trampling over each other's code by mistake), and the solution to the social problem usually amounts to a semaphore system "okay, you go ahead and take over"; baking that semaphore into the technology (by having only a single master) would keep things way simpler. ChrisA From PythonList at DancesWithMice.info Fri Aug 2 16:52:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 08:52:59 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> On 3/08/19 8:32 AM, Terry Reedy wrote: > On 8/2/2019 5:10 AM, DL Neil wrote: >> Please recommend a Python-friendly, bandwidth-respectful, (but >> effective) system for pair-programming; where the 'pair' are >> geographically separate. > 'geographically separate' could range from in the same room to a > continent away, as long as two people have separate keyboards and screens. True! As long as the tech works... My experience has always been two sharing one PC, ie taking-it-in-turns to think or to type. Do you do it differently? >> [I don't mind putting a bit of money into a good service, but $free >> for preference and F/LOSS for principle] > Intended to show the survey so-far (has he done his own 'homework'?), to save us from 'red herrings' but also to see if other approaches might exist. (such as your next thought...) > IDLE is Python-friendly, free, and FOSS.? I wonder how hard it would be > to pair programming connectivity as an extension.? A couple of questions: > > 1. Do the systems you have considered operate as an editor + satellite > terminal or as synchronized peer editors. Always the former, the local devices are merely 'repeaters' (through a web browser) of what is happening on the server. This at both edit and run/test stages. > 2. Do two systems connect directly peer-to-peer or through a server? Exclusively the latter (thus far in the investigation). -- Regards =dn From isidentical at gmail.com Fri Aug 2 13:57:39 2019 From: isidentical at gmail.com (Batuhan Taskaya) Date: Fri, 2 Aug 2019 20:57:39 +0300 Subject: Is there a simple way to wrap a built-in function for the whole package? In-Reply-To: <20190801222441.GA54533@cskk.homeip.net> References: <188ce0c3-ff6c-4f57-864d-b807da37e186@googlegroups.com> <20190801222441.GA54533@cskk.homeip.net> Message-ID: functools.partial is a better option On Fri, Aug 2, 2019, 1:25 AM Cameron Simpson wrote: > On 31Jul2019 19:16, Jach Fong wrote: > >I get a package from Pypi. The package has many modules using built-in > open() function. I like to redefine all the open() there with the default > encoding 'utf-8', but not for code outside the package. Maybe I can put my > def statement at the beginning of every module of this package, but just > wondering is there a simple way of doing it? > > I would define something like this in the __init__.py file of the > package (or in some utils.py file in the package): > > def open8(path): > return open(path, encoding='utf-8') > > and just: > > from . import open8 > > and use "open8" throughout the code instead of "open"? > > What not alias "open"? Because I would want it evident that in this code > we're doing a slightly special flavour of open. By using a distinct name > I avoid confusion about the unusual semantics. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From abarnert at yahoo.com Fri Aug 2 12:17:39 2019 From: abarnert at yahoo.com (Andrew Barnert) Date: Fri, 2 Aug 2019 09:17:39 -0700 Subject: [Python-ideas] Fwd: Re: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: <0781CAF0-F5FD-4465-B687-A21330B53537@yahoo.com> On Aug 1, 2019, at 13:38, Daniel Okey-Okoro wrote: > > > > not a strong enough justification for breaking any code that uses "no" in any other way. > > This is a very crucial point I didn't consider. > > ------------------------------------------------------------ > > What if we could lexically limit it to `if no {{everything else in the if block}}`? > > I think that would sufficiently protect us from unintentionally breaking people's code. There are some cases where a ?contextual keyword? that?s usable as an identifier outside of a specific syntactic construct could avoid ambiguity, but this isn?t one of them, because the thing immediately after the `if` in an if statement can be?and often is?an identifier. For example: total = len(votes) yes, no, other = (len(part) for part in partition_votes(votes)) if no >= total//2: # etc. I even found an actual example of the equivalent in some C++ code I had on my hard drive: if (no == ask(?)) { // ? } In Python, that would be: if no == ask(?): Also, even if that weren?t a problem, this would be very misleading syntax. If I can write `if no sales:` I?d expect to be able to write `if isopen and no sales:` or `0 if no sales else mean(sales)` or `skip = no sales` or any of the other things I can do with `not` and other operators rather than special syntax. Also, I could still write `if no sales and isopen:`, but it would do the wrong thing if `no` is special syntax that reverses the sense of the `if` rather than a normal operator that binds more tightly than `and`. From PythonList at DancesWithMice.info Fri Aug 2 17:28:30 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 09:28:30 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: <52de8b5c-96bb-383e-75aa-f379ad1e06a2@DancesWithMice.info> On 3/08/19 8:44 AM, Chris Angelico wrote: > On Sat, Aug 3, 2019 at 6:34 AM Terry Reedy wrote: >> On 8/2/2019 5:10 AM, DL Neil wrote: >>> Please recommend a Python-friendly, bandwidth-respectful, (but >>> effective) system for pair-programming; where the 'pair' are >>> geographically separate. >> >> 'geographically separate' could range from in the same room to a >> continent away, as long as two people have separate keyboards and screens. > > Though there may be differences between LAN-optimized tools and > internet-optimized ones. Correct! Koding (on my ToDo list for today) no longer offers a web-based service but offers a download for Docker or Kubernetes (or ???). The communications lag has been my biggest concern since we opened the investigation... > Not the OP, but weighing in from personal experience: I've often pair I'm hoping for more responses recounting personal experience, especially if it involves a stern warning for my sanity! (oops, too late!) > programmed using just a video call service (with screen share). The TeamViewer, and similar? I didn't mention this earlier, perhaps being carried-away by my enthusiasm for 'there must be a better way'... > biggest downside is that it has to share the full image of the screen, > which means it has to aggressively compress the video in order to > handle home-grade internet connections. (OTOH, that does mean that > it's IDE-independent, and can showcase literally anything.) If IDLE > were to grow a peer-to-peer pair programming feature, I could imagine > it being a text-only connection with a single master and any number of > slaves, where the slaves are showing a replica of the master's screen. > IMO the slaves should not need any way to directly manipulate > anything, though it may be of value to be able to highlight a block of > text and have the master see that highlight (independently of the I have used VNC-type software to slave screens, either in pairs (tutorial - mine following a trainee's work) or in a 'class set' (using my screen as a 'projector'). It seemed both finicky and fragile and whilst working well on-the-LAN (ie in-class), was too slow and 'block-y' updating the screens when we used it for remote tutorials. (of course such [also] reveals that we didn't have very high-speed connections) During such, the VNC profiles were set so that trainees' I/O devices were 'locked' to prevent clashes. However, that need doesn't apply here and is actually contrary to the objectives... > master's own text selection). Having everyone able to edit > simultaneously creates technological problems, and then a social One of the encouraging features of many options (on list in earlier post) is the facility of "multiple cursors". At first this confused me, because many text editors allow one to declare "multiple cursors" in order to perform the same action at multiple locations throughout the same source-file. In the pair-programming context, "multiple cursors" means exactly what you say: each contributor is able to work (relatively) independently of the other, and the system keeps track of who-is-doing-what! ("IDE-independent"?) > problem (when you start trampling over each other's code by mistake), > and the solution to the social problem usually amounts to a semaphore > system "okay, you go ahead and take over"; baking that semaphore into > the technology (by having only a single master) would keep things way > simpler. Which is why I assumed the need for Zoom or similar audio connection (A/V 'on top' likely to overwhelm a wi-fi link)? None seem to offer that, however some do provide a "chat" window. Yes, the "semaphore" is going to be my biggest concern on the night. When done in-person, a lot can be communicated non-verbally (and, perhaps particularly in this country: rather informally, eg even a nudge of the elbow = 'move out of the way and let me in/I got this'). I'm thinking that such will require a greater degree of formality and courtesy. Radio operators are used to the discipline of letting the other person finish talking... Contrarily, that might be handled by agreed r?les and 'separation of concerns':- Many of these services store the source code (etc) 'in the cloud', plus each contributor can share or have his/her own editor screen (your "IDE-independent", above). So, it would also be possible for one to be designing tests concurrently with the other writing code. However, perhaps we're getting away from 'traditional' pair programming, and into the area of 'just because the technology enables us do it, doesn't mean it's a good idea'! OTOH the whole point of this investigation is to see what's 'out there' and be open to whatever if might enable us to do... Thanks for your wisdom. -- Regards =dn From PythonList at DancesWithMice.info Fri Aug 2 18:19:43 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 10:19:43 +1200 Subject: [Python-ideas] Fwd: Re: PEP: add a `no` keyword as an alias for `not` In-Reply-To: <0781CAF0-F5FD-4465-B687-A21330B53537@yahoo.com> References: <0781CAF0-F5FD-4465-B687-A21330B53537@yahoo.com> Message-ID: A truly marvellous aspect of Python is its world-wide spread! Many people use Python with greater ease than they speak or write English, despite Python appearing to be a sub-set of the English language! Native English-speakers often* have difficulty following negatively-worded sentences, eg "if there were no sales". (* coming from certain cultures/languages this evaluation changes to: "usually"!) We, of the computing world, must become familiar with Boolean Algebra; and thus learn to compose a Truth-Table matrix in our heads. Psychologically this suggests we first seek "logic", and only thereafter "meaning" - is this "normal" behavior? (humor, not question) We are all familiar with the injunction: do not to use "double negatives" in a sentence, eg "I can't get no satisfaction" or "A rolling stone don't gather no moss"; because it confuses people - regardless of their English-language facility. (even more than 'big words' such as "facility" have the potential to reduce understanding!) In fact, to continue analysing our own specific language-skills, when we double-up on something, eg a BASH switch like -vv, doesn't that mean 'don't just -v, but do it MORE-SO'? Thus, doubling your negatives would mean: 'even more negative', surely? Is that what "English" says though? NB repetition, in both a positive, or negative, sense; means "more" in many cultures, even good, old English: "hear, hear!". Accordingly, I feel for the OP. Personally I dislike reading, and recoil from writing: if not something_positive: On the other hand: if something_positive: pass else: process_the_negative whilst acceptable, probably doesn't look or read any better. Perhaps an answer is to use a "flag": no_sales_today = total_sales <= 0 if no_sales_today: fire_the_sales_manager() The descriptive variable-name IS 'negative', but the if-condition becomes (somewhat) positive, removes the comprehension-reducing "not", and the construct remains a simple if-then (ie no -else). (it also uses "no" in the flow-of-communication, per OP's suggested line-of-thought) -- Regards =dn From rosuav at gmail.com Fri Aug 2 18:34:19 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Aug 2019 08:34:19 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <52de8b5c-96bb-383e-75aa-f379ad1e06a2@DancesWithMice.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <52de8b5c-96bb-383e-75aa-f379ad1e06a2@DancesWithMice.info> Message-ID: On Sat, Aug 3, 2019 at 7:30 AM DL Neil wrote: > > On 3/08/19 8:44 AM, Chris Angelico wrote: > > programmed using just a video call service (with screen share). The > > TeamViewer, and similar? > I didn't mention this earlier, perhaps being carried-away by my > enthusiasm for 'there must be a better way'... Google Hangouts, or a proprietary internal platform ("Owl") which does similar things but is better able to handle different bandwidth connections. > I have used VNC-type software to slave screens, either in pairs > (tutorial - mine following a trainee's work) or in a 'class set' (using > my screen as a 'projector'). It seemed both finicky and fragile and > whilst working well on-the-LAN (ie in-class), was too slow and 'block-y' > updating the screens when we used it for remote tutorials. (of course > such [also] reveals that we didn't have very high-speed connections) Yeah, that would be basically what I'm talking about. It works fairly well with a trainer/trainee model, as the trainer wants to be "hands off" most of the time anyway (better to talk the trainee through doing it than to grab the keyboard and do it yourself), and the "projector" model you describe is definitely that style. > > master's own text selection). Having everyone able to edit > > simultaneously creates technological problems, and then a social > > One of the encouraging features of many options (on list in earlier > post) is the facility of "multiple cursors". > > At first this confused me, because many text editors allow one to > declare "multiple cursors" in order to perform the same action at > multiple locations throughout the same source-file. In the > pair-programming context, "multiple cursors" means exactly what you say: > each contributor is able to work (relatively) independently of the > other, and the system keeps track of who-is-doing-what! ("IDE-independent"?) That would NOT be IDE-independent, as it requires help from the software itself (what I'm talking about is the way screenshare can jump across to your browser, a running app, etc, etc, and it's exactly the same as being inside the IDE). Multiple cursors is exactly what I meant when I referred to the technical problem and the social problem. The technical problem (there's only one ipt and every keystroke affects that point) can be solved with multiple cursors, but you're still left with the social problem (one person changes something up here, another changes something down there, and your changes affect each other - or, one is editing what another person tries to indent). So I'm actually quite happy with a blanket solution to the social problem by saying "only one person can edit at a time" - and forcing people to commit/push/pull to transfer the code to a new driver - and using that to avoid needing to go to the technical effort of multiple ipts. > Which is why I assumed the need for Zoom or similar audio connection > (A/V 'on top' likely to overwhelm a wi-fi link)? None seem to offer > that, however some do provide a "chat" window. Yes, some sort of audio link is HUGELY helpful, even if you do have multiple cursors. You can synchronize over it ("Okay, lemme try something") and just bounce ideas back and forth. If your software is replicating the display, you don't need video, and an audio connection is way lower bandwidth (also, a little latency can be handled - it's no big deal if you have 100ms or 250ms lag on the audio if you have snappy text updates). > Yes, the "semaphore" is going to be my biggest concern on the night. > When done in-person, a lot can be communicated non-verbally (and, > perhaps particularly in this country: rather informally, eg even a nudge > of the elbow = 'move out of the way and let me in/I got this'). "Move, I have a kit" is occasionally effective even when said by your opponents... or maybe that's exclusive to Counter-Strike... anyhow. > I'm thinking that such will require a greater degree of formality and > courtesy. Radio operators are used to the discipline of letting the > other person finish talking... Right. Works quite well IME. Basically, what I'd be interested in seeing is a multi-player game of Notepad++, in contrast to IRC. http://www.bash.org/?85514 ChrisA From PythonList at DancesWithMice.info Fri Aug 2 19:20:20 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 11:20:20 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On 3/08/19 8:57 AM, Dennis Lee Bieber wrote: > On Fri, 2 Aug 2019 21:10:32 +1200, DL Neil > declaimed the following: >> - AWS Cloud9: (apparently will run on a small, free, cloud-server) > > Cloud9 is normally available on BeagleBone Black cards (though you'd > have to open up your firewalls and maybe set up a DNS entry so others can > connect to it). However, that appears to be an older version (v3.1.4056, > 2017), not the Amazon Web Services version, and does not appear to have the > collaboration features described at > https://docs.c9.io/docs/share-a-workspace There's a great idea - put a BBB in the middle! Thanks wlfraed - will be checking the AWS version... (they claim it will even work on a 'free' server, which presumably means it would last for a whole year!) -- Regards =dn From PythonList at DancesWithMice.info Fri Aug 2 19:39:14 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 11:39:14 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <52de8b5c-96bb-383e-75aa-f379ad1e06a2@DancesWithMice.info> Message-ID: On 3/08/19 10:34 AM, Chris Angelico wrote: > On Sat, Aug 3, 2019 at 7:30 AM DL Neil wrote: >> On 3/08/19 8:44 AM, Chris Angelico wrote: > Google Hangouts, or a proprietary internal platform ("Owl") which does > similar things but is better able to handle different bandwidth > connections. Thanks. Will add to the mix... >> I have used VNC-type software to slave screens, either in pairs >> (tutorial - mine following a trainee's work) or in a 'class set' (using >> my screen as a 'projector'). It seemed both finicky and fragile and >> whilst working well on-the-LAN (ie in-class), was too slow and 'block-y' >> updating the screens when we used it for remote tutorials. (of course >> such [also] reveals that we didn't have very high-speed connections) > Yeah, that would be basically what I'm talking about. It works fairly > well with a trainer/trainee model, as the trainer wants to be "hands > off" most of the time anyway (better to talk the trainee through doing > it than to grab the keyboard and do it yourself), and the "projector" > model you describe is definitely that style. Yes. I would prefer something with a more collaborative mode - helpful rather than 'taking (over) the lead'... >>> master's own text selection). Having everyone able to edit >>> simultaneously creates technological problems, and then a social >> One of the encouraging features of many options (on list in earlier >> post) is the facility of "multiple cursors". >> At first this confused me, because many text editors allow one to >> declare "multiple cursors" in order to perform the same action at >> multiple locations throughout the same source-file. In the >> pair-programming context, "multiple cursors" means exactly what you say: >> each contributor is able to work (relatively) independently of the >> other, and the system keeps track of who-is-doing-what! ("IDE-independent"?) > That would NOT be IDE-independent, as it requires help from the > software itself (what I'm talking about is the way screenshare can > jump across to your browser, a running app, etc, etc, and it's exactly > the same as being inside the IDE). Agreed - and just because two could work 'independently'... (a) certainly doesn't make it a 'good idea'! and (b) doesn't strike me as "pair programming", particularly not in the context of a PUG meeting - as you say... > Multiple cursors is exactly what I meant when I referred to the > technical problem and the social problem. The technical problem > (there's only one ipt and every keystroke affects that point) can be > solved with multiple cursors, but you're still left with the social > problem (one person changes something up here, another changes > something down there, and your changes affect each other - or, one is > editing what another person tries to indent). So I'm actually quite > happy with a blanket solution to the social problem by saying "only > one person can edit at a time" - and forcing people to > commit/push/pull to transfer the code to a new driver - and using that > to avoid needing to go to the technical effort of multiple ipts. > >> Which is why I assumed the need for Zoom or similar audio connection >> (A/V 'on top' likely to overwhelm a wi-fi link)? None seem to offer >> that, however some do provide a "chat" window. > > Yes, some sort of audio link is HUGELY helpful, even if you do have > multiple cursors. You can synchronize over it ("Okay, lemme try > something") and just bounce ideas back and forth. If your software is > replicating the display, you don't need video, and an audio connection > is way lower bandwidth (also, a little latency can be handled - it's > no big deal if you have 100ms or 250ms lag on the audio if you have > snappy text updates). Thanks for this assessment. >> Yes, the "semaphore" is going to be my biggest concern on the night. >> When done in-person, a lot can be communicated non-verbally (and, >> perhaps particularly in this country: rather informally, eg even a nudge >> of the elbow = 'move out of the way and let me in/I got this'). > > "Move, I have a kit" is occasionally effective even when said by your > opponents... or maybe that's exclusive to Counter-Strike... anyhow. Sorry, not a gamer. However, during 'the real thing' I wouldn't have dared to say such a thing to my buddy! (mind you, he was the unit's armorer) Most of the time they pushed me down/towards the back. One of the advantages of carrying the radios! (needed to tell the airedales where to direct their fire, and which RDV we're using - please, please, please come to take us home... Forget games, try music: "I wanna go home" or "I want to get out of this place"!) Although as "nav" I did get to say "move out". Close enough? >> I'm thinking that such will require a greater degree of formality and >> courtesy. Radio operators are used to the discipline of letting the >> other person finish talking... > > Right. Works quite well IME. > > Basically, what I'd be interested in seeing is a multi-player game of > Notepad++, in contrast to IRC. http://www.bash.org/?85514 With the ability to frag your pair-programmer when (s)he makes a mistake? Remind me never to 'pair' with you! I'll see what I can find... -- Regards =dn From rosuav at gmail.com Fri Aug 2 19:46:32 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Aug 2019 09:46:32 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <52de8b5c-96bb-383e-75aa-f379ad1e06a2@DancesWithMice.info> Message-ID: On Sat, Aug 3, 2019 at 9:40 AM DL Neil wrote: > > Basically, what I'd be interested in seeing is a multi-player game of > > Notepad++, in contrast to IRC. http://www.bash.org/?85514 > > With the ability to frag your pair-programmer when (s)he makes a > mistake? Remind me never to 'pair' with you! > Oh certainly not, I don't condone team-killing :) More seriously: I did build a very simple "multi-player notepad", which I've used with various people at various times. It's simplistic and nothing like what you actually need for this job, but the concept is similar; any time you make a change, everyone sees that change. The communication channel is plain text, and it's rendered on each side locally. ChrisA From cs at cskk.id.au Fri Aug 2 19:50:02 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 3 Aug 2019 09:50:02 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: Message-ID: <20190802235002.GA32180@cskk.homeip.net> On 03Aug2019 11:39, DL Neil wrote: >On 3/08/19 10:34 AM, Chris Angelico wrote: >>On Sat, Aug 3, 2019 at 7:30 AM DL Neil wrote: >>>On 3/08/19 8:44 AM, Chris Angelico wrote: >>Google Hangouts, or a proprietary internal platform ("Owl") which does >>similar things but is better able to handle different bandwidth >>connections. > >Thanks. Will add to the mix... appear.in can also screen share along with its video conferencing, and I imagine Zoom might do so also. But a screen share is "read only" for the other party. You could both screen share of course, but it doesn't solve the keep-the-code-in-sync issue. Cheers, Cameron Simpson From jfong at ms4.hinet.net Fri Aug 2 20:46:59 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 2 Aug 2019 17:46:59 -0700 (PDT) Subject: Is there a simple way to wrap a built-in function for the whole package? In-Reply-To: References: <188ce0c3-ff6c-4f57-864d-b807da37e186@googlegroups.com> <20190801222441.GA54533@cskk.homeip.net> Message-ID: Batuhan Taskaya? 2019?8?3???? UTC+8??5?27?49???? > functools.partial is a better option > > On Fri, Aug 2, 2019, 1:25 AM Cameron Simpson wrote: > > > On 31Jul2019 19:16, Jach Fong wrote: > > >I get a package from Pypi. The package has many modules using built-in > > open() function. I like to redefine all the open() there with the default > > encoding 'utf-8', but not for code outside the package. Maybe I can put my > > def statement at the beginning of every module of this package, but just > > wondering is there a simple way of doing it? > > > > I would define something like this in the __init__.py file of the > > package (or in some utils.py file in the package): > > > > def open8(path): > > return open(path, encoding='utf-8') > > > > and just: > > > > from . import open8 > > > > and use "open8" throughout the code instead of "open"? > > > > What not alias "open"? Because I would want it evident that in this code > > we're doing a slightly special flavour of open. By using a distinct name > > I avoid confusion about the unusual semantics. > > > > Cheers, > > Cameron Simpson > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Totally agree:-) --Jach From tjreedy at udel.edu Fri Aug 2 23:23:05 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 2 Aug 2019 23:23:05 -0400 Subject: PEP: add a `no` keyword as an alias for `not` In-Reply-To: References: Message-ID: On 8/1/2019 4:06 PM, Daniel Okey-Okoro wrote: > I think that adding a `no` keyword as an alias for `not` would make for > more readable, simple, pythonic code. I am 99.99% sure that this would not be accepted. However, the discussion of the not operator is worth at least a blog post. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 3 00:02:32 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 3 Aug 2019 00:02:32 -0400 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> Message-ID: On 8/2/2019 4:52 PM, DL Neil wrote: > On 3/08/19 8:32 AM, Terry Reedy wrote: >> On 8/2/2019 5:10 AM, DL Neil wrote: >>> Please recommend a Python-friendly, bandwidth-respectful, (but >>> effective) system for pair-programming; where the 'pair' are >>> geographically separate. >> 'geographically separate' could range from in the same room to a >> continent away, as long as two people have separate keyboards and >> screens. > > True! As long as the tech works... > > My experience has always been two sharing one PC, ie taking-it-in-turns > to think or to type. Do you do it differently? I currently work on my home machine, so my recent 'pair programming' has been limited to comments and now diff suggestions on Github PRs. So I need the comments on real use cases from you and Chris to even think about something for IDLE. >> IDLE is Python-friendly, free, and FOSS.? I wonder how hard it would >> be to pair programming connectivity as an extension. This was an initially pie-in-the-sky idea that cannot solve your immediate problem. But I think now that something useful could be feasible sometime. >> 1. Do the systems you have considered operate as an editor + satellite >> terminal or as synchronized peer editors. > > Always the former, the local devices are merely 'repeaters' (through a > web browser) of what is happening on the server. This at both edit and Good. Master-satellite would be much easier. We added line numbers to IDLE's editor last week, so verbal feedback from satellite to master should be sufficient for many purposes. IDLE already intercepts keypresses to do syntax coloring and smart indentation (after \n). It should not be too hard to also send through a socket anything sent to a tkinter/tk text widget. Making a text read-only is trivial. With a real editor as satellite, the locally configured font face, font size, and syntax highlight colors can be used. Transmitting highlighting as text would require the invention of a protocol to differentiate text from such meta information. > run/test stages. Running code locally would 1. Save bandwidth. 2. Allow two users to do different things occasionally. 3. Reveal OS dependencies if on different systems. When patching IDLE, I would love to have my Macbook set as a satellite to check that code works on Mac as well as Windows. 4. Require encryption of some sort if over the public internet. Just because people download code from strangers over http is not a reason to encourage carelessness. I am pretty ignorant on what this would mean. >> 2. Do two systems connect directly peer-to-peer or through a server? > > Exclusively the latter (thus far in the investigation). The former would be the only option until someone (else) set up and supported a server. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 3 00:05:57 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 3 Aug 2019 00:05:57 -0400 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On 8/2/2019 4:44 PM, Chris Angelico wrote: in response to my enquiries > Not the OP, but weighing in from personal experience: I've often pair > programmed using just a video call service (with screen share). The > biggest downside is that it has to share the full image of the screen, > which means it has to aggressively compress the video in order to > handle home-grade internet connections. (OTOH, that does mean that > it's IDE-independent, and can showcase literally anything.) If IDLE > were to grow a peer-to-peer pair programming feature, I could imagine > it being a text-only connection with a single master and any number of > slaves, where the slaves are showing a replica of the master's screen. > IMO the slaves should not need any way to directly manipulate > anything, though it may be of value to be able to highlight a block of > text and have the master see that highlight (independently of the > master's own text selection). Having everyone able to edit > simultaneously creates technological problems, and then a social > problem (when you start trampling over each other's code by mistake), > and the solution to the social problem usually amounts to a semaphore > system "okay, you go ahead and take over"; baking that semaphore into > the technology (by having only a single master) would keep things way > simpler. Thank you for the helpful response in a area where I lack experience. My response to Daniel includes my response to the above. -- Terry Jan Reedy From PythonList at DancesWithMice.info Sat Aug 3 00:51:54 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 16:51:54 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <20190802235002.GA32180@cskk.homeip.net> References: <20190802235002.GA32180@cskk.homeip.net> Message-ID: <52aaffe8-5574-05e4-2d1c-0db25dacdcb2@DancesWithMice.info> On 3/08/19 11:50 AM, Cameron Simpson wrote: > appear.in can also screen share along with its video conferencing, and I > imagine Zoom might do so also. But a screen share is "read only" for the > other party. You could both screen share of course, but it doesn't solve > the keep-the-code-in-sync issue. Thanks Cameron. TBH I fear that the keep-the-code-in-sync issue is a bit of a 'red herring'. Do your pair-programming exercises ever involve both developing the same code-file at the same time? A simple screen-share solution has to be the MVP: - I can see the code someone wants to show/is requesting help for - we can talk through the question - but I can't 'take control', eg would have to ask the other person to scroll in order to show a piece of code 'somewhere else'. Perhaps this is good discipline? I am hoping we can 'do better'. One of the PythonAnywhere principals has come back to me (I first used this service at least a decade ago, starting when I met Harry (the testing goat) Roberts at a London PUG meeting - although I'm not sure whether the evening's topic was PA and 'testing' was mentioned, or perhaps the other way around! You know how these meetings go - and the serendipitous benefits that can be realised, although not designed/deliberate). PA's "education" services do not appear to have progressed very far (since), but at least they are happy for me to use the scheme. Yay! The other observation is that Py3.7 *IS* now available (contrary to previous msg). In PA, if I open a "console", it can be shared with all my (PA-defined) "students" as r/o. Better, is that anyone who cares to ask for help (registered as one of my students) can ask me to 'look over their shoulder'. As well as navigating the other person's source-files, I think I could initiate a test, or quick edit, in that mode. (if you'd like to give-it-a-whirl/have-a-go, they offer free accounts (with modest but quite functional facilities) and the registration process is not onerous - if we* can arrange an RDV, I'll be happy to try working as a pair...) * by "we" I mean any list-member, not just Cameron (whose suggestion heads this post) - I haven't had a chance to start evaluating the two apparently 'larger' systems, mentioned yesterday... So, the ambition for this next PUG coding-night, is to find something that offers more than the screen-share 'MVP', is well-rounded, and easy to learn/install/use on a casual basis. My hope, is that 'something' will offer services we might not have thought relevant/possible/useful, at first... (we can but dream) -- Regards =dn From robertvstepp at gmail.com Sat Aug 3 01:03:08 2019 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 3 Aug 2019 00:03:08 -0500 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On Fri, Aug 2, 2019 at 4:11 AM DL Neil wrote: > > Please recommend a Python-friendly, bandwidth-respectful, (but > effective) system for pair-programming; where the 'pair' are > geographically separate. > At work (not programming related) my department has just started using GoToMeeting. So far it has worked well. It can transmit audio and share one's screen. The host can choose to share with the remote person a particular application, his keyboard and mouse or the whole shebang. I don't know how bandwidth intensive it might be, but our intranet bandwidth is often less capable than what I have at home. Also I believe it is a paid service. boB From cs at cskk.id.au Sat Aug 3 01:17:11 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 3 Aug 2019 15:17:11 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <52aaffe8-5574-05e4-2d1c-0db25dacdcb2@DancesWithMice.info> References: <52aaffe8-5574-05e4-2d1c-0db25dacdcb2@DancesWithMice.info> Message-ID: <20190803051711.GA42224@cskk.homeip.net> On 03Aug2019 16:51, DL Neil wrote: >On 3/08/19 11:50 AM, Cameron Simpson wrote: >>appear.in can also screen share along with its video conferencing, >>and I imagine Zoom might do so also. But a screen share is "read >>only" for the other party. You could both screen share of course, >>but it doesn't solve the keep-the-code-in-sync issue. > >Thanks Cameron. > >TBH I fear that the keep-the-code-in-sync issue is a bit of a 'red >herring'. Do your pair-programming exercises ever involve both >developing the same code-file at the same time? My pair programming experience is pretty limited. If peering over someone's should is enough, you're good. If you ever swap roles (typing versus reviewing) I'd think it gets trickier. >A simple screen-share solution has to be the MVP: >- I can see the code someone wants to show/is requesting help for >- we can talk through the question >- but I can't 'take control', eg would have to ask the other person to >scroll in order to show a piece of code 'somewhere else'. > >Perhaps this is good discipline? If you're teaching, then yes, sounds good to me. Student types, teacher observes. If it's two peers (regardless of relative expertise in the current problem) I'd imagine wanting to switch around occasionally. Like: Observer: what if we do blah-blah? Coder: not sure what you mean. Observer: types short example code, because it is easier than a precise verbal explaination. Coder: if ok, adapts the example to the actual problem. If you're mentoring/tutoring, you can put the typing in the associated text messaging system - I think most video conferency things let people message inside the conference? So you're not sharing a keyboard, but you can pass text/code around for copy/paste. >One of the PythonAnywhere principals has come back to me [...] >In PA, if I open a "console", it can be shared with all my (PA-defined) >"students" as r/o. Better, is that anyone who cares to ask for help >(registered as one of my students) can ask me to 'look over their >shoulder'. As well as navigating the other person's source-files, I >think I could initiate a test, or quick edit, in that mode. > >(if you'd like to give-it-a-whirl/have-a-go, they offer free accounts >(with modest but quite functional facilities) and the registration >process is not onerous - if we* can arrange an RDV, I'll be happy to >try working as a pair...) Actually, I'd like that. But I'm in GMT+10. Guessing you're in GMT? We could take that off list. >* by "we" I mean any list-member, not just Cameron (whose suggestion >heads this post) My suggestions were merely "here're two more video conferencing services". Cheers, Cameron Simpson From cs at cskk.id.au Sat Aug 3 01:20:14 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 3 Aug 2019 15:20:14 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> References: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> Message-ID: <20190803052014.GA86417@cskk.homeip.net> On 03Aug2019 08:52, DL Neil wrote: >On 3/08/19 8:32 AM, Terry Reedy wrote: >>2. Do two systems connect directly peer-to-peer or through a server? > >Exclusively the latter (thus far in the investigation). If one party is remote and both are behind a NAT (_very_ common in Australia, for example) then you always need an external intermediary. Even if that intermediary does no more than connect some sockets from each end together and blindly pass traffic. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sat Aug 3 01:34:33 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 3 Aug 2019 17:34:33 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> Message-ID: <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> On 3/08/19 4:02 PM, Terry Reedy wrote: > On 8/2/2019 4:52 PM, DL Neil wrote: >> On 3/08/19 8:32 AM, Terry Reedy wrote: >>> On 8/2/2019 5:10 AM, DL Neil wrote: >>>> Please recommend a Python-friendly, bandwidth-respectful, (but >>>> effective) system for pair-programming; where the 'pair' are >>>> geographically separate. >>> 'geographically separate' could range from in the same room to a >>> continent away, as long as two people have separate keyboards and >>> screens. >> True! As long as the tech works... >> My experience has always been two sharing one PC, ie >> taking-it-in-turns to think or to type. Do you do it differently? > I currently work on my home machine, so my recent 'pair programming' has > been limited to comments and now diff suggestions on Github PRs.? So I > need the comments on real use cases from you and Chris to even think > about something for IDLE. Is that really "p-p" or more "code review"? What I had in-mind, and others may see it differently (and I will happily modify any contribution to whatever an individual PUG attendee might need!) is more-or-less the sort of practical question we see on the list/one hears in a dev-lab, all the time, eg 'why doesn't 'this' work?', or 'how do I...?" but with the advantage of the conversation taking-place in real-time. If the answer is trivial, that's it. Something more-involved however, may require a detailed look at the code, or 'sitting and watching' whilst the other starts to include some new 'suggestion' into their code-base. That takes us into the synergies offered by pair-programming... Use case: (possible examples) (The meeting organiser talked about a project involving Solid ID) - let's suggest the project hasn't started to-date. Perhaps he would download the code and start coding an enquiry against the API. Meantime I could be writing some Tests. - he starts work, but the API doesn't respond in the expected manner. He asks me to 'take a look', so I read the code, scroll around, ask 'why' or 'why not' questions, and within the conversation we decide an alternative approach The former, strikes me as a possible contribution to the PUG mtg, but the latter is more "pair programming" mode. In the case of Wednesday's PUG meeting, my personal goal is to offer encouragement. If that involves 'full' pair-programming I would like to be ready - if it involves more simplistic contribution, crest la vie - if we can find some new approach which 'shoots for the moon' then all my dreams will come true... >>> IDLE is Python-friendly, free, and FOSS.? I wonder how hard it would >>> be to pair programming connectivity as an extension. > > This was an initially pie-in-the-sky idea that cannot solve your > immediate problem.? But I think now that something useful could be > feasible sometime. (with all due apologies) I haven't touched Idle in years (probably v2.n - and n<5 at that). Can't remember if I did something which impacted the Idle environment, or if it was because I was doing a lot of web-work. Regardless, even after a quick scan of the v3.7 PSL docs, I don't know what I'm talking about! (as if that's anything new) >>> 1. Do the systems you have considered operate as an editor + >>> satellite terminal or as synchronized peer editors. >> >> Always the former, the local devices are merely 'repeaters' (through a >> web browser) of what is happening on the server. This at both edit and > > Good.? Master-satellite would be much easier.? We added line numbers to > IDLE's editor last week, so verbal feedback from satellite to master > should be sufficient for many purposes. Elsewhere in the thread there is much discussion of this. Regardless of the "we are all adults here" philosophy, my feeling (stuck-in-the-mud though it might be) is that one person/system has to have 'control', and the other, the 'pair' (or the 'tutor') is invited to see/do 'whatever'. However, r/o would be a show-stopping limitation. > IDLE already intercepts keypresses to do syntax coloring and smart > indentation (after \n).? It should not be too hard to also send through > a socket anything sent to a tkinter/tk text widget.? Making a text > read-only is trivial. Sounds like the sorts of things Linux's X-server does/did. > With a real editor as satellite, the locally configured font face, font > size, and syntax highlight colors can be used.? Transmitting > highlighting as text would require the invention of a protocol to > differentiate text from such meta information. > >> run/test stages. Yes, important to remember that the editor is only one tool, and that pair-programming may involve kicking-off a 'run' from the cmdLN or browsing a page from the web server (etc). > Running code locally would > 1. Save bandwidth. > 2. Allow two users to do different things occasionally. > 3. Reveal OS dependencies if on different systems.? When patching IDLE, > I would love to have my Macbook set as a satellite to check that code > works on Mac as well as Windows. Good idea! Websites frequently use services which show how different browsers (and versions) will display the same web page. > 4. Require encryption of some sort if over the public internet.? Just > because people download code from strangers over http is not a reason to > encourage carelessness.? I am pretty ignorant on what this would mean. TLS? >>> 2. Do two systems connect directly peer-to-peer or through a server? >> Exclusively the latter (thus far in the investigation). > > The former would be the only option until someone (else) set up and > supported a server. Except that when you think about it, were I viewing your screen, your m/c would indeed be a "server"! We could lose potential by arguing semantics (not my intention). In fact, we dealt with this point, above. Some of the cloud services I've reviewed present a screen very similar to a GUI editor one might use on a (local) PC. Others offer a BASH cmdLN and thus the Python REP. (I haven't tried calling for Idle, and maybe I should - some have listed VI[m], EMACS, or even Nano. Thus, it may be that a GUI-based service suits some coders, whereas others would prefer the more character-oriented approach... I'm thrilled at your interest, but am ignorant/uncertain that pair-programming and Idle go together. To which you may say that perhaps they should... In which case, I'd recommend taking a look at some of the services (listed at the beginning of this thread) to first establish 'virtue' and yes, I'll try to do a better job at roughing-out some use-cases with you... -- Regards =dn From rosuav at gmail.com Sat Aug 3 01:50:32 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Aug 2019 15:50:32 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: On Sat, Aug 3, 2019 at 3:36 PM DL Neil wrote: > > On 3/08/19 4:02 PM, Terry Reedy wrote: > > I currently work on my home machine, so my recent 'pair programming' has > > been limited to comments and now diff suggestions on Github PRs. So I > > need the comments on real use cases from you and Chris to even think > > about something for IDLE. > > Is that really "p-p" or more "code review"? I'd say that, no, commenting on GitHub PRs is not "pair programming". It's a different form of collaboration. Pair programming specifically refers to two people working in realtime on one project. > > Good. Master-satellite would be much easier. We added line numbers to > > IDLE's editor last week, so verbal feedback from satellite to master > > should be sufficient for many purposes. > > Elsewhere in the thread there is much discussion of this. Regardless of > the "we are all adults here" philosophy, my feeling (stuck-in-the-mud > though it might be) is that one person/system has to have 'control', and > the other, the 'pair' (or the 'tutor') is invited to see/do 'whatever'. > However, r/o would be a show-stopping limitation. When pair programming involves training (tutor and student, or senior and junior programmer), forcing the more experienced person to stay hands-off is a very good thing; it forces the less experienced person to actually keyboard every change, and thus is more likely to understand what's going on. But when it's two peers, you'll often want to switch out who's in control. Depending on the architecture, this might be a simple matter of flipping a switch and changing who's master and who's on a read-only clone. > > 4. Require encryption of some sort if over the public internet. Just > > because people download code from strangers over http is not a reason to > > encourage carelessness. I am pretty ignorant on what this would mean. > > TLS? > TLS doesn't really solve this problem. If you have a single central server, TLS just tells you that you're talking to that server, without proving anything about who's on the other end. Even if you directly connect the two nodes, TLS wouldn't prove who that is, unless you get a dedicated certificate. What it *can* prove is that your data stream hasn't been tampered with en route, but the problem of receiving code from strangers is still an issue. Ultimately, pair programming depends on a measure of trust - you have to be confident that the person you're pairing with isn't going to be maliciously messing with your system. However, I think it would be an extremely useful feature if the output from running the program could also be replicated to the other client. Let's say you're developing a Python script that connects to a database (eg psycopg2 + PostgreSQL). To run that locally, you'd need your own replica of the database, and that often means having your own credentials (ie having the script able to choose which set of credentials to use), replicating the database schema, and possibly even getting a duplicate of the current table contents. Way WAY easier to just run it on one computer and copy the output. > >>> 2. Do two systems connect directly peer-to-peer or through a server? > >> Exclusively the latter (thus far in the investigation). > > > > The former would be the only option until someone (else) set up and > > supported a server. > > Except that when you think about it, were I viewing your screen, your > m/c would indeed be a "server"! We could lose potential by arguing > semantics (not my intention). In fact, we dealt with this point, above. There's a difference between the conceptual and the technical here. The NAT issue may mean that, for technical reasons, a broker is needed. > I'm thrilled at your interest, but am ignorant/uncertain that > pair-programming and Idle go together. To which you may say that perhaps > they should... In which case, I'd recommend taking a look at some of the > services (listed at the beginning of this thread) to first establish > 'virtue' and yes, I'll try to do a better job at roughing-out some > use-cases with you... I think Idle could be a very useful pair programming tool, but that doesn't mean it'd be the best option available. IMO it could be an extremely light-weight one, though. ChrisA From bryon at btjanaka.net Fri Aug 2 22:08:11 2019 From: bryon at btjanaka.net (Bryon Tjanaka) Date: Fri, 2 Aug 2019 19:08:11 -0700 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <20190802235002.GA32180@cskk.homeip.net> References: <20190802235002.GA32180@cskk.homeip.net> Message-ID: Depending on how often you need to run the code, you could use a google doc and copy the code over when you need to run. Of course, if you need linters and other tools to run frequently this would not work. On Fri, Aug 2, 2019 at 4:50 PM Cameron Simpson wrote: > On 03Aug2019 11:39, DL Neil wrote: > >On 3/08/19 10:34 AM, Chris Angelico wrote: > >>On Sat, Aug 3, 2019 at 7:30 AM DL Neil > wrote: > >>>On 3/08/19 8:44 AM, Chris Angelico wrote: > >>Google Hangouts, or a proprietary internal platform ("Owl") which does > >>similar things but is better able to handle different bandwidth > >>connections. > > > >Thanks. Will add to the mix... > > appear.in can also screen share along with its video conferencing, and I > imagine Zoom might do so also. But a screen share is "read only" for the > other party. You could both screen share of course, but it doesn't solve > the keep-the-code-in-sync issue. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- [image: logo] Bryon Tjanaka *"Audentes fortuna iuvat"* btjanaka.netgithub.com/btjanaka From tjreedy at udel.edu Sat Aug 3 14:44:56 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 3 Aug 2019 14:44:56 -0400 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: On 8/3/2019 1:50 AM, Chris Angelico wrote: > On Sat, Aug 3, 2019 at 3:36 PM DL Neil wrote: >> >> On 3/08/19 4:02 PM, Terry Reedy wrote: >>> I currently work on my home machine, so my recent 'pair programming' has >>> been limited to comments and now diff suggestions on Github PRs. So I >>> need the comments on real use cases from you and Chris to even think >>> about something for IDLE. >> >> Is that really "p-p" or more "code review"? The latter. The quotes here mean "the closest I currently come to pair programming". I have often *wished* for live interaction instead. > I'd say that, no, commenting on GitHub PRs is not "pair programming". > It's a different form of collaboration. Pair programming specifically > refers to two people working in realtime on one project. > >>> Good. Master-satellite would be much easier. We added line numbers to >>> IDLE's editor last week, so verbal feedback from satellite to master >>> should be sufficient for many purposes. >> >> Elsewhere in the thread there is much discussion of this. Regardless of >> the "we are all adults here" philosophy, my feeling (stuck-in-the-mud >> though it might be) is that one person/system has to have 'control', and >> the other, the 'pair' (or the 'tutor') is invited to see/do 'whatever'. >> However, r/o would be a show-stopping limitation. > > When pair programming involves training (tutor and student, or senior > and junior programmer), forcing the more experienced person to stay > hands-off is a very good thing; it forces the less experienced person > to actually keyboard every change, and thus is more likely to > understand what's going on. But when it's two peers, you'll often want > to switch out who's in control. Depending on the architecture, this > might be a simple matter of flipping a switch and changing who's > master and who's on a read-only clone. Since master and clone are copies of the same program, switching roles should be simple, and easier than trading seats. >>> 4. Require encryption of some sort if over the public internet. Just >>> because people download code from strangers over http is not a reason to >>> encourage carelessness. I am pretty ignorant on what this would mean. >> >> TLS? >> > > TLS doesn't really solve this problem. If you have a single central > server, TLS just tells you that you're talking to that server, without > proving anything about who's on the other end. Even if you directly > connect the two nodes, TLS wouldn't prove who that is, unless you get > a dedicated certificate. What it *can* prove is that your data stream > hasn't been tampered with en route, but the problem of receiving code > from strangers is still an issue. Ultimately, pair programming depends > on a measure of trust - you have to be confident that the person > you're pairing with isn't going to be maliciously messing with your > system. > > However, I think it would be an extremely useful feature if the output > from running the program could also be replicated to the other client. > Let's say you're developing a Python script that connects to a > database (eg psycopg2 + PostgreSQL). To run that locally, you'd need > your own replica of the database, and that often means having your own > credentials (ie having the script able to choose which set of > credentials to use), replicating the database schema, and possibly > even getting a duplicate of the current table contents. Way WAY easier > to just run it on one computer and copy the output. I did not think of this scenario because I don't currently program with external libraries and DBs. Sending output seems to be a must, with running delivered code an option depending on trust and code review. It does, however, require a control message to switch incoming text from editor to shell. >>>>> 2. Do two systems connect directly peer-to-peer or through a server? >>>> Exclusively the latter (thus far in the investigation). >>> >>> The former would be the only option until someone (else) set up and >>> supported a server. >> >> Except that when you think about it, were I viewing your screen, your >> m/c would indeed be a "server"! We could lose potential by arguing >> semantics (not my intention). In fact, we dealt with this point, above. > > There's a difference between the conceptual and the technical here. > The NAT issue may mean that, for technical reasons, a broker is > needed. I believe bittorrent somehow deals with the issue, but I don't know how much a broker is used after the initial seeding. I believe some player-hosted multiplayer games run peer-to-peer after the initial introduction, but I don't know for sure. Restriction to local networks might have some use. There have been programming classes where a teacher uses IDLE projected on an overhead screen. In at least some cases, a large type size (25-40) is needed. It might be nicer to deliver to each students computer. >> I'm thrilled at your interest, but am ignorant/uncertain that >> pair-programming and Idle go together. To which you may say that perhaps >> they should... In which case, I'd recommend taking a look at some of the >> services (listed at the beginning of this thread) to first establish >> 'virtue' and yes, I'll try to do a better job at roughing-out some >> use-cases with you... > > I think Idle could be a very useful pair programming tool, but that > doesn't mean it'd be the best option available. IMO it could be an > extremely light-weight one, though. -- Terry Jan Reedy From rosuav at gmail.com Sat Aug 3 16:20:57 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Aug 2019 06:20:57 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: On Sun, Aug 4, 2019 at 4:46 AM Terry Reedy wrote: > > On 8/3/2019 1:50 AM, Chris Angelico wrote: > > When pair programming involves training (tutor and student, or senior > > and junior programmer), forcing the more experienced person to stay > > hands-off is a very good thing; it forces the less experienced person > > to actually keyboard every change, and thus is more likely to > > understand what's going on. But when it's two peers, you'll often want > > to switch out who's in control. Depending on the architecture, this > > might be a simple matter of flipping a switch and changing who's > > master and who's on a read-only clone. > > Since master and clone are copies of the same program, switching roles > should be simple, and easier than trading seats. Should be indeed, though having accidentally painted myself into a corner on many occasions, I would say it's worth writing this down as a goal all the same :) > > However, I think it would be an extremely useful feature if the output > > from running the program could also be replicated to the other client. > > Let's say you're developing a Python script that connects to a > > database (eg psycopg2 + PostgreSQL). To run that locally, you'd need > > your own replica of the database, and that often means having your own > > credentials (ie having the script able to choose which set of > > credentials to use), replicating the database schema, and possibly > > even getting a duplicate of the current table contents. Way WAY easier > > to just run it on one computer and copy the output. > > I did not think of this scenario because I don't currently program with > external libraries and DBs. Sending output seems to be a must, with > running delivered code an option depending on trust and code review. It > does, however, require a control message to switch incoming text from > editor to shell. Rather than having such a control message, perhaps it could be possible to have any number of "target window" channels? So you could have two editor windows and a shell, or even multiple shells, if Idle can do that in one process. I'm not sure how Idle's architecture is; in my experimentation, I was only able to get a single execution window. > I believe bittorrent somehow deals with the issue, but I don't know how > much a broker is used after the initial seeding. I believe some > player-hosted multiplayer games run peer-to-peer after the initial > introduction, but I don't know for sure. Hmm, bittorrent's broker is just for finding peers - it doesn't actually transfer any content. I'm pretty sure two behind-NAT torrent clients are unable to communicate unless one of them has a port forwarded to it. > Restriction to local networks might have some use. There have been > programming classes where a teacher uses IDLE projected on an overhead > screen. In at least some cases, a large type size (25-40) is needed. > It might be nicer to deliver to each students computer. The easiest way would be to have the main Idle engine able to listen on a socket OR connect to one, and then "restricting to LAN" is simply a matter of managing it in your firewall (or, in the case of many NAT networks, simply a matter of doing nothing). The broker would be a basic echo server, and if desired, it could handle encryption (TLS). Since there would potentially be many concurrent Idle replications happening, there'd need to be some sort of "room name" or something, but it could still be very simplistic. This would be a very cool feature, especially since it could bring ultra low latency pair programming even to people on mobile connections. ChrisA From PythonList at DancesWithMice.info Sat Aug 3 18:29:25 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 4 Aug 2019 10:29:25 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <20190803052014.GA86417@cskk.homeip.net> References: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <20190803052014.GA86417@cskk.homeip.net> Message-ID: On 3/08/19 5:20 PM, Cameron Simpson wrote: > On 03Aug2019 08:52, DL Neil wrote: >> On 3/08/19 8:32 AM, Terry Reedy wrote: >>> 2. Do two systems connect directly peer-to-peer or through a server? >> Exclusively the latter (thus far in the investigation). > > If one party is remote and both are behind a NAT (_very_ common in > Australia, for example) then you always need an external intermediary. > Even if that intermediary does no more than connect some sockets from > each end together and blindly pass traffic. As is the case with many of the A/V comms packages, if the software is, or appears to be, a web-browser (IP port 80); then there should be no particular problem with either NAT or firewalls. However... -- Regards =dn From rosuav at gmail.com Sat Aug 3 18:42:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Aug 2019 08:42:26 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <20190803052014.GA86417@cskk.homeip.net> Message-ID: On Sun, Aug 4, 2019 at 8:31 AM DL Neil wrote: > > On 3/08/19 5:20 PM, Cameron Simpson wrote: > > On 03Aug2019 08:52, DL Neil wrote: > >> On 3/08/19 8:32 AM, Terry Reedy wrote: > >>> 2. Do two systems connect directly peer-to-peer or through a server? > >> Exclusively the latter (thus far in the investigation). > > > > If one party is remote and both are behind a NAT (_very_ common in > > Australia, for example) then you always need an external intermediary. > > Even if that intermediary does no more than connect some sockets from > > each end together and blindly pass traffic. > > As is the case with many of the A/V comms packages, if the software is, > or appears to be, a web-browser (IP port 80); then there should be no > particular problem with either NAT or firewalls. That covers one end only - the "active" or "connecting" end. The other end has to be "passive" or "listening", and that is a lot harder to handle. Hence the need for the broker - one server has the listening ends for everyone, and all the actual Idle processes connect to that. ChrisA From PythonList at DancesWithMice.info Sat Aug 3 18:56:48 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 4 Aug 2019 10:56:48 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <20190803051711.GA42224@cskk.homeip.net> References: <52aaffe8-5574-05e4-2d1c-0db25dacdcb2@DancesWithMice.info> <20190803051711.GA42224@cskk.homeip.net> Message-ID: On 3/08/19 5:17 PM, Cameron Simpson wrote: > On 03Aug2019 16:51, DL Neil wrote: >> On 3/08/19 11:50 AM, Cameron Simpson wrote: >>> appear.in can also screen share along with its video conferencing, >>> and I imagine Zoom might do so also. But a screen share is "read >>> only" for the other party. You could both screen share of course, but >>> it doesn't solve the keep-the-code-in-sync issue. ... > My pair programming experience is pretty limited. If peering over > someone's should is enough, you're good. If you ever swap roles (typing > versus reviewing) I'd think it gets trickier. Indeed. A logical improvement over screen-sharing is the objective this investigation. >> A simple screen-share solution has to be the MVP: >> - I can see the code someone wants to show/is requesting help for >> - we can talk through the question >> - but I can't 'take control', eg would have to ask the other person to >> scroll in order to show a piece of code 'somewhere else'. >> >> Perhaps this is good discipline? > > If you're teaching, then yes, sounds good to me. Student types, teacher > observes. > > If it's two peers (regardless of relative expertise in the current > problem) I'd imagine wanting to switch around occasionally. Like: > Observer: what if we do blah-blah? Coder: not sure what you mean. > Observer: types short example code, because it is easier than a precise > verbal explaination. Coder: if ok, adapts the example to the actual > problem. Exactly! The latter better fits (my imagining of) how things will go at a PUG coding night. > If you're mentoring/tutoring, you can put the typing in the associated > text messaging system - I think most video conferency things let people > message inside the conference? So you're not sharing a keyboard, but you > can pass text/code around for copy/paste. If we are both members of the same (work/project) team and I am one of your juniors. When I have a problem and ask your advice, chances are you will quickly appreciate the problem because it is a narrow(er) field in which you have had (years of) experience. However, at a PUG Coding Night the questions will come out of left-field, in totally different and unrelated subjects. Accordingly, whereas your advice to a team-member might be almost off-the-cuff, eg something like "I use the xyz-library, why don't you start by reading-up on that?" when the subject matter is unfamiliar one needs to spend more time understanding the problem and (likely) be more tentative in suggesting a solution/avenue of investigation. Thus, being able to ask for the keyboard and mounting a quick experiment or two, might be the best way forward. My conclusion thus far: If the code is only available locally, and the requesting-person has to stop and send a copy to me, to enable such experimentation; we'll either run out of time or put our heads in the "too hard" basket! Either that, or that my skills, such as they are, are insufficient for the ambitions of the project. (likely also true given the incredible width of subjects to which Python is/can be applied!) >> One of the PythonAnywhere principals has come back to me [...] >> In PA, if I open a "console", it can be shared with all my >> (PA-defined) "students" as r/o. Better, is that anyone who cares to >> ask for help (registered as one of my students) can ask me to 'look >> over their shoulder'. As well as navigating the other person's >> source-files, I think I could initiate a test, or quick edit, in that >> mode. and has reverted again. It seems that they are keen to see if/how the service might work in this mode (cf their existing address of a more 'normal' educational environment) >> (if you'd like to give-it-a-whirl/have-a-go, they offer free accounts >> (with modest but quite functional facilities) and the registration >> process is not onerous - if we* can arrange an RDV, I'll be happy to >> try working as a pair...) > > Actually, I'd like that. But I'm in GMT+10. Guessing you're in GMT? We > could take that off list. Done! If you (ie you/in addition to Cameron) has the time/interest and would like to try this (or any other of the options), I'll be keen to participate... -- Regards =dn From PythonList at DancesWithMice.info Sat Aug 3 19:18:15 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 4 Aug 2019 11:18:15 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <20190802235002.GA32180@cskk.homeip.net> Message-ID: <8980166e-5e8d-1a20-1bda-03c9156cd8e5@DancesWithMice.info> On 3/08/19 2:08 PM, Bryon Tjanaka wrote: > Depending on how often you need to run the code, you could use a google doc > and copy the code over when you need to run. Of course, if you need linters > and other tools to run frequently this would not work. Thanks for the thought Bryon. Elsewhere there is a contribution which highlights the matter of "trust". It it's your code, *you* should maintain control. (let's imagine you are developing some project which is going to change-the-world/enable you to retire-rich - you wouldn't want to 'give that code away', would you?) So, I favor the idea (which you can see operating when code-questions appear on this list) that the 'owner' loads a pertinent sub-set of the code (sometimes a degree of subject-matter obfuscation is necessary). That way, *I* don't have access to his machine, source code repository, etc. However, there's a time-cost involved; and if we add databases, frameworks, etc, to the picture, perhaps we will quickly be overwhelmed by the sheer complexity and number of moving-parts... (aka "no silver bullet") -- Regards =dn From hongyi.zhao at gmail.com Sat Aug 3 22:33:09 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 4 Aug 2019 02:33:09 -0000 (UTC) Subject: Why they use this: duration = time.time() - self.start_time + 1 Message-ID: Hi, I read the code here: https://github.com/shichao-an/homura/blob/master/homura.py It said in line 244: duration = time.time() - self.start_time + 1 I'm very confusing why it used like this instead of the following: duration = time.time() - self.start_time Any hints? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From cs at cskk.id.au Sat Aug 3 22:44:52 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 4 Aug 2019 12:44:52 +1000 Subject: Why they use this: duration = time.time() - self.start_time + 1 In-Reply-To: References: Message-ID: <20190804024452.GA14408@cskk.homeip.net> On 04Aug2019 02:33, Hongyi Zhao wrote: >I read the code here: >https://github.com/shichao-an/homura/blob/master/homura.py > >It said in line 244: > duration = time.time() - self.start_time + 1 > >I'm very confusing why it used like this instead of the following: > duration = time.time() - self.start_time This is almost certainly because they divide by duration on the next line. By adding 1, duration will never be 0. This code does assume that time.time() never goes backwards, which is usually true. However, the system clock can be adjusted, and might go backwards. My personal habit in this circumstance is to compare the duration with 0 and avoid the division if so; I'd return speed=None in that circumstance because I cannot yet compute it. Interestingly you can see that they do exactly that logical shuffle on line 248 with the speed. You might expect they would do the same for duration but they do not. Cheers, Cameron Simpson From rosuav at gmail.com Sat Aug 3 22:47:10 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Aug 2019 12:47:10 +1000 Subject: Why they use this: duration = time.time() - self.start_time + 1 In-Reply-To: References: Message-ID: On Sun, Aug 4, 2019 at 12:36 PM Hongyi Zhao wrote: > > Hi, > > I read the code here: > > https://github.com/shichao-an/homura/blob/master/homura.py > > > It said in line 244: > > duration = time.time() - self.start_time + 1 > > I'm very confusing why it used like this instead of the following: > > duration = time.time() - self.start_time > > My guess is that it's an easy way to ensure that you never divide by zero (assuming monotonic time, which time.time() doesn't guarantee). On systems where the normal "get time" function returns an integer of seconds, adding one also forms an easy way to "round up" and include both the starting second and the ending second; but in Python, you get a float with subsecond resolution, so that doesn't really apply. BTW, I was somewhat amused to see a question about TIME in a file named "Homura". Turns out that it actually IS named after who I think it is. Hah. ChrisA From aishan0403 at gmail.com Sun Aug 4 04:29:24 2019 From: aishan0403 at gmail.com (aishan0403 at gmail.com) Date: Sun, 4 Aug 2019 01:29:24 -0700 (PDT) Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file Message-ID: I want to compare the common words from multiple .txt files based on the words in multiple .xlsx files. Could anyone kindly help with my code? I have been stuck for weeks and really need help.. Please refer to this link: https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi Any help is greatly appreciated really!! From Richard at Damon-Family.org Sun Aug 4 08:25:57 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 4 Aug 2019 08:25:57 -0400 Subject: Why they use this: duration = time.time() - self.start_time + 1 In-Reply-To: References: Message-ID: <9aeed94c-5dee-bb73-694c-962546efcb1d@Damon-Family.org> On 8/3/19 10:33 PM, Hongyi Zhao wrote: > Hi, > > I read the code here: > > https://github.com/shichao-an/homura/blob/master/homura.py > > > It said in line 244: > > duration = time.time() - self.start_time + 1 > > I'm very confusing why it used like this instead of the following: > > duration = time.time() - self.start_time > > > Any hints? > > Regards Not sure if it is the reason here (since time() returns a float), but many time like functions return a time chunk number of how many 'tick' intervals have passed, depending when in each interval you made a reading, the actual duration between the two calls is plus or minus 1 tick due to quantization error. Adding 1 tick gives you a maximal estimate of the duration, and also has the advantage of avoiding calling a time period 0 ticks long, so becomes a common idiom. This doesn't directly apply to time, as time doesn't directly count ticks, but scales them for you into real time in seconds, so +1 isn't quite right (you should add the quanta of the timer to the value), but it still has the advantage that it is a quick and dirty way to avoid the 0 duration, and after a human scale duration, doesn't perturb the value enough to make much of a difference. -- Richard Damon From hongyi.zhao at gmail.com Sun Aug 4 10:56:54 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 4 Aug 2019 14:56:54 -0000 (UTC) Subject: if bytes != str: Message-ID: Hi, I read and learn the the following code now: https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ ssrlink.py In this script, there are the following two customized functions: ---------- def to_bytes(s): if bytes != str: if type(s) == str: return s.encode('utf-8') return s def to_str(s): if bytes != str: if type(s) == bytes: return s.decode('utf-8') return s ---------- I've the following confusion on the above code: Why should use `if bytes != str:' here? I mean, this will always return True, IMO. See my following test in ipython: In[20]: bytes != str Out[20]: True Any hints on this? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Aug 4 11:06:15 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sun, 4 Aug 2019 11:06:15 -0400 Subject: if bytes != str: In-Reply-To: References: Message-ID: On 8/4/19 10:56 AM, Hongyi Zhao wrote: > Hi, > > I read and learn the the following code now: > > https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ > ssrlink.py > > In this script, there are the following two customized functions: > > > ---------- > def to_bytes(s): > if bytes != str: > if type(s) == str: > return s.encode('utf-8') > return s > > def to_str(s): > if bytes != str: > if type(s) == bytes: > return s.decode('utf-8') > return s > ---------- > > I've the following confusion on the above code: > > Why should use `if bytes != str:' here? I mean, this will always return > True, IMO. Not in Python 2: Python 2.7.16 (default, Mar 11 2019, 18:59:25) [GCC 8.2.1 20181127] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> bytes != str False From ian.g.kelly at gmail.com Sun Aug 4 11:06:26 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 Aug 2019 09:06:26 -0600 Subject: if bytes != str: In-Reply-To: References: Message-ID: On Sun, Aug 4, 2019, 9:02 AM Hongyi Zhao wrote: > Hi, > > I read and learn the the following code now: > > https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ > ssrlink.py > > > In this script, there are the following two customized functions: > > > ---------- > def to_bytes(s): > if bytes != str: > if type(s) == str: > return s.encode('utf-8') > return s > > def to_str(s): > if bytes != str: > if type(s) == bytes: > return s.decode('utf-8') > return s > ---------- > > I've the following confusion on the above code: > > Why should use `if bytes != str:' here? I mean, this will always return > True, IMO. > > See my following test in ipython: > > In[20]: bytes != str > Out[20]: True > > > Any hints on this? > In Python 2.7, bytes and str are the same type. > From ian.g.kelly at gmail.com Sun Aug 4 12:04:09 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 Aug 2019 10:04:09 -0600 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <20190802235002.GA32180@cskk.homeip.net> Message-ID: On Sat, Aug 3, 2019, 9:25 AM Bryon Tjanaka wrote: > Depending on how often you need to run the code, you could use a google doc > and copy the code over when you need to run. Of course, if you need linters > and other tools to run frequently this would not work. > I've conducted a number of remote interviews using Google Docs and while it's okay for that use case I wouldn't really recommend it for actual productivity. It's not designed to be an IDE nor does it satisfactorily replace one. > From python at mrabarnett.plus.com Sun Aug 4 13:44:38 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 4 Aug 2019 18:44:38 +0100 Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: Message-ID: On 2019-08-04 09:29, aishan0403 at gmail.com wrote: > I want to compare the common words from multiple .txt files based on the words in multiple .xlsx files. > > Could anyone kindly help with my code? I have been stuck for weeks and really need help.. > > Please refer to this link: > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > > Any help is greatly appreciated really!! > First of all, in this line: folder_path1 = os.chdir("C:/Users/xxx/Documents/xxxx/Test python dict") it changes the current working directory (not a problem), but 'chdir' returns None, so from that point 'folder_path1' has the value None. Then in this line: for file in os.listdir(folder_path1): it's actually doing: for file in os.listdir(None): which happens to work because passing it None means to return the names in the current directory. Now to your problem. This line: dictionary = cell_range.value sets 'dictionary' to the value in the spreadsheet cell, and you're doing it each time around the loop. At the end of the loop, 'dictionary' will be set to the _last_ such value. You're not collecting the value, but merely remembering the last value. Looking further on, there's this line: if txtwords in dictionary: Remember, 'dictionary' is the last value (a string), so that'll be True only if 'txtwords' is a substring of the string in 'dictionary'. That's why you're seeing only one match. From jon+usenet at unequivocal.eu Sun Aug 4 14:21:22 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 4 Aug 2019 18:21:22 -0000 (UTC) Subject: if bytes != str: References: Message-ID: On 2019-08-04, Hongyi Zhao wrote: > I read and learn the the following code now: > > https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ > ssrlink.py > > In this script, there are the following two customized functions: > > ---------- > def to_bytes(s): > if bytes != str: > if type(s) == str: > return s.encode('utf-8') > return s > > def to_str(s): > if bytes != str: > if type(s) == bytes: > return s.decode('utf-8') > return s > ---------- > > I've the following confusion on the above code: > > Why should use `if bytes != str:' here? I mean, this will always return > True, IMO. It's a Python 2 v Python 3 test. I would suggest that the following would be a better way of achieving the same end, but more efficiently, given that a Python 2 interpreter isn't going to magically turn into a Python 3 interpreter halfway through executing a program: if bytes is str: to_bytes = lambda s: s to_str = lambda b: b else: to_bytes = lambda s: s.encode('utf-8') if isinstance(s, str) else s to_str = lambda b: b.decode('utf-8') if isinstance(b, bytes) else b From python at mrabarnett.plus.com Sun Aug 4 14:29:00 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 4 Aug 2019 19:29:00 +0100 Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: Message-ID: On 2019-08-04 18:53, A S wrote: > Hi Mrab, > > Thank you so much for your detailed response, I really really > appreciate it as I have been constantly trying to seek help regarding > this issue. > > Yes, I figured that the dictionary is only capturing the last value :( > I've been trying to get it to capture and store all the values to > memory in python but it's not working.. > > Are there any improvements that I could make to allow my code to?work? > > I would be truly grateful if you could provide further insights on this.. > > Thank you so much. > Make it a set and then add the words to it. > > On Mon, 5 Aug 2019, 1:45 am MRAB, > wrote: > > On 2019-08-04 09:29, aishan0403 at gmail.com > wrote: > > I want to compare the common words from multiple .txt files > based on the words in multiple .xlsx files. > > > > Could anyone kindly help with my code? I have been stuck for > weeks and really need help.. > > > > Please refer to this link: > > > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > > > > Any help is greatly appreciated really!! > > > First of all, in this line: > > ? ? ?folder_path1 = os.chdir("C:/Users/xxx/Documents/xxxx/Test > python dict") > > it changes the current working directory (not a problem), but 'chdir' > returns None, so from that point 'folder_path1' has the value None. > > Then in this line: > > ? ? ?for file in os.listdir(folder_path1): > > it's actually doing: > > ? ? ?for file in os.listdir(None): > > which happens to work because passing it None means to return the > names > in the current directory. > > Now to your problem. > > This line: > > ? ? ?dictionary = cell_range.value > > sets 'dictionary' to the value in the spreadsheet cell, and you're > doing > it each time around the loop. At the end of the loop, 'dictionary' > will > be set to the _last_ such value. You're not collecting the value, but > merely remembering the last value. > > Looking further on, there's this line: > > ? ? ?if txtwords in dictionary: > > Remember, 'dictionary' is the last value (a string), so that'll be > True > only if 'txtwords' is a substring of the string in 'dictionary'. > > That's why you're seeing only one match. > From hongyi.zhao at gmail.com Sun Aug 4 18:57:27 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 4 Aug 2019 22:57:27 -0000 (UTC) Subject: _unquote Message-ID: Hi, See the following code excerpted from https://github.com/shichao-an/ homura/blob/master/homura.py: --- def unquote(s): res = s if not PY3: if isinstance(res, six.text_type): res = s.encode('utf-8') return _unquote(res) --- I'm very confused on the `_unquote' used above? What's the meaning of it? I cannot find its definition from the python's shipped packages. Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From python at mrabarnett.plus.com Sun Aug 4 19:15:24 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 5 Aug 2019 00:15:24 +0100 Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: Message-ID: <1aa28eed-9075-46ad-20e3-39c264d10554@mrabarnett.plus.com> On 2019-08-04 23:52, A S wrote: > Previously I had tried many methods and using set was one of them but > it didn't work out either.. I even tried to append it to a list but > it's not working out.. > "not working out"? Well, that gives me no clue as to what you were doing wrong! On Mon, 5 Aug 2019, 2:29 am MRAB, > wrote: > On 2019-08-04 18:53, A S wrote: > > Hi Mrab, > > > > Thank you so much for your detailed response, I really really > > appreciate it as I have been constantly trying to seek help > regarding > > this issue. > > > > Yes, I figured that the dictionary is only capturing the last > value :( > > I've been trying to get it to capture and store all the values to > > memory in python but it's not working.. > > > > Are there any improvements that I could make to allow my code > to?work? > > > > I would be truly grateful if you could provide further insights > on this.. > > > > Thank you so much. > > > Make it a set and then add the words to it. > > > > > On Mon, 5 Aug 2019, 1:45 am MRAB, > > >> wrote: > > > >? ? ?On 2019-08-04 09:29, aishan0403 at gmail.com > > >? ? ?> > wrote: > >? ? ?> I want to compare the common words from multiple .txt files > >? ? ?based on the words in multiple .xlsx files. > >? ? ?> > >? ? ?> Could anyone kindly help with my code? I have been stuck for > >? ? ?weeks and really need help.. > >? ? ?> > >? ? ?> Please refer to this link: > >? ? ?> > > > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > >? ? ?> > >? ? ?> Any help is greatly appreciated really!! > >? ? ?> > >? ? ?First of all, in this line: > > > >? ? ?? ? ?folder_path1 = os.chdir("C:/Users/xxx/Documents/xxxx/Test > >? ? ?python dict") > > > >? ? ?it changes the current working directory (not a problem), > but 'chdir' > >? ? ?returns None, so from that point 'folder_path1' has the > value None. > > > >? ? ?Then in this line: > > > >? ? ?? ? ?for file in os.listdir(folder_path1): > > > >? ? ?it's actually doing: > > > >? ? ?? ? ?for file in os.listdir(None): > > > >? ? ?which happens to work because passing it None means to > return the > >? ? ?names > >? ? ?in the current directory. > > > >? ? ?Now to your problem. > > > >? ? ?This line: > > > >? ? ?? ? ?dictionary = cell_range.value > > > >? ? ?sets 'dictionary' to the value in the spreadsheet cell, and > you're > >? ? ?doing > >? ? ?it each time around the loop. At the end of the loop, > 'dictionary' > >? ? ?will > >? ? ?be set to the _last_ such value. You're not collecting the > value, but > >? ? ?merely remembering the last value. > > > >? ? ?Looking further on, there's this line: > > > >? ? ?? ? ?if txtwords in dictionary: > > > >? ? ?Remember, 'dictionary' is the last value (a string), so > that'll be > >? ? ?True > >? ? ?only if 'txtwords' is a substring of the string in 'dictionary'. > > > >? ? ?That's why you're seeing only one match. > > > From jon+usenet at unequivocal.eu Sun Aug 4 19:18:05 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 4 Aug 2019 23:18:05 -0000 (UTC) Subject: _unquote References: Message-ID: On 2019-08-04, Hongyi Zhao wrote: > See the following code excerpted from https://github.com/shichao-an/ > homura/blob/master/homura.py: > > --- > def unquote(s): > res = s > if not PY3: > if isinstance(res, six.text_type): > res = s.encode('utf-8') > return _unquote(res) > --- > > I'm very confused on the `_unquote' used above? What's the meaning of > it? I cannot find its definition from the python's shipped packages. It isn't from Python's library. You need to look higher up in the file you mention in order to find where it's imported: from six.moves.urllib.parse import urlparse, unquote as _unquote So it's 'six.moves.urllib.parse.unquote'... Look up the package 'six' on pypi to find its documentation: https://pypi.org/project/six/ From python at mrabarnett.plus.com Sun Aug 4 19:21:36 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 5 Aug 2019 00:21:36 +0100 Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: Message-ID: <2ab1b505-e8d8-7ce1-b870-af83384fa63f@mrabarnett.plus.com> On 2019-08-05 00:10, A S wrote: > Oh... By set did you mean by using python function set(variable) as > something? > > So sorry for bothering you.. > Make it a set (outside the loop): ??? dictionary = set() and then add the words to it (inside the loop): ??? dictionary.add(cell_range.value) (Maybe also rename the variable to, say, "words_wanted", because calling it "dictionary" when it's not a dictionary (dict) could be confusing...) > On Mon, 5 Aug 2019, 6:52 am A S, > wrote: > > Previously I had tried many methods and using set was one of them > but it didn't work out either.. I even tried to append it to a > list but it's not working out.. > > On Mon, 5 Aug 2019, 2:29 am MRAB, > wrote: > > On 2019-08-04 18:53, A S wrote: > > Hi Mrab, > > > > Thank you so much for your detailed response, I really really > > appreciate it as I have been constantly trying to seek help > regarding > > this issue. > > > > Yes, I figured that the dictionary is only capturing the > last value :( > > I've been trying to get it to capture and store all the > values to > > memory in python but it's not working.. > > > > Are there any improvements that I could make to allow my > code to?work? > > > > I would be truly grateful if you could provide further > insights on this.. > > > > Thank you so much. > > > Make it a set and then add the words to it. > > > > > On Mon, 5 Aug 2019, 1:45 am MRAB, > > > >> wrote: > > > >? ? ?On 2019-08-04 09:29, aishan0403 at gmail.com > > >? ? ? > wrote: > >? ? ?> I want to compare the common words from multiple .txt > files > >? ? ?based on the words in multiple .xlsx files. > >? ? ?> > >? ? ?> Could anyone kindly help with my code? I have been > stuck for > >? ? ?weeks and really need help.. > >? ? ?> > >? ? ?> Please refer to this link: > >? ? ?> > > > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > >? ? ?> > >? ? ?> Any help is greatly appreciated really!! > >? ? ?> > >? ? ?First of all, in this line: > > > >? ? ?? ? ?folder_path1 = > os.chdir("C:/Users/xxx/Documents/xxxx/Test > >? ? ?python dict") > > > >? ? ?it changes the current working directory (not a > problem), but 'chdir' > >? ? ?returns None, so from that point 'folder_path1' has the > value None. > > > >? ? ?Then in this line: > > > >? ? ?? ? ?for file in os.listdir(folder_path1): > > > >? ? ?it's actually doing: > > > >? ? ?? ? ?for file in os.listdir(None): > > > >? ? ?which happens to work because passing it None means to > return the > >? ? ?names > >? ? ?in the current directory. > > > >? ? ?Now to your problem. > > > >? ? ?This line: > > > >? ? ?? ? ?dictionary = cell_range.value > > > >? ? ?sets 'dictionary' to the value in the spreadsheet cell, > and you're > >? ? ?doing > >? ? ?it each time around the loop. At the end of the loop, > 'dictionary' > >? ? ?will > >? ? ?be set to the _last_ such value. You're not collecting > the value, but > >? ? ?merely remembering the last value. > > > >? ? ?Looking further on, there's this line: > > > >? ? ?? ? ?if txtwords in dictionary: > > > >? ? ?Remember, 'dictionary' is the last value (a string), so > that'll be > >? ? ?True > >? ? ?only if 'txtwords' is a substring of the string in > 'dictionary'. > > > >? ? ?That's why you're seeing only one match. > > > From aishan0403 at gmail.com Sun Aug 4 23:28:38 2019 From: aishan0403 at gmail.com (aishan0403 at gmail.com) Date: Sun, 4 Aug 2019 20:28:38 -0700 (PDT) Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: <2ab1b505-e8d8-7ce1-b870-af83384fa63f@mrabarnett.plus.com> Message-ID: <6e0f7d19-aabb-427c-9955-709268041889@googlegroups.com> On Monday, 5 August 2019 07:21:52 UTC+8, MRAB wrote: > On 2019-08-05 00:10, A S wrote: > > Oh... By set did you mean by using python function set(variable) as > > something? > > > > So sorry for bothering you.. > > > Make it a set (outside the loop): > > ??? dictionary = set() > > and then add the words to it (inside the loop): > > ??? dictionary.add(cell_range.value) > > (Maybe also rename the variable to, say, "words_wanted", because calling > it "dictionary" when it's not a dictionary (dict) could be confusing...) > > > On Mon, 5 Aug 2019, 6:52 am A S, > > wrote: > > > > Previously I had tried many methods and using set was one of them > > but it didn't work out either.. I even tried to append it to a > > list but it's not working out.. > > > > On Mon, 5 Aug 2019, 2:29 am MRAB, > > wrote: > > > > On 2019-08-04 18:53, A S wrote: > > > Hi Mrab, > > > > > > Thank you so much for your detailed response, I really really > > > appreciate it as I have been constantly trying to seek help > > regarding > > > this issue. > > > > > > Yes, I figured that the dictionary is only capturing the > > last value :( > > > I've been trying to get it to capture and store all the > > values to > > > memory in python but it's not working.. > > > > > > Are there any improvements that I could make to allow my > > code to?work? > > > > > > I would be truly grateful if you could provide further > > insights on this.. > > > > > > Thank you so much. > > > > > Make it a set and then add the words to it. > > > > > > > > On Mon, 5 Aug 2019, 1:45 am MRAB, > > > > > > >> wrote: > > > > > >? ? ?On 2019-08-04 09:29, aishan0403 at gmail.com > > > > >? ? ? > > wrote: > > >? ? ?> I want to compare the common words from multiple .txt > > files > > >? ? ?based on the words in multiple .xlsx files. > > >? ? ?> > > >? ? ?> Could anyone kindly help with my code? I have been > > stuck for > > >? ? ?weeks and really need help.. > > >? ? ?> > > >? ? ?> Please refer to this link: > > >? ? ?> > > > > > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > > >? ? ?> > > >? ? ?> Any help is greatly appreciated really!! > > >? ? ?> > > >? ? ?First of all, in this line: > > > > > >? ? ?? ? ?folder_path1 = > > os.chdir("C:/Users/xxx/Documents/xxxx/Test > > >? ? ?python dict") > > > > > >? ? ?it changes the current working directory (not a > > problem), but 'chdir' > > >? ? ?returns None, so from that point 'folder_path1' has the > > value None. > > > > > >? ? ?Then in this line: > > > > > >? ? ?? ? ?for file in os.listdir(folder_path1): > > > > > >? ? ?it's actually doing: > > > > > >? ? ?? ? ?for file in os.listdir(None): > > > > > >? ? ?which happens to work because passing it None means to > > return the > > >? ? ?names > > >? ? ?in the current directory. > > > > > >? ? ?Now to your problem. > > > > > >? ? ?This line: > > > > > >? ? ?? ? ?dictionary = cell_range.value > > > > > >? ? ?sets 'dictionary' to the value in the spreadsheet cell, > > and you're > > >? ? ?doing > > >? ? ?it each time around the loop. At the end of the loop, > > 'dictionary' > > >? ? ?will > > >? ? ?be set to the _last_ such value. You're not collecting > > the value, but > > >? ? ?merely remembering the last value. > > > > > >? ? ?Looking further on, there's this line: > > > > > >? ? ?? ? ?if txtwords in dictionary: > > > > > >? ? ?Remember, 'dictionary' is the last value (a string), so > > that'll be > > >? ? ?True > > >? ? ?only if 'txtwords' is a substring of the string in > > 'dictionary'. > > > > > >? ? ?That's why you're seeing only one match. > > > > > My latest reply to Mrab in case anybody needs it (and p.s. I'm so sorry for spamming you Mrab): Mrab! Thank you so much for your constant replies ! I'm able to print out the words now!! Using these codes: import os, sys import xlrd from xlrd import open_workbook import openpyxl from openpyxl.reader.excel import load_workbook import xlwt from xlwt import Workbook #The filepath that I will be saving my .xls file to: filepath = ('C:/Users/Ai Shan/Documents/CPFB Work/LAN SAS MONTHLY.xls') #The .xls file: wb2 = xlrd.open_workbook('C:\\Users\\Ai Shan\\Documents\\CPFB Work\\LAN SAS MONTHLY.xls', on_demand= True) wb2 = Workbook() sheet2 = wb2.add_sheet("LAN SAS", cell_overwrite_ok=True) #The .xlxs file that contains the words I want to compare with the .txt files: folder_path1 = os.chdir("C:/Users/Ai Shan/Documents/CPFB Work/Test python dict") words= set() for file in os.listdir(folder_path1): if file.endswith(".xlsx"): wb = load_workbook(file, data_only=True) ws = wb.active words.add(str(ws['A1'].value)) #cell_range = ws['A1'] #with open('copy.txt','w+') as f: # f.write(str(cell_range.value)) # Me writing the name of each .txt file to the .xls file: for r, dir in enumerate(os.listdir("C:/Users/Ai Shan/Documents/CPFB Work/txt test python")): sheet2.write(r+1,1,dir) #Reading .txt file and trying to make the sentence into words instead of lines so that I can compare the .txt individual words with the .xlsx file: path = os.chdir("C:/Users/Ai Shan/Documents/CPFB Work/txt test python") for name in os.listdir(path): if name.endswith(".txt"): with open(name, 'r') as texts: s = texts.read() import re m = re.match(r'(?:.*?\n)(?P\w+?)\b', s) if m: word = m.group('word') if word in words: print(word) sheet2.write(r+1,2,word) wb2.save(filepath) But I'm not able to write the printed values to my excel workbook..its only printing "pear" again.. I want to get this outcome: apples orange pear But I'm only getting the last value again, am I writing the code wrongly..? From aishan0403 at gmail.com Sun Aug 4 23:31:19 2019 From: aishan0403 at gmail.com (aishan0403 at gmail.com) Date: Sun, 4 Aug 2019 20:31:19 -0700 (PDT) Subject: How to compare words from .txt file against words in .xlsx file via Python? I will then extract these words by writing it to a new .xls file In-Reply-To: References: <2ab1b505-e8d8-7ce1-b870-af83384fa63f@mrabarnett.plus.com> Message-ID: <85f2708d-890b-462c-87e2-8280e8cfb5bf@googlegroups.com> On Monday, 5 August 2019 07:21:52 UTC+8, MRAB wrote: > On 2019-08-05 00:10, A S wrote: > > Oh... By set did you mean by using python function set(variable) as > > something? > > > > So sorry for bothering you.. > > > Make it a set (outside the loop): > > ??? dictionary = set() > > and then add the words to it (inside the loop): > > ??? dictionary.add(cell_range.value) > > (Maybe also rename the variable to, say, "words_wanted", because calling > it "dictionary" when it's not a dictionary (dict) could be confusing...) > > > On Mon, 5 Aug 2019, 6:52 am A S, > > wrote: > > > > Previously I had tried many methods and using set was one of them > > but it didn't work out either.. I even tried to append it to a > > list but it's not working out.. > > > > On Mon, 5 Aug 2019, 2:29 am MRAB, > > wrote: > > > > On 2019-08-04 18:53, A S wrote: > > > Hi Mrab, > > > > > > Thank you so much for your detailed response, I really really > > > appreciate it as I have been constantly trying to seek help > > regarding > > > this issue. > > > > > > Yes, I figured that the dictionary is only capturing the > > last value :( > > > I've been trying to get it to capture and store all the > > values to > > > memory in python but it's not working.. > > > > > > Are there any improvements that I could make to allow my > > code to?work? > > > > > > I would be truly grateful if you could provide further > > insights on this.. > > > > > > Thank you so much. > > > > > Make it a set and then add the words to it. > > > > > > > > On Mon, 5 Aug 2019, 1:45 am MRAB, > > > > > > >> wrote: > > > > > >? ? ?On 2019-08-04 09:29, aishan0403 at gmail.com > > > > >? ? ? > > wrote: > > >? ? ?> I want to compare the common words from multiple .txt > > files > > >? ? ?based on the words in multiple .xlsx files. > > >? ? ?> > > >? ? ?> Could anyone kindly help with my code? I have been > > stuck for > > >? ? ?weeks and really need help.. > > >? ? ?> > > >? ? ?> Please refer to this link: > > >? ? ?> > > > > > https://stackoverflow.com/questions/57319707/how-to-compare-words-from-txt-file-against-words-in-xlsx-file-via-python-i-wi > > >? ? ?> > > >? ? ?> Any help is greatly appreciated really!! > > >? ? ?> > > >? ? ?First of all, in this line: > > > > > >? ? ?? ? ?folder_path1 = > > os.chdir("C:/Users/xxx/Documents/xxxx/Test > > >? ? ?python dict") > > > > > >? ? ?it changes the current working directory (not a > > problem), but 'chdir' > > >? ? ?returns None, so from that point 'folder_path1' has the > > value None. > > > > > >? ? ?Then in this line: > > > > > >? ? ?? ? ?for file in os.listdir(folder_path1): > > > > > >? ? ?it's actually doing: > > > > > >? ? ?? ? ?for file in os.listdir(None): > > > > > >? ? ?which happens to work because passing it None means to > > return the > > >? ? ?names > > >? ? ?in the current directory. > > > > > >? ? ?Now to your problem. > > > > > >? ? ?This line: > > > > > >? ? ?? ? ?dictionary = cell_range.value > > > > > >? ? ?sets 'dictionary' to the value in the spreadsheet cell, > > and you're > > >? ? ?doing > > >? ? ?it each time around the loop. At the end of the loop, > > 'dictionary' > > >? ? ?will > > >? ? ?be set to the _last_ such value. You're not collecting > > the value, but > > >? ? ?merely remembering the last value. > > > > > >? ? ?Looking further on, there's this line: > > > > > >? ? ?? ? ?if txtwords in dictionary: > > > > > >? ? ?Remember, 'dictionary' is the last value (a string), so > > that'll be > > >? ? ?True > > >? ? ?only if 'txtwords' is a substring of the string in > > 'dictionary'. > > > > > >? ? ?That's why you're seeing only one match. > > > > > My latest reply to Mrab in case anybody needs it (and p.s. I'm so sorry for spamming you Mrab): Mrab! Thank you so much for your constant replies ! I'm able to print out the words now!! Using these codes: import os, sys import xlrd from xlrd import open_workbook import openpyxl from openpyxl.reader.excel import load_workbook import xlwt from xlwt import Workbook #The filepath that I will be saving my .xls file to: filepath = ('C:/Users/xxx/Documents/xxx/xyz.xls') #The .xls file: wb2 = xlrd.open_workbook('C:\\Users\\xxx\\Documents\\xxx\\xyz.xls', on_demand= True) wb2 = Workbook() sheet2 = wb2.add_sheet("kksheet", cell_overwrite_ok=True) #The .xlxs file that contains the words I want to compare with the .txt files: folder_path1 = os.chdir("C:/Users/xxx/Documents/xxx/Test python dict") words= set() for file in os.listdir(folder_path1): if file.endswith(".xlsx"): wb = load_workbook(file, data_only=True) ws = wb.active words.add(str(ws['A1'].value)) #cell_range = ws['A1'] #with open('copy.txt','w+') as f: # f.write(str(cell_range.value)) # Me writing the name of each .txt file to the .xls file: for r, dir in enumerate(os.listdir("C:/Users/xxx/Documents/xxx/txt test python")): sheet2.write(r+1,1,dir) #Reading .txt file and trying to make the sentence into words instead of lines so that I can compare the .txt individual words with the .xlsx file: path = os.chdir("C:/Users/xxx/Documents/xxx/txt test python") for name in os.listdir(path): if name.endswith(".txt"): with open(name, 'r') as texts: s = texts.read() import re m = re.match(r'(?:.*?\n)(?P\w+?)\b', s) if m: word = m.group('word') if word in words: print(word) sheet2.write(r+1,2,word) wb2.save(filepath) But I'm not able to write the printed values to my excel workbook..its only printing "pear" again.. I want to get this outcome: apples orange pear But I'm only getting the last value again, am I writing the code wrongly..? From PythonList at DancesWithMice.info Mon Aug 5 02:52:14 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 18:52:14 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: Herewith a progress-report, and an attempt to respond to (interposed) questions:- I've managed to utilise Cloud9 successfully. (finally!) The bulk of the work was in wending my way through the process of setting-up the "team" (or in this application: the PUG). Starting in Cloud9 itself is straight-forward. - I started an "environment" as me/Cloud9_Admin - Ran a one-line program - Shared the environment - logged-in (another m/c) as PUG/Cloud9_User - Applied to the shared environment - Added a second line to the code (and as I did, both editor windows updated). - Ran it - Went back to being 'me'/on the first m/c - reviewed the screen - and ran it (again) from there Identical! (will try a more realistic interchange, in due course) AWS Cloud9 appears to fulfil criteria to support our PUG Coding Evening (and as discussed during this thread): - shared IDE - ability to observe - ability to develop - ability to switch r?les - collaboration facilities (haven't tried these yet) [and a more formal 'class' mode/option - not reviewed] On 4/08/19 3:45 AM, Dennis Lee Bieber wrote: > On Sat, 3 Aug 2019 11:20:20 +1200, DL Neil > declaimed the following: >> Thanks wlfraed - will be checking the AWS version... >> (they claim it will even work on a 'free' server, which presumably means >> it would last for a whole year!) > > Unfortunately, I think that "free server" is still an Amazon server -- > and still needs one to register for some level of AWS service (I wouldn't > be surprised if they want every "collaborator" to register -- as I think it > is the Cloud9 "workspace" that becomes shared, you have to invite the > collaborators into the shared workspace... be hard to do that if they were > all using one registration). > > https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/free-tier-limits.html > https://aws.amazon.com/cloud9/pricing/ > https://aws.amazon.com/ec2/pricing/ > https://aws.amazon.com/free/ Service: There are/were two: the original Cloud9/C9, and the newer/bigger/better version since Amazon took-over. There are differences! Amazon: Yes, there are folk who prefer not to deal with such service providers as a matter of principle. I am wary. However, this application is for a PUG meeting, so I'm not too worried if the system falls-over and all is lost (for example). Privacy is still an issue, however I have constructed a generic ID, which the PUG members could share - as you say, one presumes only a single user/log-in at a time; but I could multiply these (equally generic) as needed. Thus, my identity (and CrCard) is the only one 'exposed'. I was able to establish my account on behalf of my 'team'. Thus I am root user, if you will. Thereafter other userIDs could be established, together with permissions and access control. So, each individual has a separate Cloud9 identity, but it is not necessary for everyone to have an Amazon account, ability to set-up servers, etc, etc. Sharing/Inviting: As per above, a suitably-qualified user can open an "environment", and then share it with specific members of the 'team'. I was pleased to see that the docs then instructed me to go away and let 'the other person' know of his/her good fortune (cf demanding an email addr and all that might entail 'behind the curtain'). Pleasantly easy! > It's not quite clear exactly what > > "You have the flexibility to run AWS Cloud9 development environments on a > managed Amazon EC2 Linux instance or any Linux server that you are using > today. You can just choose the SSH connectivity option during Cloud9 setup > when connecting to your own Linux server that could be running anywhere > including AWS, on-premises, or any other cloud provider." > > really means. There IS a download of an installer for one's own server but > does it run the IDE, or just interface to AWS? Server: In order to use the Cloud9 system it must be able to access a file-store. I've taken a (free) t2.micro EC2 instance. As described (above), instead one may set-up an SSH link to a VPS or other addressable m/c - didn't try that. There's no "installer" or any software to download (excepting private key credentials). Access (both admin and user) is through a web browser. The multi-tabbed IDE opens within the browser and there is a "runner" process which opens in another (BASH) panel (below) quite similar in appearance to a number of the popular editor/IDES (eg PyCharm, SublimeText, Codium). NB I chose an AmazonLinux EC2 instance, and thus don't know if there is an MS-Win choice or if it might present differently! Another question which has just occurred to me, is that it may be possible to have multiple "environments" and thus multiple 'backing store' target machines - AWS or one's own/SSH-connected??? > At least they have a fairly complete documentation set > https://docs.aws.amazon.com/cloud9/latest/user-guide The documentation is voluminous and consumes a chunk of time to work-through - much of which is ascertaining what is relevant to one's own application. [?fortunately I became inured to this as a young-pup, 'sitting at the feet' of IBM!] > Now... a bit of bad news... > https://docs.aws.amazon.com/cloud9/latest/user-guide/ssh-settings.html > "It must have Python installed, and the version must be 2.7." > I didn't see anything to support running your code with 3.x -- it might > be possible (I've not read all the documentation) Not so - fortunately! When pulling-down the Run menu for the first time, one must select the type of "runner" (relevant to the source code in the editor). There is a choice of Python2 or Python3. Indeed BASH did respond to "python --version" with 2.7.n. However, I had no problems using the 3.6.8 "runner". I recollect this being the pattern a few?several versions of Linux 'back'. NB I have not tried updating the VM's software (assuming it is possible in this configuration), so maybe a v3.7 update experiment is on-the-cards... My next task (food first!) is to investigate comms options... Thanks (all) for the helpful advice and research! If you (wlfraed, or you: not wlfraed) would like to 'have a go', I'll be happy to facilitate - time and time-zones permitting. However, I suppose I should first spend a bit more time studying the fearsome security warnings before inviting too many (highly competent) 'team members'... -- Regards =dn From PythonList at DancesWithMice.info Mon Aug 5 05:45:53 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 21:45:53 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <20190802235002.GA32180@cskk.homeip.net> Message-ID: <85802a39-7da8-88ef-745d-236958b97a65@DancesWithMice.info> On 5/08/19 4:04 AM, Ian Kelly wrote: > On Sat, Aug 3, 2019, 9:25 AM Bryon Tjanaka wrote: > >> Depending on how often you need to run the code, you could use a google doc >> and copy the code over when you need to run. Of course, if you need linters >> and other tools to run frequently this would not work. >> > > I've conducted a number of remote interviews using Google Docs and while > it's okay for that use case I wouldn't really recommend it for actual > productivity. It's not designed to be an IDE nor does it satisfactorily > replace one. Agreed. I'm not sure if it is a real advantage to see 'keystrokes' during such interviews, but you can certainly do that with the Cloud9 system (please see other post, a few hours back). Another product which is worth review is PythonAnywhere (.com) which also allows 'sharing'. -- Regards =dn From hgs at dmu.ac.uk Mon Aug 5 06:38:14 2019 From: hgs at dmu.ac.uk (Hugh Sasse) Date: Mon, 5 Aug 2019 11:38:14 +0100 Subject: asyncio, transports, protocols, etc. Message-ID: <1f8b43f9-eb09-862b-4eb1-55e40f8274b2@dmu.ac.uk> Hello, I didn't get a response to this before, possibly because of lack of concision. I'd like to ask whether (provided I'm understanding this): https://docs.python.org/3/library/asyncio-protocol.html#tcp-echo-server could be improved by adding: """ Create a TCP echo server using the loop.create_server() method, send back received data. This is done by defining the Protocol, which gets the transport from the server when it is created by asyncio. """ before it, because these concepts have only just been introduced, and also whether the echo server should really be closing the connection, given RFC 862 seems to suggest it should stay open. Original message below. Thank you, Hugh Hello, I'm trying to get my head around asyncio, and I think I'm mostly there now, (but expect to be proved wrong :-)!). It appears to be about the newest of the PEPs according to my searches, including PEP 0, so I don't expect a huge amount of supporting documentation out there yet. Looking at: https://docs.python.org/3/library/asyncio-protocol.html#tcp-echo-server I know the page introduces the relationships between protocols, transports and the servers/clients that use them. When I read this code it took me longer than I would wish :-) to realise that the example defining the Echo server was doing this through the protocol, (yes, it says it *right there* :-)!) and not a Server class, so for some time I was puzzled about where 'transport' was being defined. Given these concepts are new on this page, at least ostensibly, would it make sense to introduce this example with something like: """ Create a TCP echo server using the loop.create_server() method, send back received data. This is done by defining the Protocol, which gets the transport from the server when it is created by asyncio. """ just to refresh the connection between the things in the mind of the reader? Also, according to my reading of RFC 862, I don't think the Echo server should be closing the connection just after echoing: """ TCP Based Echo Service One echo service is defined as a connection based application on TCP. A server listens for TCP connections on TCP port 7. Once a connection is established any data received is sent back. This continues until the calling user terminates the connection. """ I could have missed something here though. (If it is this protocol that is under discussion here, then a link might be useful, as well?) Why does this matter? Because it was not clear to me whether the closing of the connection was something that had to happen, as part of the functionality of the echo service or of asyncio itself. If I'm implementing something that does something based on the cmd or cmd2 module, interpreting commands, then having some kind of dialogue with the server matters. Writing documentation so that everyone will understand it and NOT get the wrong end of the stick is difficult. I don't know if this would make things more confusing for others, or even if it might have helped me. At the moment, I think it might be in the right direction, though. Thank you, Hugh -- -- Dr. Hugh Sasse, BSc(Hons), PhD Computer Systems Electronic Engineer School of Engineering and Sustainable Development DE MONTFORT UNIVERSITY From PythonList at DancesWithMice.info Mon Aug 5 06:52:49 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 22:52:49 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> On 3/08/19 5:50 PM, Chris Angelico wrote: > On Sat, Aug 3, 2019 at 3:36 PM DL Neil wrote: >> >> On 3/08/19 4:02 PM, Terry Reedy wrote: >>> Good. Master-satellite would be much easier. We added line numbers to >>> IDLE's editor last week, so verbal feedback from satellite to master >>> should be sufficient for many purposes. Elsewhere in this thread others, have been looking at NAT and broker arrangements. It has been v.interesting to read. If it is a corporation's project, then this is an option. The business of choosing ports and opening firewalls is a (?mere) matter of standardisation and coordination. (cough, cough, mumble, mumble) However, if we are talking about a public product, eg TeamViewer; then ease of operation comes to the fore. (much though I disagree with what amounts to an abuse of port-80 - specialists trying to 'manage' Internet traffic must really have things to say about such) The reason I mentioned "TeamViewer" (and A.N.Other mentioned BitTorrent) is that client-server is so much easier to implement - even if (using this example) the two (pair-programming) start as clients to some central server, but later comms are 'delegated'/re-directed to become peer-to-peer or go-direct. In the case of TV, which I use in (unpaid, much put-upon, family - you know this song!) 'technical support' mode, both the one seeking help and my own computer have to separately log-in to the TV system, the second asking to connect to the first... >> Elsewhere in the thread there is much discussion of this. Regardless of >> the "we are all adults here" philosophy, my feeling (stuck-in-the-mud >> though it might be) is that one person/system has to have 'control', and >> the other, the 'pair' (or the 'tutor') is invited to see/do 'whatever'. >> However, r/o would be a show-stopping limitation. > > When pair programming involves training (tutor and student, or senior > and junior programmer), forcing the more experienced person to stay > hands-off is a very good thing; it forces the less experienced person > to actually keyboard every change, and thus is more likely to > understand what's going on. But when it's two peers, you'll often want > to switch out who's in control. Depending on the architecture, this > might be a simple matter of flipping a switch and changing who's > master and who's on a read-only clone. I can't see the r/o version in pair-programming - although 'elsewhere' people have mentioned programmer interviews, so maybe that's it. In pair-programming both have a contribution to make. The key, requiring both technical and social/inter-personal considerations (see discussion, elsewhere), is to understand one's current r?le, and to have a clear 'break' when 'swapping seats' - in radio, that is the reason for finishing with "over" (cue Leslie Nielsen sketch), and on a ship's bridge there is a clear announcement, eg "Fred has the conn", so that 'everyone' knows who's in-charge 'now'! To me, that is mostly an inter-personal communications issue. I don't really want 'some computer' deciding when and what I might do. Others might prefer the opposite. Also, there are scenarios when both (of the pair) might be contributing by 'coding' concurrently, eg one writing tests and the other code, or one writing one class and the other a second. (but you can debate if that is "pair-programming") Python's philosophy already covers this with: "we're all adults here"... (see also 'trust', below) >>> 4. Require encryption of some sort if over the public internet. Just >>> because people download code from strangers over http is not a reason to >>> encourage carelessness. I am pretty ignorant on what this would mean. >> >> TLS? > > TLS doesn't really solve this problem. If you have a single central > server, TLS just tells you that you're talking to that server, without > proving anything about who's on the other end. Even if you directly > connect the two nodes, TLS wouldn't prove who that is, unless you get > a dedicated certificate. What it *can* prove is that your data stream > hasn't been tampered with en route, but the problem of receiving code > from strangers is still an issue. Ultimately, pair programming depends > on a measure of trust - you have to be confident that the person > you're pairing with isn't going to be maliciously messing with your > system. As above, using a client-server relationship, thus TLS/SSH are relatively natural, and certainly common, components of the whole. OT: the world of certificates has been revolutionised by LetsEncrypt.org and their free services. I assume a level of trust. Why would you pair-program with someone untrustworthy? Either you're a team or not! That said, and thinking back to the different scenarios (above), I can see the r/o option being useful in such a case. For example, some of my stats clients like to run through the code. It's a form of checking/testing, so I don't mind - they read (the math of) code far better than they can write/structure it! However, I definitely don't want them modifying anything, even if an error is found or a change requested. I want to be in-charge! (stamps foot...) > However, I think it would be an extremely useful feature if the output > from running the program could also be replicated to the other client. > Let's say you're developing a Python script that connects to a > database (eg psycopg2 + PostgreSQL). To run that locally, you'd need > your own replica of the database, and that often means having your own > credentials (ie having the script able to choose which set of > credentials to use), replicating the database schema, and possibly > even getting a duplicate of the current table contents. Way WAY easier > to just run it on one computer and copy the output. +1 >> I'm thrilled at your interest, but am ignorant/uncertain that >> pair-programming and Idle go together. To which you may say that perhaps >> they should... In which case, I'd recommend taking a look at some of the >> services (listed at the beginning of this thread) to first establish >> 'virtue' and yes, I'll try to do a better job at roughing-out some >> use-cases with you... > > I think Idle could be a very useful pair programming tool, but that > doesn't mean it'd be the best option available. IMO it could be an > extremely light-weight one, though. I've debated this issue (in fact wrote a paper on the subject) from a pedagogical perspective (but in my own training area, not Python):- Is it acceptable to train folk to code (in a particular language) without also covering the likely tools they will (also) use? So with Python, during the first lesson we could jump straight into a one-line print( "hello world" ) program using the REPL. However, an editor will be employed as soon as we want our code to persist. So should we (immediately) promote the use of a professional editor/IDE, eg PyCharm, Sublime Text, Codium, Eclipse; or a 'traditional' character editing tool, eg Vi, emacs? (please no 'religious wars' just because I mentioned both in the same sentence!) The problem is that the trainee wants to learn Python (or whatever) and a full-fat editor has a steep learning curve. Learning the editor, which should be secondary to learning the language, either starts to 'take over' or is an huge distraction from the primary learning-objectives! What about Thonny* then? A simple editor. Some nice debug features. Some useful 'illustrations' to show what's happening under-the-hood. An excellent product! Trouble is, who uses it 'in real life'? So, are we thus contemplating jumping from the REPL to 'a simple editor' (to ameliorate "cognitive load"), but later have a professional responsibility to our trainees (and their eventual employers) to move to 'something real'... * I deliberately avoided mentioning Idle (a) I don't want Terry to think of himself as a 'target', and (b) I don't know Idle to be competent to comment! OTOH remember that this thread started with a PUG Code Evening as the single use-case. It has broadened since (per above). One aspect that many of the 'solutions' listed in the original post, seemed to be aiming to cover was 'education' or 'classes'. Perhaps Idle is aiming at that use-case? Certainly I'd agree that more-and-more of our training should be enabled via Internet - but then (heavy disclaimer!) I would say that! However, I fear that the needs of pair-programming do not match particularly well the needs of a class 'broadcast' use-case - and this shows clearly amongst (my) rejects! Another use-case (for Idle) which may not be sufficiently thought-through, is that evidenced by many of the questions which appear on this list: 'Fred' has written some code, it fails in some crucial aspect, he can't see why, and requests 'more eyes'. How often is the code attached (and then stripped by the mail-reflector)? How often does someone put the code into their msg but then refer to a lineNR? (and, of course) do I need to mention "indentation"? How about a version of Idle which allows such supplicants to 'post' their code, and for list contributors to be able to run/test/amend same? Might this be a valid extension of an "editor" in this geographically dispersed and asynchronously operating world? (see also JSfiddle (etc) in the JavaScript world) I suggest that there is a lot of scope for re-thinking just how training, and more importantly/relevant to this list, "learning", can take place in this ?brave, new, world... -- Regards =dn From PythonList at DancesWithMice.info Mon Aug 5 07:08:16 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 23:08:16 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: <06177a52-06d9-07ba-9fb4-bb5c13c776ae@DancesWithMice.info> On 4/08/19 6:44 AM, Terry Reedy wrote: > On 8/3/2019 1:50 AM, Chris Angelico wrote: >> On Sat, Aug 3, 2019 at 3:36 PM DL Neil >> wrote: >>> >>> On 3/08/19 4:02 PM, Terry Reedy wrote: >>> Is that really "p-p" or more "code review"? > > The latter.? The quotes here mean "the closest I currently come to pair > programming".? I have often *wished* for live interaction instead. See elsewhere for suggestions of how Idle might be used for such (not merely as an 'editor' - assuming that is 'all' it is now) > Since master and clone are copies of the same program, switching roles > should be simple, and easier than trading seats. +1 operative words "should be"! >> However, I think it would be an extremely useful feature if the output >> from running the program could also be replicated to the other client. >> Let's say you're developing a Python script that connects to a >> database (eg psycopg2 + PostgreSQL). To run that locally, you'd need >> your own replica of the database, and that often means having your own >> credentials (ie having the script able to choose which set of >> credentials to use), replicating the database schema, and possibly >> even getting a duplicate of the current table contents. Way WAY easier >> to just run it on one computer and copy the output. > > I did not think of this scenario because I don't currently program with > external libraries and DBs.? Sending output seems to be a must, with > running delivered code an option depending on trust and code review.? It > does, however, require a control message to switch incoming text from > editor to shell. Watching the Cloud9 system 'paint' on one machine/browser a moment after I'd typed code using a second machine, brought me a childish delight (after all the reading, learning, and fiddling of accounts and permissions to get that far) > Restriction to local networks might have some use.? There have been > programming classes where a teacher uses IDLE projected on an overhead > screen.? In at least some cases, a large type size (25-40) is needed. It > might be nicer to deliver to each students computer. Disagree: there's a reason it's called the "world-wide" web! Having said that: limiting to LAN makes life SO much easier. (probably mentioned earlier/elsewhere) I *HATE* using large screens, OHP panels, video projectors, etc. Firstly, they always seem to be going wrong - the problem of too many 'moving parts'. Recently I was asked to give a user-oriented course in DB retrieval (cf programmers using SQL). I decided to use MySQL's Workbench, but that screen is so 'busy'. The local equipment was some VGA or not-much-better projector. Screen text was totally unreadable! My preference these days is to slave everyone's screen to mine, using VNC software. It's just like a slide/movie projector and as the airlines like to advertise: everyone has their own personal screen! (plus, can adjust resolution, control screen enlargement, etc, to suit personal preferences) However, a lot of training is moving away from "lectures" and certainly "class rooms". It is becoming an async world, and even if a group congregate into a single room, classes are organised so that each can work at his/her own pace. So, features to join all in "lock step" may not be so often required... (apologies if more than two-cents' worth) -- Regards =dn From PythonList at DancesWithMice.info Mon Aug 5 07:12:28 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 23:12:28 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> Message-ID: On 4/08/19 8:20 AM, Chris Angelico wrote: > On Sun, Aug 4, 2019 at 4:46 AM Terry Reedy wrote: >> On 8/3/2019 1:50 AM, Chris Angelico wrote: >> Since master and clone are copies of the same program, switching roles >> should be simple, and easier than trading seats. > > Should be indeed, though having accidentally painted myself into a > corner on many occasions, I would say it's worth writing this down as > a goal all the same :) +1 Done! >>> However, I think it would be an extremely useful feature if the output >>> from running the program could also be replicated to the other client. >>> Let's say you're developing a Python script that connects to a >>> database (eg psycopg2 + PostgreSQL). To run that locally, you'd need >>> your own replica of the database, and that often means having your own >>> credentials (ie having the script able to choose which set of >>> credentials to use), replicating the database schema, and possibly >>> even getting a duplicate of the current table contents. Way WAY easier >>> to just run it on one computer and copy the output. >> >> I did not think of this scenario because I don't currently program with >> external libraries and DBs. Sending output seems to be a must, with >> running delivered code an option depending on trust and code review. It >> does, however, require a control message to switch incoming text from >> editor to shell. > > Rather than having such a control message, perhaps it could be > possible to have any number of "target window" channels? So you could > have two editor windows and a shell, or even multiple shells, if Idle > can do that in one process. I'm not sure how Idle's architecture is; > in my experimentation, I was only able to get a single execution > window. A chat window? (yes, multiple tabs, or panels, or a floating window) An audio channel? >> I believe bittorrent somehow deals with the issue, but I don't know how >> much a broker is used after the initial seeding. I believe some >> player-hosted multiplayer games run peer-to-peer after the initial >> introduction, but I don't know for sure. > > Hmm, bittorrent's broker is just for finding peers - it doesn't > actually transfer any content. I'm pretty sure two behind-NAT torrent > clients are unable to communicate unless one of them has a port > forwarded to it. > >> Restriction to local networks might have some use. There have been >> programming classes where a teacher uses IDLE projected on an overhead >> screen. In at least some cases, a large type size (25-40) is needed. >> It might be nicer to deliver to each students computer. > > The easiest way would be to have the main Idle engine able to listen > on a socket OR connect to one, and then "restricting to LAN" is simply > a matter of managing it in your firewall (or, in the case of many NAT > networks, simply a matter of doing nothing). > > The broker would be a basic echo server, and if desired, it could > handle encryption (TLS). Since there would potentially be many > concurrent Idle replications happening, there'd need to be some sort > of "room name" or something, but it could still be very simplistic. > > This would be a very cool feature, especially since it could bring > ultra low latency pair programming even to people on mobile > connections. +1 (don't forget those of us whose "high speed broadband" still falls well short of the promised "information super highway"!) -- Regards =dn From PythonList at DancesWithMice.info Mon Aug 5 07:37:35 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 5 Aug 2019 23:37:35 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: On 5/08/19 9:59 PM, Dennis Lee Bieber wrote: > On Mon, 5 Aug 2019 18:52:14 +1200, DL Neil > declaimed the following: > >> Herewith a progress-report, and an attempt to respond to (interposed) >> questions:- >> > I didn't have questions so much as just comments based on > documentation... Your advice, ideas, and the effort you've invested, are greatly appreciated. Thank you! >> Service: >> There are/were two: the original Cloud9/C9, and the newer/bigger/better >> version since Amazon took-over. There are differences! > > The core of the "original" is what has been provided on the BBB (and is > available via an older download page -- it WILL run on a Windows box). The > "original" includes the IDE functions AND runs as the web-server. As you would expect, the newer Cloud9 is clearly superior, in function. I don't think there's a F/LOSS download though! (would be more than a slight surprise were Amazon to do so) There was a product on the original list: Koding. IIRC this is delivered as a docker module?Kubernetes. I suppose such is beyond the capacities of a BBB, even a RPi4 (USB-C confusion and higher-current demands notwithstanding)*. I don't think I'm going to find sufficient time to try that option - and offering the PUG attendees three choices now (TeamViewer, PythonAnywhere, and Cloud9) is probably more than enough and heading into 'overload' territory. That said, the idea of being able to completely control the whole service, from-soup-to-nuts, is attractive - for reasons alluded-to earlier. * was blown-away by the price/specs of the nVidia Jetson Nano (similar form-factor, SBC + add-ons), which I've been looking at for image manipulation and video editing/production. Sadly, the BBB may have 'had its day'? > Now... Off to report for jury pool summons... Having an alarm go off at > 0500 is obscene [my normal is 0730, second alarm at 0800, and crawl out of > bed at 0900, get on computer between 1000 and 1100). The claim is that "The wheels of justice turn slowly, but grind exceedingly fine.", so please ensure that you don't fall into the machinery! Perhaps you'll be more in the mood for Robin Williams: (something like) 0300! [pronounced oh-three-hundred, ie 3am, which he described as] Oh as in: Oh my God it's early! From the movie "Good Morning Vietnam", and employing typical sardonic military humor. Another (borrowed from a British unit), which may apply well to your jury-duty is "hurry up and wait"... (hope it goes well/is not too boring!) -- Regards =dn From rosuav at gmail.com Mon Aug 5 08:04:03 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Aug 2019 22:04:03 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> Message-ID: On Mon, Aug 5, 2019 at 8:54 PM DL Neil wrote: > > On 3/08/19 5:50 PM, Chris Angelico wrote: > > On Sat, Aug 3, 2019 at 3:36 PM DL Neil wrote: > >> > >> On 3/08/19 4:02 PM, Terry Reedy wrote: > >>> Good. Master-satellite would be much easier. We added line numbers to > >>> IDLE's editor last week, so verbal feedback from satellite to master > >>> should be sufficient for many purposes. > > Elsewhere in this thread others, have been looking at NAT and broker > arrangements. It has been v.interesting to read. > > If it is a corporation's project, then this is an option. The business > of choosing ports and opening firewalls is a (?mere) matter of > standardisation and coordination. (cough, cough, mumble, mumble) > > However, if we are talking about a public product, eg TeamViewer; then > ease of operation comes to the fore. (much though I disagree with what > amounts to an abuse of port-80 - specialists trying to 'manage' Internet > traffic must really have things to say about such) > > The reason I mentioned "TeamViewer" (and A.N.Other mentioned BitTorrent) > is that client-server is so much easier to implement - even if (using > this example) the two (pair-programming) start as clients to some > central server, but later comms are 'delegated'/re-directed to become > peer-to-peer or go-direct. In the case of TV, which I use in (unpaid, > much put-upon, family - you know this song!) 'technical support' mode, > both the one seeking help and my own computer have to separately log-in > to the TV system, the second asking to connect to the first... Sometimes there can be magical firewall penetration tricks that allow the traffic to go peer-to-peer after an initial handshake with some central server, but this has its own problems. On any network that I control, such tricks are disabled; if you want to listen to connections from the outside world, you get my explicit permission and an actual line in the firewall configs. > Also, there are scenarios when both (of the pair) might be contributing > by 'coding' concurrently, eg one writing tests and the other code, or > one writing one class and the other a second. (but you can debate if > that is "pair-programming") No, that's not pair programming. That's collaboration on a project, but it's not the sort of thing where you need to see the other person's screen. > > TLS doesn't really solve this problem. If you have a single central > > server, TLS just tells you that you're talking to that server, without > > proving anything about who's on the other end. Even if you directly > > connect the two nodes, TLS wouldn't prove who that is, unless you get > > a dedicated certificate. What it *can* prove is that your data stream > > hasn't been tampered with en route, but the problem of receiving code > > from strangers is still an issue. Ultimately, pair programming depends > > on a measure of trust - you have to be confident that the person > > you're pairing with isn't going to be maliciously messing with your > > system. > > As above, using a client-server relationship, thus TLS/SSH are > relatively natural, and certainly common, components of the whole. That's fine if one end is a dedicated server. > I assume a level of trust. Why would you pair-program with someone > untrustworthy? Either you're a team or not! What about poisoning the channel externally, though? If you can't directly connect a TCP socket between the two peers, the traffic will have to go out on the internet. > Is it acceptable to train folk to code (in a particular language) > without also covering the likely tools they will (also) use? > > So with Python, during the first lesson we could jump straight into a > one-line print( "hello world" ) program using the REPL. However, an > editor will be employed as soon as we want our code to persist. So > should we (immediately) promote the use of a professional editor/IDE, eg > PyCharm, Sublime Text, Codium, Eclipse; or a 'traditional' character > editing tool, eg Vi, emacs? > (please no 'religious wars' just because I mentioned both in the same > sentence!) At my work, we instruct students on how to set up one particular tech stack, including an editor, linter, source control, etc, etc. We're clear with them that these are not the only options, but for the sake of bootcamp time pressures, we aren't going to show them any others. Depending on what you're trying to do, it MAY be acceptable to teach just the language. But that won't make someone employable on its own. Like everything, "it depends" :) ChrisA From isidentical at gmail.com Mon Aug 5 08:11:53 2019 From: isidentical at gmail.com (Batuhan Taskaya) Date: Mon, 5 Aug 2019 15:11:53 +0300 Subject: Any bad patterns we can find with static analyzing Message-ID: I am developing a project called Inspector Tiger (from monty python :)) and with that project i am trying to perform a static check over the source code to find common mistakes. If you know a common mistaken pattern, it would be really great to share it with me or implement it and PR to inspector tiger. Source: https://github.com/thg-consulting/inspectortiger From hgs at dmu.ac.uk Mon Aug 5 09:43:21 2019 From: hgs at dmu.ac.uk (Hugh Sasse) Date: Mon, 5 Aug 2019 14:43:21 +0100 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> Message-ID: <740d4545-c917-ffe7-8f0e-e68c48e040c9@dmu.ac.uk> I might not have followed this thread closely enough.? I remembered there is a thing called Copilot. It connects two machines so that two people can work together. I've never used it, and have no connection with the company.? I remember reading about it on a page written by Joel Spolsky. https://www.copilot.com/About If this is the wrong answer, it may at least help define the negative space around what you want. Hugh From tjreedy at udel.edu Mon Aug 5 10:40:40 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 5 Aug 2019 10:40:40 -0400 Subject: Any bad patterns we can find with static analyzing In-Reply-To: References: Message-ID: On 8/5/2019 8:11 AM, Batuhan Taskaya wrote: > I am developing a project called Inspector Tiger (from monty python > :)) and with that project i am trying to perform a static check over > the source code to find common mistakes. If you know a common mistaken > pattern, it would be really great to share it with me or implement it > and PR to inspector tiger. > > Source: https://github.com/thg-consulting/inspectortiger Read the Python FAQ and search for documents with things like 'Python gotchas' or 'Python warts'. You can also find threads here and on Stackoverflow where the gist of a problem is using bad patterns. -- Terry Jan Reedy From hongyi.zhao at gmail.com Mon Aug 5 11:01:10 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 5 Aug 2019 15:01:10 -0000 (UTC) Subject: base = 1024 if (gnu or binary) else 1000 Message-ID: Hi, I read the source code of of `humanize/filesize.py' and find the 24 line writing as follows: base = 1024 if (gnu or binary) else 1000 It seems this is not the standard usage of if ... else .... Is this a variant of lambda or some others? Could you please give me some more hints? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From arunkumar99.ak at gmail.com Sun Aug 4 05:29:22 2019 From: arunkumar99.ak at gmail.com (Arun Kumar) Date: Sun, 4 Aug 2019 14:59:22 +0530 Subject: Python scripts Message-ID: Dear sir In python application in scripts folder files are missing then how to get those files. From rhodri at kynesim.co.uk Mon Aug 5 11:28:11 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 5 Aug 2019 16:28:11 +0100 Subject: Python scripts In-Reply-To: References: Message-ID: <78eb42b5-2c4d-ba06-7c3b-b00e347cedab@kynesim.co.uk> On 04/08/2019 10:29, Arun Kumar wrote: > In python application in scripts folder files are missing then how to > get those files. That depends on exactly what you mean by "files are missing". If (most likely) the application is trying to import a third party module that you don't have installed, the documentation coming with the application should tell you what to install and where to get it from. If files are genuinely missing from the script folder (wherever/whatever that is), contact the author of the application. If all else fails, read the documentation ;-) -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Mon Aug 5 11:41:35 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 5 Aug 2019 16:41:35 +0100 Subject: base = 1024 if (gnu or binary) else 1000 In-Reply-To: References: Message-ID: On 05/08/2019 16:01, Hongyi Zhao wrote: > Hi, > > I read the source code of of `humanize/filesize.py' and find the 24 line > writing as follows: > > base = 1024 if (gnu or binary) else 1000 > > It seems this is not the standard usage of if ... else .... It's a perfectly standard conditional *expression* (see https://docs.python.org/3/reference/expressions.html#conditional-expressions), not an if *statement* at all. It's the equivalent of "?:" in C and C-like languages. In general conditional expressions look like: if else Python evaluates the . If it is true, the expression evaluates to . If it is false, it evaluates to . In this specific case, "base" is assigned 1024 if "gnu" or "binary" are true, else it is assigned 1000. -- Rhodri James *-* Kynesim Ltd From python at mrabarnett.plus.com Mon Aug 5 11:50:21 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 5 Aug 2019 16:50:21 +0100 Subject: base = 1024 if (gnu or binary) else 1000 In-Reply-To: References: Message-ID: <1434b31d-4e61-8ee8-ea2d-b47f7c02976b@mrabarnett.plus.com> On 2019-08-05 16:01, Hongyi Zhao wrote: > Hi, > > I read the source code of of `humanize/filesize.py' and find the 24 line > writing as follows: > > base = 1024 if (gnu or binary) else 1000 > > It seems this is not the standard usage of if ... else .... > > Is this a variant of lambda or some others? Could you please give me > some more hints? > It's a "conditional expression" (also called a "ternary if") and it's mentioned in Python's documentation. In this case it does the same as: if gnu or binary: base = 1024 else: base = 1000 From dboland9 at protonmail.com Mon Aug 5 13:49:24 2019 From: dboland9 at protonmail.com (Dave) Date: Mon, 5 Aug 2019 13:49:24 -0400 Subject: Python/SQLite best practices Message-ID: I'm looking for some tips from experienced hands on on this subject. Some of the areas of interest are (feel free to add more): * Passing connections and cursors - good, bad indifferent? I try to avoid passing file handles unless necessary, so I view connections and cursors the same. Though that said, I'm not aware of any specific problems in doing so. For designs with multiple tables: * Better to pass an sql string to functions that create/add data/update/delete data and pass them to create, insert, update, delete functions; or have those functions for each table? Taking table creation for example, if there are five tables, and the sql string is passed, there would need to be six functions to do it, though the complexity of each function may be reduced a little. [table1create with sql and establishing a cursor, to table5create and then a function that executes the sql]. Best way to establish the connection and cursor, as well as close them? I have seen many ways to do this, and know that the with block can be used to create a connection and close it automatically, but the same is not true of the cursor. Also, using only a with block does not handle any errors as well as a try/with. For example: | try: | # Use with block to create connection ? it will close self. | with sqlite3.connect(path) as conn: | cur = conn.cursor() | cur.execute(sql_ProjectsTable) | cur.close() | except Error as e: | print(e) What else? Dave, From Karsten.Hilbert at gmx.net Mon Aug 5 14:12:27 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 5 Aug 2019 20:12:27 +0200 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: <20190805181227.GH6537@hermes.hilbert.loc> On Mon, Aug 05, 2019 at 01:49:24PM -0400, Dave via Python-list wrote: > * Passing connections and cursors - good, bad indifferent? I try to avoid > passing file handles unless necessary, so I view connections and cursors the > same. Connections may be more long-lived, per thread perhaps. Cursors would generally be throw-away. Transactions involving several commands may require passing around of connections and/or cursors, however. > Best way to establish the connection and cursor, as well as close them? I > have seen many ways to do this, and know that the with block can be used to > create a connection and close it automatically, but the same is not true of > the cursor. Also, using only a with block does not handle any errors as > well as a try/with. For example: > > | try: > | # Use with block to create connection ? it will close self. > | with sqlite3.connect(path) as conn: > | cur = conn.cursor() > | cur.execute(sql_ProjectsTable) > | cur.close() > | except Error as e: > | print(e) Use of try: except: finally: may come in handy for clean closure. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From Karsten.Hilbert at gmx.net Mon Aug 5 14:14:51 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 5 Aug 2019 20:14:51 +0200 Subject: Python/SQLite best practices In-Reply-To: <20190805181227.GH6537@hermes.hilbert.loc> References: <20190805181227.GH6537@hermes.hilbert.loc> Message-ID: <20190805181450.GI6537@hermes.hilbert.loc> On Mon, Aug 05, 2019 at 08:12:27PM +0200, Karsten Hilbert wrote: > Transactions involving several commands may require passing > around of connections and/or cursors, however. Among chains of python code, that is. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From David.Raymond at tomtom.com Mon Aug 5 15:03:27 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Mon, 5 Aug 2019 19:03:27 +0000 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: Not a full expert, but some notes: I believe the default Connection context manager is set up for the context to be a single transaction, with a commit on success or a rollback on a failure. As far as I know it does NOT close the connection on exiting the context manager. That only happens automatically when it's getting garbage collected/going out of scope/correct terminology that I can't seem to remember. For transactions and general use I vastly prefer using "isolation_level = None" when creating my connections, and then explicitly issuing all begin, commit, and rollback commands with cur.execute("begin;"), conn.commit(), conn.rollback() etc. contextlib.closing() can be used to wrap cursors for use with with (and also connections if they are created with isolation_level = None) with contextlib.closing(sqlite3.connect(fi, isolation_level = None)) as conn: conn.row_factory = sqlite3.Row with contextlib.closing(conn.cursor()) as cur: cur.execute("begin;") stuff conn.commit() Normally though my stuff tends to look like the below (for better or for worse): conn = sqlite3.connect(fi, isolation_level = None) try: conn.row_factory = sqlite3.Row with contextlib.closing(conn.cursor()) as cur: cur.execute("standalone query not needing an explicit transaction;") stuff cur.execute("begin;") multiple queries that needed the explicit transaction stuff cur.execute("commit;") except something bad: blah finally: conn.rollback() conn.close() -----Original Message----- From: Python-list On Behalf Of Dave via Python-list Sent: Monday, August 05, 2019 1:49 PM To: python-list at python.org Subject: Python/SQLite best practices I'm looking for some tips from experienced hands on on this subject. Some of the areas of interest are (feel free to add more): * Passing connections and cursors - good, bad indifferent? I try to avoid passing file handles unless necessary, so I view connections and cursors the same. Though that said, I'm not aware of any specific problems in doing so. For designs with multiple tables: * Better to pass an sql string to functions that create/add data/update/delete data and pass them to create, insert, update, delete functions; or have those functions for each table? Taking table creation for example, if there are five tables, and the sql string is passed, there would need to be six functions to do it, though the complexity of each function may be reduced a little. [table1create with sql and establishing a cursor, to table5create and then a function that executes the sql]. Best way to establish the connection and cursor, as well as close them? I have seen many ways to do this, and know that the with block can be used to create a connection and close it automatically, but the same is not true of the cursor. Also, using only a with block does not handle any errors as well as a try/with. For example: | try: | # Use with block to create connection ? it will close self. | with sqlite3.connect(path) as conn: | cur = conn.cursor() | cur.execute(sql_ProjectsTable) | cur.close() | except Error as e: | print(e) What else? Dave, -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Aug 5 15:10:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Aug 2019 05:10:45 +1000 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: On Tue, Aug 6, 2019 at 5:05 AM David Raymond wrote: > I believe the default Connection context manager is set up for the context to be a single transaction, with a commit on success or a rollback on a failure. As far as I know it does NOT close the connection on exiting the context manager. That only happens automatically when it's getting garbage collected/going out of scope/correct terminology that I can't seem to remember. > > > For transactions and general use I vastly prefer using "isolation_level = None" when creating my connections, and then explicitly issuing all begin, commit, and rollback commands with cur.execute("begin;"), conn.commit(), conn.rollback() etc. > > > contextlib.closing() can be used to wrap cursors for use with with > (and also connections if they are created with isolation_level = None) > > with contextlib.closing(sqlite3.connect(fi, isolation_level = None)) as conn: > conn.row_factory = sqlite3.Row > with contextlib.closing(conn.cursor()) as cur: > cur.execute("begin;") > stuff > conn.commit() > > > > Normally though my stuff tends to look like the below (for better or for worse): > > conn = sqlite3.connect(fi, isolation_level = None) > try: > conn.row_factory = sqlite3.Row > with contextlib.closing(conn.cursor()) as cur: > cur.execute("standalone query not needing an explicit transaction;") > stuff > cur.execute("begin;") > multiple queries that needed the explicit transaction > stuff > cur.execute("commit;") > except something bad: > blah > finally: > conn.rollback() > conn.close() > What's the advantage of this over letting the connection object do that for you? As the context manager exits, it will automatically either commit or roll back. If you want to guarantee closing _as well_, then you can do that, but you can at least use what already exists. (Also, I'd definitely use conn.commit() rather than cur.execute("commit"), in case there's extra functionality in the commit method.) ChrisA From arash.kh12320 at gmail.com Mon Aug 5 12:40:30 2019 From: arash.kh12320 at gmail.com (arash kohansal) Date: Mon, 5 Aug 2019 21:10:30 +0430 Subject: Please help me Message-ID: Hello ive just installed python on my pc and ive already check the path choice part but microsoft visual code can not find it and it does not have the reload item From PythonList at DancesWithMice.info Mon Aug 5 16:28:25 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 6 Aug 2019 08:28:25 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <740d4545-c917-ffe7-8f0e-e68c48e040c9@dmu.ac.uk> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <740d4545-c917-ffe7-8f0e-e68c48e040c9@dmu.ac.uk> Message-ID: <6137907c-a820-2003-f096-497060830996@DancesWithMice.info> On 6/08/19 1:43 AM, Hugh Sasse wrote: > I might not have followed this thread closely enough.? I remembered > there is a thing called Copilot. > It connects two machines so that two people can work together. > https://www.copilot.com/About > > If this is the wrong answer, it may at least help define the negative > space around what you want. Thank you Hugh. Yes, there are a few of these Copilot-style packages. The one that seems popular in 'my circle' is called TeamViewer. We will definitely offer that as an option at Wednesday's PUG mtg, and if someone requests Copilot, or similar, I'll try to adapt. No, not "negative" by any means. Many thanks! -- Regards =dn From arash.kh12320 at gmail.com Mon Aug 5 16:39:22 2019 From: arash.kh12320 at gmail.com (arash kohansal) Date: Tue, 6 Aug 2019 01:09:22 +0430 Subject: No subject Message-ID: Hello i have a laptob and working with windows 10 ive installed python in my pc and ive already check the path choice pary in the installation im working with microsoft visual studio code but it cant find the python installed extention and it doesnt have the green star on the top of python language From PythonList at DancesWithMice.info Mon Aug 5 17:07:41 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 6 Aug 2019 09:07:41 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> Message-ID: On 6/08/19 12:04 AM, Chris Angelico wrote: > On Mon, Aug 5, 2019 at 8:54 PM DL Neil wrote: >> On 3/08/19 5:50 PM, Chris Angelico wrote: >>> On Sat, Aug 3, 2019 at 3:36 PM DL Neil wrote: >>>> On 3/08/19 4:02 PM, Terry Reedy wrote: ... > Sometimes there can be magical firewall penetration tricks that allow > the traffic to go peer-to-peer after an initial handshake with some > central server, but this has its own problems. On any network that I > control, such tricks are disabled; if you want to listen to > connections from the outside world, you get my explicit permission and > an actual line in the firewall configs. Here is the point where I'll bow-out. This sort of stuff is what NetAdmins are for! Better minds than mine... >> Also, there are scenarios when both (of the pair) might be contributing >> by 'coding' concurrently, eg one writing tests and the other code, or >> one writing one class and the other a second. (but you can debate if >> that is "pair-programming") > > No, that's not pair programming. That's collaboration on a project, > but it's not the sort of thing where you need to see the other > person's screen. Agreed. "Pair-programming" seemed the closest, commonly-used, professional term to describe how one might be remotely-useful (pun!?) during the PUG's Coding Evening. It seems reasonable that if folk are working-together yet on separate components, when they link the two components, both being able to see 'the same thing' would be a natural approach, eg one writing the tests and another the code - what happens when the tests run? Anyway, this PUG mtg is going to be an 'experience'. (I'll try (almost) anything once!) ... >> Is it acceptable to train folk to code (in a particular language) >> without also covering the likely tools they will (also) use? >> >> So with Python, during the first lesson we could jump straight into a >> one-line print( "hello world" ) program using the REPL. However, an >> editor will be employed as soon as we want our code to persist. So >> should we (immediately) promote the use of a professional editor/IDE, eg >> PyCharm, Sublime Text, Codium, Eclipse; or a 'traditional' character >> editing tool, eg Vi, emacs? >> (please no 'religious wars' just because I mentioned both in the same >> sentence!) > > At my work, we instruct students on how to set up one particular tech > stack, including an editor, linter, source control, etc, etc. We're > clear with them that these are not the only options, but for the sake > of bootcamp time pressures, we aren't going to show them any others. > > Depending on what you're trying to do, it MAY be acceptable to teach > just the language. But that won't make someone employable on its own. > > Like everything, "it depends" :) Indeed! As a matter of interest (and if you don't mind sharing), which packages are included in the organisation's student "stack"? (again: no 'judgement', please) How 'expensive' or distracting is it, merely in terms of trainees failing to follow the installation/configuration instructions? Do you find 'my first program' (when trainees are first required to use the 'stack') to be a major failure/frustration/drop-out point? To what degree might that be caused by the trainee realising that (s)he has to turn 'book knowledge' into coding-action, ie 'the real world', and how much might be the 'cost' of those tools? -- Regards =dn From rosuav at gmail.com Mon Aug 5 17:21:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Aug 2019 07:21:26 +1000 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> Message-ID: On Tue, Aug 6, 2019 at 7:09 AM DL Neil wrote: > As a matter of interest (and if you don't mind sharing), which packages > are included in the organisation's student "stack"? > (again: no 'judgement', please) TBH the best stack I can describe is what we teach for JavaScript students, as they're the ones who have the bootcamp format (although that's now changing, as we have a data science bootcamp built on Python - but I don't know whether the tech stack has been settled yet). We get them to use VS Code, ESLint, Node.js, npm, git, PostgreSQL (once they get to that point), and a handful of JavaScript libraries/packages. > How 'expensive' or distracting is it, merely in terms of trainees > failing to follow the installation/configuration instructions? Not too bad; there's some cost when someone has trouble setting up eslint, or when their editor's indentation settings don't match the linter's, but it's manageable. > Do you find 'my first program' (when trainees are first required to use > the 'stack') to be a major failure/frustration/drop-out point? To what > degree might that be caused by the trainee realising that (s)he has to > turn 'book knowledge' into coding-action, ie 'the real world', and how > much might be the 'cost' of those tools? No, but I think the level of pressure in a bootcamp tends to lead to people just blindly accepting what they're given, rather than objecting to it. "You want me to use VS Code? Okay, no prob, what do I click on?". There isn't time to debate it, because within the next three hours, there are about eight hours' worth of work to be done :) Things would be different in other contexts. ChrisA From David.Raymond at tomtom.com Mon Aug 5 17:43:53 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Mon, 5 Aug 2019 21:43:53 +0000 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: "What's the advantage of this over letting the connection object do that for you? As the context manager exits, it will automatically either commit or roll back. If you want to guarantee closing _as well_, then you can do that, but you can at least use what already exists." After review I guess I should have phrased it more as a "here's what I've found for reference" rather than a "here's what _you_ should do" Part of it is large use of the Command Line Interface for SQLite, and similar command line tools for other db's, which all work in autocommit mode by default, so that's how my brain is now wired to think about executing things. The context manager transaction feature I can see using, and might actually start switching to it as it's explicit enough. Though oddly, __enter__ doesn't seem to actually begin a transaction, not even a deferred one. It's only __exit__ that either commits or rolls back. (Eh, it'd "probably" be simple enough to subclass Connection so that __enter__ and __exit__ work properly no matter the isolation_level. Famous last words) The implicit stuff I hated because it never seemed straightforward enough. Especially since there used to be implicit commits as well as implicit begins ("Changed in version 3.6: sqlite3 used to implicitly commit an open transaction before DDL statements. This is no longer the case.") Maybe because I was new to both Python and SQLite at the time, but there was a lot of "stop doing hidden stuff I didn't tell you do" getting muttered, along with others like "why do I need to commit when I never did a begin?" The documentation on it is all of 1 sentence, so there was a lot of trial an error going on. "The Python sqlite3 module by default issues a BEGIN statement implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE)." "(Also, I'd definitely use conn.commit() rather than cur.execute("commit"), in case there's extra functionality in the commit method.)" True. I know for example that if you try to rollback when not in a transaction that cur.execute("rollback;") will raise an exception whereas conn.rollback() will quietly suppress it for you. So there might be similarly useful stuff in .commit() sqlite3 is (almost) all C though, so there'd be noticeably more digging and decyphering required to check. (For me anyway) From rosuav at gmail.com Mon Aug 5 17:55:57 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Aug 2019 07:55:57 +1000 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: On Tue, Aug 6, 2019 at 7:45 AM David Raymond wrote: > The context manager transaction feature I can see using, and might actually start switching to it as it's explicit enough. Though oddly, __enter__ doesn't seem to actually begin a transaction, not even a deferred one. It's only __exit__ that either commits or rolls back. > (Eh, it'd "probably" be simple enough to subclass Connection so that __enter__ and __exit__ work properly no matter the isolation_level. Famous last words) > Easier just to leave the isolation level and let it automatically begin. (This is another reason to use the commit and rollback methods, as they may flag the connection as "hey, remember to begin before the next query".) > The implicit stuff I hated because it never seemed straightforward enough. Especially since there used to be implicit commits as well as implicit begins ("Changed in version 3.6: sqlite3 used to implicitly commit an open transaction before DDL statements. This is no longer the case.") Maybe because I was new to both Python and SQLite at the time, but there was a lot of "stop doing hidden stuff I didn't tell you do" getting muttered, along with others like "why do I need to commit when I never did a begin?" The documentation on it is all of 1 sentence, so there was a lot of trial an error going on. > I grew up on DB2 5.0 (after working in PC File and dbase), and you never did a BEGIN TRANSACTION unless you wanted to set specific parameters, but always had to COMMIT/ROLLBACK. The database itself would automatically open a transaction as soon as you do any query, and leave it open till you're done. So to me, that was never a problem. ChrisA From python at mrabarnett.plus.com Mon Aug 5 18:41:51 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 5 Aug 2019 23:41:51 +0100 Subject: Please help me In-Reply-To: References: Message-ID: On 2019-08-05 17:40, arash kohansal wrote: > Hello ive just installed python on my pc and ive already check the path > choice part but microsoft visual code can not find it and it does not have > the reload item > 1. Open Visual Studio Code. 2. Press F1, type "Python: Select Interpreter", and then press Enter. 3. Select the Python version that you installed from the list. From jonathan-lists at lightpear.com Mon Aug 5 19:01:18 2019 From: jonathan-lists at lightpear.com (Jonathan Moules) Date: Tue, 6 Aug 2019 00:01:18 +0100 Subject: Python/SQLite best practices In-Reply-To: References: Message-ID: <85d1d4f3-360c-88f2-27ae-3ef5a77b9ca5@lightpear.com> Some gotcha tips from using SQLite with Python that I've encountered. You may already know some/all of these: * SQLite doesn't have a "Truncate" function - simply delete the file if possible for larger datasets. * Explicitly committing is good because the default python sqlite3 library does it randomly and implicitly. I found that doing it only when the database is dettaching or closing speeds things up a lot. * SQLite 3 only considers up to 64bits an INTEGER. So if you want to insert a 128bit string you have to use Python string substitution (i.e. "Hello %s") rather than the SQLite variable substitution "insert into tab values (?)" * To be reliably INSERTed Byte data should be first converted to sqlite3.Binary(my_data) explicitly * By default Foreign Keys are not enforced. Enable them at connection time if you care about referential integrity! * It's typically opaque as to where the install of SQLite is that the library is using and it's very hard and not-documented as to how to update the SQLite version that Python is using. If you want an even thinner wrapper around SQLite there's APSW ( https://rogerbinns.github.io/apsw/index.html ) - I've never used it myself but it's useful to know about. There's a page with differences - https://rogerbinns.github.io/apsw/pysqlite.html#pysqlitediffs On 2019-08-05 22:43, David Raymond wrote: > "What's the advantage of this over letting the connection object do > that for you? As the context manager exits, it will automatically > either commit or roll back. If you want to guarantee closing _as > well_, then you can do that, but you can at least use what already > exists." > > After review I guess I should have phrased it more as a "here's what I've found for reference" rather than a "here's what _you_ should do" > > > Part of it is large use of the Command Line Interface for SQLite, and similar command line tools for other db's, which all work in autocommit mode by default, so that's how my brain is now wired to think about executing things. > > The context manager transaction feature I can see using, and might actually start switching to it as it's explicit enough. Though oddly, __enter__ doesn't seem to actually begin a transaction, not even a deferred one. It's only __exit__ that either commits or rolls back. > (Eh, it'd "probably" be simple enough to subclass Connection so that __enter__ and __exit__ work properly no matter the isolation_level. Famous last words) > > The implicit stuff I hated because it never seemed straightforward enough. Especially since there used to be implicit commits as well as implicit begins ("Changed in version 3.6: sqlite3 used to implicitly commit an open transaction before DDL statements. This is no longer the case.") Maybe because I was new to both Python and SQLite at the time, but there was a lot of "stop doing hidden stuff I didn't tell you do" getting muttered, along with others like "why do I need to commit when I never did a begin?" The documentation on it is all of 1 sentence, so there was a lot of trial an error going on. > "The Python sqlite3 module by default issues a BEGIN statement implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE)." > > > "(Also, I'd definitely use conn.commit() rather than > cur.execute("commit"), in case there's extra functionality in the > commit method.)" > > True. I know for example that if you try to rollback when not in a transaction that cur.execute("rollback;") will raise an exception whereas conn.rollback() will quietly suppress it for you. So there might be similarly useful stuff in .commit() > sqlite3 is (almost) all C though, so there'd be noticeably more digging and decyphering required to check. (For me anyway) > From cs at cskk.id.au Mon Aug 5 20:55:22 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 6 Aug 2019 10:55:22 +1000 Subject: Python/SQLite best practices In-Reply-To: <85d1d4f3-360c-88f2-27ae-3ef5a77b9ca5@lightpear.com> References: <85d1d4f3-360c-88f2-27ae-3ef5a77b9ca5@lightpear.com> Message-ID: <20190806005522.GA61039@cskk.homeip.net> On 06Aug2019 00:01, Jonathan Moules wrote: >Some gotcha tips from using SQLite with Python that I've encountered. [...] >* To be reliably INSERTed Byte data should be first converted to >sqlite3.Binary(my_data) explicitly Interesting. Is that Python 2 specific, or also in Python 3. Because the latter would surprise me (not saying it isn't the case). >* It's typically opaque as to where the install of SQLite is that the >library is using and it's very hard and not-documented as to how to >update the SQLite version that Python is using. On a UNIX system the command "lsof -p pid-of-running-python-process" should show the path of the sqlite library that is linked to the Python executable, which should let you learn this. >If you want an even thinner wrapper around SQLite there's APSW ( >https://rogerbinns.github.io/apsw/index.html ) - I've never used it >myself but it's useful to know about. There's a page with differences >- https://rogerbinns.github.io/apsw/pysqlite.html#pysqlitediffs And for a thicker wrapper, I've been extremely happy using SQLAlchemy for database access. It has an expression syntax where real Python expressions (containing "column" objects) evaluate to safe SQL, letting you write safe queries in nice Pythonic form, and it also has an ORM for more sophisticated use. It provided context manager for transactions and sessions for various work. Finally, it knows about a lot of backends, so you could switch backends later (eg from SQLite to PostgreSQL) if that becomes a thing. Cheers, Cameron Simpson From angel.thomas1717 at gmail.com Tue Aug 6 02:21:56 2019 From: angel.thomas1717 at gmail.com (angel.thomas1717 at gmail.com) Date: Mon, 5 Aug 2019 23:21:56 -0700 (PDT) Subject: 7 Reasons Why You Should Keep Learning C/C++ Message-ID: <80f9005e-18e2-4a5c-98fb-257246049362@googlegroups.com> Many programmers are frustrated with and leaning away toward the C/C++ programming languages because of the following reasons: (1) Very steep learning curve.. Many people joined the programming world by learning C or C++, but it?s rare for them to keep learning and mastering these two languages well because they get frustrated in handling the low-level programming elements such as pointers, the memory storage model, address alignment, templates expansion, multi-thread data races, and so on. If these elements are not handled properly, the app will have a high probability of crashing, which will frustrate the new programmer. (2) Rarely used in modern application development Nowadays we have many advanced programming languages like Java, C#, Python, Javascript, Go, etc for application development and it seems insane if someone wanted to develop a Web application or backend service in pure C/C++. The common application areas have been taken over by more advanced programming languages such as: Web front-end development: Javascript/Typescript rule everything and the three popular frameworks in frontend are Angular, React, and Vue. Web back-end service development: Javascript (Node), Python (Flask, Django), Java, and PHP are the popular technologies used. Desktop application development: QT (PyQT, C++), Electron (Javascript), WPF (C#). Mobile application development: iOS (Objective-C, Swift), Android (Java). Distributed systems, Big Data, Cloud Computing: Java, Go, Groovy, Scala. Data science, AI (Artificial Intelligence), ML (Machine Learning): Python. It looks like C/C++ are rarely used in these modern application development areas. So why should we still learn C/C++? Here are 7 reasons why you should: https://simpliv.wordpress.com/2019/08/06/7-reasons-why-you-should-keep-learning-c-c/ From hgs at dmu.ac.uk Tue Aug 6 04:54:16 2019 From: hgs at dmu.ac.uk (Hugh Sasse) Date: Tue, 6 Aug 2019 09:54:16 +0100 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: <6137907c-a820-2003-f096-497060830996@DancesWithMice.info> References: <38eb4844-0df3-ee82-cfbf-284736ad701c@etelligence.info> <740d4545-c917-ffe7-8f0e-e68c48e040c9@dmu.ac.uk> <6137907c-a820-2003-f096-497060830996@DancesWithMice.info> Message-ID: <97906586-621d-7648-bfe1-3e12e7a49702@dmu.ac.uk> On 05/08/2019 21:28, DL Neil wrote: > On 6/08/19 1:43 AM, Hugh Sasse wrote: >> I might not have followed this thread closely enough.? I remembered >> there is a thing called Copilot. >> It connects two machines so that two people can work together. >> https://www.copilot.com/About >> >> If this is the wrong answer, it may at least help define the negative >> space around what you want. > > Thank you Hugh. > > Yes, there are a few of these Copilot-style packages. The one that seems > popular in 'my circle' is called TeamViewer. > > We will definitely offer that as an option at Wednesday's PUG mtg, and > if someone requests Copilot, or similar, I'll try to adapt. > > No, not "negative" by any means. Many thanks! > Then you may find some of the recommendations on AlternativeTo useful. I've not explored them, but I've found useful things at this site before (for other things): https://alternativeto.net/software/copilot/ You probably know that site, but I didn't notice it come up in the discussion. If not: https://en.wikipedia.org/wiki/AlternativeTo -- Dr. Hugh Sasse, BSc(Hons), PhD Computer Systems Electronic Engineer School of Engineering and Sustainable Development DE MONTFORT UNIVERSITY From jonathan-lists at lightpear.com Tue Aug 6 05:14:03 2019 From: jonathan-lists at lightpear.com (Jonathan Moules) Date: Tue, 6 Aug 2019 10:14:03 +0100 Subject: Python/SQLite best practices In-Reply-To: <20190806005522.GA61039@cskk.homeip.net> References: <85d1d4f3-360c-88f2-27ae-3ef5a77b9ca5@lightpear.com> <20190806005522.GA61039@cskk.homeip.net> Message-ID: >> * To be reliably INSERTed Byte data should be first converted to >> sqlite3.Binary(my_data) explicitly > > Interesting. Is that Python 2 specific, or also in Python 3. Because > the latter would surprise me (not saying it isn't the case). Only tried on Python 3. I'm inserting raw byte versions of web-pages. I forget the exact details but I have a comment in my code to the above effect so I must have ended up bashing my head against it at some point. A zip/lzma compressed byte output doesn't need this wrapper though. > On a UNIX system the command "lsof -p pid-of-running-python-process" > should show the path of the sqlite library that is linked to the > Python executable, which should let you learn this. > Thanks, I'll have to add that to the collection. I know when I was googling around for it on *nix I came across a bunch of different answers none of which seemed to work. Windows is a simple matter of replacing the right DLL (though again not really documented). I still have no idea how to do it on *nix but that's another thread. From rosuav at gmail.com Tue Aug 6 12:56:40 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Aug 2019 02:56:40 +1000 Subject: Python/SQLite best practices In-Reply-To: References: <20190805181227.GH6537@hermes.hilbert.loc> Message-ID: On Wed, Aug 7, 2019 at 2:28 AM Dennis Lee Bieber wrote: > > On Mon, 5 Aug 2019 20:12:27 +0200, Karsten Hilbert > declaimed the following: > > > >Transactions involving several commands may require passing > >around of connections and/or cursors, however. > > > > Probably both -- as I recall, DB-API spec is that .commit() is done on > the connection, not the cursor. Though I'd prefer to put transaction > control at a single higher level > > create connection > create initial cursor > create transaction (though DB-API makes this tricky -- typically this > occurs on the first DML request that modifies data, but not for mere > SELECTs) > do stuff with cursor, maybe passing connection if "stuff" needs > secondary cursors > COMMIT or ROLLBACK based on return from "do stuff" > That would only be useful if the underlying database is capable of multiple independent transactions on a single connection, and would just get in the way otherwise. Some databases support a form of "nested transactions" where you set a savepoint and then have the option to either release the savepoint ("commit") or rollback to the savepoint; but releasing a savepoint doesn't actually commit anything, and the overall transaction still controls everything. My usual idiom with databasing code is to create a single connection (or maybe a pool if I need concurrency) and then use "with conn, conn.cursor() as cur:" to create a cursor and set up a transaction, all at once. At the end of that block, the cursor is disposed of, and the transaction committed/rolled back. ChrisA From brian.j.oney at googlemail.com Tue Aug 6 14:57:07 2019 From: brian.j.oney at googlemail.com (Brian Oney) Date: Tue, 06 Aug 2019 20:57:07 +0200 Subject: Please help me In-Reply-To: References: Message-ID: <58e1b74a551363da7c7585ff71522fc06fc11e07.camel@gmail.com> On Mon, 2019-08-05 at 21:10 +0430, arash kohansal wrote: > Hello ive just installed python on my pc and ive already check the > path > choice part but microsoft visual code can not find it and it does not > have > the reload item Check out: https://code.visualstudio.com/docs/languages/python or https://realpython.com/python-development-visual-studio-code/ From hongyi.zhao at gmail.com Wed Aug 7 09:11:56 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Wed, 7 Aug 2019 13:11:56 -0000 (UTC) Subject: For the code to generate `zen of python'. Message-ID: Hi here, I noticed that the `zen of python' is generated by the following code: d = {} for c in (65, 97): for i in range(26): d[chr(i+c)] = chr((i+13) % 26 + c) print("".join([d.get(c, c) for c in s])) But the above code is not so easy for me to figure out. Could someone please give me some explanations on it? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From p.f.moore at gmail.com Wed Aug 7 09:37:06 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 7 Aug 2019 14:37:06 +0100 Subject: For the code to generate `zen of python'. In-Reply-To: References: Message-ID: It's basically a decryption of the string s in the same module, that's encoded using the ROT13 algorithm - https://en.wikipedia.org/wiki/ROT13. This isn't meant to be secure, it's basically a little bit of fun obfuscating the actual text. The code creates a dictionary mapping encoded characters to their decoded equivalents. Decoding is done by adding 13 to the ASCII value of the letter (wrapping round from 25 back to 0). That's about it, really. Paul On Wed, 7 Aug 2019 at 14:17, Hongyi Zhao wrote: > > Hi here, > > I noticed that the `zen of python' is generated by the following code: > > d = {} > for c in (65, 97): > for i in range(26): > d[chr(i+c)] = chr((i+13) % 26 + c) > > print("".join([d.get(c, c) for c in s])) > > > But the above code is not so easy for me to figure out. Could someone > please give me some explanations on it? > > Regards > -- > .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. > -- > https://mail.python.org/mailman/listinfo/python-list From tjol at tjol.eu Wed Aug 7 09:29:00 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 7 Aug 2019 15:29:00 +0200 Subject: For the code to generate `zen of python'. In-Reply-To: References: Message-ID: On 07/08/2019 15.11, Hongyi Zhao wrote: > Hi here, > > I noticed that the `zen of python' is generated by the following code: > > d = {} > for c in (65, 97): > for i in range(26): > d[chr(i+c)] = chr((i+13) % 26 + c) > > print("".join([d.get(c, c) for c in s])) > > > But the above code is not so easy for me to figure out. Could someone > please give me some explanations on it? > > Regards This code [https://github.com/python/cpython/blob/master/Lib/this.py#L23] doesn?t ?generate? the Zen of Python, really. It just decrypts it. The Zen of Python is hidden just above those lines. Abj gur dhrfgvba vf: pna lbh svther bhg gur plcure? From phd at phdru.name Wed Aug 7 13:14:27 2019 From: phd at phdru.name (Oleg Broytman) Date: Wed, 7 Aug 2019 19:14:27 +0200 Subject: [poliastro-dev] ANN: poliastro 0.13.0 released ???? In-Reply-To: References: <34684103-9d6e-cc74-0f14-c95072f81d87@gmail.com> Message-ID: <20190807171427.6hfg2t2gsnxrhzcj@phdru.name> Can I ask you to remove python-announce from the list of addresses? It's not a mailing list for discussions. On Wed, Aug 07, 2019 at 06:16:43PM +0200, Samuel Leli??vre wrote: > Le mar. 6 ao??t 2019 ?? 08:33, Samuel Dupree a ??crit : > > > Juan Luis Cano, > > > > When will poliastro ver. 0.13.0 become available from Anaconda? At the > > time of this note, only ver. 0.12.0 is available. > > > > Lastly what is the recommended procedure to update poliastro from vers. > > 0.12.0 to 0.13.0? > > > > Sam Dupree > > > > A pull request was automatically created by a bot: > > https://github.com/conda-forge/poliastro-feedstock/pull/29 > > and Juan Luis merged it yesterday, so that the new version is > available since yesterday, see the version badge on the README at > > https://github.com/conda-forge/poliastro-feedstock > > Clicking on that badge sends to: > > https://anaconda.org/conda-forge/poliastro > > which has the installation instructions. > > Use `conda upgrade` instead of `conda install` if you want to upgrade. > -- > Python-announce-list mailing list -- python-announce-list at python.org > To unsubscribe send an email to python-announce-list-leave at python.org > https://mail.python.org/mailman3/lists/python-announce-list.python.org/ > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From ml_news at posteo.de Wed Aug 7 14:11:15 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Wed, 7 Aug 2019 20:11:15 +0200 Subject: class definition question Message-ID: <20190807201115.3ec7a9ee@arcor.com> Hi there, More often I see something like this: class Myclass: ... but sometimes I see class Myclass(object): ... Question: which way is preferable? -- Manfred From ml_news at posteo.de Wed Aug 7 15:26:13 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Wed, 7 Aug 2019 21:26:13 +0200 Subject: class definition question References: <20190807201115.3ec7a9ee@arcor.com> Message-ID: <20190807212613.332c1d14@arcor.com> On Wed, 07 Aug 2019 14:39:00 -0400 Dennis Lee Bieber wrote: > On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz > declaimed the following: > > >Hi there, > >More often I see something like this: > > > >class Myclass: > >... > > > > > >but sometimes I see > > > >class Myclass(object): > >... > > > > > >Question: which way is preferable? > > It's historical... > > Python v1.x had a form of classes. > > Python v2.x introduced "new-style" classes. "New-style" > classes /had/ to inherit from "object", as they had different > behavior from "v1.x old-style" classes which were still supported (it > would have broken too many programs). Old-style were then deprecated, > and one should have used new-style for new code. > > Python v3.x unified (removed old-style behavior differences) > and all classes inherit from "object" whether one specifies object or > not. > > Thanks a lot for the explanations. As a Python newbie (with no Pythons legacies) I only deal with Python 3. So, I will happily ignore 'object'. -- Manfred From tjreedy at udel.edu Wed Aug 7 16:36:02 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 7 Aug 2019 16:36:02 -0400 Subject: class definition question In-Reply-To: <20190807212613.332c1d14@arcor.com> References: <20190807201115.3ec7a9ee@arcor.com> <20190807212613.332c1d14@arcor.com> Message-ID: On 8/7/2019 3:26 PM, Manfred Lotz wrote: > On Wed, 07 Aug 2019 14:39:00 -0400 > Dennis Lee Bieber wrote: > >> On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz >> declaimed the following: >> >>> Hi there, >>> More often I see something like this: >>> >>> class Myclass: >>> ... >>> >>> >>> but sometimes I see >>> >>> class Myclass(object): >>> ... >>> >>> >>> Question: which way is preferable? >> >> It's historical... >> >> Python v1.x had a form of classes. >> >> Python v2.x introduced "new-style" classes. "New-style" >> classes /had/ to inherit from "object", as they had different >> behavior from "v1.x old-style" classes which were still supported (it >> would have broken too many programs). Old-style were then deprecated, >> and one should have used new-style for new code. >> >> Python v3.x unified (removed old-style behavior differences) >> and all classes inherit from "object" whether one specifies object or >> not. >> >> > > Thanks a lot for the explanations. > > As a Python newbie (with no Pythons legacies) I only deal with Python 3. > So, I will happily ignore 'object'. That is preferred, because it is extra work to write and read, with no benefit, and because myclass(object) can be seen as implying that the code once ran or is still meant to be compatible with Python 2. -- Terry Jan Reedy From lefkowitzsanford at gmail.com Wed Aug 7 16:35:48 2019 From: lefkowitzsanford at gmail.com (Sanford Lefkowitz) Date: Wed, 7 Aug 2019 13:35:48 -0700 (PDT) Subject: Trouble installing python In-Reply-To: References: Message-ID: <5eb32c99-6b63-4c57-8a27-368efed40f25@googlegroups.com> I have basically the same question. have you found an answer yet? From qubzen at gmail.com Wed Aug 7 16:36:59 2019 From: qubzen at gmail.com (Kuyateh Yankz) Date: Wed, 7 Aug 2019 13:36:59 -0700 (PDT) Subject: Python help needed Message-ID: <3c1ddad0-f345-44ee-9936-5ec5efe28eb0@googlegroups.com> #trying to write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it. def myList(aParameter): #defined finalList = [] for i in range(len(aParameter)-1): #targeting the last item in the list finalList.append('and '+ aParameter[-1]) #Removes the last item in the list, append the last item with THE and put it back, then put it into the FINAL LIST FUNCTION. return finalList spam = ['apples', 'bananas', 'tofu', 'cats'] print(myList(spam)) #Got up to this point, still couldn't get rid of the '' around the items and the []. I tried (','.join()) but could not get there. #Am I on the wrong path or there's a quick fix here? https://pastebin.com/JCXisAuz From python at mrabarnett.plus.com Wed Aug 7 19:18:02 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 8 Aug 2019 00:18:02 +0100 Subject: Python help needed In-Reply-To: <3c1ddad0-f345-44ee-9936-5ec5efe28eb0@googlegroups.com> References: <3c1ddad0-f345-44ee-9936-5ec5efe28eb0@googlegroups.com> Message-ID: <5dc957c0-b137-061b-1e0c-c484874ac09e@mrabarnett.plus.com> On 2019-08-07 21:36, Kuyateh Yankz wrote: > > #trying to write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it. > > def myList(aParameter): #defined > finalList = [] > for i in range(len(aParameter)-1): #targeting the last item in the list > finalList.append('and '+ aParameter[-1]) #Removes the last item in the list, append the last item with THE and put it back, then put it into the FINAL LIST FUNCTION. > return finalList > spam = ['apples', 'bananas', 'tofu', 'cats'] > print(myList(spam)) > > #Got up to this point, still couldn't get rid of the '' around the items and the []. I tried (','.join()) but could not get there. > #Am I on the wrong path or there's a quick fix here? > https://pastebin.com/JCXisAuz > There's a nice way of doing it using str.join. However, you do need to special-case when there's only 1 item. Start with a list: >>> spam = ['apples', 'bananas', 'tofu', 'cats'] The last item will be have an 'and', so let's remove that for the moment: >>> spam[ : -1] ['apples', 'bananas', 'tofu'] Join these items together with ', ': >>> ', '.join(spam[ : -1]) 'apples, bananas, tofu' Now for the last item: >>> ', '.join(spam[ : -1]) + ' and ' + spam[-1] 'apples, bananas, tofu and cats' For the special case, when len(spam) == 1, just return spam[0]. From angel.thomas1717 at gmail.com Thu Aug 8 03:35:49 2019 From: angel.thomas1717 at gmail.com (angel.thomas1717 at gmail.com) Date: Thu, 8 Aug 2019 00:35:49 -0700 (PDT) Subject: 10 Reasons Why You Should Keep Learning Game Development Message-ID: If you ask any software developer, there?s a decent chance that they have tried their hand at game development. It seems like a natural fit since it uses many of the same skills. What?s more, programmers come into it with the knowledge that most aspiring game makers lack: how to write good code and create effective software. However, the majority of developers and engineers either don?t stick with game development or don?t even consider it, perhaps thinking that the skills gained from game creation don?t apply to actual software development. If that sounds like you, it might be time to reconsider. Here are seven reasons why game development is actually a perfect side hobby for software developers. Click Here to continue: https://simpliv.wordpress.com/2019/08/08/10-reasons-why-you-should-keep-learning-game-development/ From email at paulstgeorge.com Thu Aug 8 02:38:37 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 8 Aug 2019 08:38:37 +0200 Subject: Python in Blender. Writing information to a file. Message-ID: <8b149812-3847-c5ee-29d9-d091c43fb524@paulstgeorge.com> I am using Python 3.5 within Blender. I want to collect values of the current settings and then write all the results to a file. I can see the settings and the values in the Python console by doing this for each of the settings | | |print(?Focal length:?,bpy.context.object.data.lens)| ---Focal length: 35.0 or I can do many at a time like this: |print("Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2])| ---Plane rotation X: 0.0 ---Plane rotation Y: 0.0 ---Plane rotation Z: 0.0 My question: How do I write all the results to a file? I have tried file.write but can only write one argument at a time. Is there a better way to open a file, write the collected information to it and then close the file? From __peter__ at web.de Thu Aug 8 04:18:57 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Aug 2019 10:18:57 +0200 Subject: Python in Blender. Writing information to a file. References: <8b149812-3847-c5ee-29d9-d091c43fb524@paulstgeorge.com> Message-ID: Paul St George wrote: > I am using Python 3.5 within Blender. I want to collect values of the > current settings and then write all the results to a file. > > I can see the settings and the values in the Python console by doing > this for each of the settings > | > | > > |print(?Focal length:?,bpy.context.object.data.lens)| > > ---Focal length: 35.0 > > > or I can do many at a time like this: > > |print("Plane rotation > X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation > Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation > Z:",bpy.data.objects["Plane"].rotation_euler[2])| > > ---Plane rotation X: 0.0 > ---Plane rotation Y: 0.0 > ---Plane rotation Z: 0.0 > > > My question: > How do I write all the results to a file? I have tried file.write but > can only write one argument at a time. Is there a better way to open a > file, write the collected information to it and then close the file? > The print() function has a keyword-only file argument. So: with open(..., "w") as outstream: print("Focal length:", bpy.context.object.data.lens, file=outstream) > |print("Plane rotation > X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation > Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation > Z:",bpy.data.objects["Plane"].rotation_euler[2])| This looks messy to me. I' probably use intermediate variables x, y, z = bpy.data.objects["Plane"].rotation_euler print( "Plane rotation X:", x, "Plane rotation Y:", y, "Plane rotation Z:", z, file=outstream, sep="\n" ) or even a loop. From larry.martell at gmail.com Thu Aug 8 10:29:33 2019 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 Aug 2019 10:29:33 -0400 Subject: AttributeError: module 'itertools' has no attribute 'imap' Message-ID: I have some code that is using the pyke package (https://sourceforge.net/projects/pyke/). That project seems fairly dead, so asking here. There is a pyke function that returns a context manager with an iterable map. In py2.7 I did this: from pyke import knowledge_engine vasculopathy_engine = knowledge_engine.engine((rule_base_source_folder, (compiled_rule_base_folder))) with vasculopathy_engine.prove_goal(...) as presentationGen: for vals, plan in presentationGen: But in py3 that fails with: AttributeError: module 'itertools' has no attribute 'imap' I tried converting presentationGen to a list but get the same error. How can I make this work in py3? From bill at baddogconsulting.com Thu Aug 8 11:20:56 2019 From: bill at baddogconsulting.com (Bill Deegan) Date: Thu, 8 Aug 2019 10:20:56 -0500 Subject: SCons 3.1.1 Released Message-ID: SCons - a software construction tool What is SCons? SCons is an Open Source software construction tool?that is, a next-generation build tool. Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache. In short, SCons is an easier, more reliable and faster way to build software. Change Log RELEASE 3.1.1 - Mon, 07 Aug 2019 20:09:12 -0500 From William Deegan: - Remove obsoleted references to DeciderNeedsNode which could cause crash when using --debug=explain From Jason Kenny - Add Fix and test for crash in 3.1.0 when using Decider('MD5-timestamp') and --debug=explain From Ben Reed: - Added -fmerge-all-constants to flags that get included in both CCFLAGS and LINKFLAGS. From Mathew Robinson: - Fix issue #3415 - Update remaining usages of EnvironmentError to SConsEnvironmentError this patch fixes issues introduced in 3.1.0 where any of the following would cause SCons to error and exit: - CacheDir not write-able - JSON encoding errors for CacheDir config - JSON decoding errors for CacheDir config From __peter__ at web.de Thu Aug 8 11:29:35 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Aug 2019 17:29:35 +0200 Subject: AttributeError: module 'itertools' has no attribute 'imap' References: Message-ID: Larry Martell wrote: > I have some code that is using the pyke package > (https://sourceforge.net/projects/pyke/). That project seems fairly > dead, so asking here. > > There is a pyke function that returns a context manager with an > iterable map. In py2.7 I did this: > > from pyke import knowledge_engine > vasculopathy_engine = > knowledge_engine.engine((rule_base_source_folder, > (compiled_rule_base_folder))) > with vasculopathy_engine.prove_goal(...) as presentationGen: > for vals, plan in presentationGen: > > But in py3 that fails with: AttributeError: module 'itertools' has no > attribute 'imap' In Python 3 the map() builtin is "lazy", so you can use that instead. > I tried converting presentationGen to a list but get the same error. > > How can I make this work in py3? The problem is in the project rather than in your code -- you have to port pyke to Python 3 before you can use it. If you want to go that route you may give the 2to3 tool a try: $ cat demo.py import itertools for i in itertools.imap(abs, [-1, 1]): print i $ 2to3 -w demo.py [...] $ cat demo.py import itertools for i in map(abs, [-1, 1]): print(i) $ From python at mrabarnett.plus.com Thu Aug 8 11:52:19 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 8 Aug 2019 16:52:19 +0100 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: <815176a3-d655-524f-9842-84c99fd1a5ec@mrabarnett.plus.com> On 2019-08-08 15:29, Larry Martell wrote: > I have some code that is using the pyke package > (https://sourceforge.net/projects/pyke/). That project seems fairly > dead, so asking here. > > There is a pyke function that returns a context manager with an > iterable map. In py2.7 I did this: > > from pyke import knowledge_engine > vasculopathy_engine = > knowledge_engine.engine((rule_base_source_folder, > (compiled_rule_base_folder))) > with vasculopathy_engine.prove_goal(...) as presentationGen: > for vals, plan in presentationGen: > > But in py3 that fails with: AttributeError: module 'itertools' has no > attribute 'imap' > > I tried converting presentationGen to a list but get the same error. > > How can I make this work in py3? > The built-in 'map' in Python 3 does what 'imap' did in Python 2. From rshepard at appl-ecosys.com Thu Aug 8 11:49:02 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 08:49:02 -0700 (PDT) Subject: Installing python3 packages using pip Message-ID: The host has Python3-3.7.4 installed. Trying to use "pip install numpy3" fails: # pip install numpy3 DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Collecting numpy3 ERROR: Could not find a version that satisfies the requirement numpy3 (from versions: none) ERROR: No matching distribution found for numpy3 How do I install numpy3, python3-matplotlib, and scipy3 using PIP? Rich From larry.martell at gmail.com Thu Aug 8 12:16:36 2019 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 Aug 2019 12:16:36 -0400 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__peter__ at web.de> wrote: > > Larry Martell wrote: > > > I have some code that is using the pyke package > > (https://sourceforge.net/projects/pyke/). That project seems fairly > > dead, so asking here. > > > > There is a pyke function that returns a context manager with an > > iterable map. In py2.7 I did this: > > > > from pyke import knowledge_engine > > vasculopathy_engine = > > knowledge_engine.engine((rule_base_source_folder, > > (compiled_rule_base_folder))) > > with vasculopathy_engine.prove_goal(...) as presentationGen: > > for vals, plan in presentationGen: > > > > But in py3 that fails with: AttributeError: module 'itertools' has no > > attribute 'imap' > > In Python 3 the map() builtin is "lazy", so you can use that instead. > > > I tried converting presentationGen to a list but get the same error. > > > > How can I make this work in py3? > > The problem is in the project rather than in your code -- you have to port > pyke to Python 3 before you can use it. If you want to go that route you may > give the 2to3 tool a try: > > $ cat demo.py > import itertools > > for i in itertools.imap(abs, [-1, 1]): > print i > $ 2to3 -w demo.py > [...] > $ cat demo.py > import itertools > > for i in map(abs, [-1, 1]): > print(i) > $ Pyke has been ported to py3. Here is the code that returns the data I am trying to process: return map(self.doctor_answer, it) I don't see anything calling imap. From larry.martell at gmail.com Thu Aug 8 12:24:53 2019 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 Aug 2019 12:24:53 -0400 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: On Thu, Aug 8, 2019 at 12:16 PM Larry Martell wrote: > > On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__peter__ at web.de> wrote: > > > > Larry Martell wrote: > > > > > I have some code that is using the pyke package > > > (https://sourceforge.net/projects/pyke/). That project seems fairly > > > dead, so asking here. > > > > > > There is a pyke function that returns a context manager with an > > > iterable map. In py2.7 I did this: > > > > > > from pyke import knowledge_engine > > > vasculopathy_engine = > > > knowledge_engine.engine((rule_base_source_folder, > > > (compiled_rule_base_folder))) > > > with vasculopathy_engine.prove_goal(...) as presentationGen: > > > for vals, plan in presentationGen: > > > > > > But in py3 that fails with: AttributeError: module 'itertools' has no > > > attribute 'imap' > > > > In Python 3 the map() builtin is "lazy", so you can use that instead. > > > > > I tried converting presentationGen to a list but get the same error. > > > > > > How can I make this work in py3? > > > > The problem is in the project rather than in your code -- you have to port > > pyke to Python 3 before you can use it. If you want to go that route you may > > give the 2to3 tool a try: > > > > $ cat demo.py > > import itertools > > > > for i in itertools.imap(abs, [-1, 1]): > > print i > > $ 2to3 -w demo.py > > [...] > > $ cat demo.py > > import itertools > > > > for i in map(abs, [-1, 1]): > > print(i) > > $ > > Pyke has been ported to py3. Here is the code that returns the data I > am trying to process: > > return map(self.doctor_answer, it) > > I don't see anything calling imap. I grepped through the entire pyke code and imap is not in there. From richardmoseley4 at gmail.com Thu Aug 8 12:25:58 2019 From: richardmoseley4 at gmail.com (Richard Moseley) Date: Thu, 8 Aug 2019 16:25:58 +0000 Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: You will need to have to install python3-pip (or equivalent on your repository) to install the version of pip suitable for use with python 3.x. The program is usually installed as 'pip3' so substitute 'pip' for 'pip3' to install or upgrade Pypy packages. Of course, if possible always create a new 'venv' and install the packages in there instead of the system, it avoids polluting the environment and makes it easier to tidy up unwanted packages at a later stage. Hope this helps, Richard Moseley. On Thu, 8 Aug 2019 at 16:03, Rich Shepard wrote: > The host has Python3-3.7.4 installed. Trying to use "pip install numpy3" > fails: > > # pip install numpy3 > DEPRECATION: Python 2.7 will reach the end of its life on January 1st, > 2020. > Please upgrade your Python as Python 2.7 won't be maintained after that > date. A future version of pip will drop support for Python 2.7. More > details > about Python 2 support in pip, can be found at > https://pip.pypa.io/en/latest/development/release-process/#python-2-support > > Collecting numpy3 > ERROR: Could not find a version that satisfies the requirement numpy3 > (from versions: none) > ERROR: No matching distribution found for numpy3 > > How do I install numpy3, python3-matplotlib, and scipy3 using PIP? > > Rich > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rhodri at kynesim.co.uk Thu Aug 8 12:26:23 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 8 Aug 2019 17:26:23 +0100 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: On 08/08/2019 17:16, Larry Martell wrote: > On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__peter__ at web.de> wrote: >> >> Larry Martell wrote: [snip] >>> But in py3 that fails with: AttributeError: module 'itertools' has no >>> attribute 'imap' >> >> In Python 3 the map() builtin is "lazy", so you can use that instead. >> >>> I tried converting presentationGen to a list but get the same error. >>> >>> How can I make this work in py3? >> >> The problem is in the project rather than in your code -- you have to port >> pyke to Python 3 before you can use it. [snip] > > Pyke has been ported to py3. Here is the code that returns the data I > am trying to process: > > return map(self.doctor_answer, it) > > I don't see anything calling imap. That suggests you aren't calling the code you think you're calling. I think a little poking with pdb or some strategic prints is in order... -- Rhodri James *-* Kynesim Ltd From paolo.cantore at t-online.de Thu Aug 8 12:26:02 2019 From: paolo.cantore at t-online.de (Paolo G. Cantore) Date: Thu, 8 Aug 2019 18:26:02 +0200 Subject: Python help needed In-Reply-To: References: <3c1ddad0-f345-44ee-9936-5ec5efe28eb0@googlegroups.com> <5dc957c0-b137-061b-1e0c-c484874ac09e@mrabarnett.plus.com> Message-ID: Am 08.08.19 um 01:18 schrieb MRAB: > On 2019-08-07 21:36, Kuyateh Yankz wrote: >> #trying to write a function that takes a list value as an argument and >> returns a string with all the items separated by a comma and a space, >> with and inserted before the last item. For example, passing the >> previous spam list to the function would return 'apples, bananas, >> tofu, and cats'. But your function should be able to work with any >> list value passed to it. >> >> def myList(aParameter): #defined >> ???? finalList = [] >> ???? for i in range(len(aParameter)-1): #targeting the last item in >> the list >> ?????? finalList.append('and '+ aParameter[-1]) #Removes the last item >> in the list, append the last item with THE and put it back, then put >> it into the FINAL LIST FUNCTION. >> ???? return finalList >> spam = ['apples', 'bananas', 'tofu', 'cats'] >> print(myList(spam)) >> >> #Got up to this point, still couldn't get rid of the '' around the >> items and the []. I tried (','.join()) but could not get there. >> #Am I on the wrong path or there's a quick fix here? >> https://pastebin.com/JCXisAuz >> > There's a nice way of doing it using str.join. However, you do need to > special-case when there's only 1 item. > > Start with a list: > > >>> spam = ['apples', 'bananas', 'tofu', 'cats'] > > The last item will be have an 'and', so let's remove that for the moment: > > >>> spam[ : -1] > ['apples', 'bananas', 'tofu'] > > Join these items together with ', ': > > >>> ', '.join(spam[ : -1]) > 'apples, bananas, tofu' > > Now for the last item: > > >>> ', '.join(spam[ : -1]) + ' and ' + spam[-1] > 'apples, bananas, tofu and cats' > > For the special case, when len(spam) == 1, just return spam[0]. > I think the special case treatment could be avoided. First: Join all items with ' and ' Second: Replace all ' and ' with ', ' except the last >>> spam = ['apples', 'bananas', 'tofu', 'cats'] >>> s = " and ".join(spam) >>> s.replace(" and ", ", ", len(spam) - 2) # except the last 'apples, bananas, tofu and cats' Or as a one liner: " and ".join(spam).replace(" and ", ", ", len(spam) - 2) It works also for a single item list: >>> spam = ['apples'] 'apples' From larry.martell at gmail.com Thu Aug 8 12:45:34 2019 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 Aug 2019 12:45:34 -0400 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: On Thu, Aug 8, 2019 at 12:34 PM Rhodri James wrote: > > On 08/08/2019 17:16, Larry Martell wrote: > > On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__peter__ at web.de> wrote: > >> > >> Larry Martell wrote: > [snip] > >>> But in py3 that fails with: AttributeError: module 'itertools' has no > >>> attribute 'imap' > >> > >> In Python 3 the map() builtin is "lazy", so you can use that instead. > >> > >>> I tried converting presentationGen to a list but get the same error. > >>> > >>> How can I make this work in py3? > >> > >> The problem is in the project rather than in your code -- you have to port > >> pyke to Python 3 before you can use it. > [snip] > > > > Pyke has been ported to py3. Here is the code that returns the data I > > am trying to process: > > > > return map(self.doctor_answer, it) > > > > I don't see anything calling imap. > > That suggests you aren't calling the code you think you're calling. I > think a little poking with pdb or some strategic prints is in order... I traced through the code with pdb. It is running from /usr/local/lib/python3.5/dist-packages/pyke and I grepped that for imap. Nothing From rshepard at appl-ecosys.com Thu Aug 8 13:29:03 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 10:29:03 -0700 (PDT) Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Thu, 8 Aug 2019, Richard Moseley wrote: > You will need to have to install python3-pip Richard, Aha! I thought it was just pip3. > Hope this helps, Richard Moseley. Yes, it does. Many thanks, Rich From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Aug 8 13:29:23 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Thu, 8 Aug 2019 13:29:23 -0400 Subject: Python help needed In-Reply-To: References: <3c1ddad0-f345-44ee-9936-5ec5efe28eb0@googlegroups.com> <5dc957c0-b137-061b-1e0c-c484874ac09e@mrabarnett.plus.com> Message-ID: <04f5958a-aef3-a2c7-6b65-58b536041def@potatochowder.com> On 8/8/19 12:26 PM, Paolo G. Cantore wrote: > I think the special case treatment could be avoided. > > First: Join all items with ' and ' > Second: Replace all ' and ' with ', ' except the last That works great, until one of the elements of the original list is "spam and eggs": >>> spam = ['apples', 'spam and eggs', 'bananas', 'tofu', 'cats'] >>> s = " and ".join(spam) >>> s.replace(" and ", ", ", len(spam) - 2) # except the last 'apples, spam, eggs, bananas and tofu and cats' Dan From __peter__ at web.de Thu Aug 8 13:32:37 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Aug 2019 19:32:37 +0200 Subject: AttributeError: module 'itertools' has no attribute 'imap' References: Message-ID: Larry Martell wrote: >> Pyke has been ported to py3. Here is the code that returns the data I >> am trying to process: >> >> return map(self.doctor_answer, it) >> >> I don't see anything calling imap. > > I grepped through the entire pyke code and imap is not in there. Fire up the python3 interpreter that you use to run your script: >>> import pyke >>> pyke.__file__ '/somewhere/pyke/__init__.py' Then grep starting in the directory shown above and be enlightened ;) If I'm wrong here's an alternative guess (I know nothing about pyke): knowledge_engine.engine((rule_base_source_folder, (compiled_rule_base_folder))) Are the rules "compiled" into Python? Then Make sure that you use separate `compiled_rule_base_folder`s for Python 2 and 3. From larry.martell at gmail.com Thu Aug 8 13:50:45 2019 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 8 Aug 2019 13:50:45 -0400 Subject: AttributeError: module 'itertools' has no attribute 'imap' In-Reply-To: References: Message-ID: On Thu, Aug 8, 2019 at 1:33 PM Peter Otten <__peter__ at web.de> wrote: > > Larry Martell wrote: > > >> Pyke has been ported to py3. Here is the code that returns the data I > >> am trying to process: > >> > >> return map(self.doctor_answer, it) > >> > >> I don't see anything calling imap. > > > > I grepped through the entire pyke code and imap is not in there. > > Fire up the python3 interpreter that you use to run your script: > > >>> import pyke > >>> pyke.__file__ > '/somewhere/pyke/__init__.py' > > Then grep starting in the directory shown above and be enlightened ;) > > If I'm wrong here's an alternative guess (I know nothing about pyke): > > knowledge_engine.engine((rule_base_source_folder, > (compiled_rule_base_folder))) > > Are the rules "compiled" into Python? Then Make sure that you use separate > `compiled_rule_base_folder`s for Python 2 and 3. I figured it out - pyke creates python code and the code created by the py2 version of pyke was still there and being used. Once I deleted those the p3y pyke recreated them and it worked. Thanks! From rshepard at appl-ecosys.com Thu Aug 8 14:01:07 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 11:01:07 -0700 (PDT) Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Thu, 8 Aug 2019, Richard Moseley wrote: > You will need to have to install python3-pip (or equivalent on your > repository) to install the version of pip suitable for use with python 3.x. > The program is usually installed as 'pip3' so substitute 'pip' for 'pip3' > to install or upgrade Pypy packages. Richard, Python3-3.7.x includes pip3. And I upgraded it using 'pip3 install --upgrade pip' so it's at the current release. However, I still cannot install numpy3: # pip3 install numpy3 Collecting numpy3 ERROR: Could not find a version that satisfies the requirement numpy3 (from versions: none) ERROR: No matching distribution found for numpy3 I'm open to all advice and learning how to install numpy3 so I can also install packages requiring it. Thanks, Rich From rosuav at gmail.com Thu Aug 8 14:24:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Aug 2019 04:24:42 +1000 Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Fri, Aug 9, 2019 at 4:02 AM Rich Shepard wrote: > > On Thu, 8 Aug 2019, Richard Moseley wrote: > > > You will need to have to install python3-pip (or equivalent on your > > repository) to install the version of pip suitable for use with python 3.x. > > The program is usually installed as 'pip3' so substitute 'pip' for 'pip3' > > to install or upgrade Pypy packages. > > Richard, > > Python3-3.7.x includes pip3. And I upgraded it using 'pip3 install --upgrade > pip' so it's at the current release. > > However, I still cannot install numpy3: > > # pip3 install numpy3 > Collecting numpy3 > ERROR: Could not find a version that satisfies the requirement numpy3 (from versions: none) > ERROR: No matching distribution found for numpy3 > > I'm open to all advice and learning how to install numpy3 so I can also > install packages requiring it. > Once you're using pip3, you don't need to specify the 3 anywhere else. It should just be "pip3 install numpy". The pip download resolver will make sure that it gets a version that's appropriate to your Python (including architecture/word size, version (x.y), etc, etc). ChrisA From python at mrabarnett.plus.com Thu Aug 8 14:33:39 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 8 Aug 2019 19:33:39 +0100 Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On 2019-08-08 19:01, Rich Shepard wrote: > On Thu, 8 Aug 2019, Richard Moseley wrote: > >> You will need to have to install python3-pip (or equivalent on your >> repository) to install the version of pip suitable for use with python 3.x. >> The program is usually installed as 'pip3' so substitute 'pip' for 'pip3' >> to install or upgrade Pypy packages. > > Richard, > > Python3-3.7.x includes pip3. And I upgraded it using 'pip3 install --upgrade > pip' so it's at the current release. > > However, I still cannot install numpy3: > > # pip3 install numpy3 > Collecting numpy3 > ERROR: Could not find a version that satisfies the requirement numpy3 (from versions: none) > ERROR: No matching distribution found for numpy3 > > I'm open to all advice and learning how to install numpy3 so I can also > install packages requiring it. > What's numpy3? Is it different from numpy? From rshepard at appl-ecosys.com Thu Aug 8 14:59:44 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 11:59:44 -0700 (PDT) Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Fri, 9 Aug 2019, Chris Angelico wrote: > Once you're using pip3, you don't need to specify the 3 anywhere else. It > should just be "pip3 install numpy". The pip download resolver will make > sure that it gets a version that's appropriate to your Python (including > architecture/word size, version (x.y), etc, etc). ChrisA, Well! This is the first I've learned of the proper way to install python3 packages from PyPI. Thank you. Numpy, scipy, and matplotlib all installed properly. Best regards, Rich From rshepard at appl-ecosys.com Thu Aug 8 15:01:57 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 12:01:57 -0700 (PDT) Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Thu, 8 Aug 2019, MRAB wrote: > What's numpy3? Is it different from numpy? I run Slackware and the SlackBuilds.org packages distinguish buiding between python2 and python3. I've used those build scripts for years but they've failed me on this new desktop and one laptop so I used pip3 instead. Rich From rosuav at gmail.com Thu Aug 8 15:04:31 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Aug 2019 05:04:31 +1000 Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Fri, Aug 9, 2019 at 5:01 AM Rich Shepard wrote: > > On Fri, 9 Aug 2019, Chris Angelico wrote: > > > Once you're using pip3, you don't need to specify the 3 anywhere else. It > > should just be "pip3 install numpy". The pip download resolver will make > > sure that it gets a version that's appropriate to your Python (including > > architecture/word size, version (x.y), etc, etc). > > ChrisA, > > Well! This is the first I've learned of the proper way to install python3 > packages from PyPI. Thank you. > > Numpy, scipy, and matplotlib all installed properly. > Awesome! There's one other potential trap you MAY fall into, but only if you have multiple Python 3s installed (eg 3.7, 3.8, and 3.9). The name "pip3" may or may not correspond to the actual Python installation that you want to target. So to be absolutely completely safe, you can write it like this: python3 -m pip install numpy If you replace "python3" with "python3.7" or something, it'll still work, and whatever you use, it'll target the same Python that you'd get when you run a script (so "python3.7 scriptname.py" will see things installed with "python3.7 -m pip install pkg"). Not something to worry about right now, but if you run into trouble, this is the longhand that "pip3" is the shorthand for. ChrisA From rshepard at appl-ecosys.com Thu Aug 8 15:20:11 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 8 Aug 2019 12:20:11 -0700 (PDT) Subject: Installing python3 packages using pip In-Reply-To: References: Message-ID: On Fri, 9 Aug 2019, Chris Angelico wrote: > There's one other potential trap you MAY fall into, but only if you have > multiple Python 3s installed (eg 3.7, 3.8, and 3.9). ChrisA, Not likely. I'm the only one using these hosts and I keep only a single, current, version of software. > So to be absolutely completely safe, you can write it like this: > > python3 -m pip install numpy > > If you replace "python3" with "python3.7" or something, it'll still > work, and whatever you use, it'll target the same Python that you'd > get when you run a script (so "python3.7 scriptname.py" will see > things installed with "python3.7 -m pip install pkg"). > > Not something to worry about right now, but if you run into trouble, > this is the longhand that "pip3" is the shorthand for. Will keep this in mind should the need arrive. Thanks, Rich From email at paulstgeorge.com Thu Aug 8 16:42:44 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 8 Aug 2019 22:42:44 +0200 Subject: Python in Blender. Writing information to a file. In-Reply-To: References: <8b149812-3847-c5ee-29d9-d091c43fb524@paulstgeorge.com> Message-ID: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> On 08/08/2019 10:18, Peter Otten wrote: > Paul St George wrote: > >> I am using Python 3.5 within Blender. I want to collect values of the >> current settings and then write all the results to a file. >> >> I can see the settings and the values in the Python console by doing >> this for each of the settings >> | >> | >> >> |print(?Focal length:?,bpy.context.object.data.lens)| >> >> ---Focal length: 35.0 >> >> >> or I can do many at a time like this: >> >> |print("Plane rotation >> X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation >> Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation >> Z:",bpy.data.objects["Plane"].rotation_euler[2])| >> >> ---Plane rotation X: 0.0 >> ---Plane rotation Y: 0.0 >> ---Plane rotation Z: 0.0 >> >> >> My question: >> How do I write all the results to a file? I have tried file.write but >> can only write one argument at a time. Is there a better way to open a >> file, write the collected information to it and then close the file? >> > The print() function has a keyword-only file argument. So: > > with open(..., "w") as outstream: > print("Focal length:", bpy.context.object.data.lens, file=outstream) > >> |print("Plane rotation >> X:",bpy.data.objects["Plane"].rotation_euler[0],"\nPlane rotation >> Y:",bpy.data.objects["Plane"].rotation_euler[1],"\nPlane rotation >> Z:",bpy.data.objects["Plane"].rotation_euler[2])| > This looks messy to me. I' probably use intermediate variables > > x, y, z = bpy.data.objects["Plane"].rotation_euler > print( > "Plane rotation X:", x, > "Plane rotation Y:", y, > "Plane rotation Z:", z, > file=outstream, sep="\n" > ) > > or even a loop. > > That worked perfectly. outstream = open(path to my file,'w') print( whatever I want to print file=outstream ) outstream.close() From spencerchief at googlemail.com Thu Aug 8 16:47:58 2019 From: spencerchief at googlemail.com (Spencer Du) Date: Thu, 8 Aug 2019 13:47:58 -0700 (PDT) Subject: How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python? Message-ID: <5cafa365-9699-462c-8cb8-198d5dee5afb@googlegroups.com> Ok so here is some code below. How do I write an if code block to execute some commands when I subscribe to the topic: microscope/light_sheet_microscope/UI and which has a message which is a device type published to it. I want to execute some code to check if the device has a python file in the currently directory because each device also relates to a python file. If the file exists then import the file into the python program else print an error message. If I need to use on_subscribe callback then tell and show me how the code is to be written and if another method then also tell me and show me how to write the code. I really appreciate all the help you can give me because this is really important for me and I am currently really struggling with MQTT because I need help with writing MQTT code because I am working on MQTT at work. import logging from datetime import timedelta import time from thespian.actors import * from transitions import Machine import paho.mqtt.client as mqtt class device(mqtt.Client): def on_connect(self, mqttc, obj, flags, rc): if rc == 0: print("Connected to broker") else: print("Connection failed") mqttc.subscribe("microscope/light_sheet_microscope/UI") def on_message(self, mqttc, userdata, message): print("message received " ,str(message.payload.decode("utf-8"))) print("message topic=",message.topic) print("message qos=",message.qos) print("message retain flag=",message.retain) def on_publish(self, mqttc, obj, mid): print("mid: "+str(mid)) def on_subscribe(self, mqttc, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def run(self): self.connect("broker.hivemq.com", 1883, 60) print("creating new instance laser") client = device("Device") client.run() client.loop_start() #start the loop device = "laser" time.sleep(2) print("Publishing message to topic","microscope/light_sheet_microscope/UI") client.publish("microscope/light_sheet_microscope/UI",device) time.sleep(2) # wait print("subscribing ") client.subscribe("microscope/light_sheet_microscope/UI") client.loop_stop() #stop the loop Thanks Spencer From spencerchief at googlemail.com Thu Aug 8 16:50:59 2019 From: spencerchief at googlemail.com (Spencer Du) Date: Thu, 8 Aug 2019 13:50:59 -0700 (PDT) Subject: How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python? In-Reply-To: <5cafa365-9699-462c-8cb8-198d5dee5afb@googlegroups.com> References: <5cafa365-9699-462c-8cb8-198d5dee5afb@googlegroups.com> Message-ID: On Thursday, 8 August 2019 22:48:11 UTC+2, Spencer Du wrote: > Ok so here is some code below. How do I write an if code block to execute some commands when I subscribe to the topic: microscope/light_sheet_microscope/UI and which has a message which is a device type published to it. I want to execute some code to check if the device has a python file in the currently directory because each device also relates to a python file. If the file exists then import the file into the python program else print an error message. If I need to use on_subscribe callback then tell and show me how the code is to be written and if another method then also tell me and show me how to write the code. I really appreciate all the help you can give me because this is really important for me and I am currently really struggling with MQTT because I need help with writing MQTT code because I am working on MQTT at work. > > import logging > from datetime import timedelta > import time > from thespian.actors import * > from transitions import Machine > import paho.mqtt.client as mqtt > > class device(mqtt.Client): > def on_connect(self, mqttc, obj, flags, rc): > if rc == 0: > print("Connected to broker") > else: > print("Connection failed") > mqttc.subscribe("microscope/light_sheet_microscope/UI") > def on_message(self, mqttc, userdata, message): > print("message received " ,str(message.payload.decode("utf-8"))) > print("message topic=",message.topic) > print("message qos=",message.qos) > print("message retain flag=",message.retain) > def on_publish(self, mqttc, obj, mid): > print("mid: "+str(mid)) > def on_subscribe(self, mqttc, obj, mid, granted_qos): > print("Subscribed: "+str(mid)+" "+str(granted_qos)) > def run(self): > self.connect("broker.hivemq.com", 1883, 60) > print("creating new instance laser") > client = device("Device") > client.run() > client.loop_start() #start the loop > device = "laser" > time.sleep(2) > print("Publishing message to topic","microscope/light_sheet_microscope/UI") > client.publish("microscope/light_sheet_microscope/UI",device) > time.sleep(2) # wait > print("subscribing ") > client.subscribe("microscope/light_sheet_microscope/UI") > client.loop_stop() #stop the loop > > Thanks > Spencer From cs at cskk.id.au Thu Aug 8 22:09:55 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 9 Aug 2019 12:09:55 +1000 Subject: Python in Blender. Writing information to a file. In-Reply-To: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> References: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> Message-ID: <20190809020955.GA41768@cskk.homeip.net> On 08Aug2019 22:42, Paul St George wrote: >On 08/08/2019 10:18, Peter Otten wrote: >>The print() function has a keyword-only file argument. So: >>with open(..., "w") as outstream: >> print("Focal length:", bpy.context.object.data.lens, file=outstream) [...] >> >That worked perfectly. > >outstream = open(path to my file,'w') >print( >whatever I want to print >file=outstream >) >outstream.close() I just wanted to point out Peter's use of the open context manager: with open(..., "w") as outstream: print stuff ... You'll notice that it does not overtly close the file. The file object returned from open() is a context manager, the "with" statement arranges to close the file when your programme exits the with suite. Importantly, the close will happen even if the code inside raises an exception, which in your "open..print..close" sequence would not reach the close call. So we recommend the "with" form of open() above. There are circumstances where it isn't useful, but they are very rare. Cheers, Cameron Simpson From kabbaraahmadadam at gmail.com Fri Aug 9 03:34:34 2019 From: kabbaraahmadadam at gmail.com (Ahmad Adam Kabbara) Date: Fri, 9 Aug 2019 10:34:34 +0300 Subject: help with tkinter In-Reply-To: References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: so when I write from tkinter import* t=Tk() tkinter.colorchooser.askcolor() I get this error message Traceback (most recent call last): File "C:\Users\kabba\Desktop\color and coordinates.py", line 3, in tkinter.colorchooser.askcolor() NameError: name 'tkinter' is not defined I also tried another way from tkinter.colorchooser import* colorchooser.askcolor() and I also got an error message Traceback (most recent call last): File "", line 1, in colorchooser.askcolor() NameError: name 'colorchooser' is not defined the only time it worked is when I typed from tkinter import colorchooser colorchooser.askcolor() On Thu, Aug 1, 2019 at 7:30 PM Rhodri James wrote: > Hi there, Adam! > > On 01/08/2019 14:31, adam kabbara wrote: > > Hello I am having trouble with tkinter when I enter the command from > tkinter import* I get an error message > > What *exactly* did you type? Please cut-and-paste from your > console/editor into the email, don't just retype it. If you did > literally type "from tkinter import*" then Python is probably > complaining that it doesn't know what "import*" means because you missed > out a space! > > Also, what *exactly* was the error message? Again, please > cut-and-paste. Python usually gives you a pretty good indication of > what you did wrong; if you show us, we can help you get used to > interpreting it for yourself. > > Happy coding! > > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > On Fri, Aug 2, 2019 at 12:11 AM Wildman via Python-list < python-list at python.org> wrote: > On Thu, 01 Aug 2019 16:31:02 +0300, adam kabbara wrote: > > > Hello I am having trouble with tkinter when I enter the command from > tkinter import* I get an error message > > > > What was the error and what version of Python are > you using? > > For Python 2 you need... from Tkinter import* > > -- > GNU/Linux user #557453 > "There are only 10 types of people in the world... > those who understand Binary and those who don't." > -Spike > -- > https://mail.python.org/mailman/listinfo/python-list > From kabbaraahmadadam at gmail.com Fri Aug 9 03:40:05 2019 From: kabbaraahmadadam at gmail.com (Ahmad Adam Kabbara) Date: Fri, 09 Aug 2019 10:40:05 +0300 Subject: help with tkinter References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: <1ynq9afkgfrqkiywgd31n5osy2m8towhcpil-46wvh685zxv8fdpxl6-qu1lzo-7ksy5yv1p88o657klwtzst3ero5cbno1zkvnesgobr-mb80jhh5auwx-9fscoxdattuu-puybws9qcrph-n5nio8.1565336405666@email.android.com> I one more thing I am using python 3 Sent from my Huawei Mobile -------- Original Message -------- Subject: Re: help with tkinter From: Ahmad Adam Kabbara To: Wildman CC: python-list at python.org so when I write**from tkinter import* t=Tk() tkinter.colorchooser.askcolor() I get this error message Traceback (most recent call last): ** File "C:\Users\kabba\Desktop\color and coordinates.py", line 3, in ****** tkinter.colorchooser.askcolor() NameError: name 'tkinter' is not defined I also tried another way** from tkinter.colorchooser import* colorchooser.askcolor() and I also got an error message Traceback (most recent call last): ** File "", line 1, in ****** colorchooser.askcolor() NameError: name 'colorchooser' is not defined the only time it worked is when I typed** from tkinter import colorchooser colorchooser.askcolor() On Thu, Aug 1, 2019 at 7:30 PM Rhodri James <[1]rhodri at kynesim.co.uk> wrote: Hi there, Adam! On 01/08/2019 14:31, adam kabbara wrote: > Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message What *exactly* did you type?** Please cut-and-paste from your console/editor into the email, don't just retype it.** If you did literally type "from tkinter import*" then Python is probably complaining that it doesn't know what "import*" means because you missed out a space! Also, what *exactly* was the error message?** Again, please cut-and-paste.** Python usually gives you a pretty good indication of what you did wrong; if you show us, we can help you get used to interpreting it for yourself. Happy coding! -- Rhodri James *-* Kynesim Ltd -- [2]https://mail.python.org/mailman/listinfo/python-list On Fri, Aug 2, 2019 at 12:11 AM Wildman via Python-list <[3]python-list at python.org> wrote: On Thu, 01 Aug 2019 16:31:02 +0300, adam kabbara wrote: > Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message > What was the error and what version of Python are you using? For Python 2 you need... from Tkinter import* -- GNU/Linux user #557453 "There are only 10 types of people in the world... those who understand Binary and those who don't." ** -Spike -- [4]https://mail.python.org/mailman/listinfo/python-list References Visible links 1. mailto:rhodri at kynesim.co.uk 2. https://mail.python.org/mailman/listinfo/python-list 3. mailto:python-list at python.org 4. https://mail.python.org/mailman/listinfo/python-list From hjp-python at hjp.at Fri Aug 9 06:52:37 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 9 Aug 2019 12:52:37 +0200 Subject: help with tkinter In-Reply-To: References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> Message-ID: <20190809105237.GC18121@hjp.at> On 2019-08-09 10:34:34 +0300, Ahmad Adam Kabbara wrote: > so when I write from > tkinter import* > t=Tk() > tkinter.colorchooser.askcolor() > I get this error message > Traceback (most recent call last): > File "C:\Users\kabba\Desktop\color and coordinates.py", line 3, in > > tkinter.colorchooser.askcolor() > NameError: name 'tkinter' is not defined You didn't import 'tkinter', you imported all symbols ('*') from tkinter. So, since you imported colorchooser, you can call colorchooser.askcolor() (not tkinter.colorchooser.askcolor()) > the only time it worked is when I typed > from tkinter import colorchooser > colorchooser.askcolor() Here you imported 'colorchooser' from tkinter. So you can call colorchooser.askcolor(). Same as above, except that you have only imported colorchooser and not the myriad of other symbols that '*' would import. 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 kabbaraahmadadam at gmail.com Fri Aug 9 07:02:35 2019 From: kabbaraahmadadam at gmail.com (Ahmad Adam Kabbara) Date: Fri, 9 Aug 2019 14:02:35 +0300 Subject: Help with tkinter Message-ID: I am having trouble with tkinter can you please help help with tkinter Inbox A adam kabbara to python-list at python.org 8 days ago Details Hello I am having trouble with tkinter when I enter the command from tkinter import* I get an error message Sent from Mail for Windows 10 2 attachments [image: Attachment] Sketch.png ? Print [image: Attachment] Sketch..png ? Print A adam kabbara Sent from Mail for Windows 10 From: adam kabbara Sent: August 1, 2019 4:30 PM To: python-list at python.org Subject: help with tkinter Hello I am havi... R Rhodri James to python-list 8 days ago Details Hi there, Adam! On 01/08/2019 14:31, adam kabbara wrote: > Hello I am having trouble with tkinter when I enter the command from > tkinter import* I get an error message > What *exactly* did you type? Please cut-and-paste from your console/editor into the email, don't just retype it. If you did literally type "from tkinter import*" then Python is probably complaining that it doesn't know what "import*" means because you missed out a space! Also, what *exactly* was the error message? Again, please cut-and-paste. Python usually gives you a pretty good indication of what you did wrong; if you show us, we can help you get used to interpreting it for yourself. Happy coding! -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list Chris Angelico Actually, Python's fine with that, but the principle is still valid: be specific about what you entered and what Python replied. ChrisA R Rhodri James Fair enough. I should try out "obvious syntax errors" before I declare them as such. W Wildman via Python-list What was the error and what version of Python are you using? For Python 2 you need... from Tkinter import* A Ahmad Adam Kabbara so when I write from tkinter import* t=Tk() tkinter.colorchooser.askcolor() I get this error message Traceback (most recent call last): File "C:\Us... A Ahmad Adam Kabbara to Wildman, python-list 3 hours ago Details so when I write from tkinter import* t=Tk() tkinter.colorchooser.askcolor() I get this error message Traceback (most recent call last): File "C:\Users\kabba\Desktop\color and coordinates.py", line 3, in tkinter.colorchooser.askcolor() NameError: name 'tkinter' is not defined I also tried another way from tkinter.colorchooser import* colorchooser.askcolor() and I also got an error message Traceback (most recent call last): File "", line 1, in colorchooser.askcolor() NameError: name 'colorchooser' is not defined the only time it worked is when I typed from tkinter import colorchooser colorchooser.askcolor() From email at paulstgeorge.com Fri Aug 9 09:54:45 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 9 Aug 2019 15:54:45 +0200 Subject: Python in Blender. Writing information to a file. In-Reply-To: <20190809020955.GA41768@cskk.homeip.net> References: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> <20190809020955.GA41768@cskk.homeip.net> Message-ID: <3b8704db-d9c8-6464-2061-72fc8a99d3e3@paulstgeorge.com> On 09/08/2019 04:09, Cameron Simpson wrote: > On 08Aug2019 22:42, Paul St George wrote: >> On 08/08/2019 10:18, Peter Otten wrote: >>> The print() function has a keyword-only file argument. So: >>> with open(..., "w") as outstream: >>> ??? print("Focal length:", bpy.context.object.data.lens, >>> file=outstream) > [...] >>> >> That worked perfectly. >> >> outstream = open(path to my file,'w') >> print( >> whatever I want to print >> file=outstream >> ) >> outstream.close() > > I just wanted to point out Peter's use of the open context manager: > > ?? with open(..., "w") as outstream: > ???? print stuff ... > > You'll notice that it does not overtly close the file. The file object > returned from open() is a context manager, the "with" statement > arranges to close the file when your programme exits the with suite. > > Importantly, the close will happen even if the code inside raises an > exception, which in your "open..print..close" sequence would not reach > the close call. > > So we recommend the "with" form of open() above. > > There are circumstances where it isn't useful, but they are very rare. > > Cheers, > Cameron Simpson > I almost understand. Are you saying I should change the first line of code to something like: |outstream = with open(path to my file,'w') # this is invalid syntax| and then delete the outstream.close() From rhodri at kynesim.co.uk Fri Aug 9 09:59:20 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 9 Aug 2019 14:59:20 +0100 Subject: Python in Blender. Writing information to a file. In-Reply-To: <3b8704db-d9c8-6464-2061-72fc8a99d3e3@paulstgeorge.com> References: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> <20190809020955.GA41768@cskk.homeip.net> <3b8704db-d9c8-6464-2061-72fc8a99d3e3@paulstgeorge.com> Message-ID: On 09/08/2019 14:54, Paul St George wrote: > > On 09/08/2019 04:09, Cameron Simpson wrote: >> On 08Aug2019 22:42, Paul St George wrote: >>> On 08/08/2019 10:18, Peter Otten wrote: >>>> The print() function has a keyword-only file argument. So: >>>> with open(..., "w") as outstream: >>>> ??? print("Focal length:", bpy.context.object.data.lens, >>>> file=outstream) >> [...] >>>> >>> That worked perfectly. >>> >>> outstream = open(path to my file,'w') >>> print( >>> whatever I want to print >>> file=outstream >>> ) >>> outstream.close() >> >> I just wanted to point out Peter's use of the open context manager: >> >> ?? with open(..., "w") as outstream: >> ???? print stuff ... >> >> You'll notice that it does not overtly close the file. The file object >> returned from open() is a context manager, the "with" statement >> arranges to close the file when your programme exits the with suite. >> >> Importantly, the close will happen even if the code inside raises an >> exception, which in your "open..print..close" sequence would not reach >> the close call. >> >> So we recommend the "with" form of open() above. >> >> There are circumstances where it isn't useful, but they are very rare. >> >> Cheers, >> Cameron Simpson >> > I almost understand. > > Are you saying I should change the first line of code to something like: > > |outstream = with open(path to my file,'w') # this is invalid syntax| > > and then delete the > > outstream.close() No, you should do what Peter wrote: with open("/path/to/file", "w") as outstream: print(my_stuff, file=outstream) -- Rhodri James *-* Kynesim Ltd From email at paulstgeorge.com Fri Aug 9 10:13:27 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 9 Aug 2019 16:13:27 +0200 Subject: String slices Message-ID: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> In the code (below) I want a new line like this: Plane rotation X: 0.0 Plane rotation Y: 0.0 Plane rotation Z: 0.0 But not like this: Plane rotation X: 0.0 Plane rotation Y: 0.0 Plane rotation Z: 0.0 Is it possible? (I am using Python 3.5 within Blender.) # import os outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w') print( "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0], "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1], "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2], file=outstream, sep="\n" ) outstream.close() From rhodri at kynesim.co.uk Fri Aug 9 09:56:58 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 9 Aug 2019 14:56:58 +0100 Subject: How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python? In-Reply-To: <5cafa365-9699-462c-8cb8-198d5dee5afb@googlegroups.com> References: <5cafa365-9699-462c-8cb8-198d5dee5afb@googlegroups.com> Message-ID: On 08/08/2019 21:47, Spencer Du via Python-list wrote: > Ok so here is some code below. How do I write an if code block to > execute some commands when I subscribe to the topic: > microscope/light_sheet_microscope/UI and which has a message which is > a device type published to it. I want to execute some code to check > if the device has a python file in the currently directory because > each device also relates to a python file. If the file exists then > import the file into the python program else print an error message. > If I need to use on_subscribe callback then tell and show me how the > code is to be written and if another method then also tell me and > show me how to write the code. I really appreciate all the help you > can give me because this is really important for me and I am > currently really struggling with MQTT because I need help with > writing MQTT code because I am working on MQTT at work. The first thing you need to do is stop, take a breath and write down step by step exactly what you want done. At the moment you sound like you are flailing about, and you aren't going to get anything done that way. Stop and relax for a moment. The example program you have already should help you figure out what information is available when. -- Rhodri James *-* Kynesim Ltd From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 9 10:26:37 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 9 Aug 2019 10:26:37 -0400 Subject: String slices In-Reply-To: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> References: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> Message-ID: <2bf642cd-a000-dd5c-bc72-cdd0d1620d4b@potatochowder.com> On 8/9/19 10:13 AM, Paul St George wrote: > In the code (below) I want a new line like this: > > Plane rotation X: 0.0 > Plane rotation Y: 0.0 > Plane rotation Z: 0.0 > > But not like this: > > Plane rotation X: > 0.0 > Plane rotation Y: > 0.0 > Plane rotation Z: > 0.0 > > Is it possible? > (I am using Python 3.5 within Blender.) > > # > import os > > outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w') > > print( > > "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0], > > "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1], > > "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2], > > file=outstream, sep="\n" > > ) > > outstream.close() > Use separate calls to print: with open(...) as outstream: plane = bpy.data.objects["Plane"] print("X:", plane.rotation_euler[0]) print("Y:", plane.rotation_euler[1]) # print Z here And please (a) use "with" instead of "open" and "close," and (b) use an email client that preserves indentation. From rhodri at kynesim.co.uk Fri Aug 9 10:29:43 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 9 Aug 2019 15:29:43 +0100 Subject: String slices In-Reply-To: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> References: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> Message-ID: <56e067eb-175b-0fac-dadd-9597b1a6201c@kynesim.co.uk> On 09/08/2019 15:13, Paul St George wrote: > In the code (below) I want a new line like this: > > Plane rotation X: 0.0 > Plane rotation Y: 0.0 > Plane rotation Z: 0.0 > > But not like this: > > Plane rotation X: > 0.0 > Plane rotation Y: > 0.0 > Plane rotation Z: > 0.0 > > Is it possible? > (I am using Python 3.5 within Blender.) > > # > import os > > outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w') > > print( > > "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0], > > "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1], > > "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2], > > file=outstream, sep="\n" > > ) > > outstream.close() The 'sep="\n"' parameter to print() means "put a newline between each item." So don't do that. Put the newlines you do want in explicitly, or use separate calls to print(): (I'm abbreviating because I really can't be bothered to type that much :-) print("X:", thing[0], "\nY:", thing[1], "\nZ:", thing[2], file=outstream) or print("X:", thing[0], file=outstream) print("Y:", thing[1], file=outstream) print("Z:", thing[2], file=outstream) I would probably use the latter, but it's just a matter of personal preference. (Actually I would probably use outstream.write() and do my own formatting, but let's not get side-tracked ;-) -- Rhodri James *-* Kynesim Ltd From __peter__ at web.de Fri Aug 9 10:49:24 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Aug 2019 16:49:24 +0200 Subject: String slices References: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> Message-ID: Paul St George wrote: > In the code (below) I want a new line like this: > > Plane rotation X: 0.0 > Plane rotation Y: 0.0 > Plane rotation Z: 0.0 > > But not like this: > > Plane rotation X: > 0.0 > Plane rotation Y: > 0.0 > Plane rotation Z: > 0.0 > > Is it possible? > print( > > "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0], > > "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1], > > "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2], > > file=outstream, sep="\n" > > ) Explanation: The newlines between all positional args of print() are caused by the sep="\n" keyword argument. You probably got the idea from my x, y, z = bpy.data.objects["Plane"].rotation_euler print( "Plane rotation X:", x, "Plane rotation Y:", y, "Plane rotation Z:", z, file=outstream, sep="\n" ) in the other thread where I introduced the bug when trying to simplify my original suggestion (which I didn't post) print( f"Plane rotation X: {x}", f"Plane rotation Y: {y}", f"Plane rotation Z: {z}", file=outstream, sep="\n" ) But as Dan says, use separate print() calls. From larry.martell at gmail.com Fri Aug 9 12:06:56 2019 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 9 Aug 2019 12:06:56 -0400 Subject: py2 to 3 base64 issues Message-ID: I have some python 2 code: def decode(key, string): decoded_chars = [] string = base64.urlsafe_b64decode(string) for i in range(len(string)): key_c = key[i % len(key)] encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) decoded_chars.append(encoded_c) decoded_string = "".join(decoded_chars) return decoded_string and if I call it like this in py2 it works as expected: s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' key = '!@#$VERYsecRet)(' decode(key, s) In py3 it fails with TypeError: ord() expected string of length 1, but int found I know that in py3 base64.urlsafe_b64decode is returning bytes not chars and that is what that is happening, and I thought the solution would be to decode it, but what codec would I use for this? From rosuav at gmail.com Fri Aug 9 12:22:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 Aug 2019 02:22:26 +1000 Subject: py2 to 3 base64 issues In-Reply-To: References: Message-ID: On Sat, Aug 10, 2019 at 2:09 AM Larry Martell wrote: > > I have some python 2 code: > > def decode(key, string): > decoded_chars = [] > string = base64.urlsafe_b64decode(string) > for i in range(len(string)): > key_c = key[i % len(key)] > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) > decoded_chars.append(encoded_c) > decoded_string = "".join(decoded_chars) > return decoded_string > > and if I call it like this in py2 it works as expected: > > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' > key = '!@#$VERYsecRet)(' > decode(key, s) > > In py3 it fails with > > TypeError: ord() expected string of length 1, but int found > > I know that in py3 base64.urlsafe_b64decode is returning bytes not > chars and that is what that is happening, and I thought the solution > would be to decode it, but what codec would I use for this? Should be safe to decode it as ASCII, since Base 64 uses strictly ASCII characters. But since you're working with bytes, possibly all you need to do is remove the ord calls, since ord(u"x") is the same as b"x"[0]. You'll then need to change the join() at the end to be just "decoded_string = bytes(decoded_chars)", or possibly that followed by a decode-to-text, depending on how your data works. ChrisA From python at mrabarnett.plus.com Fri Aug 9 12:25:11 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 9 Aug 2019 17:25:11 +0100 Subject: py2 to 3 base64 issues In-Reply-To: References: Message-ID: <01201551-2841-9d3b-b2b7-bc623ceab534@mrabarnett.plus.com> On 2019-08-09 17:06, Larry Martell wrote: > I have some python 2 code: > > def decode(key, string): > decoded_chars = [] > string = base64.urlsafe_b64decode(string) > for i in range(len(string)): > key_c = key[i % len(key)] > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) > decoded_chars.append(encoded_c) > decoded_string = "".join(decoded_chars) > return decoded_string > > and if I call it like this in py2 it works as expected: > > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' > key = '!@#$VERYsecRet)(' > decode(key, s) > > In py3 it fails with > > TypeError: ord() expected string of length 1, but int found > > I know that in py3 base64.urlsafe_b64decode is returning bytes not > chars and that is what that is happening, and I thought the solution > would be to decode it, but what codec would I use for this? > I'll use the b and u prefixes for clarity. In Python 2, b'abc'[0] is b'a' and u'abc'[0] is u'a'. In Python 3, b'abc'[0] is 65 and u'abc'[0] is u'a'. Using ord on an int raises an exception. From larry.martell at gmail.com Fri Aug 9 14:21:59 2019 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 9 Aug 2019 14:21:59 -0400 Subject: py2 to 3 base64 issues In-Reply-To: References: Message-ID: On Fri, Aug 9, 2019 at 12:23 PM Chris Angelico wrote: > > On Sat, Aug 10, 2019 at 2:09 AM Larry Martell wrote: > > > > I have some python 2 code: > > > > def decode(key, string): > > decoded_chars = [] > > string = base64.urlsafe_b64decode(string) > > for i in range(len(string)): > > key_c = key[i % len(key)] > > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) > > decoded_chars.append(encoded_c) > > decoded_string = "".join(decoded_chars) > > return decoded_string > > > > and if I call it like this in py2 it works as expected: > > > > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' > > key = '!@#$VERYsecRet)(' > > decode(key, s) > > > > In py3 it fails with > > > > TypeError: ord() expected string of length 1, but int found > > > > I know that in py3 base64.urlsafe_b64decode is returning bytes not > > chars and that is what that is happening, and I thought the solution > > would be to decode it, but what codec would I use for this? > > Should be safe to decode it as ASCII, since Base 64 uses strictly > ASCII characters. But since you're working with bytes, possibly all > you need to do is remove the ord calls, since ord(u"x") is the same as > b"x"[0]. You'll then need to change the join() at the end to be just > "decoded_string = bytes(decoded_chars)", or possibly that followed by > a decode-to-text, depending on how your data works. That doesn't work: -> encoded_c = chr(abs(string[i] - ord(key_c) % 256)) (Pdb) n TypeError: "unsupported operand type(s) for -: 'str' and 'int'" (Pdb) string 'WsXU\x8fy\x88\x89\xa7\x9c\x95\x82\x9a\xaaaXQsSZ\xaf\xaa\xc5z\xc7\xcd\xcc\xc5\xae\xc7\x8a\x96b\xb5\x97\x8c\xc5\xb7\xbb\xd3\xd8\xc9\xb5\xb7\xd6\xe9\x8e\x9b\x95' (Pdb) string[i] '\x8f' (Pdb) bytes(string[i]) '\x8f' (Pdb) type(string[i]) From email at paulstgeorge.com Fri Aug 9 14:53:26 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 9 Aug 2019 20:53:26 +0200 Subject: Python in Blender. Writing information to a file. In-Reply-To: References: <1967afdd-c838-a24c-bdeb-f5cf21ed5ce8@paulstgeorge.com> <20190809020955.GA41768@cskk.homeip.net> <3b8704db-d9c8-6464-2061-72fc8a99d3e3@paulstgeorge.com> Message-ID: On 09/08/2019 15:59, Rhodri James wrote: > On 09/08/2019 14:54, Paul St George wrote: >> >> On 09/08/2019 04:09, Cameron Simpson wrote: >>> On 08Aug2019 22:42, Paul St George wrote: >>>> On 08/08/2019 10:18, Peter Otten wrote: >>>>> The print() function has a keyword-only file argument. So: >>>>> with open(..., "w") as outstream: >>>>> ??? print("Focal length:", bpy.context.object.data.lens, >>>>> file=outstream) >>> [...] >>>>> >>>> That worked perfectly. >>>> >>>> outstream = open(path to my file,'w') >>>> print( >>>> whatever I want to print >>>> file=outstream >>>> ) >>>> outstream.close() >>> >>> I just wanted to point out Peter's use of the open context manager: >>> >>> ?? with open(..., "w") as outstream: >>> ???? print stuff ... >>> >>> You'll notice that it does not overtly close the file. The file >>> object returned from open() is a context manager, the "with" >>> statement arranges to close the file when your programme exits the >>> with suite. >>> >>> Importantly, the close will happen even if the code inside raises an >>> exception, which in your "open..print..close" sequence would not >>> reach the close call. >>> >>> So we recommend the "with" form of open() above. >>> >>> There are circumstances where it isn't useful, but they are very rare. >>> >>> Cheers, >>> Cameron Simpson >>> >> I almost understand. >> >> Are you saying I should change the first line of code to something like: >> >> |outstream = with open(path to my file,'w') # this is invalid syntax| >> >> and then delete the >> >> outstream.close() > > No, you should do what Peter wrote: > > with open("/path/to/file", "w") as outstream: > ? print(my_stuff, file=outstream) > Got it! I hadn't taken Peter's advice as code. I thought (well anyway now I have it). So thanks to Peter, Cameron and Rhodri. From torriem at gmail.com Fri Aug 9 14:43:45 2019 From: torriem at gmail.com (Michael Torrie) Date: Fri, 9 Aug 2019 12:43:45 -0600 Subject: help with tkinter In-Reply-To: <20190809105237.GC18121@hjp.at> References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> <20190809105237.GC18121@hjp.at> Message-ID: <4fb42645-f8c6-7024-014a-ee60e76fa718@gmail.com> On 8/9/19 4:52 AM, Peter J. Holzer wrote: > On 2019-08-09 10:34:34 +0300, Ahmad Adam Kabbara wrote: >> so when I write from >> tkinter import* >> t=Tk() >> tkinter.colorchooser.askcolor() >> I get this error message >> Traceback (most recent call last): >> File "C:\Users\kabba\Desktop\color and coordinates.py", line 3, in >> >> tkinter.colorchooser.askcolor() >> NameError: name 'tkinter' is not defined > > You didn't import 'tkinter', you imported all symbols ('*') from > tkinter. So, since you imported colorchooser, you can call > colorchooser.askcolor() (not tkinter.colorchooser.askcolor()) The better thing to do is remove the import * line and just "import tkinter" and then make sure all your calls to tkinter objects are fully qualified with the "tkinter." part like you've already been doing. From hjp-python at hjp.at Fri Aug 9 15:00:12 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 9 Aug 2019 21:00:12 +0200 Subject: help with tkinter In-Reply-To: <4fb42645-f8c6-7024-014a-ee60e76fa718@gmail.com> References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> <20190809105237.GC18121@hjp.at> <4fb42645-f8c6-7024-014a-ee60e76fa718@gmail.com> Message-ID: <20190809190012.GC14917@hjp.at> On 2019-08-09 12:43:45 -0600, Michael Torrie wrote: > On 8/9/19 4:52 AM, Peter J. Holzer wrote: > > You didn't import 'tkinter', you imported all symbols ('*') from > > tkinter. So, since you imported colorchooser, you can call > > colorchooser.askcolor() (not tkinter.colorchooser.askcolor()) > > The better thing to do is remove the import * line and just "import > tkinter" and then make sure all your calls to tkinter objects are fully > qualified with the "tkinter." part like you've already been doing. Agreed. 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 python at mrabarnett.plus.com Fri Aug 9 15:16:25 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 9 Aug 2019 20:16:25 +0100 Subject: py2 to 3 base64 issues In-Reply-To: References: Message-ID: On 2019-08-09 19:21, Larry Martell wrote: > On Fri, Aug 9, 2019 at 12:23 PM Chris Angelico wrote: >> >> On Sat, Aug 10, 2019 at 2:09 AM Larry Martell wrote: >> > >> > I have some python 2 code: >> > >> > def decode(key, string): >> > decoded_chars = [] >> > string = base64.urlsafe_b64decode(string) >> > for i in range(len(string)): >> > key_c = key[i % len(key)] >> > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) >> > decoded_chars.append(encoded_c) >> > decoded_string = "".join(decoded_chars) >> > return decoded_string >> > >> > and if I call it like this in py2 it works as expected: >> > >> > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' >> > key = '!@#$VERYsecRet)(' >> > decode(key, s) >> > >> > In py3 it fails with >> > >> > TypeError: ord() expected string of length 1, but int found >> > >> > I know that in py3 base64.urlsafe_b64decode is returning bytes not >> > chars and that is what that is happening, and I thought the solution >> > would be to decode it, but what codec would I use for this? >> >> Should be safe to decode it as ASCII, since Base 64 uses strictly >> ASCII characters. But since you're working with bytes, possibly all >> you need to do is remove the ord calls, since ord(u"x") is the same as >> b"x"[0]. You'll then need to change the join() at the end to be just >> "decoded_string = bytes(decoded_chars)", or possibly that followed by >> a decode-to-text, depending on how your data works. > > That doesn't work: > > -> encoded_c = chr(abs(string[i] - ord(key_c) % 256)) > (Pdb) n > TypeError: "unsupported operand type(s) for -: 'str' and 'int'" > (Pdb) string > 'WsXU\x8fy\x88\x89\xa7\x9c\x95\x82\x9a\xaaaXQsSZ\xaf\xaa\xc5z\xc7\xcd\xcc\xc5\xae\xc7\x8a\x96b\xb5\x97\x8c\xc5\xb7\xbb\xd3\xd8\xc9\xb5\xb7\xd6\xe9\x8e\x9b\x95' > (Pdb) string[i] > '\x8f' > (Pdb) bytes(string[i]) > '\x8f' > (Pdb) type(string[i]) > > 'string' is a 'str' (in Python 2 that would've been 'unicode'), so string[i] is also a 'str' and you need 'ord': encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) From larry.martell at gmail.com Fri Aug 9 15:21:18 2019 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 9 Aug 2019 15:21:18 -0400 Subject: py2 to 3 base64 issues In-Reply-To: References: Message-ID: On Fri, Aug 9, 2019 at 3:17 PM MRAB wrote: > > On 2019-08-09 19:21, Larry Martell wrote: > > On Fri, Aug 9, 2019 at 12:23 PM Chris Angelico wrote: > >> > >> On Sat, Aug 10, 2019 at 2:09 AM Larry Martell wrote: > >> > > >> > I have some python 2 code: > >> > > >> > def decode(key, string): > >> > decoded_chars = [] > >> > string = base64.urlsafe_b64decode(string) > >> > for i in range(len(string)): > >> > key_c = key[i % len(key)] > >> > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) > >> > decoded_chars.append(encoded_c) > >> > decoded_string = "".join(decoded_chars) > >> > return decoded_string > >> > > >> > and if I call it like this in py2 it works as expected: > >> > > >> > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ==' > >> > key = '!@#$VERYsecRet)(' > >> > decode(key, s) > >> > > >> > In py3 it fails with > >> > > >> > TypeError: ord() expected string of length 1, but int found > >> > > >> > I know that in py3 base64.urlsafe_b64decode is returning bytes not > >> > chars and that is what that is happening, and I thought the solution > >> > would be to decode it, but what codec would I use for this? > >> > >> Should be safe to decode it as ASCII, since Base 64 uses strictly > >> ASCII characters. But since you're working with bytes, possibly all > >> you need to do is remove the ord calls, since ord(u"x") is the same as > >> b"x"[0]. You'll then need to change the join() at the end to be just > >> "decoded_string = bytes(decoded_chars)", or possibly that followed by > >> a decode-to-text, depending on how your data works. > > > > That doesn't work: > > > > -> encoded_c = chr(abs(string[i] - ord(key_c) % 256)) > > (Pdb) n > > TypeError: "unsupported operand type(s) for -: 'str' and 'int'" > > (Pdb) string > > 'WsXU\x8fy\x88\x89\xa7\x9c\x95\x82\x9a\xaaaXQsSZ\xaf\xaa\xc5z\xc7\xcd\xcc\xc5\xae\xc7\x8a\x96b\xb5\x97\x8c\xc5\xb7\xbb\xd3\xd8\xc9\xb5\xb7\xd6\xe9\x8e\x9b\x95' > > (Pdb) string[i] > > '\x8f' > > (Pdb) bytes(string[i]) > > '\x8f' > > (Pdb) type(string[i]) > > > > > 'string' is a 'str' (in Python 2 that would've been 'unicode'), so > string[i] is also a 'str' and you need 'ord': > > encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256)) My bad - I was mistakenly running it in 2.7 - in 3.7 it's working like this: def decode(key, string): decoded_chars = [] string = base64.urlsafe_b64decode(string) for i in range(len(string)): key_c = key[i % len(key)] encoded_c = chr(abs(string[i] - ord(key_c) % 256)) decoded_chars.append(encoded_c) decoded_string = "".join(decoded_chars) return decoded_string Thanks all! From email at paulstgeorge.com Fri Aug 9 16:28:16 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 9 Aug 2019 22:28:16 +0200 Subject: String slices In-Reply-To: <56e067eb-175b-0fac-dadd-9597b1a6201c@kynesim.co.uk> References: <5b5c04b0-f961-41ee-ad68-75abf894d8c2@paulstgeorge.com> <56e067eb-175b-0fac-dadd-9597b1a6201c@kynesim.co.uk> Message-ID: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> On 09/08/2019 16:29, Rhodri James wrote: > On 09/08/2019 15:13, Paul St George wrote: >> In the code (below) I want a new line like this: >> >> Plane rotation X: 0.0 >> Plane rotation Y: 0.0 >> Plane rotation Z: 0.0 >> >> But not like this: >> >> Plane rotation X: >> 0.0 >> Plane rotation Y: >> 0.0 >> Plane rotation Z: >> 0.0 >> >> Is it possible? >> (I am using Python 3.5 within Blender.) >> >> # >> import os >> >> outstream = open(os.path.splitext(bpy.data.filepath)[0] + ".txt",'w') >> >> print( >> >> "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0], >> >> "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1], >> >> "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2], >> >> file=outstream, sep="\n" >> >> ) >> >> outstream.close() > > The 'sep="\n"' parameter to print() means "put a newline between each > item."? So don't do that.? Put the newlines you do want in explicitly, > or use separate calls to print(): > > (I'm abbreviating because I really can't be bothered to type that much > :-) > > ? print("X:", thing[0], > ??????? "\nY:", thing[1], > ??????? "\nZ:", thing[2], > ??????? file=outstream) > > or > > ? print("X:", thing[0], file=outstream) > ? print("Y:", thing[1], file=outstream) > ? print("Z:", thing[2], file=outstream) > > I would probably use the latter, but it's just a matter of personal > preference. > > (Actually I would probably use outstream.write() and do my own > formatting, but let's not get side-tracked ;-) > > > > So, I am going with your second suggestion (see below) but I would love to hear your outstream.write() side-track! import os with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as outstream: plane = bpy.data.objects["Plane"] print("Plane rotation X:",plane.rotation_euler[0], file=outstream) print("Plane rotation Y:",plane.rotation_euler[1], file=outstream) print("Plane rotation Z:",plane.rotation_euler[2], file=outstream) print("Focal length:", bpy.context.object.data.lens, file=outstream) and so on... From cs at cskk.id.au Fri Aug 9 18:04:17 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 10 Aug 2019 08:04:17 +1000 Subject: Python in Blender. Writing information to a file. In-Reply-To: References: Message-ID: <20190809220417.GA11004@cskk.homeip.net> On 09Aug2019 20:53, Paul St George wrote: >>>I almost understand. >>>Are you saying I should change the first line of code to something >>>like: >>> >>>|outstream = with open(path to my file,'w') # this is invalid syntax| >>> >>>and then delete the >>>outstream.close() >> >>No, you should do what Peter wrote: >> >>with open("/path/to/file", "w") as outstream: >>? print(my_stuff, file=outstream) >> >Got it! I hadn't taken Peter's advice as code. I thought (well anyway now I have it). So thanks to Peter, Cameron and >Rhodri. No worries. You should also got and look up "context manager" in the Python docs. It is a general mechanism where you can write: with something as name: suite of code where "something" is an object which implements a context manager. Before "suite of code" starts Python calls "something.__enter__" and when the interpreter leaves the suite Python calls "something.__exit__". Notably, it will call __exit__ no matter how you leave the suite: as usual, by falling off the end, or early with an exception or a break or a continue or a return. The __exit__ function always gets called. In the case Peter's example, "something" is "open()": the file object you get back from open() implements a context manager. Its __enter__ function does nothing, but its __exit__ function closes the file. Reliably and immediately. Cheers, Cameron Simpson (formerly cs at zip.com.au) I swear to god, officer, I'm fixing this bridge. Just go divert traffic. From cs at cskk.id.au Fri Aug 9 19:10:12 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 10 Aug 2019 09:10:12 +1000 Subject: String slices In-Reply-To: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> References: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> Message-ID: <20190809231012.GA91401@cskk.homeip.net> On 09Aug2019 22:28, Paul St George wrote: >On 09/08/2019 16:29, Rhodri James wrote: >>The 'sep="\n"' parameter to print() means "put a newline between each >>item."? So don't do that.? Put the newlines you do want in explicitly, >>or use separate calls to print(): >> >>(I'm abbreviating because I really can't be bothered to type that >>much :-) >> >>? print("X:", thing[0], >>??????? "\nY:", thing[1], >>??????? "\nZ:", thing[2], >>??????? file=outstream) >> >>or >> >>? print("X:", thing[0], file=outstream) >>? print("Y:", thing[1], file=outstream) >>? print("Z:", thing[2], file=outstream) >> >>I would probably use the latter, but it's just a matter of personal >>preference. >> >>(Actually I would probably use outstream.write() and do my own >>formatting, but let's not get side-tracked ;-) >> >So, I am going with your second suggestion (see below) but I would love >to hear your outstream.write() side-track! I am not Rhodri James, but you can just write strings to text files: outstream.write("X: ") # note, includes the space separator outstream.write(str(thing[0])) outstring.write("\n") print() is convenient, because it calls str() on any non-str argument for you, and it does the space separators and newline line ending (both overridable). You can see the above is rather verbose. But it does let you control exactly what gets written, _if_ the print separators and endings are causing you inconvenience. Personally, for text output, I use print unless there's some compelling reason not to (such as transcribing a data structure precisely, not wanting unexpected spaces and newlines; if I were hand transcribing JSON or XML or HTML or the like). Cheers, Cameron Simpson From hjp-python at hjp.at Sat Aug 10 05:45:43 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 10 Aug 2019 11:45:43 +0200 Subject: String slices In-Reply-To: <20190809231012.GA91401@cskk.homeip.net> References: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> <20190809231012.GA91401@cskk.homeip.net> Message-ID: <20190810094543.GD14917@hjp.at> On 2019-08-10 09:10:12 +1000, Cameron Simpson wrote: > On 09Aug2019 22:28, Paul St George wrote: > > On 09/08/2019 16:29, Rhodri James wrote: > > > (Actually I would probably use outstream.write() and do my own > > > formatting, but let's not get side-tracked ;-) > > > > > I would love to hear your outstream.write() side-track! > > I am not Rhodri James, but you can just write strings to text files: > > outstream.write("X: ") # note, includes the space separator > outstream.write(str(thing[0])) > outstring.write("\n") You can also format the string before passing it to write (which is probably what Rhodri meant by "do my own formatting", like this: outstream.write("X: %7.2f\n" % thing[0]) or this outstream.write("X: {0:7.2f}\n".format(thing[0])) or (since Python 3.6) this: outstream.write(f"X: {thing[0]:7.2f}\n") There are of course many variants to all three methods. 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 email at paulstgeorge.com Sat Aug 10 15:00:43 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 10 Aug 2019 21:00:43 +0200 Subject: String slices In-Reply-To: References: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> <20190809231012.GA91401@cskk.homeip.net> <20190810094543.GD14917@hjp.at> Message-ID: <2ace9908-489a-ef9d-f518-00f5b7907765@paulstgeorge.com> On 10/08/2019 17:35, Dennis Lee Bieber wrote: > On Sat, 10 Aug 2019 11:45:43 +0200, "Peter J. Holzer" > declaimed the following: > > >> There are of course many variants to all three methods. > And then one can get downright nasty... > >>>> X = 3.14 >>>> Y = 2.78 >>>> Z = 6.226E23 >>>> print("".join(["Plane rotation %s: %s\n" % (nm, vl) > ... for (nm, vl) in [("X", X), ("Y", Y), ("Z", Z)]])) > Plane rotation X: 3.14 > Plane rotation Y: 2.78 > Plane rotation Z: 6.226e+23 > > (replace "print" with "outstream.write" for use with the file) > > |outstream.write| could be very useful, thank you Peter and Cameron (neither being Rhodri James). If I wanted to learn more about formatting strings is there a better place to go than: https://docs.python.org/release/3.6.5/library/string.html?highlight=string#format-string-syntax https://pyformat.info https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html And Dennis, whatever you did there is very impressive and works perfectly but I don?t know enough to be able to use it. Please will you say more or direct me to some reference? I couldn?t find ?nasty? in the Python docs. From cs at cskk.id.au Sat Aug 10 19:56:32 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 11 Aug 2019 09:56:32 +1000 Subject: class definition question In-Reply-To: References: Message-ID: <20190810235632.GA940@cskk.homeip.net> On 07Aug2019 16:36, Terry Reedy wrote: >On 8/7/2019 3:26 PM, Manfred Lotz wrote: >>On Wed, 07 Aug 2019 14:39:00 -0400 >>Dennis Lee Bieber wrote: >>>On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz >>>declaimed the following: >>>>More often I see something like this: >>>> >>>>class Myclass: >>>>... >>>>but sometimes I see >>>>class Myclass(object): >>>>... >>>> >>>>Question: which way is preferable? >>> >>> It's historical... >>> >>> Python v1.x had a form of classes. >>> >>> Python v2.x introduced "new-style" classes. "New-style" >>>classes /had/ to inherit from "object", as they had different >>>behavior from "v1.x old-style" classes which were still supported (it >>>would have broken too many programs). Old-style were then deprecated, >>>and one should have used new-style for new code. >>> >>> Python v3.x unified (removed old-style behavior differences) >>>and all classes inherit from "object" whether one specifies object or >>>not. >> >>Thanks a lot for the explanations. >> >>As a Python newbie (with no Pythons legacies) I only deal with Python 3. >>So, I will happily ignore 'object'. > >That is preferred, because it is extra work to write and read, with no >benefit, and because myclass(object) can be seen as implying that the >code once ran or is still meant to be compatible with Python 2. By contrast, I generally use MyClass(object) because I try to write Python 2/3 compatible code unless I have a reason not to. If I _know_ I'll never use a module with Python 2, the bare MyClass: is indeed preferable. However, a lot of my code is in modules which might conceivably be used by anyone. Artificially contraining their use seems counterproductive. Cheers, Cameron Simpson From youssef.avx at gmail.com Fri Aug 9 13:33:13 2019 From: youssef.avx at gmail.com (Youssef Abdelmohsen) Date: Fri, 9 Aug 2019 19:33:13 +0200 Subject: NotADirectoryError: [Errno 20] Not a directory Message-ID: Note: Beginner I'm trying to create an html parser that will go through a folder and all its subfolders and export all html files without any html tags, in file formats CSV and TXT with each html labeled with the title of the web page in a new CSV and TXT. However I keep getting an error saying: *"Traceback (most recent call last): File "/Users/username/Documents/htmlparser/parser10.py", line 59, in for subentry in os.scandir(entry.path):NotADirectoryError: [Errno 20] Not a directory: '/Users/username/site/.DS_Store'"* Here's what I've done so far (I have bolded line 59): " import bs4 as bs import csv import glob import os import re directory = "/Users/username/site" with os.scandir(directory) as it: for entry in it: if ".html" in entry.name or re.match(r'.*?(?:\.html?$|\.html?\?.*)', entry.name) is not None: print(entry.name, entry.path) my_data = (entry) listofp = [] soup = bs.BeautifulSoup(open(my_data, "r").read()) for paragraph in soup.find_all('p'): listofp.append(paragraph.string) title = soup.title.string leftitle = [title] listception = [leftitle] for moreshit in soup.find_all('h1', 'h2', 'h3', 'h4', 'h5'): listception.append([str(moreshit.text)]) for paragraph in soup.find_all('p'): listception.append([str(paragraph.text)]) for elements in soup.find_all('li', 'td', 'div', 'span'): listception.append([str(elements.text)]) for evenmoreshit in soup.find_all('h6', 'a'): listception.append([str(evenmoreshit.text)]) num = 0 with open('export/' + title + '.csv', 'w') as csv_file: writer = csv.writer(csv_file, delimiter=',') writer.writerows(listception) file_path = os.path.join(directory, entry) text = open(file_path, mode='r').read() results = str(listception).strip('[]') results = results.replace("[", " ") results = results.replace("]", " ") results = results.replace("""\n""", " ") results_dir = "/Users/username/site/done" results_file = title + '.txt' file_path = os.path.join(results_dir, results_file) open(file_path, mode='w', encoding='UTF-8').write(results) continue * for subentry in os.scandir(entry.path):* for file in os.scandir(subentry.path): if ".html" in entry.name or re.match(r'.*?(?:\.html?$|\.html?\?.*)', entry.name) is not None: print(entry.name, entry.path) my_data = (entry) listofp = [] soup = bs.BeautifulSoup(open(my_data, "r").read()) for paragraph in soup.find_all('p'): listofp.append(paragraph.string) title = soup.title.string leftitle = [title] listception = [leftitle] for moreshit in soup.find_all('h1', 'h2', 'h3', 'h4', 'h5'): listception.append([str(moreshit.text)]) for paragraph in soup.find_all('p'): listception.append([str(paragraph.text)]) for elements in soup.find_all('li', 'td', 'div', 'span'): listception.append([str(elements.text)]) for evenmoreshit in soup.find_all('h6', 'a'): listception.append([str(evenmoreshit.text)]) num = 0 with open('export/' + title + '.csv', 'w') as csv_file: writer = csv.writer(csv_file, delimiter=',') writer.writerows(listception) file_path = os.path.join(directory, entry) text = open(file_path, mode='r').read() results = str(listception).strip('[]') results = results.replace("[", " ") results = results.replace("]", " ") results = results.replace("""\n""", " ") results_dir = "/Users/username/site/done" results_file = title + '.txt' file_path = os.path.join(results_dir, results_file) open(file_path, mode='w', encoding='UTF-8').write(results) continue Would love any help whatsoever or any suggestions of any kind. Thank you very much! From rwalton00 at gmail.com Sat Aug 10 10:12:33 2019 From: rwalton00 at gmail.com (Rob Walton) Date: Sat, 10 Aug 2019 15:12:33 +0100 Subject: help with tkinter In-Reply-To: <20190809190012.GC14917@hjp.at> References: <5d42e992.1c69fb81.a4d2f.d17e@mx.google.com> <20190809105237.GC18121@hjp.at> <4fb42645-f8c6-7024-014a-ee60e76fa718@gmail.com> <20190809190012.GC14917@hjp.at> Message-ID: Doubly agreed. Avoid import * as it makes the code a nightmare to reason about later amongst other things On Fri, 9 Aug 2019 at 20:02, Peter J. Holzer wrote: > On 2019-08-09 12:43:45 -0600, Michael Torrie wrote: > > On 8/9/19 4:52 AM, Peter J. Holzer wrote: > > > You didn't import 'tkinter', you imported all symbols ('*') from > > > tkinter. So, since you imported colorchooser, you can call > > > colorchooser.askcolor() (not tkinter.colorchooser.askcolor()) > > > > The better thing to do is remove the import * line and just "import > > tkinter" and then make sure all your calls to tkinter objects are fully > > qualified with the "tkinter." part like you've already been doing. > > Agreed. > > 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 > -- > https://mail.python.org/mailman/listinfo/python-list > From samuel.lelievre at gmail.com Wed Aug 7 12:16:43 2019 From: samuel.lelievre at gmail.com (=?UTF-8?Q?Samuel_Leli=C3=A8vre?=) Date: Wed, 7 Aug 2019 18:16:43 +0200 Subject: =?UTF-8?B?UmU6IFtwb2xpYXN0cm8tZGV2XSBBTk46IHBvbGlhc3RybyAwLjEzLjAgcmVsZWFzZWQg?= =?UTF-8?B?8J+agA==?= In-Reply-To: References: <34684103-9d6e-cc74-0f14-c95072f81d87@gmail.com> Message-ID: Le mar. 6 ao?t 2019 ? 08:33, Samuel Dupree a ?crit : > Juan Luis Cano, > > When will poliastro ver. 0.13.0 become available from Anaconda? At the > time of this note, only ver. 0.12.0 is available. > > Lastly what is the recommended procedure to update poliastro from vers. > 0.12.0 to 0.13.0? > > Sam Dupree > A pull request was automatically created by a bot: https://github.com/conda-forge/poliastro-feedstock/pull/29 and Juan Luis merged it yesterday, so that the new version is available since yesterday, see the version badge on the README at https://github.com/conda-forge/poliastro-feedstock Clicking on that badge sends to: https://anaconda.org/conda-forge/poliastro which has the installation instructions. Use `conda upgrade` instead of `conda install` if you want to upgrade. From sanketsawla34 at gmail.com Sat Aug 10 03:38:27 2019 From: sanketsawla34 at gmail.com (sanketsawla34 at gmail.com) Date: Sat, 10 Aug 2019 00:38:27 -0700 (PDT) Subject: how to setup for localhost:8000 In-Reply-To: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> References: <5ea1e31b-09ba-4b6a-be8b-58886c5c5f81@googlegroups.com> Message-ID: <2f586052-871e-441d-b19c-94ecb1037e64@googlegroups.com> please set up my localhost:8000 From __peter__ at web.de Sun Aug 11 04:58:39 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Aug 2019 10:58:39 +0200 Subject: NotADirectoryError: [Errno 20] Not a directory References: Message-ID: Youssef Abdelmohsen wrote: > Note: Beginner > > I'm trying to create an html parser that will go through a folder and all > its subfolders and export all html files without any html tags, in file > formats CSV and TXT with each html labeled with the title of the web page > in a new CSV and TXT. > > However I keep getting an error saying: > > > > > *"Traceback (most recent call last): File > "/Users/username/Documents/htmlparser/parser10.py", line 59, in > for subentry in os.scandir(entry.path):NotADirectoryError: [Errno 20] Not > a directory: '/Users/username/site/.DS_Store'"* > > Here's what I've done so far (I have bolded line 59): The error message says it: in the outer loop you encounter a *file* called ".DS_Store" that doesn't match your regex. You then pass it to the inner loop, i. e. entry.path below is a file > for subentry in os.scandir(entry.path): However os.scandir expects a *directory* rather than a file. To fix the immediate problem you can ensure that entry is a directory if entry.is_dir(): for subentry in os.scandir(entry.path): ... but wait a moment. I note that you copied the code to process the html file twice. This is bad practice as it's hard to keep the code in sync when you apply changes (you already have a bug because you refer to the `entry` variable of the outer loop in the inner loop, too). Instead use a helper functions like def is_html_file(filename): return bool(re.match(...)) def process_html_file(filename): ... The loops then become for entry in os.scandir(site_directory): if entry.is_dir(): for subentry in os.scandir(entry.path) if subentry.is_dir(): for file in os.scandir(subentry.path) if is_html_file(file.path): process_html_file(file) elif is_html_file(entry.path): process_html_file(entry.path) Hm, that still looks messy; there may be bugs. Do you really want to exclude the html files from the intermediate level? I'd suggest that instead you scan the whole tree. Enter os.walk(): for path, folders, files in os.walk(site_directory): for name in files: filename = os.path.join(path, name): if is_html_file(filename): process_html_file(filename) While this doesn't do exactly the same thing it should be much clearer what it does ;) From slefkowitz at sbcglobal.net Sun Aug 11 12:50:29 2019 From: slefkowitz at sbcglobal.net (slefkowitz at sbcglobal.net) Date: Sun, 11 Aug 2019 12:50:29 -0400 Subject: beginner question-very basic Message-ID: <0a7401d55064$e22d02d0$a6870870$@sbcglobal.net> Just getting started with Python. Downloaded 3.7.4 rom python.org I wrote program in Notepad, saved it with a ".py" extension. What do I do next? How do I execute a program? From best_lay at yahoo.com Mon Aug 12 00:32:20 2019 From: best_lay at yahoo.com (Wildman) Date: Sun, 11 Aug 2019 23:32:20 -0500 Subject: beginner question-very basic References: <0a7401d55064$e22d02d0$a6870870$@sbcglobal.net> Message-ID: On Sun, 11 Aug 2019 12:50:29 -0400, slefkowitz wrote: > Just getting started with Python. > > Downloaded 3.7.4 rom python.org > > I wrote program in Notepad, saved it with a ".py" extension. > > What do I do next? How do I execute a program? I am assuming you are using Windows since you posted with Outlook and that the python executable is in your path. Open a cmd window and enter: python \path\to\program.py -- GNU/Linux user #557453 The cow died so I don't need your bull! From PythonList at DancesWithMice.info Mon Aug 12 06:53:39 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 12 Aug 2019 22:53:39 +1200 Subject: Remote/Pair-Programming in-the-cloud In-Reply-To: References: <5e6e76dd-30b1-7916-bb2c-4165e974b968@DancesWithMice.info> <61941e61-7b29-1bd2-7cc0-13700e1a6c0b@DancesWithMice.info> <00b75d3a-c3b8-9834-99ec-c1f854761bc5@DancesWithMice.info> Message-ID: On 7/08/19 4:20 AM, Dennis Lee Bieber wrote: > {Playing Devil's Advocate} If this list had avatars, I would graffiti yours to have horns and a tail! No. Many have also requested feedback. Sadly the news is not good. Herewith:- > On Tue, 6 Aug 2019 09:07:41 +1200, DL Neil > declaimed the following: > >> Anyway, this PUG mtg is going to be an 'experience'. >> (I'll try (almost) anything once!) > The only thing missing is capturing your PoV of the meeting (with > screens) as a video for later streaming on YouTube Once the link was made, we addressed the entire mtg, briefing members on the experiment and the possibilities if offers. Only thereafter was it down to individuals or small groups (although I suspect everyone was subjected to every word I uttered - not the best approach - must check...). In this jurisdiction, every single person present would have had to consent to the video. However, as it turned-out, such would have been less than helpful. Sigh! Feedback/Observations: The PUG meeting/experiment did not go very well. To be fair, I think that the live-demo gremlins were alive and well, and more responsible than anything/anyone else, but... (as I've always said to my staff, having learned from (bitter) experience, start earlier than anyone else with enough time to test' everything, in-situ, before we start. The mtg organiser is/was no tutor of mine, is undoubtedly a busy boy, and may not have had prior access to the room/computer/network/...!) The first issue was difficulty persuading Zoom to link. In the end there were two Zoom-s running at the other end, but we elected to leave-alone not actually knowing which was hosting the connection. This process is normally quite straight-forward, and I've not experienced such before. Sadly, but a harbinger of what was to come... Attempts to connect to AWS Cloud9 were completely fruitless. Whereas the remote PC had no trouble, at the PUG, entering access information resulted in nothing beyond 'the spinning wheel'. Similarly, whilst we both managed to both log-in to PythonAnywhere, we made it no further. In the end, I was (reduced to) screen-sharing, and chatting with folk about their projects. (the purpose of the meeting - so, not 'all bad' then) Aside: I was interested to hear how one member is performing local development and then 'parcelling-up' his Flask app into a "script". Each time he wants to test 'on the web', the script builds a new Docker-instance. Most of the Python, pip3, etc, is held within some cache (I'm not a Docker-person). It all happens acceptably quickly - please see other thread where we discussed VMs, containers, and Pyenvs... Have not heard-back from the mtg organiser, since. Am hoping he is busy, rather than upset... Meantime, assuming that the host-machine was an older lap-top (based upon screen resolution only), I tried further combinations of hardware and network (beyond previous preparation-experiments), including resurrecting an old Windows Vista lap-top (I use Linux) which first needed its Firefox considerably updated (although that may have been AWS Cloud9's demand rather than PA's - can't recall). Once that prerequisite was in-place, no problems were experienced! In any (other) combination of hardware, OpSys, networking, etc; I have no trouble using PythonAnywhere or AWS Cloud9 between two computers, including at the local public library (and through their firewall/security/decency/etc filters). Conclusion: the local university's foibles were likely to have been the source of our comms 'problems'. What next? - continue to narrow-down possible issues, with the meeting organiser - more experiments* - (possibly) consider other software choices (earlier in this thread) - equip the host-machine with head-set - better brief/prepare mtg participants in 'what to expect'**. * A fellow list-member and I are planning further experiments, hopefully this week. If you are also interested, please feel free to contact me off-list... ** As mentioned earlier, "pair programming" and/or my attempt to remotely support our PUG's Coding Evenings, require abilities AND facilities to "verbalise", "share", and "swap". Yes it would (perhaps) be best if one package delivered 'all', but as long as multiple tools will work happily together, success is possible. The key though is to realise the social side of pair-programming, a willingness to share thoughts, communicate with each-other, etc. Thereafter to adapt to the 'remote' wrinkle. We haven't reached the point of being able to explore such factors. PythonAnywhere: Have greatly appreciated the interest of one of their principals. Sent them feedback, with observations, suggestions, and questions. Pending response, it is likely that I will 'drop' that option. In the final analysis, I don't think PA a tool for "pair programming"; particularly not when compared with (say) AWS Cloud9 which offers a "chat" panel, dynamic editing, and the ability to "swap". Whilst PA's console sessions appear auto-magically on both machines, editor sessions are not shared dynamically (require manual intervention/update requests). That said, in no way detracts from PythonAnywhere's primary objective of delivering cloud-based Python dev and prod environments. Summary: A disappointing first-attempt. As long as (at least) two people are interested, it's worth investing further time and efforts... -- Regards =dn From rhodri at kynesim.co.uk Mon Aug 12 09:24:50 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 12 Aug 2019 14:24:50 +0100 Subject: String slices In-Reply-To: <20190810094543.GD14917@hjp.at> References: <47df7486-c4a8-2cc3-ccc4-e19663ed148b@paulstgeorge.com> <20190809231012.GA91401@cskk.homeip.net> <20190810094543.GD14917@hjp.at> Message-ID: <11fe83c5-a3be-1988-64ed-53adf96e8516@kynesim.co.uk> On 10/08/2019 10:45, Peter J. Holzer wrote: > On 2019-08-10 09:10:12 +1000, Cameron Simpson wrote: >> On 09Aug2019 22:28, Paul St George wrote: >>> On 09/08/2019 16:29, Rhodri James wrote: >>>> (Actually I would probably use outstream.write() and do my own >>>> formatting, but let's not get side-tracked ;-) >>>> >>> I would love to hear your outstream.write() side-track! >> >> I am not Rhodri James, but you can just write strings to text files: >> >> outstream.write("X: ") # note, includes the space separator >> outstream.write(str(thing[0])) >> outstring.write("\n") > > You can also format the string before passing it to write (which is > probably what Rhodri meant by "do my own formatting", like this: > > outstream.write("X: %7.2f\n" % thing[0]) > > or this > > outstream.write("X: {0:7.2f}\n".format(thing[0])) > > or (since Python 3.6) this: > > outstream.write(f"X: {thing[0]:7.2f}\n") > > There are of course many variants to all three methods. That is indeed what I meant. I do enough random dumping of things to files for debugging purposes that outstream.write() is second nature to me now. I once even went as far as sys.stdout.write() before sanity caught up with me ;-) -- Rhodri James *-* Kynesim Ltd From morphex at gmail.com Mon Aug 12 03:14:55 2019 From: morphex at gmail.com (morphex) Date: Mon, 12 Aug 2019 00:14:55 -0700 (PDT) Subject: Web framework for static pages Message-ID: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Hi. After a long break, I'm starting to work with web development again, in my company Nidelven IT. http://www.nidelven-it.no I've used Zope and Plone since the early days, as well as other web systems / frameworks, Python-based, some PHP, Java etc. However, I would like to add another tool to my toolbox, another weapon to the arsenal.. Some customers would want static pages, and that's something I want to offer. What frameworks are there for generating static web pages in Python? What are the features of each? Thanks, Morten From brian.j.oney at googlemail.com Mon Aug 12 12:13:32 2019 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 12 Aug 2019 18:13:32 +0200 Subject: Web framework for static pages In-Reply-To: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: On August 12, 2019 9:14:55 AM GMT+02:00, morphex wrote: >Hi. > >What frameworks are there for generating static web pages in Python? I have used: https://github.com/Frozen-Flask/Frozen-Flask It's pretty simple. Develop with flask and then "freeze" it. I am looking forward to further answers. HTH From torriem at gmail.com Mon Aug 12 12:30:08 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Aug 2019 10:30:08 -0600 Subject: Web framework for static pages In-Reply-To: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: <5d6098c0-0aae-4372-d663-c0c961c49f69@gmail.com> On 8/12/19 1:14 AM, morphex wrote: > What frameworks are there for generating static web pages in Python? What are the features of each? A quick google search reveals a number of them. Pelican, Hyde, etc. From vinay_sajip at yahoo.co.uk Mon Aug 12 13:33:20 2019 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 12 Aug 2019 17:33:20 +0000 (UTC) Subject: ANN: A new version (0.4.5) of python-gnupg has been released. References: <1333670321.6029360.1565631200779.ref@mail.yahoo.com> Message-ID: <1333670321.6029360.1565631200779@mail.yahoo.com> A new version of the Python module which wraps GnuPG has been released. What Changed?============= This is an enhancement and bug-fix release, and all users are encouraged toupgrade. Brief summary: * Fixed #107: Improved documentation. * Fixed #112: Raised a ValueError if a gnupghome is specified which is not an? existing directory. * Fixed #113: Corrected stale link in the documentation. * Fixed #116: Updated documentation to clarify when spurious key-expired/? signature-expired messages might be seen. * Fixed #119: Added --yes to avoid pinentry when deleting secret keys with? GnuPG >= 2.1. * A warning is logged if gpg returns a non-zero return code. * Added ``extra_args`` to ``import_keys``. * Added support for CI using AppVeyor. This release [2] has been signed with my code signing key: Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86 Recent changes to PyPI don't show the GPG signature with the download links.An alternative download source where the signatures are available is the project'sown downloads page [5]. What Does It Do?================The gnupg module allows Python programs to make use of thefunctionality provided by the Gnu Privacy Guard (abbreviated GPG orGnuPG). Using this module, Python programs can encrypt and decryptdata, digitally sign documents and verify digital signatures, manage(generate, list and delete) encryption keys, using proven Public KeyInfrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as itmakes use of the subprocess module which appeared in that version ofPython. This module is a newer version derived from earlier work byAndrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')>>> gpg.list_keys() [{...'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2','keyid': '197D5DAC68F1AAB2','length': '1024','type': 'pub','uids': ['', 'Gary Gross (A test user) ']},{...'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A','keyid': '0C5FEFA7A921FC4A','length': '1024',...'uids': ['', 'Danny Davis (A test user) ']}]>>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A'])>>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n\nhQIOA/6NHMDTXUwcEAf.-----END PGP MESSAGE-----\n'>>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret')>>> str(decrypted) 'Hello, world!'>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')>>> verified = gpg.verify(str(signed))>>> print "Verified" if verified else "Not verified" 'Verified' As always, your feedback is most welcome (especially bug reports [3],patches and suggestions for improvement, or any other points via themailing list/discussion group [4]). Enjoy! Cheers Vinay SajipRed Dove Consultants Ltd. [1] https://bitbucket.org/vinay.sajip/python-gnupg[2] https://pypi.org/project/python-gnupg/0.4.5[3] https://bitbucket.org/vinay.sajip/python-gnupg/issues[4] https://groups.google.com/forum/#!forum/python-gnupg[5] https://bitbucket.org/vinay.sajip/python-gnupg/downloads/-------------------------------------- From morphex at gmail.com Mon Aug 12 12:35:44 2019 From: morphex at gmail.com (morphex) Date: Mon, 12 Aug 2019 09:35:44 -0700 (PDT) Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <5d6098c0-0aae-4372-d663-c0c961c49f69@gmail.com> Message-ID: <1caf9667-5304-413a-a892-5be34baa5843@googlegroups.com> Why Google it, when I have an Oracle? ? -Morten From morphex at gmail.com Mon Aug 12 18:01:38 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 00:01:38 +0200 Subject: Web framework for static pages References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: On 12.08.2019 18:13, Brian Oney wrote: > > > On August 12, 2019 9:14:55 AM GMT+02:00, morphex wrote: >> Hi. >> > >> What frameworks are there for generating static web pages in Python? > > I have used: > https://github.com/Frozen-Flask/Frozen-Flask > > It's pretty simple. Develop with flask and then "freeze" it. > > I am looking forward to further answers. OK, so now I know Flask can freeze applications. With Zope and Plone, I have a lot of what I need in terms of web application development. What I guess I'm looking for, is something that will help create a static website, in a simple and efficient manner. Without being bloated. I don't have a lot of hair on my head, but I would be pulling it out because of some of the websites I see today, their heavy-handed use of different Javascript frameworks etc. How would I go about creating a simple website with a front page, an about page, a product page and a contact page? Without any server-side handling of data, so it could be entirely served by for example Apache. And with it having well-formed XHTML, proper CSS, little Javascript, scaling to different screen and web browsers (wow, it's been so long I forgot it was called responsive design) and so on, being a nice little package. -Morten From hongyi.zhao at gmail.com Mon Aug 12 18:17:26 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 12 Aug 2019 22:17:26 -0000 (UTC) Subject: About the #python irc channel on freenode. Message-ID: Hi, Sorry for bothering here for this not technically python issue. I want to chat some issues on the #python irc channel hosted on freenode. But try so many times still cann't succeed. Could anyone here give me some hint if you can successfully do this thing? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From cs at cskk.id.au Mon Aug 12 18:29:55 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 13 Aug 2019 08:29:55 +1000 Subject: Web framework for static pages In-Reply-To: References: Message-ID: <20190812222955.GA6382@cskk.homeip.net> On 13Aug2019 00:01, Morten W. Petersen wrote: >What I guess I'm looking for, is something that will help create a >static website, in a simple and efficient manner. Without being >bloated. > >I don't have a lot of hair on my head, but I would be pulling it out >because of some of the websites I see today, their heavy-handed use of >different Javascript frameworks etc. > >How would I go about creating a simple website with a front page, an >about page, a product page and a contact page? Without any >server-side handling of data, so it could be entirely served by for >example Apache. > >And with it having well-formed XHTML, proper CSS, little Javascript, >scaling to different screen and web browsers (wow, it's been so long I >forgot it was called responsive design) and so on, being a nice little >package. The common search term is "static site generator". There are several out there. I haven't any experience with which to offer an opinion though. Cheers, Cameron Simpson From hongyi.zhao at gmail.com Mon Aug 12 19:56:50 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 12 Aug 2019 23:56:50 -0000 (UTC) Subject: About the #python irc channel on freenode. References: <87ftm6ou3e.fsf@nightsong.com> Message-ID: On Mon, 12 Aug 2019 16:13:41 -0700, Paul Rubin wrote: > It's always worked ok for me. But I always be put into the #python-unregistered channel as follows: ---------- Now talking on #python-unregistered * Topic for #python-unregistered is: Welcome to #python-unregistered! You've been put here because #python requires you to register your nickname with Freenode. For more information about registering on Freenode, ask #freenode. For more information about #python,#python-* moderation, #python-ops. * Topic for #python-unregistered set by lvh!~lvh at python/psf/lvh (Fri Jul 1 16:44:19 2011) ------------- I've tried to register the nickname as it told. But still cannot success. Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From jon+usenet at unequivocal.eu Mon Aug 12 20:14:27 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 13 Aug 2019 00:14:27 -0000 (UTC) Subject: Web framework for static pages References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: On 2019-08-12, Morten W. Petersen wrote: > What I guess I'm looking for, is something that will help create a > static website, in a simple and efficient manner. Without being bloated. > > I don't have a lot of hair on my head, but I would be pulling it out > because of some of the websites I see today, their heavy-handed use of > different Javascript frameworks etc. > > How would I go about creating a simple website with a front page, an > about page, a product page and a contact page? Without any server-side > handling of data, so it could be entirely served by for example Apache. If it's really that small then it sounds like what you are looking for is known as a "text editor". From bouncingcats at gmail.com Mon Aug 12 21:30:36 2019 From: bouncingcats at gmail.com (David) Date: Tue, 13 Aug 2019 11:30:36 +1000 Subject: About the #python irc channel on freenode. In-Reply-To: References: <87ftm6ou3e.fsf@nightsong.com> Message-ID: On Tue, 13 Aug 2019 at 10:00, Hongyi Zhao wrote: > > But I always be put into the #python-unregistered channel as follows: > > ---------- > Now talking on #python-unregistered > * Topic for #python-unregistered is: Welcome to #python-unregistered! > You've been put here because #python requires you to register your > nickname with Freenode. For more information about registering on > Freenode, ask #freenode. For more information about #python,#python-* > moderation, #python-ops. > * Topic for #python-unregistered set by lvh!~lvh at python/psf/lvh (Fri Jul > 1 16:44:19 2011) > ------------- > > I've tried to register the nickname as it told. But still cannot success. The #python channel always works for me. The best place to ask for help is to do what it says in the message you were given ... "For more information about registering on Freenode, ask #freenode. " Have you asked for help in the #freenode channel? /join #freenode and ask there, no registration is required to do that. Be sure to communicate in short, clear sentences. Then wait for someone to answer you. Do not leave the channel after asking for help, wait for at least an hour. Any person might answer you, and sometimes random people there make mischief. But the people who are "ops" in that channel are freenode staff. They will help you and they have admin powers. Sometimes depending on time of day or day of week the staff might be absent. If so, just wait a few hours and try again. From pengyu.ut at gmail.com Mon Aug 12 23:38:33 2019 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 12 Aug 2019 22:38:33 -0500 Subject: How to load cookies from a json input in python-requests? Message-ID: ``` import requests s = requests.Session() import json s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin))) ``` I used the above command to load cookies from a json file. But I got the following error. Does anybody know how to fix the error? Thanks. ``` Traceback (most recent call last): File "/xxx/xxx.py", line 15, in s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin))) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/cookies.py", line 345, in set_cookie if hasattr(cookie.value, 'startswith') and cookie.value.startswith('"') and cookie.value.endswith('"'): AttributeError: 'RequestsCookieJar' object has no attribute 'value' ``` -- Regards, Peng From abrault at mapgears.com Tue Aug 13 01:19:38 2019 From: abrault at mapgears.com (Alexandre Brault) Date: Tue, 13 Aug 2019 01:19:38 -0400 Subject: How to load cookies from a json input in python-requests? In-Reply-To: References: Message-ID: On 2019-08-12 11:38 p.m., Peng Yu wrote: > ``` > import requests > s = requests.Session() > import json > s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin))) > ``` > > I used the above command to load cookies from a json file. But I got > the following error. Does anybody know how to fix the error? Thanks. > > ``` > Traceback (most recent call last): > File "/xxx/xxx.py", line 15, in > s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin))) > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/cookies.py", > line 345, in set_cookie > if hasattr(cookie.value, 'startswith') and > cookie.value.startswith('"') and cookie.value.endswith('"'): > AttributeError: 'RequestsCookieJar' object has no attribute 'value' > ``` set_cookie is used to add an individual cookie in an existing cookiejar. You might want to have a look at requests.utils.add_dict_to_cookiejar(s.cookies, json.load(...)) or passing the result of requests.utils.cookiejar_from_dict ti the cookies argument of requests.Session From PythonList at DancesWithMice.info Tue Aug 13 05:36:25 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 13 Aug 2019 21:36:25 +1200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> On 13/08/19 10:01 AM, Morten W. Petersen wrote: > On 12.08.2019 18:13, Brian Oney wrote: >> On August 12, 2019 9:14:55 AM GMT+02:00, morphex >> wrote: >>> Hi. >>> What frameworks are there for generating static web pages in Python? >> I have used: >> https://github.com/Frozen-Flask/Frozen-Flask >> It's pretty simple. Develop with flask and then "freeze" it. >> >> I am looking forward to further answers. > > OK, so now I know Flask can freeze applications. With Zope and Plone, I > have a lot of what I need in terms of web application development. > > What I guess I'm looking for, is something that will help create a > static website, in a simple and efficient manner.? Without being bloated. Which have you examined and rejected/like? > I don't have a lot of hair on my head, but I would be pulling it out > because of some of the websites I see today, their heavy-handed use of > different Javascript frameworks etc. True! > How would I go about creating a simple website with a front page, an > about page, a product page and a contact page?? Without any server-side > handling of data, so it could be entirely served by for example Apache. There are a thousand and one web-sites and training courses which discuss these topics! > And with it having well-formed XHTML, proper CSS, little Javascript, > scaling to different screen and web browsers (wow, it's been so long I > forgot it was called responsive design) and so on, being a nice little > package. Don't even think about XHTML. HTML5! Yes, "responsive". As said, there's plenty 'out there'. Today's InBox included reference to <<>> https://github.com/getpelican It seems they make good use of a number of Python features, which will presumably reduce learning-time for Pythonista! -- Regards =dn From morphex at gmail.com Tue Aug 13 06:44:28 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 12:44:28 +0200 Subject: Web framework for static pages In-Reply-To: <20190812222955.GA6382@cskk.homeip.net> References: <20190812222955.GA6382@cskk.homeip.net> Message-ID: Right. That was a useful term, I've got some things to look at there. -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 00.29 skrev Cameron Simpson : > On 13Aug2019 00:01, Morten W. Petersen wrote: > >What I guess I'm looking for, is something that will help create a > >static website, in a simple and efficient manner. Without being > >bloated. > > > >I don't have a lot of hair on my head, but I would be pulling it out > >because of some of the websites I see today, their heavy-handed use of > >different Javascript frameworks etc. > > > >How would I go about creating a simple website with a front page, an > >about page, a product page and a contact page? Without any > >server-side handling of data, so it could be entirely served by for > >example Apache. > > > >And with it having well-formed XHTML, proper CSS, little Javascript, > >scaling to different screen and web browsers (wow, it's been so long I > >forgot it was called responsive design) and so on, being a nice little > >package. > > The common search term is "static site generator". There are several out > there. I haven't any experience with which to offer an opinion though. > > Cheers, > Cameron Simpson > From morphex at gmail.com Tue Aug 13 06:49:24 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 12:49:24 +0200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: Yes. Well, one of the ideas of the web is being able to create a website using simple tools like that. And I like that idea. And for one site, either small or very specialized and well-funded, that would be an OK choice. However, I want to offer customers websites that cover their needs, without costing too much. Also, apart from taking a lot of time, manually changing different websites using a text editor is tedious and error-prone. -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 02.17 skrev Jon Ribbens via Python-list < python-list at python.org>: > On 2019-08-12, Morten W. Petersen wrote: > > What I guess I'm looking for, is something that will help create a > > static website, in a simple and efficient manner. Without being bloated. > > > > I don't have a lot of hair on my head, but I would be pulling it out > > because of some of the websites I see today, their heavy-handed use of > > different Javascript frameworks etc. > > > > How would I go about creating a simple website with a front page, an > > about page, a product page and a contact page? Without any server-side > > handling of data, so it could be entirely served by for example Apache. > > If it's really that small then it sounds like what you are looking for > is known as a "text editor". > -- > https://mail.python.org/mailman/listinfo/python-list > From morphex at gmail.com Tue Aug 13 06:54:24 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 12:54:24 +0200 Subject: Web framework for static pages In-Reply-To: <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: I was hoping to avoid testing a lot of different systems, spending time there. So that's why I'm asking here. I don't need a guide to create a website, maybe a refresher on some topics. Ideally I'd want a static site generator that makes it easy and quick to create a website which is pretty, accessible, works across browsers and standards compliant and doesn't freeze the browser on a low-end phone. And where it is easy to override using for example plain or template HTML, or extend programmatic features using some plugins or just subclassing. Do you know of a XML DTD for HTML5 by the way? -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 11.39 skrev DL Neil : > On 13/08/19 10:01 AM, Morten W. Petersen wrote: > > On 12.08.2019 18:13, Brian Oney wrote: > >> On August 12, 2019 9:14:55 AM GMT+02:00, morphex > >> wrote: > >>> Hi. > >>> What frameworks are there for generating static web pages in Python? > >> I have used: > >> https://github.com/Frozen-Flask/Frozen-Flask > >> It's pretty simple. Develop with flask and then "freeze" it. > >> > >> I am looking forward to further answers. > > > > OK, so now I know Flask can freeze applications. With Zope and Plone, I > > have a lot of what I need in terms of web application development. > > > > What I guess I'm looking for, is something that will help create a > > static website, in a simple and efficient manner. Without being bloated. > > Which have you examined and rejected/like? > > > > I don't have a lot of hair on my head, but I would be pulling it out > > because of some of the websites I see today, their heavy-handed use of > > different Javascript frameworks etc. > > True! > > > > How would I go about creating a simple website with a front page, an > > about page, a product page and a contact page? Without any server-side > > handling of data, so it could be entirely served by for example Apache. > > There are a thousand and one web-sites and training courses which > discuss these topics! > > > > And with it having well-formed XHTML, proper CSS, little Javascript, > > scaling to different screen and web browsers (wow, it's been so long I > > forgot it was called responsive design) and so on, being a nice little > > package. > > Don't even think about XHTML. HTML5! > > Yes, "responsive". > > > As said, there's plenty 'out there'. Today's InBox included reference to > << Static site generator that supports Markdown and reST syntax. Powered by > Python.>>> > https://github.com/getpelican > > It seems they make good use of a number of Python features, which will > presumably reduce learning-time for Pythonista! > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From jon+usenet at unequivocal.eu Tue Aug 13 08:29:05 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 13 Aug 2019 12:29:05 -0000 (UTC) Subject: Web framework for static pages References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: On 2019-08-13, Morten W. Petersen wrote: > Ideally I'd want a static site generator that makes it easy and quick to > create a website which is pretty, accessible, works across browsers and > standards compliant and doesn't freeze the browser on a low-end phone. That isn't what they do. All those requirements are to do with the HTML templates that you use for the site, regardless of whether it's a static or dynamic site. > Do you know of a XML DTD for HTML5 by the way? There isn't one. However I would very strongly recommend NOT using XHTML. Nobody uses XHTML and no browsers support it except inasmuch as they parse it by pretending it's HTML. Just use the HTML representation of HTML 5. I think the most commonly-used static site generator is probably Jekyll. It's in Ruby but that's basically irrelevant unless you're a Jekyll developer - as a user you just use the Liquid templating system, which is more-or-less identical to Django's. From cspealma at redhat.com Tue Aug 13 08:53:54 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Tue, 13 Aug 2019 08:53:54 -0400 Subject: About the #python irc channel on freenode. In-Reply-To: References: <87ftm6ou3e.fsf@nightsong.com> Message-ID: The #python channel only allows registered Freenode users in. You can learn about registration on Freenode here: https://freenode.net/kb/answer/registration Once you've got a registered account you can join #python and should find many helpful people ready to help you. On Mon, Aug 12, 2019 at 8:00 PM Hongyi Zhao wrote: > On Mon, 12 Aug 2019 16:13:41 -0700, Paul Rubin wrote: > > > It's always worked ok for me. > > But I always be put into the #python-unregistered channel as follows: > > ---------- > Now talking on #python-unregistered > * Topic for #python-unregistered is: Welcome to #python-unregistered! > You've been put here because #python requires you to register your > nickname with Freenode. For more information about registering on > Freenode, ask #freenode. For more information about #python,#python-* > moderation, #python-ops. > * Topic for #python-unregistered set by lvh!~lvh at python/psf/lvh (Fri Jul > 1 16:44:19 2011) > ------------- > > I've tried to register the nickname as it told. But still cannot success. > > Regards > -- > .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From larry.martell at gmail.com Tue Aug 13 09:30:56 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 13 Aug 2019 09:30:56 -0400 Subject: MySQLdb for 3.6 on RHEL7 Message-ID: I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) for python3.6 on RHEL7. When I import it, it fails: # python3.6 Python 3.6.8 (default, Jun 11 2019, 15:15:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb Traceback (most recent call last): File "", line 1, in File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", line 18, in from . import _mysql ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: undefined symbol: mysql_kill Has anyone seen and resolved this? From songofacandy at gmail.com Tue Aug 13 09:42:54 2019 From: songofacandy at gmail.com (Inada Naoki) Date: Tue, 13 Aug 2019 22:42:54 +0900 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: Why do you use RHEL? I believe people use RHEL to get support from Red Hat, instead of community support. 2019?8?13?(?) 22:32 Larry Martell : > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) > for python3.6 on RHEL7. > > When I import it, it fails: > > # python3.6 > Python 3.6.8 (default, Jun 11 2019, 15:15:01) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import MySQLdb > Traceback (most recent call last): > File "", line 1, in > File > "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", > line 18, in > from . import _mysql > ImportError: > /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_ > mysql.cpython-36m-x86_64-linux-gnu.so: > undefined symbol: mysql_kill > > Has anyone seen and resolved this? > -- > https://mail.python.org/mailman/listinfo/python-list > From larry.martell at gmail.com Tue Aug 13 09:53:08 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 13 Aug 2019 09:53:08 -0400 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Tue, Aug 13, 2019 at 9:43 AM Inada Naoki wrote: > > Why do you use RHEL? That is not my choice. > I believe people use RHEL to get support from Red Hat, instead of community support. I do not believe Red Hat supports this package. > > 2019?8?13?(?) 22:32 Larry Martell : >> >> I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) >> for python3.6 on RHEL7. >> >> When I import it, it fails: >> >> # python3.6 >> Python 3.6.8 (default, Jun 11 2019, 15:15:01) >> [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import MySQLdb >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", >> line 18, in >> from . import _mysql >> ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: >> undefined symbol: mysql_kill >> >> Has anyone seen and resolved this? >> -- >> https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Aug 13 09:58:06 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Aug 2019 23:58:06 +1000 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Tue, Aug 13, 2019 at 11:33 PM Larry Martell wrote: > > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) > for python3.6 on RHEL7. > > When I import it, it fails: > > # python3.6 > Python 3.6.8 (default, Jun 11 2019, 15:15:01) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import MySQLdb > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", > line 18, in > from . import _mysql > ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: > undefined symbol: mysql_kill > > Has anyone seen and resolved this? Not specifically, but that looks like a versioning conflict. Most likely, your mysqlclient is too old for MySQLdb to connect to. Did you get one of them from your system package manager and the other from pip? If so, try to get both from the same place. ChrisA From morphex at gmail.com Tue Aug 13 10:00:30 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 16:00:30 +0200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: Ok. Isn't it a bit splitting of hairs to talk about static site generators and their templates? Wouldn't a static site generator that can create a good, usable website with little input be desirable? I could pick and choose CSS templates, HTML templates and write some of my own, but that takes quite a bit of time. Yes, my fixation on XML HTML might be a bit purist or perfectionist, but isn't it strange that there isn't a DTD for XML HTML 5? Is it the ability to write websites using a text editor only what makes web companies continue the malformed input cycle, or is it legacy websites? -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 14.32 skrev Jon Ribbens via Python-list < python-list at python.org>: > On 2019-08-13, Morten W. Petersen wrote: > > Ideally I'd want a static site generator that makes it easy and quick to > > create a website which is pretty, accessible, works across browsers and > > standards compliant and doesn't freeze the browser on a low-end phone. > > That isn't what they do. All those requirements are to do with the > HTML templates that you use for the site, regardless of whether it's > a static or dynamic site. > > > Do you know of a XML DTD for HTML5 by the way? > > There isn't one. However I would very strongly recommend NOT using > XHTML. Nobody uses XHTML and no browsers support it except inasmuch > as they parse it by pretending it's HTML. Just use the HTML > representation of HTML 5. > > I think the most commonly-used static site generator is probably > Jekyll. It's in Ruby but that's basically irrelevant unless you're > a Jekyll developer - as a user you just use the Liquid templating > system, which is more-or-less identical to Django's. > -- > https://mail.python.org/mailman/listinfo/python-list > From morphex at gmail.com Tue Aug 13 10:01:10 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 16:01:10 +0200 Subject: Web framework for static pages In-Reply-To: <16649B00-709C-4E24-BE0B-B7C02EA82A7D@mostrom.pp.se> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> <16649B00-709C-4E24-BE0B-B7C02EA82A7D@mostrom.pp.se> Message-ID: Ok, will take a look at those. -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 14.39 skrev Jan Erik Mostr?m : > On 13 Aug 2019, at 12:54, Morten W. Petersen wrote: > > > I was hoping to avoid testing a lot of different systems, spending time > > there. > > Depending on your needs I would look at Hugo or Pelican > > = jem > From grant.b.edwards at gmail.com Tue Aug 13 10:26:18 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 13 Aug 2019 14:26:18 -0000 (UTC) Subject: Web framework for static pages References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: On 2019-08-13, Jon Ribbens via Python-list wrote: > If it's really that small then it sounds like what you are looking for > is known as a "text editor". Bah. Kids these days. $ cat > index.hmtl -- Grant Edwards grant.b.edwards Yow! My vaseline is at RUNNING... gmail.com From imsophyguo at gmail.com Tue Aug 13 07:58:06 2019 From: imsophyguo at gmail.com (Sophy Guo) Date: Tue, 13 Aug 2019 12:58:06 +0100 Subject: Research Invitation for OSS Community. Many thanks! Message-ID: Dear Python Community Members, I am a master student based in the University of Leeds (UK), currently conducting a research in regards to investigating how open source software community culture, governance and structure, motivation of participation influence the innovation capability of OSS community. I found Python community is very active and supportive with members around the world, which makes it perfect for this research. I am writing to ask if you could help to take part in this research for more accurate results. This research data is to be collected via questionnaire with the anonymous link below: https://leedsubs.eu.qualtrics.com/jfe/form/SV_cUPSObEbxQqEX1b The questionnaire should take you 5-10 minutes to complete. Your participation is very important to disclose the relationship between community culture, governance structure, motivation of participation and the innovation capability of OSS community. I would very much appreciate if you could help to participate this research, and if you have any questions about the research, I am happy to answer, just e-mail me on bn18xg at leeds.ac.uk. Thanks a lot! Best Regards, Sophy Guo From vinayakgopakumar36 at gmail.com Tue Aug 13 09:35:38 2019 From: vinayakgopakumar36 at gmail.com (Vinayak Gopakumar) Date: Tue, 13 Aug 2019 19:05:38 +0530 Subject: Fwd: Startup problems In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Vinayak Gopakumar Date: Tue, Aug 13, 2019 at 5:53 AM Subject: Startup problems To: dear developer, I'm having problems while starting IDLE 3.7.4. With this problem, I cannot finish my studies properly. The screenshot of the problem is attached to this mail. I hope that you would provide assistance for me for recovering the above-said problem From morphex at gmail.com Tue Aug 13 10:30:34 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 16:30:34 +0200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: HMTL? Good you weren't in cat input after a newline. ? -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 16.28 skrev Grant Edwards : > On 2019-08-13, Jon Ribbens via Python-list wrote: > > > If it's really that small then it sounds like what you are looking for > > is known as a "text editor". > > Bah. Kids these days. > > $ cat > index.hmtl > > -- > Grant Edwards grant.b.edwards Yow! My vaseline is > at RUNNING... > gmail.com > > -- > https://mail.python.org/mailman/listinfo/python-list > From jon+usenet at unequivocal.eu Tue Aug 13 11:19:58 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 13 Aug 2019 15:19:58 -0000 (UTC) Subject: Web framework for static pages References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: On 2019-08-13, Morten W. Petersen wrote: > Ok. Isn't it a bit splitting of hairs to talk about static site generators > and their templates? No, not even slightly. You appear to be thinking that static site generators come with a pre-made set of design templates, and as far as I am aware they generally do not. > Wouldn't a static site generator that can create a good, usable website > with little input be desirable? That's the purpose of all of them I should imagine. > I could pick and choose CSS templates, HTML templates and write some of my > own, but that takes quite a bit of time. It's time you need to spend. Otherwise, use Wordpress, optionally with a static site generator plugin. > Yes, my fixation on XML HTML might be a bit purist or perfectionist, but > isn't it strange that there isn't a DTD for XML HTML 5? Is it the ability > to write websites using a text editor only what makes web companies > continue the malformed input cycle, or is it legacy websites? I'm not sure why you think that using XML is in any way "pure" or "perfect", nor why not using XML means your input is "malformed". Just use HTML 5, and indeed you should check your code to ensure it is pure, perfect and well-formed. From larry.martell at gmail.com Tue Aug 13 11:48:00 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 13 Aug 2019 11:48:00 -0400 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico wrote: > > On Tue, Aug 13, 2019 at 11:33 PM Larry Martell wrote: > > > > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) > > for python3.6 on RHEL7. > > > > When I import it, it fails: > > > > # python3.6 > > Python 3.6.8 (default, Jun 11 2019, 15:15:01) > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import MySQLdb > > Traceback (most recent call last): > > File "", line 1, in > > File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", > > line 18, in > > from . import _mysql > > ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: > > undefined symbol: mysql_kill > > > > Has anyone seen and resolved this? > > Not specifically, but that looks like a versioning conflict. Most > likely, your mysqlclient is too old for MySQLdb to connect to. > > Did you get one of them from your system package manager and the other > from pip? If so, try to get both from the same place. So I have MySQL from the system package manager, but mysqlclient is not available there. And I was not able to get that from pip either, as the install failed. I had to download the source, edit the site.cfg file and build it. But I just found python36-mysql.x86_64 as a package so I uninstalled mysqlclient and installed that from the repo. That did not get the above error, but now I get this: raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__) django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 1.3.12. From brian.j.oney at googlemail.com Tue Aug 13 12:02:16 2019 From: brian.j.oney at googlemail.com (Brian Oney) Date: Tue, 13 Aug 2019 18:02:16 +0200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: On August 13, 2019 4:00:30 PM GMT+02:00, "Morten W. Petersen" wrote: >Ok. Isn't it a bit splitting of hairs to talk about static site >generators >and their templates? > >Wouldn't a static site generator that can create a good, usable website >with little input be desirable? > >I could pick and choose CSS templates, HTML templates and write some of >my >own, but that takes quite a bit of time. > >Yes, my fixation on XML HTML might be a bit purist or perfectionist, >but >isn't it strange that there isn't a DTD for XML HTML 5? Is it the >ability >to write websites using a text editor only what makes web companies >continue the malformed input cycle, or is it legacy websites? > >-Morten It's all text. Or do you have a better suggestion? What is wrong with templates? From rosuav at gmail.com Tue Aug 13 14:14:46 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 04:14:46 +1000 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Wed, Aug 14, 2019 at 1:48 AM Larry Martell wrote: > > On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico wrote: > > > > On Tue, Aug 13, 2019 at 11:33 PM Larry Martell wrote: > > > > > > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) > > > for python3.6 on RHEL7. > > > > > > When I import it, it fails: > > > > > > # python3.6 > > > Python 3.6.8 (default, Jun 11 2019, 15:15:01) > > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux > > > Type "help", "copyright", "credits" or "license" for more information. > > > >>> import MySQLdb > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", > > > line 18, in > > > from . import _mysql > > > ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: > > > undefined symbol: mysql_kill > > > > > > Has anyone seen and resolved this? > > > > Not specifically, but that looks like a versioning conflict. Most > > likely, your mysqlclient is too old for MySQLdb to connect to. > > > > Did you get one of them from your system package manager and the other > > from pip? If so, try to get both from the same place. > > So I have MySQL from the system package manager, but mysqlclient is > not available there. That seems very odd. The mysqlclient binary might be just under a different name? I'm not familiar with RHEL, but on my Debian, there are packages like "mysql-server-5.7" and corresponding "mysql-client-5.7". Or do you mean the Python client? > And I was not able to get that from pip either, > as the install failed. I had to download the source, edit the site.cfg > file and build it. But I just found python36-mysql.x86_64 as a package > so I uninstalled mysqlclient and installed that from the repo. Based on this, I'm thinking possibly you meant the Python client. It may still be that you need to install the C client for the Python one to connect to. Although.... if you got python36-mysql from your system repo, that ought to drag in the appropriate mysqlclient. So now I'm very confused. > That did not get the above error, but now I get this: > > raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is > required; you have %s.' % Database.__version__) > django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or > newer is required; you have 1.3.12. This claims to be a Django error, though, so maybe the issue here isn't with MySQLdb but with Django?? Maybe everything up above is actually correctly matched, but too old? ChrisA From PythonList at DancesWithMice.info Tue Aug 13 14:44:27 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 14 Aug 2019 06:44:27 +1200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> Message-ID: <3f858b22-8bc5-a93b-1ac2-1c38e246277e@DancesWithMice.info> On 14/08/19 2:26 AM, Grant Edwards wrote: > On 2019-08-13, Jon Ribbens via Python-list wrote: > >> If it's really that small then it sounds like what you are looking for >> is known as a "text editor". > > Bah. Kids these days. > > $ cat > index.hmtl [roaring with laughter] Oh come now. Surely a person with your depth of experience realises that all cats have moved to Facebook and YouTube, leaving their HTML in yesterday's litter box? -- Regards =dn From dboland9 at protonmail.com Tue Aug 13 14:42:51 2019 From: dboland9 at protonmail.com (Dave) Date: Tue, 13 Aug 2019 14:42:51 -0400 Subject: Create multiple sqlite tables, many-to-many design Message-ID: Oops! Just posted this to the wrong newsgroup. Sorry!!! ------------------------------------------------------------ I'm doing a Python app that uses SQLite, and am stumbling on a few questions. I've read a lot of books and documentation, but two questions still allude me. Hope someone that been there done this can help. Below is a note I sent to the SQLite mailing list yesterday. So far, nothing. Need to get going, so many thanks! I'm doing an app. that uses sqlite, and has a many-to-many relationship. The areas I need some guidance are: * Best way to create multiple tables the first time the app. is started. * How to create a MTM relationship and add/modify data. I can create tables (Python) by putting the code in discrete functions for each table and passing just the path to the database. I can also create a calling function that gets a connection and passes that. What is the pro-con of each since each seems to work? Better ideas? Some of the tables are related. For example: Hiking_Table Trails_Table Joining_Table ----------------- -------------------- ----------------- hike_id PK trail_id PK hike_id FK hike_date TEXT trail_name TEXT trail_id FK hike_destination TEXT trail_rating REAL hike_rating REAL trail_comments TEXT hike_comments TEXT So far, so good. I know how to create the tables. What I am struggling with is how do I insert data into the joining table or don"t I? If so, do I need to query the other two tables to get the auto-number ID's? Some things I have read suggest that the joining table just contains references, so there is no actual insert. A pointer to information how to do this would be appreciated. As for queries, I think I use joins, but a pointer on how to do this would also be appreciated. Thanks, Dave From rosuav at gmail.com Tue Aug 13 14:59:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 04:59:42 +1000 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: Message-ID: On Wed, Aug 14, 2019 at 4:50 AM Dave via Python-list wrote: > Some of the tables are related. For example: > > Hiking_Table Trails_Table Joining_Table > ----------------- -------------------- ----------------- > hike_id PK trail_id PK hike_id FK > hike_date TEXT trail_name TEXT trail_id FK > hike_destination TEXT trail_rating REAL > hike_rating REAL trail_comments TEXT > hike_comments TEXT > > So far, so good. I know how to create the tables. What I am struggling > with is how do I insert data into the joining table or don"t I? If so, > do I need to query the other two tables to get the auto-number ID's? > Some things I have read suggest that the joining table just contains > references, so there is no actual insert. A pointer to information how > to do this would be appreciated. As for queries, I think I use joins, > but a pointer on how to do this would also be appreciated. The joining table is a real thing, and will have real inserts. It might be easier to think of this as two separate one-to-many relationships; for the sake of demonstration, I'm going to add another column to your joining table. hike_sections ==> hike_id references hikes, trail_id references trails, companion_name You've decided to have someone with you for some sections of your hike. As such, what we have is a number of "mini-hikes" that make up a single hike (that's a one-to-many relationship between hikes and sections), and also a single trail can be a section of any number of hikes (so, another one-to-many relationship between trails and sections). For any given section, there is exactly one companion. Does this make the many-to-many relationship a bit easier to understand? It'll work exactly the same way even if you have no ancillary information in that joining table. ChrisA From joel.goldstick at gmail.com Tue Aug 13 15:05:05 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 13 Aug 2019 15:05:05 -0400 Subject: Web framework for static pages In-Reply-To: <3f858b22-8bc5-a93b-1ac2-1c38e246277e@DancesWithMice.info> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <3f858b22-8bc5-a93b-1ac2-1c38e246277e@DancesWithMice.info> Message-ID: On Tue, Aug 13, 2019 at 2:46 PM DL Neil wrote: > > On 14/08/19 2:26 AM, Grant Edwards wrote: > > On 2019-08-13, Jon Ribbens via Python-list wrote: > > > >> If it's really that small then it sounds like what you are looking for > >> is known as a "text editor". > > > > Bah. Kids these days. > > > > $ cat > index.hmtl > > [roaring with laughter] > > > > Oh come now. Surely a person with your depth of experience realises that > all cats have moved to Facebook and YouTube, leaving their HTML in > yesterday's litter box? > > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list pardon my drive by comment, but this is close to trolling. Whatever is offered is shot down. XHTML seems to have been a road that went nowhere because the browser makers didn't like it. HTML5 seemed to be a big step forward. I used a program called Citydesk a long time ago that I think could do what the op might like. But its long gone. I think django could be used to make static pages quite easily. Its not hard to learn, and in the event your client wants more, django can do that too -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From larry.martell at gmail.com Tue Aug 13 15:05:42 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 13 Aug 2019 15:05:42 -0400 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Tue, Aug 13, 2019 at 2:16 PM Chris Angelico wrote: > > On Wed, Aug 14, 2019 at 1:48 AM Larry Martell wrote: > > > > On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico wrote: > > > > > > On Tue, Aug 13, 2019 at 11:33 PM Larry Martell wrote: > > > > > > > > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) > > > > for python3.6 on RHEL7. > > > > > > > > When I import it, it fails: > > > > > > > > # python3.6 > > > > Python 3.6.8 (default, Jun 11 2019, 15:15:01) > > > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux > > > > Type "help", "copyright", "credits" or "license" for more information. > > > > >>> import MySQLdb > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > File "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py", > > > > line 18, in > > > > from . import _mysql > > > > ImportError: /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so: > > > > undefined symbol: mysql_kill > > > > > > > > Has anyone seen and resolved this? > > > > > > Not specifically, but that looks like a versioning conflict. Most > > > likely, your mysqlclient is too old for MySQLdb to connect to. > > > > > > Did you get one of them from your system package manager and the other > > > from pip? If so, try to get both from the same place. > > > > So I have MySQL from the system package manager, but mysqlclient is > > not available there. > > That seems very odd. The mysqlclient binary might be just under a > different name? I'm not familiar with RHEL, but on my Debian, there > are packages like "mysql-server-5.7" and corresponding > "mysql-client-5.7". Or do you mean the Python client? Yes, the python client, which is called mysqlclient but imported as MySQLdb (https://pypi.org/project/mysqlclient/). > > And I was not able to get that from pip either, > > as the install failed. I had to download the source, edit the site.cfg > > file and build it. But I just found python36-mysql.x86_64 as a package > > so I uninstalled mysqlclient and installed that from the repo. The reason that would not install from pip was because the path to mysql_config was not correct in site.cfg - once I changed that I was able to build it, but then it gave the other error. > Based on this, I'm thinking possibly you meant the Python client. It > may still be that you need to install the C client for the Python one > to connect to. Although.... if you got python36-mysql from your system > repo, that ought to drag in the appropriate mysqlclient. So now I'm > very confused. > > > That did not get the above error, but now I get this: > > > > raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is > > required; you have %s.' % Database.__version__) > > django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or > > newer is required; you have 1.3.12. > > This claims to be a Django error, though, so maybe the issue here > isn't with MySQLdb but with Django?? Maybe everything up above is > actually correctly matched, but too old? I got around that by changing the code in django to not require that version. From morphex at gmail.com Tue Aug 13 16:12:15 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Tue, 13 Aug 2019 22:12:15 +0200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <3f858b22-8bc5-a93b-1ac2-1c38e246277e@DancesWithMice.info> Message-ID: Hi Joel. I don't disagree with what you're saying, but is there a documented way of making Django produce a neat set of static pages? It would be nice to use a web application framework to create pages, because it would after that be easy to add a little bit of logic if a customer wants it. A contact form, an order form, etc. Zope/Plone has its own set of features and applications I know well, if a customer wants a dynamic website with a lot of logic (dynamic pages). -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx tir. 13. aug. 2019, 21.08 skrev Joel Goldstick : > On Tue, Aug 13, 2019 at 2:46 PM DL Neil > wrote: > > > > On 14/08/19 2:26 AM, Grant Edwards wrote: > > > On 2019-08-13, Jon Ribbens via Python-list > wrote: > > > > > >> If it's really that small then it sounds like what you are looking for > > >> is known as a "text editor". > > > > > > Bah. Kids these days. > > > > > > $ cat > index.hmtl > > > > [roaring with laughter] > > > > > > > > Oh come now. Surely a person with your depth of experience realises that > > all cats have moved to Facebook and YouTube, leaving their HTML in > > yesterday's litter box? > > > > -- > > Regards =dn > > -- > > https://mail.python.org/mailman/listinfo/python-list > > pardon my drive by comment, but this is close to trolling. Whatever > is offered is shot down. XHTML seems to have been a road that went > nowhere because the browser makers didn't like it. HTML5 seemed to be > a big step forward. I used a program called Citydesk a long time ago > that I think could do what the op might like. But its long gone. I > think django could be used to make static pages quite easily. Its not > hard to learn, and in the event your client wants more, django can do > that too > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > -- > https://mail.python.org/mailman/listinfo/python-list > From joel.goldstick at gmail.com Tue Aug 13 16:28:06 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 13 Aug 2019 16:28:06 -0400 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <3f858b22-8bc5-a93b-1ac2-1c38e246277e@DancesWithMice.info> Message-ID: On Tue, Aug 13, 2019 at 4:12 PM Morten W. Petersen wrote: > > Hi Joel. > > I don't disagree with what you're saying, but is there a documented way of making Django produce a neat set of static pages? > > It would be nice to use a web application framework to create pages, because it would after that be easy to add a little bit of logic if a customer wants it. A contact form, an order form, etc. Django has a feature called static pages.. I'm not up to the latest, but check that you. Perhaps it will work for you > > Zope/Plone has its own set of features and applications I know well, if a customer wants a dynamic website with a lot of logic (dynamic pages). > > -Morten > > Blogging at http://blogologue.com > Tweeting at https://twitter.com/blogologue > On Instagram https://instagram.com/morphexx > > tir. 13. aug. 2019, 21.08 skrev Joel Goldstick : >> >> On Tue, Aug 13, 2019 at 2:46 PM DL Neil wrote: >> > >> > On 14/08/19 2:26 AM, Grant Edwards wrote: >> > > On 2019-08-13, Jon Ribbens via Python-list wrote: >> > > >> > >> If it's really that small then it sounds like what you are looking for >> > >> is known as a "text editor". >> > > >> > > Bah. Kids these days. >> > > >> > > $ cat > index.hmtl >> > >> > [roaring with laughter] >> > >> > >> > >> > Oh come now. Surely a person with your depth of experience realises that >> > all cats have moved to Facebook and YouTube, leaving their HTML in >> > yesterday's litter box? >> > >> > -- >> > Regards =dn >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> pardon my drive by comment, but this is close to trolling. Whatever >> is offered is shot down. XHTML seems to have been a road that went >> nowhere because the browser makers didn't like it. HTML5 seemed to be >> a big step forward. I used a program called Citydesk a long time ago >> that I think could do what the op might like. But its long gone. I >> think django could be used to make static pages quite easily. Its not >> hard to learn, and in the event your client wants more, django can do >> that too >> >> -- >> Joel Goldstick >> http://joelgoldstick.com/blog >> http://cc-baseballstats.info/stats/birthdays >> -- >> https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From moevyas at gmail.com Tue Aug 13 15:31:53 2019 From: moevyas at gmail.com (Moe Vyas) Date: Tue, 13 Aug 2019 15:31:53 -0400 Subject: Opening Python 3.8 in Visual Studio 2019 Message-ID: Greetings. Can anyone please, tell me how to open Python 3.8 Interpreter in the Visual Studio 2019. I have downloaded both of these on my Windows laptop and now am struggling to make them work together!!? Thanks in advance. *Regards* *Moe Vyas* From python at mrabarnett.plus.com Tue Aug 13 16:45:29 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Aug 2019 21:45:29 +0100 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: Message-ID: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> On 2019-08-13 19:59, Chris Angelico wrote: > On Wed, Aug 14, 2019 at 4:50 AM Dave via Python-list > wrote: >> Some of the tables are related. For example: >> >> Hiking_Table Trails_Table Joining_Table >> ----------------- -------------------- ----------------- >> hike_id PK trail_id PK hike_id FK >> hike_date TEXT trail_name TEXT trail_id FK >> hike_destination TEXT trail_rating REAL >> hike_rating REAL trail_comments TEXT >> hike_comments TEXT >> >> So far, so good. I know how to create the tables. What I am struggling >> with is how do I insert data into the joining table or don"t I? If so, >> do I need to query the other two tables to get the auto-number ID's? >> Some things I have read suggest that the joining table just contains >> references, so there is no actual insert. A pointer to information how >> to do this would be appreciated. As for queries, I think I use joins, >> but a pointer on how to do this would also be appreciated. > > The joining table is a real thing, and will have real inserts. It > might be easier to think of this as two separate one-to-many > relationships; for the sake of demonstration, I'm going to add another > column to your joining table. > > hike_sections ==> hike_id references hikes, trail_id references > trails, companion_name > > You've decided to have someone with you for some sections of your > hike. As such, what we have is a number of "mini-hikes" that make up a > single hike (that's a one-to-many relationship between hikes and > sections), and also a single trail can be a section of any number of > hikes (so, another one-to-many relationship between trails and > sections). For any given section, there is exactly one companion. > > Does this make the many-to-many relationship a bit easier to > understand? It'll work exactly the same way even if you have no > ancillary information in that joining table. > Might I also suggest dropping unnecessary prefixes from the field names. For example, "hike_comments" in "Hiking_Table" can be called just "comments" because it's clear from the context that a field called "comments" in the hiking table will contain comments about hiking, if you see what I mean. From dboland9 at protonmail.com Tue Aug 13 17:11:56 2019 From: dboland9 at protonmail.com (Dave) Date: Tue, 13 Aug 2019 17:11:56 -0400 Subject: Create multiple sqlite tables, many-to-many design References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On 8/13/19 4:45 PM, MRAB wrote: > On 2019-08-13 19:59, Chris Angelico wrote: >> On Wed, Aug 14, 2019 at 4:50 AM Dave via Python-list >> wrote: >>> Some of the tables are related.? For example: >>> >>> Hiking_Table???????????? Trails_Table??????????? Joining_Table >>> -----------------??????? --------------------??? ----------------- >>> hike_id???? PK?????????? trail_id? PK??????????? hike_id?? FK >>> hike_date? TEXT????????? trail_name? TEXT??????? trail_id?? FK >>> hike_destination TEXT??? trail_rating REAL >>> hike_rating? REAL??????? trail_comments TEXT >>> hike_comments? TEXT >>> >>> So far, so good.? I know how to create the tables.? What I am struggling >>> with is how do I insert data into the joining table or don"t I?? If so, >>> do I need to query the other two tables to get the auto-number ID's? >>> Some things I have read suggest that the joining table just contains >>> references, so there is no actual insert.? A pointer to information how >>> to do this would be appreciated.? As for queries, I think I use joins, >>> but a pointer on how to do this would also be appreciated. >> >> The joining table is a real thing, and will have real inserts. It >> might be easier to think of this as two separate one-to-many >> relationships; for the sake of demonstration, I'm going to add another >> column to your joining table. >> >> hike_sections ==> hike_id references hikes, trail_id references >> trails, companion_name >> >> You've decided to have someone with you for some sections of your >> hike. As such, what we have is a number of "mini-hikes" that make up a >> single hike (that's a one-to-many relationship between hikes and >> sections), and also a single trail can be a section of any number of >> hikes (so, another one-to-many relationship between trails and >> sections). For any given section, there is exactly one companion. >> >> Does this make the many-to-many relationship a bit easier to >> understand? It'll work exactly the same way even if you have no >> ancillary information in that joining table. >> > Might I also suggest dropping unnecessary prefixes from the field names. > For example, "hike_comments" in "Hiking_Table" can be called just > "comments" because it's clear from the context that a field called > "comments" in the hiking table will contain comments about hiking, if > you see what I mean. I do indeed. I did that so it was easy for everyone to follow. Having started with assm. and C, I have to remind myself to be more explanatory in naming. Guess I over-did it. The actual code is different. htbl, ttbl, jtbl, etc. Too short? Dave, From dboland9 at protonmail.com Tue Aug 13 17:21:29 2019 From: dboland9 at protonmail.com (Dave) Date: Tue, 13 Aug 2019 17:21:29 -0400 Subject: Create multiple sqlite tables, many-to-many design References: Message-ID: On 8/13/19 2:59 PM, Chris Angelico wrote: > On Wed, Aug 14, 2019 at 4:50 AM Dave via Python-list > wrote: >> Some of the tables are related. For example: >> >> Hiking_Table Trails_Table Joining_Table >> ----------------- -------------------- ----------------- >> hike_id PK trail_id PK hike_id FK >> hike_date TEXT trail_name TEXT trail_id FK >> hike_destination TEXT trail_rating REAL >> hike_rating REAL trail_comments TEXT >> hike_comments TEXT >> >> So far, so good. I know how to create the tables. What I am struggling >> with is how do I insert data into the joining table or don"t I? If so, >> do I need to query the other two tables to get the auto-number ID's? >> Some things I have read suggest that the joining table just contains >> references, so there is no actual insert. A pointer to information how >> to do this would be appreciated. As for queries, I think I use joins, >> but a pointer on how to do this would also be appreciated. > > The joining table is a real thing, and will have real inserts. It > might be easier to think of this as two separate one-to-many > relationships; for the sake of demonstration, I'm going to add another > column to your joining table. > > hike_sections ==> hike_id references hikes, trail_id references > trails, companion_name > > You've decided to have someone with you for some sections of your > hike. As such, what we have is a number of "mini-hikes" that make up a > single hike (that's a one-to-many relationship between hikes and > sections), and also a single trail can be a section of any number of > hikes (so, another one-to-many relationship between trails and > sections). For any given section, there is exactly one companion. > > Does this make the many-to-many relationship a bit easier to > understand? It'll work exactly the same way even if you have no > ancillary information in that joining table. > > ChrisA > Chris, Thanks for the note. I get the theory of MTM and the join table. It is the implementation I don't get. Let me see if I can demonstrate my confusion using pseudo code. def dbTables_create (dbpath): sql_HikeTable = """ CREATE TABLE IF NOT EXISTS hike ( hike_id INTEGER AUTO_INCREMENT PRIMARY KEY, hike_date TEXT, hike_destination TEXT, hike_rating REAL, hike_comments TEXT ) """ sql_TrailTable = """ CREATE TABLE IF NOT EXISTS trail ( trail_id INTEGER AUTO_INCREMENT PRIMARY KEY, trail_name TEXT, trail_rating REAL, trail_comment TEXT ) """ sql_JoiningTable = """ CREATE TABLE IF NOT EXISTS hike_trail ( hike_id INTEGER trail_id INTEGER ) """ # Some more code to open connection, create cursor, execute SQL. def getUserInput (): # Code to get the user input. # The user input is: hdate = "2019-05-28" hdestination = "Top of White Face Mountain, NY." hrating = 5.0 # Rating scale 1.0 (bad) to 5.0 (perfect). hcomments "Got to do again. Better shoes needed." tname1 = "Brookside" trating1 = 4.5 tcomments1 = "Easy" tname2 = "Wilmington Trail" trating2 = 4.9 tcomments2 = "Awesome!!" def dbDataInsert(): sql_HikeInsert = """ INSERT INTO hike ( hike_date, hike_destination, hike_rating, hike_comments ) VALUES ( hdate, hdestination, hrating, hcomments ) """ sql_TrailInsert = """ NSERT INTO trail ( trail_name, trail_rating, trail_comment ) VALUES ( tname1, trating1, tcomments1 ) """ sql_TrailInsert = """ NSERT INTO trail ( trail_name, trail_rating, trail_comment ) VALUES ( tname2, trating2, tcomments2 ) """ """ ---> Now what? I need to populate the join (hike_trail) table. Do I query the tables to get the id's? Is there another way? This is the part I really don't get. """ Dave, From rshepard at appl-ecosys.com Tue Aug 13 17:31:11 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Aug 2019 14:31:11 -0700 (PDT) Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Tue, 13 Aug 2019, Dave via Python-list wrote: > I do indeed. I did that so it was easy for everyone to follow. Having > started with assm. and C, I have to remind myself to be more explanatory > in naming. Guess I over-did it. The actual code is different. htbl, ttbl, > jtbl, etc. Too short? Dave, I encourage you to step back and approach your project from a different side. Databases, especially relational ones using SQL, are a very different world from Assembly, C, Python, and other procedural/functional/whatever languages. Read Joe Celko's books, starting with his SQL Programming Guide, then SQL for Smarties. A book on relational database design (other than these) would help. One I've used is Van der Laans' 'Introductory SQL'. SQL is a set language and thinking in sets is different from thinking in step-wise procedures. With SQL to tell the engine what you want, not how to do it. The engine decides the optimal way of getting the results you want from the tables. There are three components of SQL; most of us use only two of them: DDL (Data Definition Language) to define tables and relationships and DML (Data Manipulation Language) which we use to write queries. When you get your head around all this consider using Python and SQLAlchemy with SQLite3, postgresql, or whatever you want for the database back end. Good luck! Rich From rosuav at gmail.com Tue Aug 13 17:43:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 07:43:42 +1000 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: Message-ID: On Wed, Aug 14, 2019 at 7:26 AM Dave via Python-list wrote: > Thanks for the note. I get the theory of MTM and the join table. It is > the implementation I don't get. Let me see if I can demonstrate my > confusion using pseudo code. > > def dbDataInsert(): > > sql_HikeInsert = """ INSERT INTO hike ( > hike_date, > hike_destination, > hike_rating, > hike_comments ) > VALUES ( > hdate, > hdestination, > hrating, > hcomments ) """ > > sql_TrailInsert = """ NSERT INTO trail ( > trail_name, > trail_rating, > trail_comment ) > VALUES ( > tname1, > trating1, > tcomments1 ) """ > > sql_TrailInsert = """ NSERT INTO trail ( > trail_name, > trail_rating, > trail_comment ) > VALUES ( > tname2, > trating2, > tcomments2 ) """ > > """ ---> Now what? I need to populate the join (hike_trail) table. > Do I query the tables to get the id's? Is there another > way? This is the part I really don't get. """ > Gotcha! Some database engines (including PostgreSQL) allow you to add a RETURNING clause to your INSERT statement, which will then turn it into a combined "insert, then select from the newly-inserted rows". SQLite3 does not have this, but there is a special attribute on the cursor (which you haven't shown in the cut-down example here, but I presume you know what I'm talking about) to retrieve the ID of the newly-inserted row: https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.lastrowid So after inserting into the hike table, you can grab the ID of that row off the cursor, and then same after the trail. Then you just insert into the join table using those IDs. A proper RETURNING clause is far more flexible (it can handle multiple rows, it can be chained into other queries, etc), but this should be sufficient for what you're doing here. ChrisA From rshepard at appl-ecosys.com Tue Aug 13 17:46:38 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Aug 2019 14:46:38 -0700 (PDT) Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Tue, 13 Aug 2019, Rich Shepard wrote: > Read Joe Celko's books, starting with his SQL Programming Guide, then SQL That should be SQL Programming Style Rich From amirrezaheidarysbu at gmail.com Tue Aug 13 17:47:17 2019 From: amirrezaheidarysbu at gmail.com (amirrezaheidarysbu at gmail.com) Date: Tue, 13 Aug 2019 14:47:17 -0700 (PDT) Subject: How to plot a data including date and time? Message-ID: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> I have a .csv file, in first column I have date and hour, and in the second column I have energy use data. How can I make a bar chart with Date and time as the x axis and the energy use as the Y axis? Thanks From dboland9 at protonmail.com Tue Aug 13 17:58:15 2019 From: dboland9 at protonmail.com (Dave) Date: Tue, 13 Aug 2019 17:58:15 -0400 Subject: Create multiple sqlite tables, many-to-many design References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On 8/13/19 5:46 PM, Rich Shepard wrote: > On Tue, 13 Aug 2019, Rich Shepard wrote: > >> Read Joe Celko's books, starting with his SQL Programming Guide, then SQL > > That should be SQL Programming Style > > Rich Rich, On my next trip to BN I'll see if they have them. That is long term though. Right now I just need to know how to populate the join table and anything else that has escaped me. SQL is cool. SQL + Python (or C or C++ or Java) is more cool. Lot easier to understand than pointer math in C. Dave, From rshepard at appl-ecosys.com Tue Aug 13 18:15:31 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Aug 2019 15:15:31 -0700 (PDT) Subject: How to plot a data including date and time? In-Reply-To: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> Message-ID: On Tue, 13 Aug 2019, amirrezaheidarysbu at gmail.com wrote: > I have a .csv file, in first column I have date and hour, and in the > second column I have energy use data. How can I make a bar chart with Date > and time as the x axis and the energy use as the Y axis? First, find yourself a plotting program (R and PSTricks are two I use; matplotlib also does a fine job). Second, learn what data format and manipulation that application uses on provided data. Third, learn that application/language and plot your data after importing it to the application. Rich From rosuav at gmail.com Tue Aug 13 18:19:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 08:19:26 +1000 Subject: How to plot a data including date and time? In-Reply-To: References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> Message-ID: On Wed, Aug 14, 2019 at 8:17 AM Rich Shepard wrote: > > On Tue, 13 Aug 2019, amirrezaheidarysbu at gmail.com wrote: > > > I have a .csv file, in first column I have date and hour, and in the > > second column I have energy use data. How can I make a bar chart with Date > > and time as the x axis and the energy use as the Y axis? > > First, find yourself a plotting program (R and PSTricks are two I use; > matplotlib also does a fine job). Given that we're on python-list here, matplotlib would be the obvious choice here :) ChrisA From cs at cskk.id.au Tue Aug 13 18:36:17 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 14 Aug 2019 08:36:17 +1000 Subject: Fwd: Startup problems In-Reply-To: References: Message-ID: <20190813223617.GA70220@cskk.homeip.net> On 13Aug2019 19:05, Vinayak Gopakumar wrote: >dear developer, > I'm having problems while starting IDLE 3.7.4. With >this problem, I cannot finish my studies properly. The screenshot of the >problem is attached to this mail. This list discards all attachments. A cut/paste of error messages inline in the message text is required to show us any errors. (This has the advantage that we can ourselve copy that text, which is useful in replies.) > I hope that you would provide assistance for me for recovering the >above-said problem Please describe your operating system and where you obtained your ptyhon install, and what you did to start IDLE. Otherwise we do not have enough context to assist. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Tue Aug 13 15:37:52 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 14 Aug 2019 07:37:52 +1200 Subject: Web framework for static pages In-Reply-To: References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> Message-ID: <130b0f38-24c6-3b26-c2d7-4aaa8dda6a63@DancesWithMice.info> On 13/08/19 10:54 PM, Morten W. Petersen wrote: > I was hoping to avoid testing a lot of different systems, spending time > there. Sooner or later you have to make a decision - and be responsible for it to your clients. > So that's why I'm asking here. People here are helpful. The more time you put-in, the more inclined folk are to help further. > I don't need a guide to create a website, maybe a refresher on some topics. Respectfully, and knowing only the little posted here, this seems an under-statement, eg you don't appear know how HTML5 succeeds and exceeds XHTML (and has done so for many years). Do you under-estimate how much things have developed during the last decade? > Ideally I'd want a static site generator that makes it easy and quick to > create a website which is pretty, accessible, works across browsers and > standards compliant and doesn't freeze the browser on a low-end phone. In, XHTML??? This stuff is not straight-forward. Neither is it Python/a topic for this list. Whilst I place myself in the 'master' category for HTML5 development and cheerfully regard manually knocking-out the likes of an "About Us" static page using nothing more than a basic editor as "quick and easy", there is no room for such 'purity' and idealism when phones and 'responsive' elements enter the picture. "Here be dragons"! I'm wary of claiming such a skill-level in Python - particularly given its incredibly wide range of application. That side of the process can be simple or complex - you choose. [this further to comment after next para] "Flask" has been mentioned, and over many years Mig has contributed numbers of tutorials, videos, articles, and books; which IMHO make it easy to understand that package - and most others (in this category). As such, I recommend it as a great starting-point, even if that learning better-equips you to change to something else later! (see also mention in other contributions to this thread) > And where it is easy to override using for example plain or template > HTML, or extend programmatic features using some plugins or just > subclassing. Using Python as an 'engine' to generate a web-site, either as a static file-set or as part of a web server is relatively trivial. Some of your more detailed specs will likely lead you down one or another path. What inspiration did you get from reading-up about Flask? Pelican? Other suggestions made 'here'? In what way did they not meet the mark? > Do you know of a XML DTD for HTML5 by the way? See above. (How is a web page declared to be HTML5, cf any other format? How does one ensure that a web page is 'HTML5-compliant'? How does/can one do "pretty" in (X)HTML?) -- Regards =dn From PythonList at DancesWithMice.info Tue Aug 13 16:22:43 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 14 Aug 2019 08:22:43 +1200 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: <1369d7c6-9518-917d-be3a-d510eba54f12@DancesWithMice.info> On 14/08/19 6:14 AM, Chris Angelico wrote: > On Wed, Aug 14, 2019 at 1:48 AM Larry Martell wrote: >> >> On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico wrote: >>> >>> On Tue, Aug 13, 2019 at 11:33 PM Larry Martell wrote: >>>> >>>> I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/) >>>> for python3.6 on RHEL7. >>>> When I import it, it fails: ... >>>> Has anyone seen and resolved this? >>> >>> Not specifically, but that looks like a versioning conflict. Most >>> likely, your mysqlclient is too old for MySQLdb to connect to. +1 >>> Did you get one of them from your system package manager and the other >>> from pip? If so, try to get both from the same place. >> >> So I have MySQL from the system package manager, but mysqlclient is >> not available there. By which you mean RedHat's repository? > That seems very odd. The mysqlclient binary might be just under a > different name? I'm not familiar with RHEL, but on my Debian, there > are packages like "mysql-server-5.7" and corresponding > "mysql-client-5.7". Or do you mean the Python client? Just in case: please be aware that the MySQL-client which enables a cmdLN interface to the server, is quite different from the Python-Connector which will be called from Python code. >> And I was not able to get that from pip either, >> as the install failed. I had to download the source, edit the site.cfg >> file and build it. But I just found python36-mysql.x86_64 as a package >> so I uninstalled mysqlclient and installed that from the repo. > > Based on this, I'm thinking possibly you meant the Python client. It > may still be that you need to install the C client for the Python one > to connect to. Although.... if you got python36-mysql from your system > repo, that ought to drag in the appropriate mysqlclient. So now I'm > very confused. +1 >> That did not get the above error, but now I get this: >> raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is >> required; you have %s.' % Database.__version__) >> django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or >> newer is required; you have 1.3.12. > > This claims to be a Django error, though, so maybe the issue here > isn't with MySQLdb but with Django?? Maybe everything up above is > actually correctly matched, but too old? I often develop on CentOS/Fedora* whereas the client has paid-for RedHat support. To keep the two environments in-sync, I always use the MySQL (Community) repo(s). * which is yet another 'battle' because "MariaDB" may be installed by-default, in preference to MySQL) As Chris has said, there are combinations of clients and servers, many of which are incompatible. Like him, I've stuck with MySQL v5 by reason of exactly this sort of inter-dependence (MySQL-Workbench? - admittedly a decision made, I estimate, over one year ago) - whereas MySQL Community will 'favor' v8.n! Recommend: - clear-out 'everything' MySQL-related - install the MySQL (Community) site's repo (v5 or v8, as you see fit) - using rpm/yum/dnf, assemble your tool-set directly from them (single-source!) - test using the MySQL cmdLN client - only thereafter move to testing the Python/Django connection. I have no problems with/complaints about MySQL's Python-Connector (and usually stick to the simpler interface/API). Various alternative interfaces (to MySQL's) seem quite similar, and often require identical code/function calls from within Python... I can't speak to the Django-MySQL interface. When the time comes, your client can shell-out for MySQL support, and build (essentially) the same environment for the 'live env', from those repos! -- Regards =dn From rosuav at gmail.com Tue Aug 13 19:40:30 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 09:40:30 +1000 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: <1369d7c6-9518-917d-be3a-d510eba54f12@DancesWithMice.info> References: <1369d7c6-9518-917d-be3a-d510eba54f12@DancesWithMice.info> Message-ID: On Wed, Aug 14, 2019 at 9:27 AM DL Neil wrote: > > On 14/08/19 6:14 AM, Chris Angelico wrote: > > That seems very odd. The mysqlclient binary might be just under a > > different name? I'm not familiar with RHEL, but on my Debian, there > > are packages like "mysql-server-5.7" and corresponding > > "mysql-client-5.7". Or do you mean the Python client? > > Just in case: please be aware that the MySQL-client which enables a > cmdLN interface to the server, is quite different from the > Python-Connector which will be called from Python code. Hmm. Where would the C libraries be? I would have thought "mysql-client" included the necessary binary library for the Python MySQL .so to link against. It's been ages since I dug into any of the details of MySQL setup. I moved completely to PostgreSQL years ago and haven't looked back. > As Chris has said, there are combinations of clients and servers, many > of which are incompatible. Like him, I've stuck with MySQL v5 by reason > of exactly this sort of inter-dependence (MySQL-Workbench? - admittedly > a decision made, I estimate, over one year ago) - whereas MySQL > Community will 'favor' v8.n! Actually I've "stuck" with version 5 simply because it's currently installed here and I haven't seen fit to uninstall it. Which probably means that Debian's repositories are still shipping a 5.x. But on analysis, this is turning out to be actually MariaDB... no idea whether that's significant or not. > Recommend: > - clear-out 'everything' MySQL-related > - install the MySQL (Community) site's repo (v5 or v8, as you see fit) > - using rpm/yum/dnf, assemble your tool-set directly from them > (single-source!) > - test using the MySQL cmdLN client > - only thereafter move to testing the Python/Django connection. That sounds like a good plan. > I have no problems with/complaints about MySQL's Python-Connector (and > usually stick to the simpler interface/API). > > Various alternative interfaces (to MySQL's) seem quite similar, and > often require identical code/function calls from within Python... > > I can't speak to the Django-MySQL interface. > > When the time comes, your client can shell-out for MySQL support, and > build (essentially) the same environment for the 'live env', from those > repos! Another thing to consider is additional middleware like SQLAlchemy, which may make things easier, but may just add more complications. ChrisA From morphex at gmail.com Tue Aug 13 19:41:32 2019 From: morphex at gmail.com (Morten W. Petersen) Date: Wed, 14 Aug 2019 01:41:32 +0200 Subject: Web framework for static pages In-Reply-To: <130b0f38-24c6-3b26-c2d7-4aaa8dda6a63@DancesWithMice.info> References: <0990a24a-faca-4ac3-829d-cd1182bd9df1@googlegroups.com> <25a4f3b8-a3eb-efb5-0efd-336aac3f304b@DancesWithMice.info> <130b0f38-24c6-3b26-c2d7-4aaa8dda6a63@DancesWithMice.info> Message-ID: Hi "DL Neil". I find your argumentation combative and provoking. I have an ex that has made my life difficult for the last 6 years, blocking me from seeing my kids, she acts in a similar way. I don't have the time, energy or the will to bring more of that stuff into my life, so I won't reply to this type of email. -Morten Blogging at http://blogologue.com Tweeting at https://twitter.com/blogologue On Instagram https://instagram.com/morphexx ons. 14. aug. 2019, 01.27 skrev DL Neil : > On 13/08/19 10:54 PM, Morten W. Petersen wrote: > > I was hoping to avoid testing a lot of different systems, spending time > > there. > > Sooner or later you have to make a decision - and be responsible for it > to your clients. > > > > So that's why I'm asking here. > > People here are helpful. The more time you put-in, the more inclined > folk are to help further. > > > > I don't need a guide to create a website, maybe a refresher on some > topics. > > Respectfully, and knowing only the little posted here, this seems an > under-statement, eg you don't appear know how HTML5 succeeds and exceeds > XHTML (and has done so for many years). Do you under-estimate how much > things have developed during the last decade? > > > > Ideally I'd want a static site generator that makes it easy and quick to > > create a website which is pretty, accessible, works across browsers and > > standards compliant and doesn't freeze the browser on a low-end phone. > > In, XHTML??? > > This stuff is not straight-forward. Neither is it Python/a topic for > this list. > > Whilst I place myself in the 'master' category for HTML5 development and > cheerfully regard manually knocking-out the likes of an "About Us" > static page using nothing more than a basic editor as "quick and easy", > there is no room for such 'purity' and idealism when phones and > 'responsive' elements enter the picture. "Here be dragons"! > > I'm wary of claiming such a skill-level in Python - particularly given > its incredibly wide range of application. That side of the process can > be simple or complex - you choose. > > [this further to comment after next para] > "Flask" has been mentioned, and over many years Mig has contributed > numbers of tutorials, videos, articles, and books; which IMHO make it > easy to understand that package - and most others (in this category). As > such, I recommend it as a great starting-point, even if that learning > better-equips you to change to something else later! > (see also mention in other contributions to this thread) > > > > And where it is easy to override using for example plain or template > > HTML, or extend programmatic features using some plugins or just > > subclassing. > > Using Python as an 'engine' to generate a web-site, either as a static > file-set or as part of a web server is relatively trivial. Some of your > more detailed specs will likely lead you down one or another path. What > inspiration did you get from reading-up about Flask? Pelican? Other > suggestions made 'here'? In what way did they not meet the mark? > > > > Do you know of a XML DTD for HTML5 by the way? > > See above. > (How is a web page declared to be HTML5, cf any other format? How does > one ensure that a web page is 'HTML5-compliant'? How does/can one do > "pretty" in (X)HTML?) > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Tue Aug 13 19:42:19 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Aug 2019 00:42:19 +0100 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On 2019-08-13 22:11, Dave via Python-list wrote: > On 8/13/19 4:45 PM, MRAB wrote: >> On 2019-08-13 19:59, Chris Angelico wrote: >>> On Wed, Aug 14, 2019 at 4:50 AM Dave via Python-list >>> wrote: >>>> Some of the tables are related.? For example: >>>> >>>> Hiking_Table???????????? Trails_Table??????????? Joining_Table >>>> -----------------??????? --------------------??? ----------------- >>>> hike_id???? PK?????????? trail_id? PK??????????? hike_id?? FK >>>> hike_date? TEXT????????? trail_name? TEXT??????? trail_id?? FK >>>> hike_destination TEXT??? trail_rating REAL >>>> hike_rating? REAL??????? trail_comments TEXT >>>> hike_comments? TEXT >>>> [snip] >> Might I also suggest dropping unnecessary prefixes from the field names. >> For example, "hike_comments" in "Hiking_Table" can be called just >> "comments" because it's clear from the context that a field called >> "comments" in the hiking table will contain comments about hiking, if >> you see what I mean. > > I do indeed. I did that so it was easy for everyone to follow. Having > started with assm. and C, I have to remind myself to be more explanatory > in naming. Guess I over-did it. The actual code is different. htbl, > ttbl, jtbl, etc. Too short? > Definitely! :-) Another thing you might want to avoid is naming something with what it is, e.g. "Trails_Table" (why not just "Trails"). From rshepard at appl-ecosys.com Tue Aug 13 20:04:37 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Aug 2019 17:04:37 -0700 (PDT) Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Wed, 14 Aug 2019, MRAB wrote: >> The actual code is different. htbl, ttbl, jtbl, etc. Too short? >> > Definitely! :-) > > Another thing you might want to avoid is naming something with what it is, > e.g. "Trails_Table" (why not just "Trails"). Another reason to read Celko's 'SQL Programming Style.' In the 1970s I was writing FORTRAN ecosystem models punched on 80-column Hollerith cards using an IBM 029 keypunch. Everything was as short as possible, especially variable names. There were two valuable lessons I learned (in addition to marking a Sharpie pen line diagonally across the card deck to make it easier to put back in sequence when the box was dropped): 1. Make variable names fully descriptive. 2. Write many comments to explain what things are and why you're doing things the way you are. The reason is that within 6 months (or less) you will look at your schema and code and have no idea what's going on or why you wrote it like that. Table names are commonly written with initial uppercase letters; variables in all lowercase. Leave CamelCase in the desert. Use underscores between words, e.g., hike_id, trail_nbr, not hyphens. And, you might not be the only person looking at the schema and code needing to understand what's going on. Rich From python at mrabarnett.plus.com Tue Aug 13 20:18:11 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Aug 2019 01:18:11 +0100 Subject: Opening Python 3.8 in Visual Studio 2019 In-Reply-To: References: Message-ID: On 2019-08-13 20:31, Moe Vyas wrote: > Greetings. > Can anyone please, tell me how to open Python 3.8 Interpreter in the Visual > Studio 2019. I have downloaded both of these on my Windows laptop and now > am struggling to make them work together!!? > Have a read here: https://docs.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-01-create-project?view=vs-2019 From songofacandy at gmail.com Tue Aug 13 21:49:39 2019 From: songofacandy at gmail.com (Inada Naoki) Date: Wed, 14 Aug 2019 10:49:39 +0900 Subject: MySQLdb for 3.6 on RHEL7 In-Reply-To: References: Message-ID: On Wed, Aug 14, 2019 at 4:10 AM Larry Martell wrote: > > > > And I was not able to get that from pip either, > > > as the install failed. I had to download the source, edit the site.cfg > > > file and build it. But I just found python36-mysql.x86_64 as a package > > > so I uninstalled mysqlclient and installed that from the repo. > > The reason that would not install from pip was because the path to > mysql_config was not correct in site.cfg - once I changed that I was > able to build it, but then it gave the other error. > It's wrong. The path to mysql_config is not defined in site.cfg by default. There is example configuration but it's commented out. By default mysqlclient searches mysql_config from PATH. You had not reported enough information from start. You should explain which C mysql client library you are using and how you build mysqlclient. Since you said you need to specify the path of mysql_config, I suppose you're not using MySQL or C mysql client library provided by your distro. But you have not show enough information about it yet. This is linking error. The error is happened from C library. You need to report about it, at least: * How did you installed C mysql client library. * The output of the `mysql_config` * The output of the `ldd /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so` Regards, -- Inada Naoki From wiwindson at gmail.com Wed Aug 14 00:04:52 2019 From: wiwindson at gmail.com (Windson Yang) Date: Wed, 14 Aug 2019 12:04:52 +0800 Subject: fopen() and open() in cpython Message-ID: After my investigation, I found Since Python maintains its own buffer when read/write files, the build-in python open() function will call the open() system call instead of calling standard io fopen() for caching. So when we read/write a file in Python, it would not call fopen(), fopen() only use for Python itself but not for python user. Am I correct? From amirrezaheidarysbu at gmail.com Wed Aug 14 03:49:33 2019 From: amirrezaheidarysbu at gmail.com (amirrezaheidarysbu at gmail.com) Date: Wed, 14 Aug 2019 00:49:33 -0700 (PDT) Subject: How to plot a data including date and time? In-Reply-To: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> Message-ID: <23d45668-fa47-4640-832a-5a5c64600b95@googlegroups.com> On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah... at gmail.com wrote: > I have a .csv file, in first column I have date and hour, and in the second column I have energy use data. How can I make a bar chart with Date and time as the x axis and the energy use as the Y axis? > > Thanks Thank you for your guidance. I am already using matplotlib but I do not know how to import a column of date and time and to use it properly as the x axis. can you tell me the code? Thanks From greg.ewing at canterbury.ac.nz Wed Aug 14 07:02:53 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 14 Aug 2019 23:02:53 +1200 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: MRAB wrote: > Another thing you might want to avoid is naming something with what it > is, e.g. "Trails_Table" (why not just "Trails"). Or possibly just "Trail", since any table potentially contains multiple rows, so making all your table names plural doesn't add any information. -- Greg From rosuav at gmail.com Wed Aug 14 07:15:05 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Aug 2019 21:15:05 +1000 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Wed, Aug 14, 2019 at 9:06 PM Gregory Ewing wrote: > > MRAB wrote: > > Another thing you might want to avoid is naming something with what it > > is, e.g. "Trails_Table" (why not just "Trails"). > > Or possibly just "Trail", since any table potentially contains > multiple rows, so making all your table names plural doesn't > add any information. > I prefer to say "Trails" for the table, and "Trail" would then refer to a single row from that table. ChrisA From rshepard at appl-ecosys.com Wed Aug 14 08:39:51 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 14 Aug 2019 05:39:51 -0700 (PDT) Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Wed, 14 Aug 2019, Chris Angelico wrote: > I prefer to say "Trails" for the table, and "Trail" would then refer to a > single row from that table. +1 Rich From nospam at yrl.co.uk Wed Aug 14 09:49:53 2019 From: nospam at yrl.co.uk (Elliott Roper) Date: Wed, 14 Aug 2019 14:49:53 +0100 Subject: How to plot a data including date and time? References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> <23d45668-fa47-4640-832a-5a5c64600b95@googlegroups.com> Message-ID: <0001HW.23044901039E772C70000CA972EF@news.giganews.com> On 14 Aug 2019, amirrezaheidarysbu at gmail.com wrote (in article<23d45668-fa47-4640-832a-5a5c64600b95 at googlegroups.com>): > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah... at gmail.com > wrote: > > I have a .csv file, in first column I have date and hour, and in the second > > column I have energy use data. How can I make a bar chart with Date and > > time as the x axis and the energy use as the Y axis? > > > > Thanks > > Thank you for your guidance. I am already using matplotlib but I do not know > how to import a column of date and time and to use it properly as the x axis. > can you tell me the code? > > Thanks If you don't mind using a steam hammer to crack a nut, it is amazing what you can do with pandas using just the "10 minute guide" chapter in the (shudder) 10,000 page manual. The chief benefit is how thoroughly it protects you from Numpy and Matplotlib. I solved a similar problem (tracking home blood pressure with exponentially weighted means) up and running in half a day from a completely cold start. The graphing bit is a delight. However, if you want to do something that the 10 minute guide does not cover, you can lose a man-month without really trying. Pandas is a beautiful monster! Here's the relevant bit import numpy as np import pandas as pd import matplotlib.pyplot as plt import pytz from pytz import common_timezones, all_timezones #preparing the csv from a text file elided as irrelevant #except that the .csv headings have to be Date Systolic Diastolic for this to work as designed # Plot the intermediate file with pandas after adding exponentially weighted means df = pd.read_csv('Blood pressure.csv') df['Date'] = pd.to_datetime(df['Date']) df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() plt.ioff() df.plot(x='Date') print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more healthy levels plt.ylabel('mm Hg') plt.suptitle("Home BP record") plt.show() That should give you a start -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From nospam at yrl.co.uk Wed Aug 14 09:54:47 2019 From: nospam at yrl.co.uk (Elliott Roper) Date: Wed, 14 Aug 2019 14:54:47 +0100 Subject: How to plot a data including date and time? References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> <23d45668-fa47-4640-832a-5a5c64600b95@googlegroups.com> <0001HW.23044901039E772C70000CA972EF@news.giganews.com> Message-ID: <0001HW.23044A27039EBC0770000CA972EF@news.giganews.com> On 14 Aug 2019, Elliott Roper wrote (in article<0001HW.23044901039E772C70000CA972EF at news.giganews.com>): > On 14 Aug 2019, amirrezaheidarysbu at gmail.com wrote > (in article<23d45668-fa47-4640-832a-5a5c64600b95 at googlegroups.com>): > > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah... at gmail.com > > wrote: Oh Damn! Here is an attempt to stop the code running into a single line.. > > > > > I have a .csv file, in first column I have date and hour, and in the second > > > column I have energy use data. How can I make a bar chart with Date and > > > time as the x axis and the energy use as the Y axis? > > > > > > Thanks > > > > Thank you for your guidance. I am already using matplotlib but I do not know > > how to import a column of date and time and to use it properly as the x > > axis. > > can you tell me the code? > > > > Thanks > > If you don't mind using a steam hammer to crack a nut, it is amazing what you > can do with pandas using just the "10 minute guide" chapter in the (shudder) > 10,000 page manual. The chief benefit is how thoroughly it protects you from > Numpy and Matplotlib. > I solved a similar problem (tracking home blood pressure with exponentially > weighted means) up and running in half a day from a completely cold start. > The graphing bit is a delight. However, if you want to do something that the > 10 minute guide does not cover, you can lose a man-month without really > trying. Pandas is a beautiful monster! > > Here's the relevant bit > > import numpy as np > > import pandas as pd > > import matplotlib.pyplot as plt > > > #preparing the csv from a text file elided as irrelevant > > #except that the .csv headings have to be Date Systolic Diastolic for this to > work as designed > > # Plot the intermediate file with pandas after adding exponentially weighted > means > > df = pd.read_csv('Blood pressure.csv') > > df['Date'] = pd.to_datetime(df['Date']) > > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() > > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() > > plt.ioff() > > df.plot(x='Date') > > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more > healthy levels > > plt.ylabel('mm Hg') > > plt.suptitle("Home BP record") > > plt.show() > > That should give you a start -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From george at fischhof.hu Wed Aug 14 11:30:29 2019 From: george at fischhof.hu (George Fischhof) Date: Wed, 14 Aug 2019 17:30:29 +0200 Subject: How to plot a data including date and time? In-Reply-To: <0001HW.23044A27039EBC0770000CA972EF@news.giganews.com> References: <4852efec-8916-4410-8ffd-b5f4db8b43be@googlegroups.com> <23d45668-fa47-4640-832a-5a5c64600b95@googlegroups.com> <0001HW.23044901039E772C70000CA972EF@news.giganews.com> <0001HW.23044A27039EBC0770000CA972EF@news.giganews.com> Message-ID: Elliott Roper ezt ?rta (id?pont: 2019. aug. 14., Sze 15:56): > On 14 Aug 2019, Elliott Roper wrote > (in article<0001HW.23044901039E772C70000CA972EF at news.giganews.com>): > > > On 14 Aug 2019, amirrezaheidarysbu at gmail.com wrote > > (in article<23d45668-fa47-4640-832a-5a5c64600b95 at googlegroups.com>): > > > > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, > amirrezah... at gmail.com > > > wrote: > > Oh Damn! Here is an attempt to stop the code running into a single line.. > > > > > > > I have a .csv file, in first column I have date and hour, and in the > second > > > > column I have energy use data. How can I make a bar chart with Date > and > > > > time as the x axis and the energy use as the Y axis? > > > > > > > > Thanks > > > > > > Thank you for your guidance. I am already using matplotlib but I do > not know > > > how to import a column of date and time and to use it properly as the x > > > axis. > > > can you tell me the code? > > > > > > Thanks > > > > > If you don't mind using a steam hammer to crack a nut, it is amazing > what you > > can do with pandas using just the "10 minute guide" chapter in the > (shudder) > > 10,000 page manual. The chief benefit is how thoroughly it protects you > from > > Numpy and Matplotlib. > > I solved a similar problem (tracking home blood pressure with > exponentially > > weighted means) up and running in half a day from a completely cold > start. > > The graphing bit is a delight. However, if you want to do something that > the > > 10 minute guide does not cover, you can lose a man-month without really > > trying. Pandas is a beautiful monster! > > > > Here's the relevant bit > > > > import numpy as np > > > > import pandas as pd > > > > import matplotlib.pyplot as plt > > > > > > #preparing the csv from a text file elided as irrelevant > > > > #except that the .csv headings have to be Date Systolic Diastolic for > this to > > work as designed > > > > # Plot the intermediate file with pandas after adding exponentially > weighted > > means > > > > df = pd.read_csv('Blood pressure.csv') > > > > df['Date'] = pd.to_datetime(df['Date']) > > > > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() > > > > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() > > > > plt.ioff() > > > > df.plot(x='Date') > > > > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more > > healthy levels > > > > plt.ylabel('mm Hg') > > > > plt.suptitle("Home BP record") > > > > plt.show() > > > > That should give you a start > > -- > To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 > 3CF7 > 637F 896B C810 E199 7E5C A9E4 8E59 E248 > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, Pygal is a very good and easy to use charting library BR, George > From eryksun at gmail.com Wed Aug 14 12:27:25 2019 From: eryksun at gmail.com (eryk sun) Date: Wed, 14 Aug 2019 11:27:25 -0500 Subject: fopen() and open() in cpython In-Reply-To: References: Message-ID: On 8/13/19, Windson Yang wrote: > After my investigation, I found Since Python maintains its own buffer when > read/write files, the build-in python open() function will call the open() > system call instead of calling standard io fopen() for caching. So when we > read/write a file in Python, it would not call fopen(), fopen() only use > for Python itself but not for python user. Am I correct? Python 2 I/O wraps C FILE streams (i.e. fopen, fclose, fread, fwrite, fgets). Python 3 has its own I/O stack (raw, buffered, text) that aims to be more reliably cross-platform than C FILE streams. Python 3 still uses FILE streams internally in some cases (e.g. to read pyvenv.cfg at startup). FYI in Windows open() or _wopen() is a C runtime library function, not a system function. It calls the Windows API function CreateFile, which calls the NT system function, NtCreateFile. It's similarly layered for all calls, e.g. read() calls ReadFile or ReadConsoleW, which calls NtReadFile or NtDeviceIoControlFile (ReadConsoleW). From amirrezaheidarysbu at gmail.com Wed Aug 14 15:18:51 2019 From: amirrezaheidarysbu at gmail.com (amirrezaheidarysbu at gmail.com) Date: Wed, 14 Aug 2019 12:18:51 -0700 (PDT) Subject: In following subplot I have to change the first plot into a bar plot. But using plt.bar rather than plt.plot gives a white plot ! Message-ID: <8172ac50-4839-47ca-92de-1fee72f649de@googlegroups.com> plt.Figure() plt.subplots_adjust(top=0.945, bottom=0.05, left=0.04, right=0.985, hspace=0.67, wspace=0.345) plt.subplot(6,1,1) plt.plot(Date,Energy, "r") plt.title("Hourly hot water energy use") plt.ylabel("kWh") plt.margins(x=0) plt.subplot(6,1,2) plt.plot(Date,Tin) plt.title("Indoor air temperature") plt.ylabel("Celsius") plt.margins(x=0) plt.subplot(6,1,3) plt.plot(Date,RHin, "g") plt.title("Indoor air relative humidity") plt.ylabel("%") plt.margins(x=0) plt.subplot(6,1,4) plt.plot(Date,Tamb, "darkblue") plt.title("Ambient air temperature") plt.ylabel("Celsius") plt.margins(x=0) plt.subplot(6,1,5) plt.plot(Date,Insol, "gold") plt.title("Solar insolation") plt.ylabel("$W/m^2$") plt.margins(x=0) plt.subplot(6,1,6) plt.plot(Date,Wind, "darkslategrey") plt.title("Wind speed") plt.ylabel("$m/s$") plt.margins(x=0) plt.show() From wiwindson at gmail.com Wed Aug 14 22:31:04 2019 From: wiwindson at gmail.com (Windson Yang) Date: Thu, 15 Aug 2019 10:31:04 +0800 Subject: fopen() and open() in cpython In-Reply-To: References: Message-ID: Thank you so much for the answer, now it makes sense :D eryk sun ?2019?8?15??? ??12:27??? > On 8/13/19, Windson Yang wrote: > > After my investigation, I found Since Python maintains its own buffer > when > > read/write files, the build-in python open() function will call the > open() > > system call instead of calling standard io fopen() for caching. So when > we > > read/write a file in Python, it would not call fopen(), fopen() only use > > for Python itself but not for python user. Am I correct? > > Python 2 I/O wraps C FILE streams (i.e. fopen, fclose, fread, fwrite, > fgets). Python 3 has its own I/O stack (raw, buffered, text) that aims > to be more reliably cross-platform than C FILE streams. Python 3 still > uses FILE streams internally in some cases (e.g. to read pyvenv.cfg at > startup). > > FYI in Windows open() or _wopen() is a C runtime library function, not > a system function. It calls the Windows API function CreateFile, which > calls the NT system function, NtCreateFile. It's similarly layered for > all calls, e.g. read() calls ReadFile or ReadConsoleW, which calls > NtReadFile or NtDeviceIoControlFile (ReadConsoleW). > From greg.ewing at canterbury.ac.nz Thu Aug 15 05:35:59 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 15 Aug 2019 21:35:59 +1200 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: Chris Angelico wrote: > I prefer to say "Trails" for the table, and "Trail" would then refer > to a single row from that table. That makes sense for a data structure in your program that contains a collection of rows. But I've come to the view that SQL tends to read better if the names of the database tables are singular, because in SQL you're writing assertions about individual rows, not the tables in their entirety. So I would write something like select T.name, T.id from Trail T but I would assign the resulting list of rows to a variable named "trails" in my program. -- Greg From rosuav at gmail.com Thu Aug 15 05:58:43 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Aug 2019 19:58:43 +1000 Subject: Create multiple sqlite tables, many-to-many design In-Reply-To: References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: On Thu, Aug 15, 2019 at 7:41 PM Gregory Ewing wrote: > > Chris Angelico wrote: > > I prefer to say "Trails" for the table, and "Trail" would then refer > > to a single row from that table. > > That makes sense for a data structure in your program that contains a > collection of rows. But I've come to the view that SQL tends to read > better if the names of the database tables are singular, because in SQL > you're writing assertions about individual rows, not the tables in > their entirety. > > So I would write something like > > select T.name, T.id from Trail T > > but I would assign the resulting list of rows to a variable named > "trails" in my program. > You're selecting from a collection of trails. I don't see a conflict here. It's the same as taking a list of values and then filtering it - even though assertions are made about individuals, you are filtering the entire list: early_things = [thing for thing in things if thing.name < 'M'] ChrisA From __peter__ at web.de Thu Aug 15 06:36:14 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Aug 2019 12:36:14 +0200 Subject: Create multiple sqlite tables, many-to-many design References: <356b5c63-6b89-6544-4485-4472e446a677@mrabarnett.plus.com> Message-ID: Chris Angelico wrote: > On Thu, Aug 15, 2019 at 7:41 PM Gregory Ewing > wrote: >> >> Chris Angelico wrote: >> > I prefer to say "Trails" for the table, and "Trail" would then refer >> > to a single row from that table. >> >> That makes sense for a data structure in your program that contains a >> collection of rows. But I've come to the view that SQL tends to read >> better if the names of the database tables are singular, because in SQL >> you're writing assertions about individual rows, not the tables in >> their entirety. >> >> So I would write something like >> >> select T.name, T.id from Trail T >> >> but I would assign the resulting list of rows to a variable named >> "trails" in my program. >> > > You're selecting from a collection of trails. I don't see a conflict > here. It's the same as taking a list of values and then filtering it - > even though assertions are made about individuals, you are filtering > the entire list: > > early_things = [thing for thing in things if thing.name < 'M'] If list comprehensions were like sql queries then the above would be early_things = [things.* from things where things.name < "M"] That doesn't read well as the condition works on one thing at a time. However, I'm so used to select things.* from things where things.name < "M" in the sql context that I still prefer it. Also, in simple queries you can omit the table name. From email at paulstgeorge.com Thu Aug 15 16:00:17 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 15 Aug 2019 22:00:17 +0200 Subject: absolute path to a file Message-ID: Can someone please tell me how to get the absolute path to a file? I have tried os.path.abspath. In the code below I have a problem in the final line (15). # |import bpy|| ||import os|| || ||texture_list = []|| || ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as outstream:|| || || ||?for obj in bpy.context.scene.objects:|| ||??? for s in obj.material_slots:|| ||??????? if s.material and s.material.use_nodes:|| ||??????????? for n in s.material.node_tree.nodes:|| ||??????????????? if n.type == 'TEX_IMAGE':|| ||??????????????????? texture_list += [n.image]|| ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', os.path.abspath(n.image.filepath), file=outstream)|| |# This gives me: ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif ---Plane uses image02.tif saved at //../images/image02.tif which is at //images/image02.tif But I want an absolute path such as: ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif If it is relevant, my files are on a Mac. Hence the escaped forward slash. -- Paul St George http://www.paulstgeorge.com http://www.devices-of-wonder.com From rosuav at gmail.com Thu Aug 15 16:09:33 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Aug 2019 06:09:33 +1000 Subject: absolute path to a file In-Reply-To: References: Message-ID: On Fri, Aug 16, 2019 at 6:01 AM Paul St George wrote: > > Can someone please tell me how to get the absolute path to a file? I > have tried os.path.abspath. In the code below I have a problem in the > final line (15). > > # > |import bpy|| > ||import os|| > || > ||texture_list = []|| > || > ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as > outstream:|| > || > || > || for obj in bpy.context.scene.objects:|| > || for s in obj.material_slots:|| > || if s.material and s.material.use_nodes:|| > || for n in s.material.node_tree.nodes:|| > || if n.type == 'TEX_IMAGE':|| > || texture_list += [n.image]|| > ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which > is at', os.path.abspath(n.image.filepath), file=outstream)|| > |# > > This gives me: > ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif > ---Plane uses image02.tif saved at //../images/image02.tif which is at > //images/image02.tif > > But I want an absolute path such as: > ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif > ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif > > If it is relevant, my files are on a Mac. Hence the escaped forward slash. > I don't understand the meaning of "escaped forward slash". What does that mean, and how does it affect your path names? -- not a Mac person -- ChrisA From ml_news at posteo.de Thu Aug 15 16:52:06 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Thu, 15 Aug 2019 22:52:06 +0200 Subject: absolute path to a file References: Message-ID: <20190815225206.44cec075@arcor.com> On Thu, 15 Aug 2019 22:00:17 +0200 Paul St George wrote: > Can someone please tell me how to get the absolute path to a file? I > have tried os.path.abspath. In the code below I have a problem in the > final line (15). > > # > |import bpy|| > ||import os|| > || > ||texture_list = []|| > || > ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as > outstream:|| > || > || > ||?for obj in bpy.context.scene.objects:|| > ||??? for s in obj.material_slots:|| > ||??????? if s.material and s.material.use_nodes:|| > ||??????????? for n in s.material.node_tree.nodes:|| > ||??????????????? if n.type == 'TEX_IMAGE':|| > ||??????????????????? texture_list += [n.image]|| > ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, > 'which is at', os.path.abspath(n.image.filepath), file=outstream)|| > |# > > This gives me: > ---Plane uses image01.tif saved at //image01.tif which is > at //image01.tif ---Plane uses image02.tif saved > at //../images/image02.tif which is at //images/image02.tif > > But I want an absolute path such as: > ---Plane uses image01.tif saved > at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif > saved at /Users/Lion/Desktop/images/image02.tif > > If it is relevant, my files are on a Mac. Hence the escaped forward > slash. > I did this: from pathlib import Path abs_myfile = Path('./myfile').resolve() which worked fine for me. -- Manfred From cs at cskk.id.au Thu Aug 15 19:00:38 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 16 Aug 2019 09:00:38 +1000 Subject: absolute path to a file In-Reply-To: <20190815225206.44cec075@arcor.com> References: <20190815225206.44cec075@arcor.com> Message-ID: <20190815230038.GA60558@cskk.homeip.net> On 15Aug2019 22:52, Manfred Lotz wrote: >On Thu, 15 Aug 2019 22:00:17 +0200 >Paul St George wrote: >> But I want an absolute path such as: >> ---Plane uses image01.tif saved >> at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif >> saved at /Users/Lion/Desktop/images/image02.tif >> >> If it is relevant, my files are on a Mac. Hence the escaped forward >> slash. You don't need to double the leading slash on a Mac. On 15Aug2019 22:52, Manfred Lotz wrote: >I did this: >from pathlib import Path >abs_myfile = Path('./myfile').resolve() >which worked fine for me. There is also os.path.realpath(filename) for this purpose. In modern Python that also accepts a Pathlike object. Cheers, Cameron Simpson From ml_news at posteo.de Thu Aug 15 23:44:55 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Fri, 16 Aug 2019 05:44:55 +0200 Subject: absolute path to a file References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> Message-ID: <20190816054455.7491bfe2@arcor.com> On Fri, 16 Aug 2019 09:00:38 +1000 Cameron Simpson wrote: > On 15Aug2019 22:52, Manfred Lotz wrote: > >I did this: > >from pathlib import Path > >abs_myfile = Path('./myfile').resolve() > >which worked fine for me. > > There is also os.path.realpath(filename) for this purpose. In modern > Python that also accepts a Pathlike object. Thanks for this. I changed my code to use your suggestion which seems to be better for the situation where I used resolve() before. -- Manfred From pankaj.jangid at gmail.com Fri Aug 16 07:08:39 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Fri, 16 Aug 2019 16:38:39 +0530 Subject: Your IDE's? References: <86ef6u1ohi.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > John Doe writes: > >> What is your favorite Python IDE? > > Maybe the Atom editor will get there some day, though for now I hear > many complaints that with many plug-ins active it's just too slow when > doing the kind of complex tasks we expect of a programmer's editor like > Vim or GNU Emacs. I also use Emacs for all my coding requirements. Atom will probably be abandonded now. Github is now acquired by Microsoft and hence their is no point for them to run two similar projects. The community might fork it though. -- Pankaj Planet Earth. From email at paulstgeorge.com Fri Aug 16 12:26:00 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 16 Aug 2019 18:26:00 +0200 Subject: absolute path to a file In-Reply-To: <20190816054455.7491bfe2@arcor.com> References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> Message-ID: Thank you Manfred and Cameron! I think the problem may lie within syntax rather than vocabulary. The code works in one place but not where I use it in my script*. Cameron?s suggestion works when I try |?print('test1:', os.path.realpath(bpy.data.filepath))| This returns: |/Users/Lion/Desktop/test8/tifftest8.blend| BUT does not work with |?print('test2:',os.path.realpath(n.image.filepath))| This returns only |/image01.tif| Here is my full script: # starts |import bpy|| ||import os|| ||from pathlib import Path || || ||texture_list = []|| || ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as outstream:|| || || ||?for obj in bpy.context.scene.objects:|| ||??? for s in obj.material_slots:|| ||??????? if s.material and s.material.use_nodes:|| ||??????????? for n in s.material.node_tree.nodes:|| ||??????????????? if n.type == 'TEX_IMAGE':|| ||??????????????????? texture_list += [n.image]|| ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', os.path.realpath(n.image.filepath), file=outstream)|| |||| |# ends Notes: Chris, I only mention the extra leading slash on my Mac in case anyone wonders why it is there. Python puts it there to escape the following slash. Perhaps I should also mention (in case it is relevant) that I am calling my script ?texturescript.py? from the Python console of Blender. I use: |filename = "/Users/Lion/Desktop/test8/texturescript.py"|| ||exec(compile(open(filename).read(), filename, 'exec'))| * My original |os.path.abspath| also works (and doesn?t work) in these circumstances. As does Manfred?s: |Path('./myfile').resolve()|. On 16/08/2019 05:44, Manfred Lotz wrote: > On Fri, 16 Aug 2019 09:00:38 +1000 > Cameron Simpson wrote: > >> On 15Aug2019 22:52, Manfred Lotz wrote: >>> I did this: >> >from pathlib import Path >>> abs_myfile = Path('./myfile').resolve() >>> which worked fine for me. >> There is also os.path.realpath(filename) for this purpose. In modern >> Python that also accepts a Pathlike object. > Thanks for this. > > I changed my code to use your suggestion which seems to > be better for the situation where I used resolve() before. > -- Paul St George http://www.paulstgeorge.com http://www.devices-of-wonder.com +44(0)7595 37 1302 From rosuav at gmail.com Fri Aug 16 12:37:14 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Aug 2019 02:37:14 +1000 Subject: absolute path to a file In-Reply-To: References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> Message-ID: On Sat, Aug 17, 2019 at 2:27 AM Paul St George wrote: > BUT does not work with > | print('test2:',os.path.realpath(n.image.filepath))| > > This returns only > |/image01.tif| > > > Notes: > Chris, I only mention the extra leading slash on my Mac in case anyone > wonders why it is there. Python puts it there to escape the following slash. I still don't understand what you mean by that, because there's no concept of "escaping" with these slashes. It looks like you're actually working with absolute paths (starting with the leading slash) when you want to work with relative paths (NOT starting with a leading slash). The double slash isn't "escaping" anything, to my knowledge, and Python would not add it. >From the look of things, you really are getting a valid absolute path - "/image01.tif" is already absolute. It just isn't the path you want. ChrisA From email at paulstgeorge.com Fri Aug 16 15:28:18 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 16 Aug 2019 21:28:18 +0200 Subject: absolute path to a file In-Reply-To: References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> Message-ID: <7228e9d8-37f0-4ee3-3ae5-dae401210e2a@paulstgeorge.com> On 16/08/2019 18:37, Chris Angelico wrote: > On Sat, Aug 17, 2019 at 2:27 AM Paul St George wrote: >> BUT does not work with >> | print('test2:',os.path.realpath(n.image.filepath))| >> >> This returns only >> |/image01.tif| >> >> >> Notes: >> Chris, I only mention the extra leading slash on my Mac in case anyone >> wonders why it is there. Python puts it there to escape the following slash. > > I still don't understand what you mean by that, because there's no > concept of "escaping" with these slashes. It looks like you're > actually working with absolute paths (starting with the leading slash) > when you want to work with relative paths (NOT starting with a leading > slash). The double slash isn't "escaping" anything, to my knowledge, > and Python would not add it. > > From the look of things, you really are getting a valid absolute path > - "/image01.tif" is already absolute. It just isn't the path you want. > > ChrisA > Yes, perhaps I am using the wrong terms. I want to find the path that looks like this: /Users/Lion/Desktop/test8/image01.tif With such a path, I can find the image file. I cannot find the file with only /image01.tif It is safe to ignore what I said about the double forward slashes. I am not using these. I only observed their presence and made a guess at their meaning. Paul From rosuav at gmail.com Fri Aug 16 15:43:14 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Aug 2019 05:43:14 +1000 Subject: absolute path to a file In-Reply-To: <7228e9d8-37f0-4ee3-3ae5-dae401210e2a@paulstgeorge.com> References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> <7228e9d8-37f0-4ee3-3ae5-dae401210e2a@paulstgeorge.com> Message-ID: On Sat, Aug 17, 2019 at 5:28 AM Paul St George wrote: > > On 16/08/2019 18:37, Chris Angelico wrote: > > On Sat, Aug 17, 2019 at 2:27 AM Paul St George wrote: > >> BUT does not work with > >> | print('test2:',os.path.realpath(n.image.filepath))| > >> > >> This returns only > >> |/image01.tif| > >> > >> > >> Notes: > >> Chris, I only mention the extra leading slash on my Mac in case anyone > >> wonders why it is there. Python puts it there to escape the following slash. > > > > I still don't understand what you mean by that, because there's no > > concept of "escaping" with these slashes. It looks like you're > > actually working with absolute paths (starting with the leading slash) > > when you want to work with relative paths (NOT starting with a leading > > slash). The double slash isn't "escaping" anything, to my knowledge, > > and Python would not add it. > > > > From the look of things, you really are getting a valid absolute path > > - "/image01.tif" is already absolute. It just isn't the path you want. > > > > ChrisA > > > > Yes, perhaps I am using the wrong terms. I want to find the path that > looks like this: > /Users/Lion/Desktop/test8/image01.tif > > With such a path, I can find the image file. I cannot find the file with > only /image01.tif > > It is safe to ignore what I said about the double forward slashes. I am > not using these. I only observed their presence and made a guess at > their meaning. > When your path starts with "/Users", that means the Users directory which is found in the root directory of your hard drive. When your path starts with "/image01.tif", that means that image01.tif needs to be in the root directory. If that's not the case (which I highly suspect), then you do NOT want a leading slash - just use "image01.tif", which means the file should be in the *current* directory. ChrisA From garyfallidis at gmail.com Fri Aug 16 16:46:31 2019 From: garyfallidis at gmail.com (Eleftherios Garyfallidis) Date: Fri, 16 Aug 2019 16:46:31 -0400 Subject: ANN: DIPY 1.0.0 - a historic release Message-ID: We are excited to announce a new major and historic release of Diffusion Imaging in Python (DIPY). DIPY 1.0.0 is out! Please cite using the following DOI: 10.3389/fninf.2014.00008 DIPY 1.0.0 (Monday, 5 August 2019) This release received contributions from 17 developers (the full release notes are at: https://dipy.org/documentation/1.0.0./release_notes/release1.0/). Thank you all for your contributions and feedback! A new DIPY era is starting: this release is compatible with python 3.5+ and breaks backward compatibility with 0.x.x. Please click here to check API changes or look at the end of this email. The 0.16.x series will have extended bug-fix-only support for Python 2.7 until June 2020. Highlights of this release include: - Critical API changes - New awesome website - Large refactoring of tracking API - New denoising algorithm: MP-PCA - New Gibbs ringing removal - New interpolation module: dipy.core.interpolation - New reconstruction models: Mean Signal DKI, MTMS-CSD - Increased coordinate systems consistency - New object to manage safely tractography data: StatefulTractogram - New command line interface for downloading datasets: FetchFlow - Horizon updated, medical visualization interface powered by QuickBundlesX - Removed all deprecated functions and parameters - Removed compatibility with Python 2.7 - Updated minimum dependencies version (Numpy, Scipy) - All tutorials updated to API changes and 3 new added - Large documentation update - Closed 289 issues and merged 98 pull requests Note: - DIPY 0.16.x will be the last series to support python 2. The next release, DIPY 1.0, will support python 3 only. To upgrade or install DIPY Run the following command in your terminal: pip install --upgrade dipy or conda install -c conda-forge dipy This version of DIPY depends on nibabel (2.4.0+). For visualization you need FURY (0.3.0+). Questions or suggestions? For any questions go to http://dipy.org, or send an e-mail to dipy at python.org We also have an instant messaging service and chat room available at https://gitter.im/nipy/dipy On behalf of the DIPY developers, Eleftherios Garyfallidis, Ariel Rokem, Serge Koudoro https://dipy.org/contributors API Changes Some of the changes introduced in the 1.0 release will break backwards compatibility with previous versions. This release is compatible with Python 3.5+ Reconstruction The spherical harmonics bases mrtrix and fibernav have been renamed to tournier07 and descoteaux07 after the deprecation cycle started in the 0.15 release. We changed dipy.data.default_sphere from symmetric724 to repulsion724 which is more evenly distributed. Segmentation The API of dipy.segment.mask.median_otsu has changed in the following ways: if you are providing a 4D volume, vol_idx is now a required argument. The order of parameters has also changed. Tractogram loading and saving The API of dipy.io.streamlines.load_tractogram and dipy.io.streamlines.save_tractogram has changed in the following ways: When loading trk, tck, vtk, fib, or dpy) a reference nifti file is needed to guarantee proper spatial transformation handling. Spatial transformation handling Functions from dipy.tracking.streamlines were modified to enforce the affine parameter and uniform docstrings. deform_streamlines select_by_rois, orient_by_rois, _extract_vals and values_from_volume. Functions from dipy.tracking.utils were modified to enforce the affine parameter and uniform docstring. density_map connectivity_matrix, seeds_from_mask, random_seeds_from_mask, target, target_line_based, near_roi, length and path_length were all modified. The function affine_for_trackvis, move_streamlines, flexi_tvis_affine and get_flexi_tvis_affine were deleted. Functions from dipy.tracking.life were modified to enforce the affine parameter and uniform docstring. voxel2streamline, setup and fit from class FiberModel were all modified. afq_profile from dipy.stats.analysis was modified in a similar way. Simulations - dipy.sims.voxel.SingleTensor has been replaced by dipy.sims.voxel.single_tensor - dipy.sims.voxel.MultiTensor has been replaced by dipy.sims.voxel.multi_tensor - dipy.sims.voxel.SticksAndBall has been replaced by dipy.sims.voxel.sticks_and_ball Interpolation All interpolation functions have been moved to a new module name dipy.core.interpolation Tracking The voxel_size parameter has been removed from the following function: - dipy.tracking.utils.connectivity_matrix - dipy.tracking.utils.density_map - dipy.tracking.utils.stremline_mapping - dipy.tracking._util._mapping_to_voxel The dipy.reconst.peak_direction_getter.PeaksAndMetricsDirectionGetter has been renamed dipy.reconst.peak_direction_getter.EuDXDirectionGetter. The LocalTracking and ParticleFilteringTracking functions were moved from dipy.tracking.local.localtrackingto dipy.tracking.local_tracking. They now need to be imported from dipy.tracking.local_tracking. - functions argument tissue_classifier were renamed stopping_criterion The TissueClassifier were renamed StoppingCriterion and moved from dipy.tracking.local.tissue_classifier to dipy.tracking.stopping_criterion. They now need to be imported from dipy.tracking.stopping_criterion. - TissueClassifier -> StoppingCriterion - BinaryTissueClassifier -> BinaryStoppingCriterion - ThresholdTissueClassifier -> ThresholdStoppingCriterion - ConstrainedTissueClassifier -> AnatomicalStoppingCriterion - ActTissueClassifier -> ActStoppingCriterion - CmcTissueClassifier -> CmcStoppingCriterion The dipy.tracking.local.tissue_classifier.TissueClass was renamed dipy.tracking.stopping_criterion.StreamlineStatus. The EuDX tracking function has been removed. EuDX tractography can be performed using dipy.tracking.local_tracking using dipy.reconst.peak_direction_getter.EuDXDirectionGetter. Streamlines dipy.io.trackvis has been removed. Use dipy.io.streamline instead. Other - dipy.external package has been removed. - dipy.fixes package has been removed. - dipy.segment.quickbundes module has been removed. - dipy.reconst.peaks module has been removed. - Compatibility with Python 2.7 has been removed From greg.ewing at canterbury.ac.nz Fri Aug 16 19:07:56 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 17 Aug 2019 11:07:56 +1200 Subject: absolute path to a file In-Reply-To: References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> Message-ID: > On Sat, Aug 17, 2019 at 2:27 AM Paul St George wrote: > >>BUT does not work with >>| print('test2:',os.path.realpath(n.image.filepath))| >> >>This returns only >>|/image01.tif| What does n.image.filepath look like on its own? If it starts with a leading slash, then os.path.realpath will think it's already an absolute path and leave it alone. The problem then is why it's getting a leading slash in the first place. It looks like the result of something naively trying to append a filename to an empty directory path. -- Greg From arj.python at gmail.com Fri Aug 16 22:18:12 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 17 Aug 2019 06:18:12 +0400 Subject: Your IDE's? In-Reply-To: References: Message-ID: XD John Doe, seems like an anonymous survey. I use sublime text, with linter + anaconda exec when needed. It also has an in-built run mode if you want to use it. The main advantage for me is that it is light. I used many IDEs before settling on this one. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From hongyi.zhao at gmail.com Sat Aug 17 00:12:34 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sat, 17 Aug 2019 04:12:34 +0000 (UTC) Subject: Your IDE's? References: <86ef6u1ohi.fsf@benfinney.id.au> <87h86gwvt0.fsf@nightsong.com> Message-ID: On Fri, 16 Aug 2019 16:10:51 -0700, Paul Rubin wrote: > Does Microsoft have another product that is similar to Atom? What is > it? > Just wondering. I use Emacs myself. vscode: https://code.visualstudio.com/ From arj.python at gmail.com Sat Aug 17 05:39:38 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 17 Aug 2019 13:39:38 +0400 Subject: Meanwhile Norwegian trolls created ... Message-ID: Was browsing when i came across this hilarious piece of text: *Once upon a time there was a programming language called C. And it had 2 memory management functions: malloc() and free(). But it was too complicated. Bjarne Stroustrup decided that C memory management should be easier. So he invented C++. In addition to malloc() and free(), C++ had new, delete, destructors, RAII, auto and shared pointers. Guido van Rossum found that C++ was also not simple enough. He chose another way and invented Python - a language which doesn?t have even malloc() or free(). Meanwhile Norwegian trolls created the C++ GUI library Qt. It simplifies memory management by deleting objects automatically when it thinks the objects are not needed. A man called Phil Thompson was upset that a cool library like Qt doesn?t exist in the excellent Python language. He combined them in the PyQt project. But it is not so easy to combine different memory management paradigms. Let?s see what the pitfalls are. (Text above is a fairy tale. Text below contains code and technical information)* source: http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html Yours, Abdur-Rahmaan Janhangeer pythonmembers.club | github Mauritius From email at paulstgeorge.com Sat Aug 17 05:51:47 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Aug 2019 11:51:47 +0200 Subject: absolute path to a file In-Reply-To: References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> Message-ID: <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> On 17/08/2019 01:07, Gregory Ewing wrote: >> On Sat, Aug 17, 2019 at 2:27 AM Paul St George >> wrote: >> >>> BUT does not work with >>> | print('test2:',os.path.realpath(n.image.filepath))| >>> >>> This returns only >>> |/image01.tif| > > What does n.image.filepath look like on its own? If it starts > with a leading slash, then os.path.realpath will think it's > already an absolute path and leave it alone. > > The problem then is why it's getting a leading slash in the > first place. It looks like the result of something naively > trying to append a filename to an empty directory path. > Gregory, Thank you for this. You ask what n.image.filepath looks like on its own. Here (below) are some tests and the results: You are right about the leading slashes. I have tried to remove them and then use os.path.realpath and os.path.abspath but it is as if the slash is still there. Perhaps there is a better way to remove the slash - perhaps by getting the name of the file. Then I could find the true path to the directory that contains the file, and finally join the two together. But there must be a simpler way? print('Track A:',n.image.filepath) ---Track A: //image01.tif print('Track B:',n.image.filepath[1:]) ---Track B: /image01.tif print('Track C:',n.image.filepath[2:]) ---Track C: image01.tif print('Track D from Track B:',os.path.realpath(n.image.filepath)) ---Track D from Track B: /image01.tif print('Track E from Track B:',os.path.realpath(n.image.filepath[1:])) ---Track E from Track B: /image01.tif print('Track F from Track C:',os.path.realpath(n.image.filepath[2:])) ---Track F from Track C: /image01.tif print('Track G from Track C:',os.path.abspath(n.image.filepath[2:])) ---Track G from Track C: /image01.tif From pankaj.jangid at gmail.com Sat Aug 17 06:18:41 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Sat, 17 Aug 2019 15:48:41 +0530 Subject: Meanwhile Norwegian trolls created ... References: Message-ID: Abdur-Rahmaan Janhangeer writes: > Was browsing when i came across this hilarious piece of text: > > source: http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html > I haven't searched for it though, but I guess if there is a Qt like framework in Rust then a Python wrapper around it would behave more meaningfully. -- Pankaj Planet Earth. From ml_news at posteo.de Sat Aug 17 07:09:47 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 17 Aug 2019 13:09:47 +0200 Subject: absolute path to a file References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> Message-ID: <20190817130947.4f74ccd1@arcor.com> Hi Paul, Here an example how I used both functions https://gitlab.com/snippets/1886520 Hope this helps. -- Manfred From __peter__ at web.de Sat Aug 17 09:37:36 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 17 Aug 2019 15:37:36 +0200 Subject: absolute path to a file References: Message-ID: Paul St George wrote: > Can someone please tell me how to get the absolute path to a file? I > have tried os.path.abspath. In the code below I have a problem in the > final line (15). > > # > |import bpy|| Is this blender? If so the "//" prefix starts making sense: https://docs.blender.org/api/current/bpy.path.html I'd try bpy.path.abspath() instead of os.pathabspath(). > ||import os|| > || > ||texture_list = []|| > || > ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as > outstream:|| > || > || > ||for obj in bpy.context.scene.objects:|| > ||for s in obj.material_slots:|| > ||if s.material and s.material.use_nodes:|| > ||for n in s.material.node_tree.nodes:|| > ||if n.type == 'TEX_IMAGE':|| > ||texture_list += [n.image]|| > ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which > is at', os.path.abspath(n.image.filepath), file=outstream)|| > |# > > This gives me: > ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif > ---Plane uses image02.tif saved at //../images/image02.tif which is at > //images/image02.tif > > But I want an absolute path such as: > ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif > ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif > > If it is relevant, my files are on a Mac. Hence the escaped forward slash. > From email at paulstgeorge.com Sat Aug 17 10:21:55 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Aug 2019 16:21:55 +0200 Subject: absolute path to a file In-Reply-To: References: Message-ID: On 17/08/2019 15:37, Peter Otten wrote: > Paul St George wrote: > >> Can someone please tell me how to get the absolute path to a file? I >> have tried os.path.abspath. In the code below I have a problem in the >> final line (15). >> >> # >> |import bpy|| > > Is this blender? If so the "//" prefix starts making sense: > > https://docs.blender.org/api/current/bpy.path.html > > I'd try bpy.path.abspath() instead of os.pathabspath(). > > >> ||import os|| >> || >> ||texture_list = []|| >> || >> ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as >> outstream:|| >> || >> || >> ||for obj in bpy.context.scene.objects:|| >> ||for s in obj.material_slots:|| >> ||if s.material and s.material.use_nodes:|| >> ||for n in s.material.node_tree.nodes:|| >> ||if n.type == 'TEX_IMAGE':|| >> ||texture_list += [n.image]|| >> ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which >> is at', os.path.abspath(n.image.filepath), file=outstream)|| >> |# >> >> This gives me: >> ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif >> ---Plane uses image02.tif saved at //../images/image02.tif which is at >> //images/image02.tif >> >> But I want an absolute path such as: >> ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif >> ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif >> >> If it is relevant, my files are on a Mac. Hence the escaped forward slash. >> > > Yes, it is Blender and the bpy.path.abspath() works! And thank you also for the link to the docs. They say: Returns the absolute path relative to the current blend file using the ?//? prefix. So does Blender have its own Python!!!!??? From email at paulstgeorge.com Sat Aug 17 11:10:51 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Aug 2019 17:10:51 +0200 Subject: absolute path to a file In-Reply-To: References: <20190815225206.44cec075@arcor.com> <20190815230038.GA60558@cskk.homeip.net> <20190816054455.7491bfe2@arcor.com> <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> Message-ID: On 17/08/2019 16:32, Dennis Lee Bieber wrote: > On Sat, 17 Aug 2019 11:51:47 +0200, Paul St George > declaimed the following: > > >> print('Track E from Track B:',os.path.realpath(n.image.filepath[1:])) >> ---Track E from Track B: /image01.tif >> > > Just for giggles, what happens if you preface that with a single > period... > > print('Track E from Track B:',os.path.realpath("." + > n.image.filepath[1:])) > > > print('Track E for giggles from Track B:',os.path.realpath("." + n.image.filepath[1:])) gives: Track E for giggles from Track B: /images/blah.tif From Richard at Damon-Family.org Sat Aug 17 11:22:45 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 17 Aug 2019 11:22:45 -0400 Subject: absolute path to a file In-Reply-To: References: Message-ID: On 8/17/19 10:21 AM, Paul St George wrote: > Yes, it is Blender and the bpy.path.abspath() works! > And thank you also for the link to the docs. They say: > Returns the absolute path relative to the current blend file using the > ?//? prefix. > > So does Blender have its own Python!!!!??? I don't think it has its own Python, but it sounds like it sort of extends the file system, and uses a leading // for something special. That means files that begin with // need to be processes through the blender library and not be used directly to the OS. -- Richard Damon From email at paulstgeorge.com Sat Aug 17 15:54:24 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Aug 2019 21:54:24 +0200 Subject: absolute path to a file In-Reply-To: References: Message-ID: <4f81000f-f81f-ff82-40cb-abd134d28af1@paulstgeorge.com> On 17/08/2019 15:37, Peter Otten wrote: > Paul St George wrote: > >> Can someone please tell me how to get the absolute path to a file? I >> have tried os.path.abspath. In the code below I have a problem in the >> final line (15). >> >> # >> |import bpy|| > > Is this blender? If so the "//" prefix starts making sense: > > https://docs.blender.org/api/current/bpy.path.html > > I'd try bpy.path.abspath() instead of os.pathabspath(). > > >> ||import os|| >> || >> ||texture_list = []|| >> || >> ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as >> outstream:|| >> || >> || >> ||for obj in bpy.context.scene.objects:|| >> ||for s in obj.material_slots:|| >> ||if s.material and s.material.use_nodes:|| >> ||for n in s.material.node_tree.nodes:|| >> ||if n.type == 'TEX_IMAGE':|| >> ||texture_list += [n.image]|| >> ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which >> is at', os.path.abspath(n.image.filepath), file=outstream)|| >> |# >> >> This gives me: >> ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif >> ---Plane uses image02.tif saved at //../images/image02.tif which is at >> //images/image02.tif >> >> But I want an absolute path such as: >> ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif >> ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif >> >> If it is relevant, my files are on a Mac. Hence the escaped forward slash. >> > > Now following Peter's immensely useful nudge towards bpy.path.abspath(), I have learned that Blender uses a special kind of relative path. These paths start with ?//? . The double slashes replace the path to the blend file?s directory. This means that py.path.abspath() gives a path that is absolute for most of its length then relative towards the end. The good news is that I have found a way to tidy this. os.path.abspath(bpy.path.abspath(p)) This gives a fully absolute file path. The bpy.path.abspath function takes care of the ?//? replacing it with the full path to the file, while os.path.abspath takes care of any other unwelcome relative ?../? that might remain. Thanks to everyone for their help! Paul From cs at cskk.id.au Sat Aug 17 20:03:16 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 18 Aug 2019 10:03:16 +1000 Subject: absolute path to a file In-Reply-To: <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> References: <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> Message-ID: <20190818000316.GA13173@cskk.homeip.net> On 17Aug2019 11:51, Paul St George wrote: > print('Track D from Track B:',os.path.realpath(n.image.filepath)) >---Track D from Track B: /image01.tif > > print('Track E from Track B:',os.path.realpath(n.image.filepath[1:])) >---Track E from Track B: /image01.tif > > print('Track F from Track C:',os.path.realpath(n.image.filepath[2:])) >---Track F from Track C: /image01.tif I know these may just be cut/paste, but you can shorten this by: from os.path import realpath print('Track F from Track C:',realpath(n.image.filepath[2:])) I have 2 other questions: 1: Is image01.tif a real existing file when you ran this code? realpath kind of expects that - it may do nothing for something which doesn't exist. I'd point out that realpath(3), which you get from the command "man 3 realpath", says: The realpath() function will resolve both absolute and relative paths and return the absolute pathname corresponding to file_name. All components of file_name must exist when realpath() is called. Most of the things in the os module are just thin wrappers for the OS supplied functions, which is why the MacOS realpath library function is relevant. 2: What is your current working directory when you run this code? If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename). 3: What is the airspeed velocity of an unladen swallow? https://www.python.org/dev/peps/pep-0234/#rationale Cheers, Cameron Simpson (formerly cs at zip.com.au) From tanyasharma2615 at gmail.com Sun Aug 18 02:56:59 2019 From: tanyasharma2615 at gmail.com (tanyasharma2615 at gmail.com) Date: Sat, 17 Aug 2019 23:56:59 -0700 (PDT) Subject: What makes Python so popular? Message-ID: Guys, checkout this super interesting post https://www.facebook.com/knowledgco/photos/a.217166592268251/396317004353208/?type=3&theater Also Learn about interesting online courses on Python here: www.knowledg.co From barry at barrys-emacs.org Sun Aug 18 02:44:21 2019 From: barry at barrys-emacs.org (Barry) Date: Sun, 18 Aug 2019 07:44:21 +0100 Subject: Meanwhile Norwegian trolls created ... In-Reply-To: References: Message-ID: <59220937-28F1-4FA1-89AE-03CE4D04C157@barrys-emacs.org> In practice PyQt works very well and you do not encounter problems with memory management or crashes. Barry > On 17 Aug 2019, at 10:39, Abdur-Rahmaan Janhangeer wrote: > > Was browsing when i came across this hilarious piece of text: > > *Once upon a time there was a programming language called C. And it had 2 > memory management functions: malloc() and free(). But it was too > complicated. Bjarne Stroustrup decided that C memory management should be > easier. So he invented C++. In addition to malloc() and free(), C++ had > new, delete, destructors, RAII, auto and shared pointers. Guido van Rossum > found that C++ was also not simple enough. He chose another way and > invented Python - a language which doesn?t have even malloc() or free(). > Meanwhile Norwegian trolls created the C++ GUI library Qt. It simplifies > memory management by deleting objects automatically when it thinks the > objects are not needed. A man called Phil Thompson was upset that a cool > library like Qt doesn?t exist in the excellent Python language. He combined > them in the PyQt project. But it is not so easy to combine different memory > management paradigms. Let?s see what the pitfalls are. (Text above is a > fairy tale. Text below contains code and technical information)* > > source: http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html > > Yours, > > Abdur-Rahmaan Janhangeer > pythonmembers.club | github > > Mauritius > -- > https://mail.python.org/mailman/listinfo/python-list From hongyi.zhao at gmail.com Sun Aug 18 09:42:57 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sun, 18 Aug 2019 13:42:57 +0000 (UTC) Subject: dnsstamp.py failed to parse the 'sdns://' string. Message-ID: Hi, I installed the https://pypi.org/project/dnsstamps/, and parsing the DNS stamps string of google dns, I meet the following error: $ dnsstamp.py parse sdns:// AgUAAAAAAAAABzguOC44LjigHvYkz_9ea9O63fP92_3qVlRn43cpncfuZnUWbzAMwbkgdoAkR6AZkxo_AEMExT_cbBssN43Evo9zs5_ZyWnftEUKZG5zLmdvb2dsZQovZG5zLXF1ZXJ5 Unable to parse stamp Any hints for this issue? Regards From email at paulstgeorge.com Sun Aug 18 11:29:38 2019 From: email at paulstgeorge.com (Paul St George) Date: Sun, 18 Aug 2019 17:29:38 +0200 Subject: absolute path to a file In-Reply-To: <20190818000316.GA13173@cskk.homeip.net> References: <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> <20190818000316.GA13173@cskk.homeip.net> Message-ID: <5df8475d-0983-e108-1984-2712f69de845@paulstgeorge.com> On 18/08/2019 02:03, Cameron Simpson wrote: > On 17Aug2019 11:51, Paul St George wrote: >> print('Track D? from Track B:',os.path.realpath(n.image.filepath)) >> ---Track D? from Track B: /image01.tif >> >> print('Track E? from Track B:',os.path.realpath(n.image.filepath[1:])) >> ---Track E? from Track B: /image01.tif >> >> print('Track F from Track C:',os.path.realpath(n.image.filepath[2:])) >> ---Track F from Track C: /image01.tif > > I know these may just be cut/paste, but you can shorten this by: > > ?? from os.path import realpath > ?? print('Track F from Track C:',realpath(n.image.filepath[2:])) > > I have 2 other questions: > > 1: Is image01.tif a real existing file when you ran this code? > > realpath kind of expects that - it may do nothing for something which > doesn't exist. I'd point out that realpath(3), which you get from the > command "man 3 realpath", says: > > ?? The realpath() function will resolve both absolute and relative > paths and > ?? return the absolute pathname corresponding to file_name.? All > ?? components of file_name must exist when realpath() is called. > > Most of the things in the os module are just thin wrappers for the OS > supplied functions, which is why the MacOS realpath library function is > relevant. > > 2: What is your current working directory when you run this code? > > If the underlying OS realpath fails, the Python library function might > fall back on os.path.join(os.getcwd(), filename). > > 3: What is the airspeed velocity of an unladen swallow? > > https://www.python.org/dev/peps/pep-0234/#rationale > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) 1: Is image01.tif a real existing file when you ran this code? Yes. image01.tif is real, existing and apparent. >>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', realpath(n.image.filepath)) gives: Plane uses image01.tif saved at //image01.tif which is at /image01.tif (Chris and Peter lead me to believe that Blender has a special kind of relative path. The double slashes replace the path to the blend file?s directory.) realpath has done something but I know not what. 2a: What is your current working directory when you run this code? Well, there at least two answers to that question. Within Blender's Python Console: >>> os.getcwd() ?/? But I am *guessing* the real location of the CWD is /Applications/Blender/blender.app/Contents/Resources/2.79/scripts I tried using realpath, bpy.path.abspath, and os.path.abspath on this forward slash but nothing changed. For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd())) 2b: If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename). It should, shouldn?t it. But it doesn?t. Anyway, wouldn?t this be an absolute path via the location of the CWD? 3: What is the airspeed velocity of an unladen swallow? Do you know the speed and direction of the swallow? From pkpearson at nowhere.invalid Sun Aug 18 15:18:01 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2019 19:18:01 GMT Subject: Xlabel and ylabel are not shown References: <1605d97b-125f-40a9-905f-691d6a169287@googlegroups.com> Message-ID: On Sat, 17 Aug 2019 10:58:43 -0700 (PDT), Amirreza Heidari wrote: > plt.figure(1) > plt.plot(history.history["loss"], "b", label="Mean Square Error of training") > plt.plot(history.history["val_loss"], "g", label="Mean Square Error [snip] > plt.legend() > plt.xlabel("Epoche") > plt.ylabel("Mean Square Error") > plt.xlim(0,200) > plt.show() > plt.savefig(r"C:\Users\aheidari\Dropbox\Dissertation\primary hot [snip] It works for me (using simple, fake data points, of course). Perhaps you could tell us which versions of Python and matplotlib you're using? -- To email me, substitute nowhere->runbox, invalid->com. From email at paulstgeorge.com Sun Aug 18 11:29:38 2019 From: email at paulstgeorge.com (Paul St George) Date: Sun, 18 Aug 2019 17:29:38 +0200 Subject: absolute path to a file In-Reply-To: <20190818000316.GA13173@cskk.homeip.net> References: <8089081e-dd97-13dd-484b-83bfddec2cee@paulstgeorge.com> <20190818000316.GA13173@cskk.homeip.net> Message-ID: <5df8475d-0983-e108-1984-2712f69de845@paulstgeorge.com> On 18/08/2019 02:03, Cameron Simpson wrote: > On 17Aug2019 11:51, Paul St George wrote: >> print('Track D? from Track B:',os.path.realpath(n.image.filepath)) >> ---Track D? from Track B: /image01.tif >> >> print('Track E? from Track B:',os.path.realpath(n.image.filepath[1:])) >> ---Track E? from Track B: /image01.tif >> >> print('Track F from Track C:',os.path.realpath(n.image.filepath[2:])) >> ---Track F from Track C: /image01.tif > > I know these may just be cut/paste, but you can shorten this by: > > ?? from os.path import realpath > ?? print('Track F from Track C:',realpath(n.image.filepath[2:])) > > I have 2 other questions: > > 1: Is image01.tif a real existing file when you ran this code? > > realpath kind of expects that - it may do nothing for something which > doesn't exist. I'd point out that realpath(3), which you get from the > command "man 3 realpath", says: > > ?? The realpath() function will resolve both absolute and relative > paths and > ?? return the absolute pathname corresponding to file_name.? All > ?? components of file_name must exist when realpath() is called. > > Most of the things in the os module are just thin wrappers for the OS > supplied functions, which is why the MacOS realpath library function is > relevant. > > 2: What is your current working directory when you run this code? > > If the underlying OS realpath fails, the Python library function might > fall back on os.path.join(os.getcwd(), filename). > > 3: What is the airspeed velocity of an unladen swallow? > > https://www.python.org/dev/peps/pep-0234/#rationale > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) 1: Is image01.tif a real existing file when you ran this code? Yes. image01.tif is real, existing and apparent. >>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', realpath(n.image.filepath)) gives: Plane uses image01.tif saved at //image01.tif which is at /image01.tif (Chris and Peter lead me to believe that Blender has a special kind of relative path. The double slashes replace the path to the blend file?s directory.) realpath has done something but I know not what. 2a: What is your current working directory when you run this code? Well, there at least two answers to that question. Within Blender's Python Console: >>> os.getcwd() ?/? But I am *guessing* the real location of the CWD is /Applications/Blender/blender.app/Contents/Resources/2.79/scripts I tried using realpath, bpy.path.abspath, and os.path.abspath on this forward slash but nothing changed. For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd())) 2b: If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename). It should, shouldn?t it. But it doesn?t. Anyway, wouldn?t this be an absolute path via the location of the CWD? 3: What is the airspeed velocity of an unladen swallow? Do you know the speed and direction of the swallow? From cs at cskk.id.au Sun Aug 18 19:31:05 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 19 Aug 2019 09:31:05 +1000 Subject: absolute path to a file In-Reply-To: <5df8475d-0983-e108-1984-2712f69de845@paulstgeorge.com> References: <5df8475d-0983-e108-1984-2712f69de845@paulstgeorge.com> Message-ID: <20190818233105.GA63917@cskk.homeip.net> Paul, I can see we must train you in the interleaved response style :-) On 18Aug2019 17:29, Paul St George wrote: >On 18/08/2019 02:03, Cameron Simpson wrote: >1: Is image01.tif a real existing file when you ran this code? > >Yes. image01.tif is real, existing and apparent. But in what directory? What is its _actual_ full path as you expect it to be? >>>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, >'which is at', realpath(n.image.filepath)) >gives: >Plane uses image01.tif saved at //image01.tif which is at /image01.tif > >(Chris and Peter lead me to believe that Blender has a special kind of >relative path. The double slashes replace the path to the blend file?s >directory.) realpath has done something but I know not what. I expect that realpath has normalised the string '//image01.tif' into the normal UNIX path '/image01.tif'. Because realpath works with UNIX paths, '//image01.tif' is not the path to an existing file from its point of view, because that would be in / ('//' is equivalent to '/' in UNIX, because multiple slashes coalesce). >2a: >What is your current working directory when you run this code? > >Well, there at least two answers to that question. Within Blender's >Python Console: >>>> os.getcwd() >?/? Did you run the other code in Blender's Console? The thing to bear in mind is that on many GUI desktops a GUI application's working directory may be '/'. Specificly, _not_ your home directory. This is because they're invoked (usually) by the desktop manager programme. And also because it sidesteps awkward situations like having the working directory in some removable medium such as a thumb drive, which might get removed. So the Blender CWD is _not_ your home directory or whatever directory your terminal prompt may be in. And therefore things that depend on the current directory will behave counterintuitively. In your case, by getting '/' from os.getcwd(). So: if the image01.tif file is _not_ in '/' (which I expect to be the case) then Python's realpath will be doing a lexical operation because as far as it is concerned the pathname ('//image01.tif') is not the path of an existing file. And its getcwd() isn't what you expect, thus the result not being what you want. >But I am *guessing* the real location of the CWD is >/Applications/Blender/blender.app/Contents/Resources/2.79/scripts This isn't a meaningful statement to me. The CWD is the working directory of the python interpreter running your code. If that is the Blender Console and the consale says the cwd is '/', then that's what it is. In particular, if you invoke some Python script as /path/to/script.py, your cwd does not magicly become '/path/to'. The cwd is a per process ephemeral thing, which is why the shell "cd" command works: it switches the working directory for the shell, and that context is inherited by child processes (your commands). >I tried using realpath, bpy.path.abspath, and os.path.abspath on this >forward slash but nothing changed. Because the leading slash makes it an absolute path by UNIX rules. The cwd never gets a look in; it is irrelevant. >For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd())) os.path.join is pretty lexical; it largely exists to avoid wiring in an OS-dependent path separator into your code (eg Windows' '\\' versus UNIX '/' or OS9 ':'). But it notices an absolute path in the sequence and discards earlier values, so the second getcwd is kept; not sure why this is useful behaviour. But putting an absolute path on the right hand end of a join isn't meaningful either, so the result is at best amusing anyway. >2b: >If the underlying OS realpath fails, the Python library function might >fall back on os.path.join(os.getcwd(), filename). > >It should, shouldn?t it. But it doesn?t. Well, I over simplified. If your path doesn't stat() (== "resolve directly to a filesystem object", on which the OS realpath relies), Python's realpath seems to be doing a _purely lexical_ path normalisation, like os.path.normpath. So, what have you passed in? '//image01.tif'. That is an absolute path. The cwd is not relevant, realpath runs with it as is. 'image01.tif' is not in '/', so it doesn't stat(), so we just normalise the path to '/image01.tif'. Alternative values: 'image01.tif' (your n.image.filepath[2:], to skip the Blender specific '//' relative pathname notation). That is a relative path. Can we stat it? That will happen in the Python interpreter's cwd, which apparently is Blender's cwd, which is '/'. And there's no '/image01.tif', so it doesn't stat. Back to lexcial work: normpath(os.path.join(os.getcwd(),filename)) i.e.: normpath(os.path.joinpath('/','image01.tif')) which becomes '/image01.tif'. >Anyway, wouldn?t this be an absolute path via the location of the CWD? That's not a meaningful term to me. An absolute path begins with a slash and doesn't depend on the cwd to locate the filesystem object. A relative path does not begin with a slash, and uses the cwd as the starting point to locate the filesystem object. I suspect that you need to resolve two issues: 1: What is the working directory in which image01.tif actually resides? It looks like that is _not_ the getcwd() which Blender gets, because it is a GUI app whose cwd is not your work area. That will cause _all_ relative paths to resolve incorrectly from your pointof view. 2: Are you getting a path for image01.tif from Blender using its special relative path notation, the leading '//'? Which is alluded to here: https://docs.blender.org/manual/en/latest/files/blend/save_load.html If you're working with such a path, you want to transform this into a path to the directory from this the "Blender relative" path was obtained, such as the directory used in some file chooser dialogue box. So you might want to write an unBlenderiser (untested example): from os.path import isabs, join as joinpath def unblenderise(filename, context_dir=None): # transmute Blender "relative" path if filename.startswith('//'): filename = filename[2:] if not isabs(filename) and context_dir is not None: # attach the filename to `context_dir` if supplied filename = joinpath(context_dir, filename) return filename The idea here is to get back a meaningful UNIX path from a Blender path. It first strips a leading '//'. Next, _if_ the filename is relative _and_ you supplied the optional context_dir (eg the directory used for a file brwoser dialogue box), then it prepends that context directory. This _does not_ call abspath or realpath or anything, it just returns a filename which can be used with them. The idea is that if you know where image01.tif lives, you could supply that as the context directory. 3: We could grip it by the husk. Cheers, Cameron Simpson From email at paulstgeorge.com Mon Aug 19 02:52:24 2019 From: email at paulstgeorge.com (Paul St George) Date: Mon, 19 Aug 2019 08:52:24 +0200 Subject: absolute path to a file In-Reply-To: <20190818233105.GA63917@cskk.homeip.net> References: <5df8475d-0983-e108-1984-2712f69de845@paulstgeorge.com> <20190818233105.GA63917@cskk.homeip.net> Message-ID: On 19/08/2019 01:31, Cameron Simpson wrote: > Paul, I can see we must train you in the interleaved response style :-) > > On 18Aug2019 17:29, Paul St George wrote: >> On 18/08/2019 02:03, Cameron Simpson wrote: >> 1: Is image01.tif a real existing file when you ran this code? >> >> Yes. image01.tif is real, existing and apparent. > > But in what directory? What is its _actual_ full path as you expect it > to be? Aha. The Blender file that I am using to test this on has two images used as textures. They reside at: /Users/Lion/Desktop/test8/image01.tif /Users/Lion/Desktop/images/image02.tif The Blender file is at /Users/Lion/Desktop/test8/tifftest8.blend > >>>>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, >> 'which is at', realpath(n.image.filepath)) >> gives: >> Plane uses image01.tif saved at //image01.tif which is at /image01.tif >> >> (Chris and Peter lead me to believe that Blender has a special kind of >> relative path. The double slashes replace the path to the blend file?s >> directory.) realpath has done something but I know not what. > > I expect that realpath has normalised the string '//image01.tif' into > the normal UNIX path '/image01.tif'. Because realpath works with UNIX > paths, '//image01.tif' is not the path to an existing file from its > point of view, because that would be in / ('//' is equivalent to '/' in > UNIX, because multiple slashes coalesce). > >> 2a: >> What is your current working directory when you run this code? >> >> Well, there at least two answers to that question. Within Blender's >> Python Console: >>>>> os.getcwd() >> ?/? > > Did you run the other code in Blender's Console? I ran this from Blender's console: >>>filename = "/Users/Lion/Desktop/test8/readout.py" >>>exec(compile(open(filename).read(), filename, 'exec')) I ran os.getcwd() from both within /Users/Lion/Desktop/test8/readout.py and directly within the Blender console. >> ?/? > > The thing to bear in mind is that on many GUI desktops a GUI > application's working directory may be '/'. Specificly, _not_ your home > directory. This is because they're invoked (usually) by the desktop > manager programme. And also because it sidesteps awkward situations like > having the working directory in some removable medium such as a thumb > drive, which might get removed. > > So the Blender CWD is _not_ your home directory or whatever directory > your terminal prompt may be in. > > And therefore things that depend on the current directory will behave > counterintuitively. In your case, by getting '/' from os.getcwd(). > > So: if the image01.tif file is _not_ in '/' (which I expect to be the > case) then Python's realpath will be doing a lexical operation because > as far as it is concerned the pathname ('//image01.tif') is not the path > of an existing file. And its getcwd() isn't what you expect, thus the > result not being what you want. > >> But I am *guessing* the real location of the CWD is >> /Applications/Blender/blender.app/Contents/Resources/2.79/scripts > > This isn't a meaningful statement to me. The CWD is the working > directory of the python interpreter running your code. If that is the > Blender Console and the consale says the cwd is '/', then that's what it > is. > > In particular, if you invoke some Python script as /path/to/script.py, > your cwd does not magicly become '/path/to'. > > The cwd is a per process ephemeral thing, which is why the shell "cd" > command works: it switches the working directory for the shell, and that > context is inherited by child processes (your commands). > >> I tried using realpath, bpy.path.abspath, and os.path.abspath on this >> forward slash but nothing changed. > > Because the leading slash makes it an absolute path by UNIX rules. The > cwd never gets a look in; it is irrelevant. > >> For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd())) > > os.path.join is pretty lexical; it largely exists to avoid wiring in an > OS-dependent path separator into your code (eg Windows' '\\' versus UNIX > '/' or OS9 ':'). But it notices an absolute path in the sequence and > discards earlier values, so the second getcwd is kept; not sure why this > is useful behaviour. But putting an absolute path on the right hand end > of a join isn't meaningful either, so the result is at best amusing anyway. > >> 2b: >> If the underlying OS realpath fails, the Python library function might >> fall back on os.path.join(os.getcwd(), filename). >> >> It should, shouldn?t it. But it doesn?t. > > Well, I over simplified. If your path doesn't stat() (== "resolve > directly to a filesystem object", on which the OS realpath relies), > Python's realpath seems to be doing a _purely lexical_ path > normalisation, like os.path.normpath. > > So, what have you passed in? '//image01.tif'. That is an absolute path. > The cwd is not relevant, realpath runs with it as is. 'image01.tif' is > not in '/', so it doesn't stat(), so we just normalise the path to > '/image01.tif'. > > Alternative values: > > 'image01.tif' (your n.image.filepath[2:], to skip the Blender specific > '//' relative pathname notation). That is a relative path. Can we stat > it? That will happen in the Python interpreter's cwd, which apparently > is Blender's cwd, which is '/'. And there's no '/image01.tif', so it > doesn't stat. Back to lexcial work: > > ?normpath(os.path.join(os.getcwd(),filename)) > > i.e.: > > ?normpath(os.path.joinpath('/','image01.tif')) > > which becomes '/image01.tif'. > >> Anyway, wouldn?t this be an absolute path via the location of the CWD? > > That's not a meaningful term to me. > > An absolute path begins with a slash and doesn't depend on the cwd to > locate the filesystem object. > > A relative path does not begin with a slash, and uses the cwd as the > starting point to locate the filesystem object. > > I suspect that you need to resolve two issues: > > 1: What is the working directory in which image01.tif actually resides? > It looks like that is _not_ the getcwd() which Blender gets, because it > is a GUI app whose cwd is not your work area. That will cause _all_ > relative paths to resolve incorrectly from your pointof view. > > 2: Are you getting a path for image01.tif from Blender using its special > relative path notation, the leading '//'? > > Which is alluded to here: > > ?https://docs.blender.org/manual/en/latest/files/blend/save_load.html > > If you're working with such a path, you want to transform this into a > path to the directory from this the "Blender relative" path was > obtained, such as the directory used in some file chooser dialogue box. > So you might want to write an unBlenderiser (untested example): > > ?from os.path import isabs, join as joinpath > > ?def unblenderise(filename, context_dir=None): > ?? # transmute Blender "relative" path > ?? if filename.startswith('//'): > ???? filename = filename[2:] > ?? if not isabs(filename) and context_dir is not None: > ???? # attach the filename to `context_dir` if supplied > ???? filename = joinpath(context_dir, filename) > ?? return filename > > The idea here is to get back a meaningful UNIX path from a Blender path. > It first strips a leading '//'. Next, _if_ the filename is relative > _and_ you supplied the optional context_dir (eg the directory used for a > file brwoser dialogue box), then it prepends that context directory. > > This _does not_ call abspath or realpath or anything, it just returns a > filename which can be used with them. > > The idea is that if you know where image01.tif lives, you could supply > that as the context directory. Yes! Until Peter Otten's timely intervention, I was trying to do this and had managed to join the path_to_the_folder_that_contains_the_Blender_file to the_name_of_the_image (stripped of its preceding slashes). Your unblenderise looks much better than my nascent saneblender so thank you. I will explore more! Does it depend on knowing where image01.tif lives and manually supplying that? I had been trying to use os.path.dirname() but of course only getting '//' so getting back to where I had started. > > 3: We could grip it by the husk. > > Cheers, > Cameron Simpson From jfong at ms4.hinet.net Mon Aug 19 05:10:40 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 19 Aug 2019 02:10:40 -0700 (PDT) Subject: Which editor is suited for view a python package's source? Message-ID: I like to download one package's source and study it in an editor. It allows me to open the whole package as a project and let me jump from a reference in one file to its definition in another file back and forth. It will be even better if it can handle the import modules too. (Maybe this is too much:-) Can anyone recommend such a tool? --Jach From nick.a.sarbicki at gmail.com Mon Aug 19 05:33:00 2019 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Mon, 19 Aug 2019 10:33:00 +0100 Subject: Which editor is suited for view a python package's source? In-Reply-To: References: Message-ID: PyCharm takes you to the source code within the editor for any variables/functions/classes/modules if you ctrl+click on what you want to see. It allows you to browse the relevant bits of code quickly, as well as let you change them in your local environment if need be. That way you don't have to download the source separately, you can just use it as a normal dependency. But if you want to view the source of a project in isolation I imagine any common editor will suffice. Personally I'll tend to look where the source is hosted (GitHub, GitLab etc) instead of downloading it. But I can understand why some may not trust this. On Mon, 19 Aug 2019, 10:17 , wrote: > I like to download one package's source and study it in an editor. It > allows me to open the whole package as a project and let me jump from a > reference in one file to its definition in another file back and forth. It > will be even better if it can handle the import modules too. (Maybe this is > too much:-) > > Can anyone recommend such a tool? > > --Jach > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Mon Aug 19 08:16:34 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 19 Aug 2019 22:16:34 +1000 Subject: absolute path to a file In-Reply-To: References: Message-ID: <20190819121634.GA69703@cskk.homeip.net> On 19Aug2019 08:52, Paul St George wrote: >On 19/08/2019 01:31, Cameron Simpson wrote: >>On 18Aug2019 17:29, Paul St George wrote: >>>On 18/08/2019 02:03, Cameron Simpson wrote: >>>1: Is image01.tif a real existing file when you ran this code? >>>Yes. image01.tif is real, existing and apparent. >>But in what directory? What is its _actual_ full path as you expect it >>to be? > >Aha. The Blender file that I am using to test this on has two images >used as textures. They reside at: >/Users/Lion/Desktop/test8/image01.tif >/Users/Lion/Desktop/images/image02.tif > >The Blender file is at /Users/Lion/Desktop/test8/tifftest8.blend There's a remark on that web page I mentioned that suggests that the leading '//' indicates the filename is relative to the Blender model, so the context directory for the '//' is likely /Users/Lion/Desktop/test8. >>>(Chris and Peter lead me to believe that Blender has a special kind >>>of relative path. The double slashes replace the path to the blend >>>file?s directory.) realpath has done something but I know not what. realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it is a special Blender path. First you need to convert it. By replacing '//' with the blend file's directory. Then you can call realpath. If you still need to. [...snip...] >>So you might want to write an unBlenderiser (untested example): >> >> ?from os.path import isabs, join as joinpath >> >> ?def unblenderise(filename, context_dir=None): >> ?? # transmute Blender "relative" path >> ?? if filename.startswith('//'): >> ???? filename = filename[2:] >> ?? if not isabs(filename) and context_dir is not None: >> ???? # attach the filename to `context_dir` if supplied >> ???? filename = joinpath(context_dir, filename) >> ?? return filename >> >>The idea here is to get back a meaningful UNIX path from a Blender >>path. It first strips a leading '//'. Next, _if_ the filename is >>relative _and_ you supplied the optional context_dir (eg the >>directory used for a file brwoser dialogue box), then it prepends >>that context directory. >> >>This _does not_ call abspath or realpath or anything, it just >>returns a filename which can be used with them. >> >>The idea is that if you know where image01.tif lives, you could >>supply that as the context directory. > >Yes! Until Peter Otten's timely intervention, I was trying to do this >and had managed to join the >path_to_the_folder_that_contains_the_Blender_file to >the_name_of_the_image (stripped of its preceding slashes). > >Your unblenderise looks much better than my nascent saneblender so >thank you. I will explore more! Looks like you want wd=os.path.dirname(path_of_blend_file). >Does it depend on knowing where image01.tif lives and manually >supplying that? Sort of. What you've got is '//image01.tif', which is Blender's special notation indicating a filename relative to the blend file's directory. All the Python library stuff expects an OS path (OS==UNIX on a Mac). So you want to convert that into a UNIX path. For example: from os.path import dirname # Get this from somewhere just hardwiring it for the example. # Maybe from your 'n' object below? blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' blender_image_file = n.image.filename unix_image_file = unblenderise(blender_image_file, dirname(blend_file)) Now you have a UNIX path. If blend_file is an absolute path, unix_image_path will also be an absolute path. But if blend_file is a relative path (eg you opened up "tifftest8.blend") unix_image_path will be a relative path. You don't need to use realpath or abspath on that _unless_ you need to reference the file from any directory (i.e. _not_ relative to where you currently are). Cheers, Cameron Simpson From dboland9 at protonmail.com Mon Aug 19 08:43:21 2019 From: dboland9 at protonmail.com (Dave) Date: Mon, 19 Aug 2019 08:43:21 -0400 Subject: Application Preferences Message-ID: The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? Thanks, Dave From python at bdurham.com Mon Aug 19 09:22:53 2019 From: python at bdurham.com (Malcolm Greene) Date: Mon, 19 Aug 2019 07:22:53 -0600 Subject: Application Preferences In-Reply-To: References: Message-ID: <49155cf9-b358-417f-a125-f19b0a51ad5a@www.fastmail.com> Hi Dave, > The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? We handle the "where is my config file" question by defaulting to script's current directory, then a script-specific folder within their home directory. Users can override that behavior by setting a script specific environment variable or by using a command line switch to point to a different location or config file. We store our preferences in an INI style config file which we've found easier to support when there's problems. Malcolm From dboland9 at protonmail.com Mon Aug 19 09:53:59 2019 From: dboland9 at protonmail.com (Dave) Date: Mon, 19 Aug 2019 09:53:59 -0400 Subject: Application Preferences References: <49155cf9-b358-417f-a125-f19b0a51ad5a@www.fastmail.com> Message-ID: On 8/19/19 9:22 AM, Malcolm Greene wrote: > Hi Dave, > >> The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? > > We handle the "where is my config file" question by defaulting to script's current directory, then a script-specific folder within their home directory. Users can override that behavior by setting a script specific environment variable or by using a command line switch to point to a different location or config file. > > We store our preferences in an INI style config file which we've found easier to support when there's problems. > > Malcolm > > Malcolm, Thanks for the reply. I agree that a traditional INI file is the easiest way, especially since Python supports them. So if I understand you, your apps look like this: -App Dir | +-App Code Folder | +-(File to direct to home folder) -Home Folder (the default location, but user can select other locations) | +-App INI Folder | +-App INI file From python at bdurham.com Mon Aug 19 11:08:38 2019 From: python at bdurham.com (Malcolm Greene) Date: Mon, 19 Aug 2019 09:08:38 -0600 Subject: Application Preferences In-Reply-To: References: <49155cf9-b358-417f-a125-f19b0a51ad5a@www.fastmail.com> Message-ID: <85768688-0aa2-47d0-b12f-6e374067bd12@www.fastmail.com> Hi Dave, > I agree that a traditional INI file is the easiest way, especially since Python supports them. So if I understand you, your apps look like this: Yes with the following nuance for our application sized scripts that require multiple configuration files. In this latter case, we place all config files in a ../conf folder (see the OR option below). -App Dir | +-App Code Folder (src) | +-App INI file OR -App Dir | +-conf | +-App INI file AND -Home Folder (the default location, but user can select other locations) | +-App INI Folder | +-App INI file Malcolm From hongyi.zhao at gmail.com Fri Aug 16 18:54:25 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 16 Aug 2019 22:54:25 -0000 (UTC) Subject: Using scapy to defeat the dns poisoning, is it possible? Message-ID: Hi, See my following testings: $ dig www.twitter.com @8.8.8.8 +short 66.220.147.44 While the tcpdump gives the following at the meanwhile: $ sudo tcpdump -n 'host 8.8.8.8 and port 53' tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on enp5s0, link-type EN10MB (Ethernet), capture size 262144 bytes 06:49:35.779852 IP 192.168.1.2.59443 > 8.8.8.8.53: 56457+ [1au] A? www.twitter.com. (44) 06:49:35.818492 IP 8.8.8.8.53 > 192.168.1.2.59443: 56457 1/0/0 A 66.220.147.44 (49) 06:49:35.818531 IP 8.8.8.8.53 > 192.168.1.2.59443: 56457 1/0/0 A 69.171.248.65 (49) 06:49:35.824454 IP 8.8.8.8.53 > 192.168.1.2.59443: 56457 3/0/1 CNAME twitter.com., A 104.244.42.129, A 104.244.42.65 (90) As you can see, the dns is poisoned, is it possible to defeat this with scapy or some techniques with python? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. From amirrezaheidarysbu at gmail.com Sat Aug 17 13:58:43 2019 From: amirrezaheidarysbu at gmail.com (Amirreza Heidari) Date: Sat, 17 Aug 2019 10:58:43 -0700 (PDT) Subject: Xlabel and ylabel are not shown Message-ID: <1605d97b-125f-40a9-905f-691d6a169287@googlegroups.com> plt.figure(1) plt.plot(history.history["loss"], "b", label="Mean Square Error of training") plt.plot(history.history["val_loss"], "g", label="Mean Square Error of validation") plt.legend() plt.xlabel("Epoche") plt.ylabel("Mean Square Error") plt.xlim(0,200) plt.show() plt.savefig(r"C:\Users\aheidari\Dropbox\Dissertation\primary hot water use prediction\Diagrams\UnivariateTrainingerror.png", dpi=1200) From john_ladasky at sbcglobal.net Mon Aug 19 00:11:37 2019 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 18 Aug 2019 21:11:37 -0700 (PDT) Subject: Meanwhile Norwegian trolls created ... In-Reply-To: References: Message-ID: <6901ca7a-24fd-4e85-9b32-4839d8a6629d@googlegroups.com> On Saturday, August 17, 2019 at 2:40:14 AM UTC-7, Abdur-Rahmaan Janhangeer wrote: > But it is not so easy to combine different memory management paradigms. Oh, I feel this. I love the look and feel of PyQt5, but object management has bitten me more than once. From iranna.gani28 at gmail.com Mon Aug 19 14:10:35 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Mon, 19 Aug 2019 23:40:35 +0530 Subject: How to login remote windos device using python Message-ID: Hi Team, can you please let me know, How to login the remote Windows machine using python?? Thanks From rgaddi at highlandtechnology.invalid Mon Aug 19 14:25:01 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 19 Aug 2019 11:25:01 -0700 Subject: My pseudocode to Python? In-Reply-To: References: Message-ID: On 8/19/19 10:43 AM, Stefan Ram wrote: > Can someone kindly translate my pseudocode to terse Python: > > list = \ > [ 'afaueghauihaiuhgaiuhgaiuhgaeihui', > 'erghariughauieghaiughahgaihgaiuhgaiuh', > 'rejganregairghaiurghaiuhgauihgauighaei', > if x: 'argaeruighaiurhauirguiahuiahgiauhgaeuihi', > 'reiugaheirughauierhgauiaeihauiehgiuaehuih' > 'ejiaeigaiuegreaiugheiugheaiughauighaiughaiu' > 'egairughauirghauiruiegihgruiehgiuaehgiaue' ] > > ? I want the list to have the seven strings shown as entries > if bool(x) is True, but otherwise the list should only have > six entries - without the entry directly behind "if x: ". > > mylist = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] if not x: del mylist[3] -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From barry at barrys-emacs.org Mon Aug 19 13:53:08 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 19 Aug 2019 18:53:08 +0100 Subject: Application Preferences In-Reply-To: References: Message-ID: <29CF5F65-AC87-4A03-A34F-ED3F9FD5E90F@barrys-emacs.org> > On 19 Aug 2019, at 13:43, Dave via Python-list wrote: > > The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? There are expected locations for config files and data files on each OS. On macOS you would use ~/Library/Preferences/ and put a file or a folder of files in there. The convention is use your website name as the base name of the file or folder. For example for scm-workbench I use: org.barrys-emacs.scm-workbench as the folder name for all the scm-workbench files. On Windows you can use a file or folder in %APPDATA% that is named after your app. You should find the folder by doing a win32 API call to get the value. See getPreferencesDir() in https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_platform_win32_specific.py for how to get the value. On Linux the XDG spec says that you should put config files in ~/.config/ and data files in ~/.local/share/. Doing XDG to the spec is a little involved. I have some experimental code that implements the logic for config the XdgConfigPath class in: https://github.com/barry-scott/CLI-tools/blob/master/Source/smart_find/__init__.py Putting a file directly in the $HOME folder is no longer recommended. The format of the config data you are free to choose. I have been using JSON files recently as it allow for structured data. Barry From dboland9 at protonmail.com Mon Aug 19 15:03:41 2019 From: dboland9 at protonmail.com (Dave) Date: Mon, 19 Aug 2019 15:03:41 -0400 Subject: Application Preferences References: <29CF5F65-AC87-4A03-A34F-ED3F9FD5E90F@barrys-emacs.org> Message-ID: On 8/19/19 1:53 PM, Barry Scott wrote: > > >> On 19 Aug 2019, at 13:43, Dave via Python-list wrote: >> >> The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? > > There are expected locations for config files and data files on each OS. > > On macOS you would use ~/Library/Preferences/ and put a file or a folder of files in there. > The convention is use your website name as the base name of the file or folder. > For example for scm-workbench I use: org.barrys-emacs.scm-workbench as the folder name for > all the scm-workbench files. > > On Windows you can use a file or folder in %APPDATA% that is named after your app. You should > find the folder by doing a win32 API call to get the value. See getPreferencesDir() in > https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_platform_win32_specific.py > for how to get the value. > > On Linux the XDG spec says that you should put config files in ~/.config/ and data files > in ~/.local/share/. Doing XDG to the spec is a little involved. I have some experimental > code that implements the logic for config the XdgConfigPath class in: > https://github.com/barry-scott/CLI-tools/blob/master/Source/smart_find/__init__.py > > Putting a file directly in the $HOME folder is no longer recommended. > > The format of the config data you are free to choose. > I have been using JSON files recently as it allow for structured data. > > > Barry > Barry, and all, I agree that various OS's have a favorite place to put things. Python has a library that will help. However, there are valid reasons to let the customer choose. Perhaps the drive/folder is a journaling one, or one that is backed up multiple times per day. My take is to start with the OS solution, but let the customer decide. How did this thread show up in the SQLite mailing list anyway? Really has nothing to do with SQLite that I can see. Dave, From dboland9 at protonmail.com Mon Aug 19 14:01:17 2019 From: dboland9 at protonmail.com (dboland9) Date: Mon, 19 Aug 2019 18:01:17 +0000 Subject: Application Preferences In-Reply-To: <29CF5F65-AC87-4A03-A34F-ED3F9FD5E90F@barrys-emacs.org> References: <29CF5F65-AC87-4A03-A34F-ED3F9FD5E90F@barrys-emacs.org> Message-ID: Wow, what happened here? I posted this to the Python discussion group as it is a Python question, not an SQL question. That said, I agree with what you have said, and that was the plan. Plans get changed. A number of apps. allow the user to specify the location of data and configuration files, and for good reason. Some folders are auto-backup in that they are either journaled or backed up multiple times per day. I think that is the argument in this case. Dave, Sent with [ProtonMail](https://protonmail.com) Secure Email. ??????? Original Message ??????? On Monday, August 19, 2019 1:53 PM, Barry Scott wrote: >> On 19 Aug 2019, at 13:43, Dave via Python-list wrote: >> >> The plan for an app that I'm doing was to use SQLite for data and to hold the preference settings as some apps do. The plan was changed last week to allow the user to select the location of the data files (SQLite) rather than putting it where the OS would dictate. Ok with that, but it brings up some questions. First, I will need to have a file that points to the location of the data file since that can't be hard coded. Second, if I have to have a file that is likely part of the application group of files, would it make more sense to use a more traditional preferences file? How have other Python app developers done in this case? > > There are expected locations for config files and data files on each OS. > > On macOS you would use ~/Library/Preferences/ and put a file or a folder of files in there. > The convention is use your website name as the base name of the file or folder. > For example for scm-workbench I use: org.barrys-emacs.scm-workbench as the folder name for > all the scm-workbench files. > > On Windows you can use a file or folder in %APPDATA% that is named after your app. You should > find the folder by doing a win32 API call to get the value. See getPreferencesDir() in > https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_platform_win32_specific.py > for how to get the value. > > On Linux the XDG spec says that you should put config files in ~/.config/ and data files > in ~/.local/share/. Doing XDG to the spec is a little involved. I have some experimental > code that implements the logic for config the XdgConfigPath class in: > https://github.com/barry-scott/CLI-tools/blob/master/Source/smart_find/__init__.py > > Putting a file directly in the $HOME folder is no longer recommended. > > The format of the config data you are free to choose. > I have been using JSON files recently as it allow for structured data. > > Barry From email at paulstgeorge.com Mon Aug 19 16:06:00 2019 From: email at paulstgeorge.com (Paul St George) Date: Mon, 19 Aug 2019 22:06:00 +0200 Subject: absolute path to a file In-Reply-To: <20190819121634.GA69703@cskk.homeip.net> References: <20190819121634.GA69703@cskk.homeip.net> Message-ID: On 19/08/2019 14:16, Cameron Simpson wrote: > On 19Aug2019 08:52, Paul St George wrote: >> On 19/08/2019 01:31, Cameron Simpson wrote: >>> On 18Aug2019 17:29, Paul St George wrote: >>>> On 18/08/2019 02:03, Cameron Simpson wrote: >>>> 1: Is image01.tif a real existing file when you ran this code? >>>> Yes. image01.tif is real, existing and apparent. >>> But in what directory? What is its _actual_ full path as you expect >>> it to be? >> >> Aha. The Blender file that I am using to test this on has two images >> used as textures. They reside at: >> /Users/Lion/Desktop/test8/image01.tif >> /Users/Lion/Desktop/images/image02.tif >> >> The Blender file is at /Users/Lion/Desktop/test8/tifftest8.blend > > There's a remark on that web page I mentioned that suggests that the > leading '//' indicates the filename is relative to the Blender model, so > the context directory for the '//' is likely /Users/Lion/Desktop/test8. Yes. That makes sense. The reason I was testing with two images, one at /Users/Lion/Desktop/test8/image01.tif and the other at /Users/Lion/Desktop/images/image02.tif is that I cannot rely on images being in the same folder as the Blender file. So, let's assume the context directory is /Users/Lion/Desktop/test8 and see how we get on below. > >>>> (Chris and Peter lead me to believe that Blender has a special kind >>>> of relative path. The double slashes replace the path to the blend >>>> file?s directory.) realpath has done something but I know not what. > > realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it is > a special Blender path. First you need to convert it. By replacing '//' > with the blend file's directory. Then you can call realpath. If you > still need to. Understood. Now. Thanks! > > [...snip...] Did you just [...snip...] yourself? >>> So you might want to write an unBlenderiser (untested example): >>> >>> ?from os.path import isabs, join as joinpath >>> >>> ?def unblenderise(filename, context_dir=None): >>> ?? # transmute Blender "relative" path >>> ?? if filename.startswith('//'): >>> ???? filename = filename[2:] >>> ?? if not isabs(filename) and context_dir is not None: >>> ???? # attach the filename to `context_dir` if supplied >>> ???? filename = joinpath(context_dir, filename) >>> ?? return filename >>> >>> The idea here is to get back a meaningful UNIX path from a Blender >>> path. It first strips a leading '//'. Next, _if_ the filename is >>> relative _and_ you supplied the optional context_dir (eg the >>> directory used for a file brwoser dialogue box), then it prepends >>> that context directory. >>> >>> This _does not_ call abspath or realpath or anything, it just returns >>> a filename which can be used with them. >>> >>> The idea is that if you know where image01.tif lives, you could >>> supply that as the context directory. >> >> Yes! Until Peter Otten's timely intervention, I was trying to do this >> and had managed to join the >> path_to_the_folder_that_contains_the_Blender_file to >> the_name_of_the_image (stripped of its preceding slashes). >> >> Your unblenderise looks much better than my nascent saneblender so >> thank you. I will explore more! > > Looks like you want wd=os.path.dirname(path_of_blend_file). Thank you! > >> Does it depend on knowing where image01.tif lives and manually >> supplying that? > > Sort of. > > What you've got is '//image01.tif', which is Blender's special notation > indicating a filename relative to the blend file's directory. All the > Python library stuff expects an OS path (OS==UNIX on a Mac). So you want > to convert that into a UNIX path.? For example: > > ?? from os.path import dirname > > ?? # Get this from somewhere just hardwiring it for the example. > ?? # Maybe from your 'n' object below? > ?? blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' Is this setting a relative path? > > ?? blender_image_file = n.image.filename > > ?? unix_image_file = unblenderise(blender_image_file, dirname(blend_file)) > > Now you have a UNIX path. If blend_file is an absolute path, > unix_image_path will also be an absolute path. But if blend_file is a > relative path (eg you opened up "tifftest8.blend") unix_image_path will > be a relative path. Does unix_image_path = unix_image_file? Two possibilities here. blend_file (and so unix_image_file) is an absolute path OR blend_file (and so unix_image_file) is a relative path. I just want to check my understanding. If I supply the path to blend_file then it is absolute, and if I ask Python to generate the path to blend_file from within Blender it is relative. Have I got it? > > You don't need to use realpath or abspath on that _unless_ you need to > reference the file from any directory (i.e. _not_ relative to where you > currently are). If I decided not to supply the path and so ended up with a relative UNIX path, I could now use realpath or abspath to find the absolute path. Have I still got it? # I combined your unblenderise and your use of it (see below). Is my attempt error free? It works very well. So thank you! I tested it with a Blend file that had two images, one in the same folder as the Blend file and the other was in a folder on the Desktop called 'images'. The initial results were: Plane uses image01.tif saved at //image01.tif which is at /Users/Lion/Desktop/test8/image01.tif Plane uses image02.tif saved at //../images/image02.tif which is at /Users/Lion/Desktop/test8/../images/image02.tif BUT as you say, this was easily sorted by using os.path.realpath or os.path.abspath. Both worked equally well. Plane uses image01.tif saved at //image01.tif which is at /Users/Lion/Desktop/test8/image01.tif Plane uses image02.tif saved at //../images/image02.tif which is at /Users/Lion/Desktop/images/image02.tif So, everything now works. Thank you again. I am just a little unclear on the absolute and relative, hence my questions. > > Cheers, > Cameron Simpson #some of this can be tidied later import bpy import os from os.path import realpath from os.path import isabs, join as joinpath from os.path import dirname def unblenderise(filename, context_dir=None): if filename.startswith('//'): filename = filename[2:] if not isabs(filename) and context_dir is not None: # attach the filename to `context_dir` if supplied filename = joinpath(context_dir, filename) return filename blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' texture_list = [] for obj in bpy.context.scene.objects: for s in obj.material_slots: if s.material and s.material.use_nodes: for n in s.material.node_tree.nodes: if n.type == 'TEX_IMAGE': texture_list += [n.image] print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', unblenderise(n.image.filepath, dirname(blend_file))) print('Texture list:',texture_list) From aeros167 at gmail.com Mon Aug 19 17:43:34 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Mon, 19 Aug 2019 17:43:34 -0400 Subject: My pseudocode to Python? In-Reply-To: References: Message-ID: Rather than starting with all seven strings in the list and deleting one if a conditional is not true, why not start with 6 elements (with the one in index 3 missing) and insert the 7th element into the third index? >>> mylist = ['a', 'b', 'c', 'e', 'f', 'g'] >>> if x: >>> mylist.insert(3, 'd') >>> mylist ['a', 'b', 'c', 'd', 'e', 'f', 'g'] Regards, Kyle Stanley (aeros167) On Mon, Aug 19, 2019 at 2:30 PM Rob Gaddi wrote: > On 8/19/19 10:43 AM, Stefan Ram wrote: > > Can someone kindly translate my pseudocode to terse Python: > > > > list = \ > > [ 'afaueghauihaiuhgaiuhgaiuhgaeihui', > > 'erghariughauieghaiughahgaihgaiuhgaiuh', > > 'rejganregairghaiurghaiuhgauihgauighaei', > > if x: 'argaeruighaiurhauirguiahuiahgiauhgaeuihi', > > 'reiugaheirughauierhgauiaeihauiehgiuaehuih' > > 'ejiaeigaiuegreaiugheiugheaiughauighaiughaiu' > > 'egairughauirghauiruiegihgruiehgiuaehgiaue' ] > > > > ? I want the list to have the seven strings shown as entries > > if bool(x) is True, but otherwise the list should only have > > six entries - without the entry directly behind "if x: ". > > > > > > mylist = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] > if not x: > del mylist[3] > > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Mon Aug 19 20:03:05 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Aug 2019 17:03:05 -0700 Subject: Which editor is suited for view a python package's source? In-Reply-To: References: Message-ID: Uh oh. Editor wars. The most popular choices today are probably PyCharm and VSCode. I prefer vim with the syntastic plugin (and a few other plugins including Jedi), but I've heard good things about the other two. And emacs almost certainly can edit/view Python files well, though I haven't heard much about that. HTH. On Mon, Aug 19, 2019 at 2:15 AM wrote: > I like to download one package's source and study it in an editor. It > allows me to open the whole package as a project and let me jump from a > reference in one file to its definition in another file back and forth. It > will be even better if it can handle the import modules too. (Maybe this is > too much:-) > > Can anyone recommend such a tool? > > --Jach > -- > https://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Mon Aug 19 20:26:50 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Aug 2019 17:26:50 -0700 Subject: Your IDE's? In-Reply-To: References: Message-ID: I just mentioned essentially this in another thread, but I really like vim with syntastic and jedi plus a few other plugins. I keep all my vim config at http://stromberg.dnsalias.org/svn/vimrc/trunk/ so it's easy to set up a new machine. I haven't used it on anything but Debian/Ubuntu/Mint recently though, so other OS'es/Distributions may not work. It also does bash, lua, etcetera. On Mon, Mar 25, 2019 at 2:40 PM John Doe wrote: > > What is your favorite Python IDE? > > -- > https://mail.python.org/mailman/listinfo/python-list > From aeros167 at gmail.com Mon Aug 19 21:14:03 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Mon, 19 Aug 2019 21:14:03 -0400 Subject: Which editor is suited for view a python package's source? In-Reply-To: References: Message-ID: > The most popular choices today are probably PyCharm and VSCode. I prefer > vim with the syntastic plugin (and a few other plugins including Jedi), but > I've heard good things about the other two. Personally, I've been using VSCode with the Python and Vim extensions. I've used PyCharm as well and have no issues with it, but I've found VSCode to be significantly more customizable. I also like that VSCode works across a number of different languages instead of being exclusive to Python, so it works great as a general purpose editor. I'm not a huge fan of switching between different editors constantly, so I usually use Vim for plaintext and VSCode for anything programming related. On Mon, Aug 19, 2019 at 8:03 PM Dan Stromberg wrote: > Uh oh. Editor wars. > > The most popular choices today are probably PyCharm and VSCode. I prefer > vim with the syntastic plugin (and a few other plugins including Jedi), but > I've heard good things about the other two. And emacs almost certainly can > edit/view Python files well, though I haven't heard much about that. > > HTH. > > On Mon, Aug 19, 2019 at 2:15 AM wrote: > > > I like to download one package's source and study it in an editor. It > > allows me to open the whole package as a project and let me jump from a > > reference in one file to its definition in another file back and forth. > It > > will be even better if it can handle the import modules too. (Maybe this > is > > too much:-) > > > > Can anyone recommend such a tool? > > > > --Jach > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From aeros167 at gmail.com Mon Aug 19 21:33:46 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Mon, 19 Aug 2019 21:33:46 -0400 Subject: How to login remote windos device using python In-Reply-To: References: Message-ID: I would recommend checking out WMI: https://pypi.org/project/WMI/ For remote connection as a named user (official WMI docs): http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user Also, another example (unofficial): https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python. This was done in Python2, but the example is still useful. On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati wrote: > Hi Team, > > can you please let me know, How to login the remote Windows machine using > python?? > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From jfong at ms4.hinet.net Mon Aug 19 22:24:32 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 19 Aug 2019 19:24:32 -0700 (PDT) Subject: Which editor is suited for view a python package's source? In-Reply-To: References: Message-ID: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> Nick Sarbicki? 2019?8?19???? UTC+8??5?33?27???? > PyCharm takes you to the source code within the editor for any > variables/functions/classes/modules if you ctrl+click on what you want to > see. It allows you to browse the relevant bits of code quickly, as well as > let you change them in your local environment if need be. > > That way you don't have to download the source separately, you can just use > it as a normal dependency. > > But if you want to view the source of a project in isolation I imagine any > common editor will suffice. Personally I'll tend to look where the source > is hosted (GitHub, GitLab etc) instead of downloading it. But I can > understand why some may not trust this. > > On Mon, 19 Aug 2019, 10:17 , wrote: > > > I like to download one package's source and study it in an editor. It > > allows me to open the whole package as a project and let me jump from a > > reference in one file to its definition in another file back and forth. It > > will be even better if it can handle the import modules too. (Maybe this is > > too much:-) > > > > Can anyone recommend such a tool? > > > > --Jach > > -- > > https://mail.python.org/mailman/listinfo/python-list > > There is a free community version of PyCharm. Will it support the cross-reference of viewing different files in different subdirectory? and what Windows versions it requires? --Jach From alan at csail.mit.edu Mon Aug 19 23:27:48 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 19 Aug 2019 23:27:48 -0400 Subject: My pseudocode to Python? References: Message-ID: <86tvacplcb.fsf@richard.bawden.org> ram at zedat.fu-berlin.de (Stefan Ram) writes: > for i in range( len( list )- 1, 0, -1 ): > if list[ i ]is None: del list[ i ] list = [x for x in list if x is not None] -- Alan Bawden From alan at csail.mit.edu Mon Aug 19 23:31:09 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 19 Aug 2019 23:31:09 -0400 Subject: My pseudocode to Python? References: <86tvacplcb.fsf@richard.bawden.org> Message-ID: <86o90kpl6q.fsf@richard.bawden.org> Alan Bawden writes: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > > for i in range( len( list )- 1, 0, -1 ): > > if list[ i ]is None: del list[ i ] > > list = [x for x in list if x is not None] Except 'list' is a bad name to use... -- Alan Bawden From aeros167 at gmail.com Tue Aug 20 00:00:13 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Tue, 20 Aug 2019 00:00:13 -0400 Subject: My pseudocode to Python? In-Reply-To: <86o90kpl6q.fsf@richard.bawden.org> References: <86tvacplcb.fsf@richard.bawden.org> <86o90kpl6q.fsf@richard.bawden.org> Message-ID: > Except 'list' is a bad name to use... Definitely, it's not a good practice to use any reserved names, especially built-in ones. A pretty common substitute I've seen is "ls", but it would be preferable to have something more descriptive of the elements within the list. But, for basic examples, "ls" should be fine. On Mon, Aug 19, 2019 at 11:35 PM Alan Bawden wrote: > Alan Bawden writes: > > > ram at zedat.fu-berlin.de (Stefan Ram) writes: > > > for i in range( len( list )- 1, 0, -1 ): > > > if list[ i ]is None: del list[ i ] > > > > list = [x for x in list if x is not None] > > Except 'list' is a bad name to use... > > -- > Alan Bawden > -- > https://mail.python.org/mailman/listinfo/python-list > From nick.a.sarbicki at gmail.com Tue Aug 20 01:33:02 2019 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Tue, 20 Aug 2019 06:33:02 +0100 Subject: Which editor is suited for view a python package's source? In-Reply-To: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> References: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> Message-ID: Yes the community edition works fine. It seems to require a 64 bit version of Windows 7 or higher (I'm not sure as I haven't used Windows in years). On Tue, 20 Aug 2019, 03:27 , wrote: > Nick Sarbicki? 2019?8?19???? UTC+8??5?33?27???? > > PyCharm takes you to the source code within the editor for any > > variables/functions/classes/modules if you ctrl+click on what you want to > > see. It allows you to browse the relevant bits of code quickly, as well > as > > let you change them in your local environment if need be. > > > > That way you don't have to download the source separately, you can just > use > > it as a normal dependency. > > > > But if you want to view the source of a project in isolation I imagine > any > > common editor will suffice. Personally I'll tend to look where the source > > is hosted (GitHub, GitLab etc) instead of downloading it. But I can > > understand why some may not trust this. > > > > On Mon, 19 Aug 2019, 10:17 , wrote: > > > > > I like to download one package's source and study it in an editor. It > > > allows me to open the whole package as a project and let me jump from a > > > reference in one file to its definition in another file back and > forth. It > > > will be even better if it can handle the import modules too. (Maybe > this is > > > too much:-) > > > > > > Can anyone recommend such a tool? > > > > > > --Jach > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > There is a free community version of PyCharm. Will it support the > cross-reference of viewing different files in different subdirectory? and > what Windows versions it requires? > > --Jach > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Tue Aug 20 03:19:30 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 20 Aug 2019 08:19:30 +0100 Subject: Application Preferences In-Reply-To: <0eulle1jmb9cueup1tpvr93frbfuce13k3@4ax.com> References: <29CF5F65-AC87-4A03-A34F-ED3F9FD5E90F@barrys-emacs.org> <0eulle1jmb9cueup1tpvr93frbfuce13k3@4ax.com> Message-ID: <35D03832-C3A5-4C74-B219-E5F256DA91F6@barrys-emacs.org> > On 19 Aug 2019, at 20:37, Dennis Lee Bieber wrote: > > On Mon, 19 Aug 2019 18:01:17 +0000, dboland9 via Python-list > declaimed the following: > >> Wow, what happened here? I posted this to the Python discussion group as it is a Python question, not an SQL question. That said, I agree with what you have said, and that was the plan. Plans get changed. A number of apps. allow the user to specify the location of data and configuration files, and for good reason. Some folders are auto-backup in that they are either journaled or backed up multiple times per day. I think that is the argument in this case. >> > The trick with allowing a user to specify said location is that, unless > you use some standard location to store the redirection, the user has to > always provide the location when launching the application. And if you are > using a standard location for the redirection, you might as well use that > for the configuration data (since redirected user data location can be > stored in the config file). I understood your requirements. User picks the folder to store app files into. The app then needs to store that folder somewhere. I would ask the user for the their preferred location and store that folder in a OS standard location. I do exactly that with Scm-Workbench. The user picks the folder to check out repos into and I store that choice in the standard location. Barry From noah-list at enabled.com Tue Aug 20 04:57:35 2019 From: noah-list at enabled.com (Noah) Date: Tue, 20 Aug 2019 01:57:35 -0700 Subject: python requests get from API and post to another API and remote u' Message-ID: Hi, I am trying to migrate information and data between two systems using their corresponding APIs. I am using python requests. I place a get request and the response from the API is "{'id': 32, 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}" I then take that information and attempt post it to the other API. The data is not accepted and the result is an HTTP 400 code. I tried posting with postman and still rejected. I can post to the second API if I change the data to look like this: {"id": 32, "description": "Firewall Outside", "address": "10.10.10.230/30"} How can I remove all u' from the get data or from the data I am attempting to post? Cheers\ From iranna.gani28 at gmail.com Tue Aug 20 05:15:32 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Tue, 20 Aug 2019 14:45:32 +0530 Subject: How to login remote windos device using python In-Reply-To: References: Message-ID: Hi Kyle, I have tried with as per above attached links and it leads following error: NOTE: Its able to connect local Failed to connect remote windows >>> import wmi >>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXXXXXX", password="XXXXXXXX") Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect handle_com_error () File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error raise klass (com_error=err) wmi.x_wmi: On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley wrote: > I would recommend checking out WMI: https://pypi.org/project/WMI/ > > For remote connection as a named user (official WMI docs): > http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user > > Also, another example (unofficial): > https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python. > This was done in Python2, but the example is still useful. > > On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati > wrote: > >> Hi Team, >> >> can you please let me know, How to login the remote Windows machine using >> python?? >> >> Thanks >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From rosuav at gmail.com Tue Aug 20 05:18:06 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Aug 2019 19:18:06 +1000 Subject: python requests get from API and post to another API and remote u' In-Reply-To: References: Message-ID: On Tue, Aug 20, 2019 at 6:59 PM Noah wrote: > > Hi, > > I am trying to migrate information and data between two systems using > their corresponding APIs. I am using python requests. > > I place a get request and the response from the API is "{'id': 32, > 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}" > > I then take that information and attempt post it to the other API. The > data is not accepted and the result is an HTTP 400 code. > > I tried posting with postman and still rejected. > > I can post to the second API if I change the data to look like this: > {"id": 32, "description": "Firewall Outside", "address": "10.10.10.230/30"} > > How can I remove all u' from the get data or from the data I am > attempting to post? > Use Python 3. Your problems with Unicode will either disappear, or become a lot clearer. ChrisA From cs at cskk.id.au Tue Aug 20 05:43:13 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 20 Aug 2019 19:43:13 +1000 Subject: absolute path to a file In-Reply-To: References: Message-ID: <20190820094313.GA60150@cskk.homeip.net> Please remember to CC the list. On 19Aug2019 22:06, Paul St George wrote: >On 19/08/2019 14:16, Cameron Simpson wrote: [...] >>There's a remark on that web page I mentioned that suggests that the >>leading '//' indicates the filename is relative to the Blender model, >>so the context directory for the '//' is likely >>/Users/Lion/Desktop/test8. > >Yes. That makes sense. The reason I was testing with two images, one >at /Users/Lion/Desktop/test8/image01.tif and the other at >/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images >being in the same folder as the Blender file. > >So, let's assume the context directory is /Users/Lion/Desktop/test8 >and see how we get on below. [...] >>realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it >>is a special Blender path. First you need to convert it. By replacing >>'//' with the blend file's directory. Then you can call realpath. If >>you still need to. > >Understood. Now. Thanks! >> >>[...snip...] > >Did you just [...snip...] yourself? Yes. It keeps the surrounding context manageable. In this way you know to which text I am referring, without having to wade through paragraphs to guess what may be relevant. >> ?? from os.path import dirname >> >> ?? # Get this from somewhere just hardwiring it for the example. >> ?? # Maybe from your 'n' object below? >> ?? blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' >Is this setting a relative path? >> >> ?? blender_image_file = n.image.filename >> >> ?? unix_image_file = unblenderise(blender_image_file, dirname(blend_file)) >> >>Now you have a UNIX path. If blend_file is an absolute path, >>unix_image_path will also be an absolute path. But if blend_file is >>a relative path (eg you opened up "tifftest8.blend") unix_image_path >>will be a relative path. > >Does unix_image_path = unix_image_file? Yeah, sorry, my mistake. >Two possibilities here. >blend_file (and so unix_image_file) is an absolute path OR blend_file >(and so unix_image_file) is a relative path. > >I just want to check my understanding. If I supply the path to >blend_file then it is absolute, and if I ask Python to generate the >path to blend_file from within Blender it is relative. Have I got it? Not quite. What seems to be the situation is: You've got some object from Blender called "n.image", which has a ".file" attribute which is a Blender reference to the image file of the form "//image01.tif". I presume that Blender has enough state inside "n" or "n.image" to locate this in the real filesystem; maybe it has some link to the Blender model of your blend file, and thus knows the path to the blend file and since //image01.tif is a reference relative to the blend file, it can construct the UNIX path to the file. You want to know the UNIX pathname to the image file (maybe you want to pass it to some unrelated application to view the file or something). So you need to do what Blender would do if it needs a UNIX path (eg to open the file). The formula for that is dirname(path_to_blendfile) with n.image.file[2:] appended to it. So that's what we do with unblenderise(): if the filename is a "Blender relative name", rip off the "//" and prepend the blend file directory path. That gets you a UNIX path which you can hand to any function expecting a normal operating system pathname. Whether that is an absolute path or a relative path is entirely "does the resulting path start with a '/'"? An absolute path starts with a slash and is relative to the root of the filesystem. You can use such a path regardless of what your current working directory is, because it doesn't use the working directory. A relative path doesn't start with a slash and is relative to the current working directory. It only works if you're in the right working directory. _Because_ a relative path depends on the _your_ working directory, usually we pass around absolute paths if we need to tell something else about a file, because that will work regardless if what _their_ working directory may be. So, you may well want to turn a relative path into an absolute path... >If I decided not to supply the path and so ended up with a relative >UNIX path, I could now use realpath or abspath to find the absolute >path. Have I still got it? This is correct. Abspath may even call realpath to do its work, unsure. >It works very well. So thank you! I tested it with a Blend file that >had two images, one in the same folder as the Blend file and the other >was in a folder on the Desktop called 'images'. > >The initial results were: >Plane uses image01.tif saved at //image01.tif which is at >/Users/Lion/Desktop/test8/image01.tif >Plane uses image02.tif saved at //../images/image02.tif which is at >/Users/Lion/Desktop/test8/../images/image02.tif >BUT as you say, this was easily sorted by using os.path.realpath or >os.path.abspath. Both worked equally well. Yep. Abspath does some things in a purely lexical way: it resolves '.' and '..' components in the path even if they don't exist. For example it resolves 'a/b/c/d/../../../../foo' for me even though here 'a/b/c/d' doesn't exist: it see the '.. and strips off the preceeding component, repeatedly. So it starts with 'foo' after that pahse and prepends the working directory path. The system realpath is not documented to work if some of the path is fictitious, but the Python realpath seems to work even then, maybe it falls back to abspath or something. Abspath takes a relative path and returns you an absolute path with the '.' and '..' components stripped out. Realpath follows symlinks and stuff and returns you the direct absolute path _after_ all that - one that doesn't traverse symlinks. For your purposes the results are equally functional. >Plane uses image01.tif saved at //image01.tif which is at >/Users/Lion/Desktop/test8/image01.tif >Plane uses image02.tif saved at //../images/image02.tif which is at >/Users/Lion/Desktop/images/image02.tif > >So, everything now works. Thank you again. I am just a little unclear >on the absolute and relative, hence my questions. Hope the above xaplinations help. Cheers, Cameron Simpson From countryone77 at gmail.com Tue Aug 20 05:53:34 2019 From: countryone77 at gmail.com (Bev In TX) Date: Tue, 20 Aug 2019 04:53:34 -0500 Subject: Which editor is suited for view a python package's source? In-Reply-To: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> References: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> Message-ID: <96CB8DF1-1624-46B3-B098-CD74EAE53D4F@gmail.com> Search for ?Choose? (without the quote marks) on the following webpage to see the differences between the community and commercial versions: https://www.jetbrains.com/pycharm/features/ From the following webpage, ?Microsoft Windows 7 SP1 or later? https://www.jetbrains.com/help/pycharm/installation-guide.html?_ga=2.186403823.798151923.1566294266-889030968.1566294266 Bev > On Aug 19, 2019, at 9:24 PM, jfong at ms4.hinet.net wrote: > > Nick Sarbicki? 2019?8?19???? UTC+8??5?33?27???? >> PyCharm takes you to the source code within the editor for any >> variables/functions/classes/modules if you ctrl+click on what you want to >> see. It allows you to browse the relevant bits of code quickly, as well as >> let you change them in your local environment if need be. >> >> That way you don't have to download the source separately, you can just use >> it as a normal dependency. >> >> But if you want to view the source of a project in isolation I imagine any >> common editor will suffice. Personally I'll tend to look where the source >> is hosted (GitHub, GitLab etc) instead of downloading it. But I can >> understand why some may not trust this. >> >>> On Mon, 19 Aug 2019, 10:17 , wrote: >>> >>> I like to download one package's source and study it in an editor. It >>> allows me to open the whole package as a project and let me jump from a >>> reference in one file to its definition in another file back and forth. It >>> will be even better if it can handle the import modules too. (Maybe this is >>> too much:-) >>> >>> Can anyone recommend such a tool? >>> >>> --Jach >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> > > There is a free community version of PyCharm. Will it support the cross-reference of viewing different files in different subdirectory? and what Windows versions it requires? > > --Jach > -- > https://mail.python.org/mailman/listinfo/python-list From countryone77 at gmail.com Tue Aug 20 05:58:44 2019 From: countryone77 at gmail.com (Bev In TX) Date: Tue, 20 Aug 2019 04:58:44 -0500 Subject: Which editor is suited for view a python package's source? In-Reply-To: <96CB8DF1-1624-46B3-B098-CD74EAE53D4F@gmail.com> References: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> <96CB8DF1-1624-46B3-B098-CD74EAE53D4F@gmail.com> Message-ID: <74D01A3E-83AA-4435-B06D-D658D497BFD7@gmail.com> Sorry, I meant to trim the older portion :-( Bev in TX > On Aug 20, 2019, at 4:53 AM, Bev In TX wrote: > > Search for ?Choose? (without the quote marks) on the following webpage to see the differences between the community and commercial versions: > https://www.jetbrains.com/pycharm/features/ > > From the following webpage, ?Microsoft Windows 7 SP1 or later? > https://www.jetbrains.com/help/pycharm/installation-guide.html?_ga=2.186403823.798151923.1566294266-889030968.1566294266 > > Bev > >> From iranna.gani28 at gmail.com Tue Aug 20 06:37:21 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Tue, 20 Aug 2019 16:07:21 +0530 Subject: Is it able to connect remote win system from Linux using python Message-ID: Hi Team, can you please let me know , is there any module to connect the remote Windows system from Linux using python module? Thanks, Iranna M From iranna.gani28 at gmail.com Tue Aug 20 06:38:04 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Tue, 20 Aug 2019 16:08:04 +0530 Subject: How to login remote windos device using python In-Reply-To: References: Message-ID: Thanks Kyle Its working fine On Tue, Aug 20, 2019 at 2:45 PM Iranna Mathapati wrote: > Hi Kyle, > > I have tried with as per above attached links and it leads following error: > NOTE: Its able to connect local > > Failed to connect remote windows > >>> import wmi > >>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXXXXXX", password="XXXXXXXX") > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect > handle_com_error () > File "C:\Python27\lib\site-packages\wmi.py", line 241, in > handle_com_error > raise klass (com_error=err) > wmi.x_wmi: occurred.', (0, u'SWbemLocator', u'The RPC server is unavailable. ', None, > 0, -2147023174), None)> > > On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley wrote: > >> I would recommend checking out WMI: https://pypi.org/project/WMI/ >> >> For remote connection as a named user (official WMI docs): >> http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user >> >> Also, another example (unofficial): >> https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python. >> This was done in Python2, but the example is still useful. >> >> On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati >> wrote: >> >>> Hi Team, >>> >>> can you please let me know, How to login the remote Windows machine using >>> python?? >>> >>> Thanks >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> From cl at isbd.net Tue Aug 20 07:32:15 2019 From: cl at isbd.net (Chris Green) Date: Tue, 20 Aug 2019 12:32:15 +0100 Subject: Is it able to connect remote win system from Linux using python References: Message-ID: Iranna Mathapati wrote: > Hi Team, > > can you please let me know , is there any module to connect the remote > Windows system from Linux using python module? > We need more information, what sort of 'connect' to a remote Windows system do you want? I.e.:- Do you want to run a Windows desktop remotely? Do you want to send messages to the Windows machine? Do you want to exchange files with the Windows machine? Do you want to run a command line on the Windows machine? ... or something else? -- Chris Green ? From flebber.crue at gmail.com Tue Aug 20 08:00:56 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 20 Aug 2019 05:00:56 -0700 (PDT) Subject: Enumerate - int object not subscriptable Message-ID: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Hi I want to do basic math with a list. a = [1, 2, 3, 4, 5, 6, 7, 8] for idx, num in enumerate(a): print(idx, num) This works, but say I want to print the item value at the next index as well as the current. for idx, num in enumerate(a): print(num[idx + 1], num) I am expecting 2, 1. But am receiving TypeError: 'int' object is not subscriptable Why? Cheers Sayth From frank at chagford.com Tue Aug 20 08:47:40 2019 From: frank at chagford.com (Frank Millman) Date: Tue, 20 Aug 2019 14:47:40 +0200 Subject: Enumerate - int object not subscriptable In-Reply-To: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: <792143f5-c02f-6451-6122-9a99ed0892b8@chagford.com> On 2019-08-20 2:00 PM, Sayth Renshaw wrote: > Hi > > I want to do basic math with a list. > > a = [1, 2, 3, 4, 5, 6, 7, 8] > > for idx, num in enumerate(a): > print(idx, num) > > This works, but say I want to print the item value at the next index as well as the current. > > for idx, num in enumerate(a): > print(num[idx + 1], num) > > I am expecting 2, 1. > > But am receiving > > TypeError: 'int' object is not subscriptable > > Why? > I think you want a[idx+1], not num[idx+1]. Bear in mind that you will get IndexError for the last item in the list. Frank Millman From frank at chagford.com Tue Aug 20 08:47:40 2019 From: frank at chagford.com (Frank Millman) Date: Tue, 20 Aug 2019 14:47:40 +0200 Subject: Enumerate - int object not subscriptable In-Reply-To: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: <792143f5-c02f-6451-6122-9a99ed0892b8@chagford.com> On 2019-08-20 2:00 PM, Sayth Renshaw wrote: > Hi > > I want to do basic math with a list. > > a = [1, 2, 3, 4, 5, 6, 7, 8] > > for idx, num in enumerate(a): > print(idx, num) > > This works, but say I want to print the item value at the next index as well as the current. > > for idx, num in enumerate(a): > print(num[idx + 1], num) > > I am expecting 2, 1. > > But am receiving > > TypeError: 'int' object is not subscriptable > > Why? > I think you want a[idx+1], not num[idx+1]. Bear in mind that you will get IndexError for the last item in the list. Frank Millman From blindanagram at nowhere.com Tue Aug 20 08:47:06 2019 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 20 Aug 2019 13:47:06 +0100 Subject: Enumerate - int object not subscriptable In-Reply-To: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: On 20/08/2019 13:00, Sayth Renshaw wrote: > Hi > > I want to do basic math with a list. > > > for idx, num in enumerate(a): > print(idx, num) > > This works, but say I want to print the item value at the next index as well as the current. > > for idx, num in enumerate(a): > print(num[idx + 1], num) a = [1, 2, 3, 4, 5, 6, 7, 8] for idx, num in enumerate(a): print(a[idx + 1], num) From cousinstanley at gmail.com Tue Aug 20 09:36:10 2019 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 20 Aug 2019 06:36:10 -0700 Subject: Enumerate - int object not subscriptable References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: Sayth Renshaw wrote: > I want to do basic math with a list. > > a = [1, 2, 3, 4, 5, 6, 7, 8] > > for idx, num in enumerate(a): > print(idx, num) > > This works, but say I want to print the item value > at the next index as well as the current. > > for idx, num in enumerate(a): > > print(num[idx + 1], num) > .... #!/usr/bin/env python3 # sum each adjacent pair of elements in a list ls = list( range( 10 , 1 , -1 ) ) print('\n ' , ls , '\n' ) for enum , n in enumerate( range( len( ls ) - 1 ) ) : i_left , i_rite = ls[ n : n + 2 ] i_tot = i_left + i_rite print( ' {:2d} : {:2d} + {:2d} = {:4d} '.format( enum , i_left , i_rite , i_tot ) ) -- Stanley C. Kitching Human Being Phoenix, Arizona From iranna.gani28 at gmail.com Tue Aug 20 11:06:24 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Tue, 20 Aug 2019 20:36:24 +0530 Subject: Is it able to connect remote win system from Linux using python In-Reply-To: References: Message-ID: Hi Chris, Want to run a command line on the remote windows machine [on powershell command line] from linux device I want to check what are the drivers are installed on the remote window machine from a Linux machine using python. Thanks, On Tue, Aug 20, 2019 at 5:05 PM Chris Green wrote: > Iranna Mathapati wrote: > > Hi Team, > > > > can you please let me know , is there any module to connect the remote > > Windows system from Linux using python module? > > > We need more information, what sort of 'connect' to a remote Windows > system do you want? I.e.:- > > Do you want to run a Windows desktop remotely? > > Do you want to send messages to the Windows machine? > > Do you want to exchange files with the Windows machine? > > Do you want to run a command line on the Windows machine? > > ... or something else? > > -- > Chris Green > ? > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Tue Aug 20 13:15:06 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Aug 2019 11:15:06 -0600 Subject: Enumerate - int object not subscriptable In-Reply-To: References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: Or use the "pairwise" recipe from the itertools docs: from itertools import tee def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return zip(a, b) for num1, num2 in pairwise(a): print(num1, num2) On Tue, Aug 20, 2019 at 7:42 AM Cousin Stanley wrote: > Sayth Renshaw wrote: > > > I want to do basic math with a list. > > > > a = [1, 2, 3, 4, 5, 6, 7, 8] > > > > for idx, num in enumerate(a): > > print(idx, num) > > > > This works, but say I want to print the item value > > at the next index as well as the current. > > > > for idx, num in enumerate(a): > > > > print(num[idx + 1], num) > > .... > > > #!/usr/bin/env python3 > > # sum each adjacent pair of elements in a list > > ls = list( range( 10 , 1 , -1 ) ) > > print('\n ' , ls , '\n' ) > > for enum , n in enumerate( range( len( ls ) - 1 ) ) : > > i_left , i_rite = ls[ n : n + 2 ] > > i_tot = i_left + i_rite > > print( ' {:2d} : {:2d} + {:2d} = {:4d} '.format( enum , i_left , > i_rite , i_tot ) ) > > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > -- > https://mail.python.org/mailman/listinfo/python-list > From david at lowryduda.com Tue Aug 20 13:18:30 2019 From: david at lowryduda.com (David Lowry-Duda) Date: Tue, 20 Aug 2019 13:18:30 -0400 Subject: Xlabel and ylabel are not shown In-Reply-To: References: Message-ID: <20190820171830.GA2098@mail.lowryduda.com> There are two main ways of creating a plot in matplotlib: the pyplot MATLAB-style system and an object-oriented system. Although many tutorials online use the MATLAB interface, it is usually a good idea to use the object-oriented system. I mention this here because after one calls `plt.plot()`, it can be a bit nonintuitive how to alter the plot through the MATLAB-style interface. I think this might be happening here. If you provide a complete minimally-running-code sample, I'd be happy to go through it in a bit more detail. - David Lowry-Duda From email at paulstgeorge.com Tue Aug 20 15:06:54 2019 From: email at paulstgeorge.com (Paul St George) Date: Tue, 20 Aug 2019 21:06:54 +0200 Subject: absolute path to a file In-Reply-To: <20190820094313.GA60150@cskk.homeip.net> References: <20190820094313.GA60150@cskk.homeip.net> Message-ID: On 20/08/2019 11:43, Cameron Simpson wrote: > Please remember to CC the list. Instead of 'Post a followup to this newsgroup' or 'To: python-list at python.org'? > > On 19Aug2019 22:06, Paul St George wrote: >> On 19/08/2019 14:16, Cameron Simpson wrote: > [...] >>> There's a remark on that web page I mentioned that suggests that the >>> leading '//' indicates the filename is relative to the Blender model, >>> so the context directory for the '//' is likely >>> /Users/Lion/Desktop/test8. >> >> Yes. That makes sense. The reason I was testing with two images, one >> at /Users/Lion/Desktop/test8/image01.tif and the other at >> /Users/Lion/Desktop/images/image02.tif is that I cannot rely on images >> being in the same folder as the Blender file. >> >> So, let's assume the context directory is /Users/Lion/Desktop/test8 >> and see how we get on below. > [...] >>> realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it >>> is a special Blender path. First you need to convert it. By replacing >>> '//' with the blend file's directory. Then you can call realpath. If >>> you still need to. >> >> Understood. Now. Thanks! >>> >>> [...snip...] >> >> Did you just [...snip...] yourself? > > Yes. It keeps the surrounding context manageable. In this way you know > to which text I am referring, without having to wade through paragraphs > to guess what may be relevant. > >>> ?? from os.path import dirname >>> >>> ?? # Get this from somewhere just hardwiring it for the example. >>> ?? # Maybe from your 'n' object below? >>> ?? blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' >> Is this setting a relative path? >>> >>> ?? blender_image_file = n.image.filename >>> >>> ?? unix_image_file = unblenderise(blender_image_file, >>> dirname(blend_file)) >>> >>> Now you have a UNIX path. If blend_file is an absolute path, >>> unix_image_path will also be an absolute path. But if blend_file is a >>> relative path (eg you opened up "tifftest8.blend") unix_image_path >>> will be a relative path. >> >> Does unix_image_path = unix_image_file? > > Yeah, sorry,? my mistake. > >> Two possibilities here. >> blend_file (and so unix_image_file) is an absolute path OR blend_file >> (and so unix_image_file) is a relative path. >> >> I just want to check my understanding. If I supply the path to >> blend_file then it is absolute, and if I ask Python to generate the >> path to blend_file from within Blender it is relative. Have I got it? > > Not quite. What seems to be the situation is: > > You've got some object from Blender called "n.image", which has a > ".file" attribute which is a Blender reference to the image file of the > form "//image01.tif". > > I presume that Blender has enough state inside "n" or "n.image" to > locate this in the real filesystem; maybe it has some link to the > Blender model of your blend file, and thus knows the path to the blend > file and since //image01.tif is a reference relative to the blend file, > it can construct the UNIX path to the file. > > You want to know the UNIX pathname to the image file (maybe you want to > pass it to some unrelated application to view the file or something). Exactly. I am using Python to log a series of experiments. If I have a record of the settings and the assets used, I can better learn from what works and so repeat the successes and avoid the failures. > > So you need to do what Blender would do if it needs a UNIX path (eg to > open the file). > > The formula for that is dirname(path_to_blendfile) with n.image.file[2:] > appended to it. So that's what we do with unblenderise(): if the > filename is a "Blender relative name", rip off the "//" and prepend the > blend file directory path. That gets you a UNIX path which you can hand > to any function expecting a normal operating system pathname. > > Whether that is an absolute path or a relative path is entirely "does > the resulting path start with a '/'"? We used blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' So, if I read you correctly, this is an absolute path. When we used unblenderise on it, out popped a path that was partly but not wholly relative. The latter half of the path is relative to the absolute first half (/Users/Lion/Desktop/test8/). /Users/Lion/Desktop/test8/../images/image02.tif It starts with a slash but cannot be pasted into "Go to...". But maybe that is an absolute path in UNIX? > > An absolute path starts with a slash and is relative to the root of the > filesystem. You can use such a path regardless of what your current > working directory is, because it doesn't use the working directory. > > A relative path doesn't start with a slash and is relative to the > current working directory. It only works if you're in the right working > directory. > > _Because_ a relative path depends on the _your_ working directory, > usually we pass around absolute paths if we need to tell something else > about a file, because that will work regardless if what _their_ working > directory may be. > > So, you may well want to turn a relative path into an absolute path... > >> If I decided not to supply the path and so ended up with a relative >> UNIX path, I could now use realpath or abspath to find the absolute >> path. Have I still got it? > > This is correct. > > Abspath may even call realpath to do its work, unsure. > >> It works very well. So thank you! I tested it with a Blend file that >> had two images, one in the same folder as the Blend file and the other >> was in a folder on the Desktop called 'images'. >> >> The initial results were: >> Plane uses image01.tif saved at //image01.tif which is at >> /Users/Lion/Desktop/test8/image01.tif >> Plane uses image02.tif saved at //../images/image02.tif which is at >> /Users/Lion/Desktop/test8/../images/image02.tif >> BUT as you say, this was easily sorted by using os.path.realpath or >> os.path.abspath. Both worked equally well. > > Yep. Abspath does some things in a purely lexical way: it resolves '.' > and '..' components in the path even if they don't exist. For example it > resolves 'a/b/c/d/../../../../foo' for me even though here 'a/b/c/d' > doesn't exist: it see the '.. and strips off the preceeding component, > repeatedly. So it starts with 'foo' after that pahse? and prepends the > working directory path. > > The system realpath is not documented to work if some of the path is > fictitious, but the Python realpath seems to work even then, maybe it > falls back to abspath or something. > > Abspath takes a relative path and returns you an absolute path with the > '.' and '..' components stripped out. > > Realpath follows symlinks and stuff and returns you the direct absolute > path _after_ all that - one that doesn't traverse symlinks. > > For your purposes the results are equally functional. > >> Plane uses image01.tif saved at //image01.tif which is at >> /Users/Lion/Desktop/test8/image01.tif >> Plane uses image02.tif saved at //../images/image02.tif which is at >> /Users/Lion/Desktop/images/image02.tif >> >> So, everything now works. Thank you again. I am just a little unclear >> on the absolute and relative, hence my questions. > > Hope the above xaplinations help. Yes, very much. Thank you. > > Cheers, > Cameron Simpson From michael.stemper at gmail.com Tue Aug 20 17:11:54 2019 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Tue, 20 Aug 2019 16:11:54 -0500 Subject: Style suggestions/critiques Message-ID: I recently wrote a couple of modules (more to come) to help me use the tikz package in TeX/LaTeX. Since it's all to do with drawing, I have a lot of points in R^2. Being unimaginative, I implemented them as ordered pairs (2-tuples) of floats. E.g.: p1 = 3,4 p2 = 5,6 Naturally, lines are implemented as ordered pairs[1] of points: line = p1,p2 This all seems reasonably simple and intuitive (to me). However, in order to actually do some manipulation, I have stuff like: # Unpack the lines l1p1,l1p2 = line1 l1x1,l1y1 = l1p1 l1x2,l1y2 = l1p2 l2p1,l2p2 = line2 l2x1,l2y1 = l2p1 l2x2,l2y2 = l2p2 spattered all over. Although this is simple enough, I find it aesthetically unappealing. Is there some better idiom that I should be using, or is this really in accord with The Zen of Python? [1] (I could have done sets, I suppose, but orientation might be useful at some point.) -- Michael F. Stemper The FAQ for rec.arts.sf.written is at: http://leepers.us/evelyn/faqs/sf-written Please read it before posting. From cs at cskk.id.au Tue Aug 20 17:56:13 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 21 Aug 2019 07:56:13 +1000 Subject: absolute path to a file In-Reply-To: References: Message-ID: <20190820215613.GA95218@cskk.homeip.net> On 20Aug2019 21:06, Paul St George wrote: >On 20/08/2019 11:43, Cameron Simpson wrote: >>Please remember to CC the list. >Instead of 'Post a followup to this newsgroup' or 'To: >python-list at python.org'? Hmm. I've been getting some of your posts directly to me as email with no obvious python-list at python.org to/cc header. Maybe some interaction with gmane? If you've been posting to the gmane newsgroup and CCing me privately that is likely fine, and I've misread the event (provided gmane backfeeds to the mailing list). [...] >We used >blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' >So, if I read you correctly, this is an absolute path. > >When we used unblenderise on it, out popped a path that was partly but >not wholly relative. The latter half of the path is relative to the >absolute first half (/Users/Lion/Desktop/test8/). > >/Users/Lion/Desktop/test8/../images/image02.tif > >It starts with a slash but cannot be pasted into "Go to...". But maybe >that is an absolute path in UNIX? Yes. It starts with a slash. If you hand this to abspath it would fold out the "test8/.." part and give you a more direct absolute path. And realpath would traverse the path looking for symlinks etc and fold out the same pair as a side effect of traversing the path. But realpath is symlink aware. If test8 were a symlink to some remote part of the filesystem so that the TIF image were also elswhere, you'd get a direct path to that remote location. For example, on our home server my ~/media directory is actually a symlink to an area on our 8TB RAID-1 volume: [~]borg*> pwd /home/cameron [~]borg*> ls -ld media lrwxrwxrwx 1 cameron cameron 9 Nov 2 2017 media -> 8TB/media In fact "8TB" is also a symlink. So let's look: [~]borg*> python3 Python 3.7.1 (default, Nov 14 2018, 10:38:43) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from os.path import abspath, realpath >>> abspath('media') '/home/cameron/media' >>> realpath('media') '/app8tb/cameron/media' Both are valid absolute paths to the media directory. Realpath has follwed the symlinks and given a direct route from '/' which does not go through any symlinks. Abspath has not bothered with such effort. Cheers, Cameron Simpson (formerly cs at zip.com.au) From jfong at ms4.hinet.net Tue Aug 20 21:26:59 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 20 Aug 2019 18:26:59 -0700 (PDT) Subject: Which editor is suited for view a python package's source? In-Reply-To: References: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> Message-ID: <5edc3fd9-af83-4412-b8eb-9ee8dd8e160d@googlegroups.com> Nick Sarbicki? 2019?8?20???? UTC+8??1?33?32???? > Yes the community edition works fine. > > It seems to require a 64 bit version of Windows 7 or higher (I'm not sure > as I haven't used Windows in years). > > On Tue, 20 Aug 2019, 03:27 , wrote: > > > Nick Sarbicki? 2019?8?19???? UTC+8??5?33?27???? > > > PyCharm takes you to the source code within the editor for any > > > variables/functions/classes/modules if you ctrl+click on what you want to > > > see. It allows you to browse the relevant bits of code quickly, as well > > as > > > let you change them in your local environment if need be. > > > > > > That way you don't have to download the source separately, you can just > > use > > > it as a normal dependency. > > > > > > But if you want to view the source of a project in isolation I imagine > > any > > > common editor will suffice. Personally I'll tend to look where the source > > > is hosted (GitHub, GitLab etc) instead of downloading it. But I can > > > understand why some may not trust this. > > > > > > On Mon, 19 Aug 2019, 10:17 , wrote: > > > > > > > I like to download one package's source and study it in an editor. It > > > > allows me to open the whole package as a project and let me jump from a > > > > reference in one file to its definition in another file back and > > forth. It > > > > will be even better if it can handle the import modules too. (Maybe > > this is > > > > too much:-) > > > > > > > > Can anyone recommend such a tool? > > > > > > > > --Jach > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > There is a free community version of PyCharm. Will it support the > > cross-reference of viewing different files in different subdirectory? and > > what Windows versions it requires? > > > > --Jach > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Then, I can only download the older version 2016.2.3 for my old 32 bit system:-( --Jach From Richard at Damon-Family.org Tue Aug 20 21:31:11 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 20 Aug 2019 21:31:11 -0400 Subject: absolute path to a file In-Reply-To: <20190820215613.GA95218@cskk.homeip.net> References: <20190820215613.GA95218@cskk.homeip.net> Message-ID: <3d1b43a3-2825-1f88-6386-089e5b23000b@Damon-Family.org> On 8/20/19 5:56 PM, Cameron Simpson wrote: > > Hmm. I've been getting some of your posts directly to me as email with > no obvious python-list at python.org to/cc header. Maybe some interaction > with gmane? If you've been posting to the gmane newsgroup and CCing me > privately that is likely fine, and I've misread the event (provided > gmane backfeeds to the mailing list). I think gmane feed the newsgroup comp.lang.python which feeds python-list at python.org. Python-list probably then sees that you already were getting a direct copy so omits sending you the duplicate. -- Richard Damon From aeros167 at gmail.com Tue Aug 20 21:36:21 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Tue, 20 Aug 2019 21:36:21 -0400 Subject: Which editor is suited for view a python package's source? In-Reply-To: <5edc3fd9-af83-4412-b8eb-9ee8dd8e160d@googlegroups.com> References: <2d728c2d-30d0-4824-8047-d8bf6533c951@googlegroups.com> <5edc3fd9-af83-4412-b8eb-9ee8dd8e160d@googlegroups.com> Message-ID: > Then, I can only download the older version 2016.2.3 for my old 32 bit system:-( You could always use VSCode with the Python extension instead: https://code.visualstudio.com/Download. There's support for 32bit Windows as long as you're on 7, 8, or 10. I haven't used it myself though, I most use the 64bit Linux version. On Tue, Aug 20, 2019 at 9:30 PM wrote: > Nick Sarbicki? 2019?8?20???? UTC+8??1?33?32???? > > Yes the community edition works fine. > > > > It seems to require a 64 bit version of Windows 7 or higher (I'm not sure > > as I haven't used Windows in years). > > > > On Tue, 20 Aug 2019, 03:27 , wrote: > > > > > Nick Sarbicki? 2019?8?19???? UTC+8??5?33?27???? > > > > PyCharm takes you to the source code within the editor for any > > > > variables/functions/classes/modules if you ctrl+click on what you > want to > > > > see. It allows you to browse the relevant bits of code quickly, as > well > > > as > > > > let you change them in your local environment if need be. > > > > > > > > That way you don't have to download the source separately, you can > just > > > use > > > > it as a normal dependency. > > > > > > > > But if you want to view the source of a project in isolation I > imagine > > > any > > > > common editor will suffice. Personally I'll tend to look where the > source > > > > is hosted (GitHub, GitLab etc) instead of downloading it. But I can > > > > understand why some may not trust this. > > > > > > > > On Mon, 19 Aug 2019, 10:17 , wrote: > > > > > > > > > I like to download one package's source and study it in an editor. > It > > > > > allows me to open the whole package as a project and let me jump > from a > > > > > reference in one file to its definition in another file back and > > > forth. It > > > > > will be even better if it can handle the import modules too. (Maybe > > > this is > > > > > too much:-) > > > > > > > > > > Can anyone recommend such a tool? > > > > > > > > > > --Jach > > > > > -- > > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > There is a free community version of PyCharm. Will it support the > > > cross-reference of viewing different files in different subdirectory? > and > > > what Windows versions it requires? > > > > > > --Jach > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > Then, I can only download the older version 2016.2.3 for my old 32 bit > system:-( > > --Jach > -- > https://mail.python.org/mailman/listinfo/python-list > From aldwinaldwindev at gmail.com Tue Aug 20 21:51:12 2019 From: aldwinaldwindev at gmail.com (Aldwin Pollefeyt) Date: Wed, 21 Aug 2019 09:51:12 +0800 Subject: Style suggestions/critiques In-Reply-To: References: Message-ID: The Zen of Python is readability? Does this look neater? x11, y11, x12, y12, x21, y21, x22, y22 = line1[0] + line1[1] + line2[0] + line2[1] Compared to tuples, lists are maybe more useful if you need to manipulate the coordinates. line1 = [ [1, 2], [3, 4] ] line1[1][0] = 5 line1[0] = [2, 3] or _p1, _p2, _x, _y = 0, 1, 0, 1 line1 = [ [1, 2], [3, 4] ] line1[_p2][_x] = 5 line1[_p1] = [2, 3] On Wed, Aug 21, 2019 at 5:15 AM Michael F. Stemper < michael.stemper at gmail.com> wrote: > I recently wrote a couple of modules (more to come) to help me > use the tikz package in TeX/LaTeX. Since it's all to do with > drawing, I have a lot of points in R^2. Being unimaginative, I > implemented them as ordered pairs (2-tuples) of floats. E.g.: > > p1 = 3,4 > p2 = 5,6 > > Naturally, lines are implemented as ordered pairs[1] of points: > > line = p1,p2 > > This all seems reasonably simple and intuitive (to me). However, > in order to actually do some manipulation, I have stuff like: > > # Unpack the lines > l1p1,l1p2 = line1 > l1x1,l1y1 = l1p1 > l1x2,l1y2 = l1p2 > l2p1,l2p2 = line2 > l2x1,l2y1 = l2p1 > l2x2,l2y2 = l2p2 > > spattered all over. Although this is simple enough, I find it > aesthetically unappealing. > > Is there some better idiom that I should be using, or is this > really in accord with The Zen of Python? > > [1] (I could have done sets, I suppose, but orientation might be > useful at some point.) > > -- > Michael F. Stemper > The FAQ for rec.arts.sf.written is at: > http://leepers.us/evelyn/faqs/sf-written > Please read it before posting. > -- > https://mail.python.org/mailman/listinfo/python-list > From grant.b.edwards at gmail.com Tue Aug 20 22:09:31 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 21 Aug 2019 02:09:31 -0000 (UTC) Subject: absolute path to a file References: <20190820215613.GA95218@cskk.homeip.net> <3d1b43a3-2825-1f88-6386-089e5b23000b@Damon-Family.org> Message-ID: On 2019-08-21, Richard Damon wrote: > I think gmane feed the newsgroup comp.lang.python which feeds > python-list at python.org. No, gmane is a gateway to python-list at python.org. -- Grant From PythonList at DancesWithMice.info Tue Aug 20 22:57:42 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 21 Aug 2019 14:57:42 +1200 Subject: Style suggestions/critiques In-Reply-To: References: Message-ID: <4dab172d-a430-d717-6798-e8d00602eada@DancesWithMice.info> On 21/08/19 9:11 AM, Michael F. Stemper wrote: > I recently wrote a couple of modules (more to come) to help me > use the tikz package in TeX/LaTeX. Since it's all to do with > drawing, I have a lot of points in R^2. Being unimaginative, I > implemented them as ordered pairs (2-tuples) of floats. E.g.: > p1 = 3,4 > p2 = 5,6 > > Naturally, lines are implemented as ordered pairs[1] of points: > line = p1,p2 > > This all seems reasonably simple and intuitive (to me). However, > in order to actually do some manipulation, I have stuff like: > # Unpack the lines > l1p1,l1p2 = line1 > l1x1,l1y1 = l1p1 > l1x2,l1y2 = l1p2 > l2p1,l2p2 = line2 > l2x1,l2y1 = l2p1 > l2x2,l2y2 = l2p2 > spattered all over. Although this is simple enough, I find it > aesthetically unappealing. Agreed, but could more descriptive names be used? > Is there some better idiom that I should be using, or is this > really in accord with The Zen of Python? > [1] (I could have done sets, I suppose, but orientation might be > useful at some point.) Assuming that the code does-stuff with/to lines, eg rotate the line 0.2 radians about some nominated rotational-center; maybe construct a class, eg class Line(): def __init__( self, starting_point, ending_point ): self.starting_point = starting_point self.ending_point = ending_point def rotate( self, angle, center ): ... The same could also be said for a Point class. However, if they are 'only' Cartesian coordinates and no methods ever apply(???), then maybe named-tuples or a dict? (thus able to refer to p1.x and p1.y (or p1[ "x" ], etc) ) Using examples from above: p1 = Point( 3, 4 ) # p1 = 3,4 p2 = Point( 5, 6 ) # p2 = 5,6 line = Line( p1, p2 ) # line = p1,p2 and instead of: > l1p1,l1p2 = line1 Do things now appear to be closer to self-documenting? Also, we can now use: p1.x #instead of l1p1, and p1.y #instead of l1p2 In fact, chances-are you won't ever do this because any point/line manipulation would become a method (hidden-away) within the respective class... -- Regards =dn From flebber.crue at gmail.com Wed Aug 21 00:07:31 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 20 Aug 2019 21:07:31 -0700 (PDT) Subject: Enumerate - int object not subscriptable In-Reply-To: References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: On Wednesday, 21 August 2019 03:16:01 UTC+10, Ian wrote: > Or use the "pairwise" recipe from the itertools docs: > > from itertools import tee > > def pairwise(iterable): > "s -> (s0,s1), (s1,s2), (s2, s3), ..." > a, b = tee(iterable) > next(b, None) > return zip(a, b) > > for num1, num2 in pairwise(a): > print(num1, num2) > > > Stanley C. Kitching > > Human Being > > Phoenix, Arizona > > > > -- This definitely ended up being the ticket. def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return zip(a, b) def output_data(s): serie = fibo(input_length) x = [] y = [] for num1, num2 in pairwise(serie): y.append( num2 / num1) for item in y: x.append(y.index(item)) draw_graph(x, y) ######## Kept trying with the enumerate style for i, num in enumerate(serie): while i < len(serie)-1: x.append(int(serie[i + 1])/ int(serie[i])) i += 1 but just couldn't quite get it to work. Itertools definitely made it easier. for i, num in enumerate(serie): while i < len(serie)-1: x.append(int(serie[i + 1])/ int(serie[i])) i += 1 From pankaj.jangid at gmail.com Wed Aug 21 00:37:28 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Wed, 21 Aug 2019 10:07:28 +0530 Subject: python requests get from API and post to another API and remote u' References: Message-ID: Noah writes: > I place a get request and the response from the API is "{'id': 32, > 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}" > > I then take that information and attempt post it to the other API. > The data is not accepted and the result is an HTTP 400 code. > > I tried posting with postman and still rejected. > > I can post to the second API if I change the data to look like this: > {"id": 32, "description": "Firewall Outside", "address": > "10.10.10.230/30"} This could be python version issue at your end. But I am thinking why this is getting rejected by Postman as well. Try with vREST. -- Pankaj Jangid From email at paulstgeorge.com Wed Aug 21 02:30:50 2019 From: email at paulstgeorge.com (Paul St George) Date: Wed, 21 Aug 2019 08:30:50 +0200 Subject: absolute path to a file In-Reply-To: References: <20190820215613.GA95218@cskk.homeip.net> <3d1b43a3-2825-1f88-6386-089e5b23000b@Damon-Family.org> Message-ID: On 21/08/2019 04:09, Grant Edwards wrote: > On 2019-08-21, Richard Damon wrote: > >> I think gmane feed the newsgroup comp.lang.python which feeds >> python-list at python.org. > > No, gmane is a gateway to python-list at python.org. > > -- > Grant > I use https://mail.python.org/pipermail/python-list/ to confirm that any post has gone where it should. And it has. From __peter__ at web.de Wed Aug 21 03:07:22 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Aug 2019 09:07:22 +0200 Subject: Enumerate - int object not subscriptable References: <0eb8639e-635b-48e1-a7dd-9221a8fd8bd1@googlegroups.com> Message-ID: Sayth Renshaw wrote: > def output_data(s): > serie = fibo(input_length) > x = [] > y = [] > > for num1, num2 in pairwise(serie): > y.append( num2 / num1) It looks like y contains unique values. In that case replace > for item in y: > x.append(y.index(item)) with x = list(range(len(x))) or use a single loop for index, (num1, num2) in enumerate(pairwise(serie)): x.append(index) y.append( num2 / num1) > draw_graph(x, y) > Kept trying with the enumerate style > for i, num in enumerate(serie): > while i < len(serie)-1: > x.append(int(serie[i + 1])/ int(serie[i])) > i += 1 There should be only one loop; use if ... to avoid the IndexError for i, num in enumerate(serie): if i < len(serie)-1: x.append(serie[i + 1]/ num) y.append(i) or clip the list: for i, num in enumerate(serie[:-1]): x.append(serie[i + 1]/ num) y.append(i) But I would definitely recommend pairwise(). From kloro2006 at gmail.com Wed Aug 21 02:12:00 2019 From: kloro2006 at gmail.com (tom arnall) Date: Tue, 20 Aug 2019 23:12:00 -0700 Subject: absolute path to a file In-Reply-To: <20190820094313.GA60150@cskk.homeip.net> References: <20190820094313.GA60150@cskk.homeip.net> Message-ID: Thanks. Hope you found a solution to the problem. On Tue, Aug 20, 2019, 2:51 AM Cameron Simpson wrote: > Please remember to CC the list. > > On 19Aug2019 22:06, Paul St George wrote: > >On 19/08/2019 14:16, Cameron Simpson wrote: > [...] > >>There's a remark on that web page I mentioned that suggests that the > >>leading '//' indicates the filename is relative to the Blender model, > >>so the context directory for the '//' is likely > >>/Users/Lion/Desktop/test8. > > > >Yes. That makes sense. The reason I was testing with two images, one > >at /Users/Lion/Desktop/test8/image01.tif and the other at > >/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images > >being in the same folder as the Blender file. > > > >So, let's assume the context directory is /Users/Lion/Desktop/test8 > >and see how we get on below. > [...] > >>realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it > >>is a special Blender path. First you need to convert it. By replacing > >>'//' with the blend file's directory. Then you can call realpath. If > >>you still need to. > > > >Understood. Now. Thanks! > >> > >>[...snip...] > > > >Did you just [...snip...] yourself? > > Yes. It keeps the surrounding context manageable. In this way you know > to which text I am referring, without having to wade through paragraphs > to guess what may be relevant. > > >> from os.path import dirname > >> > >> # Get this from somewhere just hardwiring it for the example. > >> # Maybe from your 'n' object below? > >> blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend' > >Is this setting a relative path? > >> > >> blender_image_file = n.image.filename > >> > >> unix_image_file = unblenderise(blender_image_file, > dirname(blend_file)) > >> > >>Now you have a UNIX path. If blend_file is an absolute path, > >>unix_image_path will also be an absolute path. But if blend_file is > >>a relative path (eg you opened up "tifftest8.blend") unix_image_path > >>will be a relative path. > > > >Does unix_image_path = unix_image_file? > > Yeah, sorry, my mistake. > > >Two possibilities here. > >blend_file (and so unix_image_file) is an absolute path OR blend_file > >(and so unix_image_file) is a relative path. > > > >I just want to check my understanding. If I supply the path to > >blend_file then it is absolute, and if I ask Python to generate the > >path to blend_file from within Blender it is relative. Have I got it? > > Not quite. What seems to be the situation is: > > You've got some object from Blender called "n.image", which has a > ".file" attribute which is a Blender reference to the image file of the > form "//image01.tif". > > I presume that Blender has enough state inside "n" or "n.image" to > locate this in the real filesystem; maybe it has some link to the > Blender model of your blend file, and thus knows the path to the blend > file and since //image01.tif is a reference relative to the blend file, > it can construct the UNIX path to the file. > > You want to know the UNIX pathname to the image file (maybe you want to > pass it to some unrelated application to view the file or something). > > So you need to do what Blender would do if it needs a UNIX path (eg to > open the file). > > The formula for that is dirname(path_to_blendfile) with n.image.file[2:] > appended to it. So that's what we do with unblenderise(): if the > filename is a "Blender relative name", rip off the "//" and prepend the > blend file directory path. That gets you a UNIX path which you can hand > to any function expecting a normal operating system pathname. > > Whether that is an absolute path or a relative path is entirely "does > the resulting path start with a '/'"? > > An absolute path starts with a slash and is relative to the root of the > filesystem. You can use such a path regardless of what your current > working directory is, because it doesn't use the working directory. > > A relative path doesn't start with a slash and is relative to the > current working directory. It only works if you're in the right working > directory. > > _Because_ a relative path depends on the _your_ working directory, > usually we pass around absolute paths if we need to tell something else > about a file, because that will work regardless if what _their_ working > directory may be. > > So, you may well want to turn a relative path into an absolute path... > > >If I decided not to supply the path and so ended up with a relative > >UNIX path, I could now use realpath or abspath to find the absolute > >path. Have I still got it? > > This is correct. > > Abspath may even call realpath to do its work, unsure. > > >It works very well. So thank you! I tested it with a Blend file that > >had two images, one in the same folder as the Blend file and the other > >was in a folder on the Desktop called 'images'. > > > >The initial results were: > >Plane uses image01.tif saved at //image01.tif which is at > >/Users/Lion/Desktop/test8/image01.tif > >Plane uses image02.tif saved at //../images/image02.tif which is at > >/Users/Lion/Desktop/test8/../images/image02.tif > >BUT as you say, this was easily sorted by using os.path.realpath or > >os.path.abspath. Both worked equally well. > > Yep. Abspath does some things in a purely lexical way: it resolves '.' > and '..' components in the path even if they don't exist. For example it > resolves 'a/b/c/d/../../../../foo' for me even though here 'a/b/c/d' > doesn't exist: it see the '.. and strips off the preceeding component, > repeatedly. So it starts with 'foo' after that pahse and prepends the > working directory path. > > The system realpath is not documented to work if some of the path is > fictitious, but the Python realpath seems to work even then, maybe it > falls back to abspath or something. > > Abspath takes a relative path and returns you an absolute path with the > '.' and '..' components stripped out. > > Realpath follows symlinks and stuff and returns you the direct absolute > path _after_ all that - one that doesn't traverse symlinks. > > For your purposes the results are equally functional. > > >Plane uses image01.tif saved at //image01.tif which is at > >/Users/Lion/Desktop/test8/image01.tif > >Plane uses image02.tif saved at //../images/image02.tif which is at > >/Users/Lion/Desktop/images/image02.tif > > > >So, everything now works. Thank you again. I am just a little unclear > >on the absolute and relative, hence my questions. > > Hope the above xaplinations help. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From toby at tobiah.org Wed Aug 21 14:27:41 2019 From: toby at tobiah.org (Tobiah) Date: Wed, 21 Aug 2019 11:27:41 -0700 Subject: itertools cycle() docs question Message-ID: In the docs for itertools.cycle() there is a bit of equivalent code given: def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... saved = [] for element in iterable: yield element saved.append(element) while saved: for element in saved: yield element Is that really how it works? Why make the copy of the elements? This seems to be equivalent: def cycle(iterable): while iterable: for thing in iterable: yield thing From cspealma at redhat.com Wed Aug 21 14:32:57 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Aug 2019 14:32:57 -0400 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: The point is to demonstrate the effect, not the specific implementation. On Wed, Aug 21, 2019 at 2:30 PM Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > def cycle(iterable): > # cycle('ABCD') --> A B C D A B C D A B C D ... > saved = [] > for element in iterable: > yield element > saved.append(element) > while saved: > for element in saved: > yield element > > > Is that really how it works? Why make > the copy of the elements? This seems > to be equivalent: > > > def cycle(iterable): > while iterable: > for thing in iterable: > yield thing > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From heindsight at kruger.dev Wed Aug 21 14:32:36 2019 From: heindsight at kruger.dev (Heinrich Kruger) Date: Wed, 21 Aug 2019 18:32:36 +0000 Subject: python requests get from API and post to another API and remote u' In-Reply-To: References: Message-ID: ??????? Original Message ??????? On Tuesday, August 20, 2019 10:18 AM, Chris Angelico wrote: > On Tue, Aug 20, 2019 at 6:59 PM Noah noah-list at enabled.com wrote: > > > Hi, > > I am trying to migrate information and data between two systems using > > their corresponding APIs. I am using python requests. > > I place a get request and the response from the API is "{'id': 32, > > 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}" > > I then take that information and attempt post it to the other API. The > > data is not accepted and the result is an HTTP 400 code. > > I tried posting with postman and still rejected. > > I can post to the second API if I change the data to look like this: > > {"id": 32, "description": "Firewall Outside", "address": "10.10.10.230/30"} > > How can I remove all u' from the get data or from the data I am > > attempting to post? > > Use Python 3. Your problems with Unicode will either disappear, or > become a lot clearer. > > ChrisA > Yep, you should definitely aim to use Python 3. However, I looks like you are converting a dict to a string to generate your POST data, instead of properly serialising it as JSON. Perhaps you did something like: resp = requests.get('https://example.com/api/data') data = resp.json() requests.post('https://example.com/api/other_data', data=str(data)) Or maybe you did something like print(resp.json()) and copy/pasted the result. You will probably be better off keeping your data as a dict and using the 'json' keyword argument to 'requests.post'. For example: resp = requests.get('https://example.com/api/data') data = resp.json() requests.post('https://example.com/api/other_data', json=data) See https://2.python-requests.org/en/stable/user/quickstart/#more-complicated-post-requests for more detail. -- Heinrich Kruger From rgaddi at highlandtechnology.invalid Wed Aug 21 14:38:28 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 21 Aug 2019 11:38:28 -0700 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: On 8/21/19 11:27 AM, Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > ??? def cycle(iterable): > ??????? # cycle('ABCD') --> A B C D A B C D A B C D ... > ??????? saved = [] > ??????? for element in iterable: > ??????????? yield element > ??????????? saved.append(element) > ??????? while saved: > ??????????? for element in saved: > ??????????????? yield element > > > Is that really how it works?? Why make > the copy of the elements?? This seems > to be equivalent: > > > ??? def cycle(iterable): > ??????? while iterable: > ??????????? for thing in iterable: > ??????????????? yield thing You assume that the initial iterable is reusable. If its not, the only way you can go back to the beginning is to have kept track of it yourself. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rmlibre at riseup.net Wed Aug 21 15:35:52 2019 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Wed, 21 Aug 2019 12:35:52 -0700 Subject: Style suggestions/critiques (rmlibre) In-Reply-To: References: Message-ID: <66d0bd317b38df354b5b4c0ae70e2db9@riseup.net> You might could consider using numpy, and storing the points in a list or list-like class. numpy can convert a list into an array, and then you can do one line binary operations on each element in the list. An example, let's assume we start with your implementation, and make a list of your lines: import numpy as np l1p1 = l1x1, l1y1 = 0, 0 l1p2 = l1x2, l1y2 = 0, 1 line1 = (l1p1, l1p2) l2p1 = l2x1, l2y1 = 1, 1 l2p2 = l2x2, l2y2 = 1, 2 line2 = (l2p1, l2p2) lines = [line1, line2] # Now convert this into a multi-dimentional array with numpy array = np.array(lines) print(array) >array( > [[[0, 0], [0, 1]], [[1, 1], [1, 2]]] >) print(array + 2) >array( > [[[2, 2], [2, 3]], [[3, 3], [3, 4]]] >) # This works with other binary operators as well. I suggest looking into # numpy arrays and how you can easily manipulate them. This has the added # benefit of having !extremely fast runtime. # But, I would prefer to create a class with methods like .make_new_line() # that takes four points as keyword arguments and a name for the line. These # can be stored in the instance object as a dictionary &/or namedtuple. That way # the class automatically names each component of a point, each point, and each # line for you. Consider a __getitem__ method as well to return a dict or # namedtuple for a certain line. Then you can call them easily with something like class Lines: """make your custom lines class""" lines = Lines() lines.make_new_line("line1", x1=0, y1=1, x2=1, y2=2) print(lines["line1"]) >array([[0, 1], [1, 2]]) print(lines["line1"]["p1"]) >array([0, 1]) # this would look cleaner with namedtuple syntax. I suggest googling that. # Then you can get syntax like lines["line1"].x1 >0 # I prefer dot syntax to bracketed key look-ups. So I might even do some # self.__dict__ manipulation in .make_new_line to add the name of the line # directly to the instance dictionary. But this comes with too many warnings # than I will go into. But, then you can automagically get syntax like print(lines.line1.p2) >array([1, 2]) # The up-front cost would be greater with creating new classes # with custom functionality, but your code will greatly increase # in readability, maintainability and expressiveness. And, it # will just be better in the long run to have a class to automate # all the things you want to be able to do with your lines # and simplify your experience with managing and creating them. On 2019-08-21 16:00, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Enumerate - int object not subscriptable (Ian Kelly) > 2. Re: Xlabel and ylabel are not shown (David Lowry-Duda) > 3. Re: absolute path to a file (Paul St George) > 4. Style suggestions/critiques (Michael F. Stemper) > 5. Re: absolute path to a file (Cameron Simpson) > 6. Re: Which editor is suited for view a python package's > source? (jfong at ms4.hinet.net) > 7. Re: absolute path to a file (Richard Damon) > 8. Re: Which editor is suited for view a python package's > source? (Kyle Stanley) > 9. Re: Style suggestions/critiques (Aldwin Pollefeyt) > 10. Re: absolute path to a file (Grant Edwards) > 11. Re: Style suggestions/critiques (DL Neil) > 12. Re: Enumerate - int object not subscriptable (Sayth Renshaw) > 13. Re: python requests get from API and post to another API and > remote u' (Pankaj Jangid) > 14. Re: absolute path to a file (Paul St George) > 15. Re: Enumerate - int object not subscriptable (Peter Otten) From toby at tobiah.org Wed Aug 21 15:52:44 2019 From: toby at tobiah.org (Tobiah) Date: Wed, 21 Aug 2019 12:52:44 -0700 Subject: itertools cycle() docs question References: Message-ID: On 8/21/19 11:38 AM, Rob Gaddi wrote: > On 8/21/19 11:27 AM, Tobiah wrote: >> In the docs for itertools.cycle() there is a bit of equivalent code >> given: >> >> def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D >> ... saved = [] for element in iterable: yield element >> saved.append(element) while saved: for element in saved: yield >> element >> >> >> Is that really how it works? Why make the copy of the elements? >> This seems to be equivalent: >> >> >> def cycle(iterable): while iterable: for thing in iterable: yield >> thing > > You assume that the initial iterable is reusable. If its not, the > only way you can go back to the beginning is to have kept track of it > yourself. > I see. What is an example of an iterable that is not reusable? From python.list at tim.thechases.com Wed Aug 21 15:10:06 2019 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 21 Aug 2019 14:10:06 -0500 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: <20190821141006.04986b74@bigbox.attlocal.net> On 2019-08-21 11:27, Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > def cycle(iterable): > # cycle('ABCD') --> A B C D A B C D A B C D ... > saved = [] > for element in iterable: > yield element > saved.append(element) > while saved: > for element in saved: > yield element > > > Is that really how it works? Why make > the copy of the elements? This seems > to be equivalent: > > > def cycle(iterable): > while iterable: > for thing in iterable: > yield thing Compare the results of >>> import itertools as i >>> def tobiahcycle(iterable): ... while iterable: ... for thing in iterable: ... yield thing ... >>> def testiter(): ... yield input() ... yield input() ... Now, see how many times input() gets called for itertools.islice() >>> for v in i.islice(i.cycle(testiter()), 6): print(v) Note that you only provide input twice, once for each yield statement. Compare that to your tobiahcycle() method: >>> for v in i.islice(tobiahcycle(testiter()), 6): print(v) The yield gets called every time through the interator and it doesn't produce the same results. -tkc From rosuav at gmail.com Wed Aug 21 16:00:41 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Aug 2019 06:00:41 +1000 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: On Thu, Aug 22, 2019 at 5:56 AM Tobiah wrote: > > On 8/21/19 11:38 AM, Rob Gaddi wrote: > > On 8/21/19 11:27 AM, Tobiah wrote: > >> In the docs for itertools.cycle() there is a bit of equivalent code > >> given: > >> > >> def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D > >> ... saved = [] for element in iterable: yield element > >> saved.append(element) while saved: for element in saved: yield > >> element > >> > >> > >> Is that really how it works? Why make the copy of the elements? > >> This seems to be equivalent: > >> > >> > >> def cycle(iterable): while iterable: for thing in iterable: yield > >> thing > > > > You assume that the initial iterable is reusable. If its not, the > > only way you can go back to the beginning is to have kept track of it > > yourself. > > > > I see. What is an example of an iterable that is not reusable? Just call iter() on pretty much any iterable, and you'll get back something that's not reusable. ChrisA From ian.g.kelly at gmail.com Wed Aug 21 16:10:06 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 21 Aug 2019 14:10:06 -0600 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: On Wed, Aug 21, 2019 at 12:36 PM Calvin Spealman wrote: > > The point is to demonstrate the effect, not the specific implementation. But still yes, that's pretty much exactly what it does. The main difference between the "roughly equivalent to" code and the actual implementation is that the former is in Python while the latter is in C. From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Aug 21 14:42:38 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Wed, 21 Aug 2019 14:42:38 -0400 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: <456d5532-09df-0ce0-d04b-f4b70020223f@potatochowder.com> On 8/21/19 2:32 PM, Calvin Spealman wrote: > The point is to demonstrate the effect, not the specific implementation. Once you've gone through the iterable once, it's falsey, which means that the while loop will end. But if you copy all the elements to a real list, then the while loop is infinite. Dan > On Wed, Aug 21, 2019 at 2:30 PM Tobiah wrote: > >> In the docs for itertools.cycle() there is >> a bit of equivalent code given: >> >> def cycle(iterable): >> # cycle('ABCD') --> A B C D A B C D A B C D ... >> saved = [] >> for element in iterable: >> yield element >> saved.append(element) >> while saved: >> for element in saved: >> yield element >> >> >> Is that really how it works? Why make >> the copy of the elements? This seems >> to be equivalent: >> >> >> def cycle(iterable): >> while iterable: >> for thing in iterable: >> yield thing >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From rosuav at gmail.com Wed Aug 21 17:02:27 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Aug 2019 07:02:27 +1000 Subject: itertools cycle() docs question In-Reply-To: <456d5532-09df-0ce0-d04b-f4b70020223f@potatochowder.com> References: <456d5532-09df-0ce0-d04b-f4b70020223f@potatochowder.com> Message-ID: On Thu, Aug 22, 2019 at 6:55 AM Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 8/21/19 2:32 PM, Calvin Spealman wrote: > > The point is to demonstrate the effect, not the specific implementation. > > Once you've gone through the iterable once, it's falsey, > which means that the while loop will end. But if you copy > all the elements to a real list, then the while loop is > infinite. Hmm, not all iterables are falsey after exhaustion. The point of the "while saved" is to skip the loop if you cycle nothing, but you can't depend on the four line version. ChrisA From tjreedy at udel.edu Thu Aug 22 01:58:38 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Aug 2019 01:58:38 -0400 Subject: itertools cycle() docs question In-Reply-To: References: Message-ID: On 8/21/2019 2:27 PM, Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > ??? def cycle(iterable): > ??????? # cycle('ABCD') --> A B C D A B C D A B C D ... > ??????? saved = [] > ??????? for element in iterable: > ??????????? yield element > ??????????? saved.append(element) > ??????? while saved: > ??????????? for element in saved: > ??????????????? yield element > > > Is that really how it works?? Why make > the copy of the elements?? This seems > to be equivalent: > > ??? def cycle(iterable): > ??????? while iterable: > ??????????? for thing in iterable: > ??????????????? yield thing Try this experiment: from itertools import cycle def cycle2(iterable): while iterable: for thing in iterable: yield thing for i, v in zip(range(20), cycle(i*i for i in range(4))): print(i, v) for i, v in zip(range(20), cycle2(i*i for i in range(4))): print(i, v) -- Terry Jan Reedy From email at paulstgeorge.com Thu Aug 22 03:34:36 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 22 Aug 2019 09:34:36 +0200 Subject: Newbie question about Python syntax Message-ID: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> I have the Python API for the Map Value Node here: . All well and good. Now I just want to write a simple line of code such as: import bpy ... >>>print(bpy.types.CompositorNodeMapValue.max[0]) If this works, I will do something similar for max, min, offset and then size. I know my embarrassingly feeble attempt is wrong because the console tells me: AttributeError: type object 'CompositorNodeMapValue' has no attribute 'max' Could anyone (please) point me in the right direction? Thanks, Paul From cs at cskk.id.au Thu Aug 22 05:49:25 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 22 Aug 2019 19:49:25 +1000 Subject: Newbie question about Python syntax In-Reply-To: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> Message-ID: <20190822094925.GA63285@cskk.homeip.net> On 22Aug2019 09:34, Paul St George wrote: >I have the Python API for the Map Value Node here: . > >All well and good. Now I just want to write a simple line of code such as: > >import bpy >>>>print(bpy.types.CompositorNodeMapValue.max[0]) [...] >AttributeError: type object 'CompositorNodeMapValue' has no attribute >'max' CompositorNodeMapValue is a class. All the attributes described are for instances of the class. So you need to do something that _gives_ you an instance of CompositorNodeMapValue. That instance should have a .max array. Cheers, Cameron Simpson From email at paulstgeorge.com Thu Aug 22 07:19:12 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 22 Aug 2019 13:19:12 +0200 Subject: Newbie question about Python syntax In-Reply-To: <20190822094925.GA63285@cskk.homeip.net> References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> <20190822094925.GA63285@cskk.homeip.net> Message-ID: On 22/08/2019 11:49, Cameron Simpson wrote: > On 22Aug2019 09:34, Paul St George wrote: >> I have the Python API for the Map Value Node here: >> . >> >> >> All well and good. Now I just want to write a simple line of code such >> as: >> >> import bpy >>>>> print(bpy.types.CompositorNodeMapValue.max[0]) > [...] >> AttributeError: type object 'CompositorNodeMapValue' has no attribute >> 'max' > > CompositorNodeMapValue is a class. All the attributes described are for > instances of the class. So you need to do something that _gives_ you an > instance of CompositorNodeMapValue. That instance should have a .max array. > > Cheers, > Cameron Simpson Gulp. Thank you. I did ask for a pointer but perhaps I need a roadmap. I have tried to do something that gives me an instance of CompositorNodeMapValue. I don't think I should humiliate myself further by sharing my attempts so could you please show me what the code should look like. From rosuav at gmail.com Thu Aug 22 08:32:09 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Aug 2019 22:32:09 +1000 Subject: Newbie question about Python syntax In-Reply-To: References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> <20190822094925.GA63285@cskk.homeip.net> Message-ID: On Thu, Aug 22, 2019 at 9:20 PM Paul St George wrote: > > On 22/08/2019 11:49, Cameron Simpson wrote: > > On 22Aug2019 09:34, Paul St George wrote: > >> I have the Python API for the Map Value Node here: > >> . > >> > >> > >> All well and good. Now I just want to write a simple line of code such > >> as: > >> > >> import bpy > >>>>> print(bpy.types.CompositorNodeMapValue.max[0]) > > [...] > >> AttributeError: type object 'CompositorNodeMapValue' has no attribute > >> 'max' > > > > CompositorNodeMapValue is a class. All the attributes described are for > > instances of the class. So you need to do something that _gives_ you an > > instance of CompositorNodeMapValue. That instance should have a .max array. > > > > Cheers, > > Cameron Simpson > > Gulp. Thank you. I did ask for a pointer but perhaps I need a roadmap. > > I have tried to do something that gives me an instance of > CompositorNodeMapValue. I don't think I should humiliate myself further > by sharing my attempts so could you please show me what the code should > look like. > Don't think of it as humiliating yourself - you're asking for fairly specific advice, so showing your code is the best way to get that sort of advice. We don't bite :) ChrisA From nospam_2019 at efbe.prima.de Thu Aug 22 09:49:28 2019 From: nospam_2019 at efbe.prima.de (nospam_2019 at efbe.prima.de) Date: Thu, 22 Aug 2019 15:49:28 +0200 Subject: Tkinter Progress Bar In-Reply-To: References: Message-ID: Am 22.08.19 um 15:19 schrieb Daniel: > If i have a figure like 13247347347437x23828328382? how to make a > progress bar in tkinter that shows the time the pc takes to give the > result? > https://docs.python.org/3/library/tkinter.ttk.html?highlight=progressbar From rosuav at gmail.com Thu Aug 22 11:59:08 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Aug 2019 01:59:08 +1000 Subject: itertools cycle() docs question In-Reply-To: <7fdtlep9qusjnrkfugvus7u0nlelvhv3kb@4ax.com> References: <7fdtlep9qusjnrkfugvus7u0nlelvhv3kb@4ax.com> Message-ID: On Fri, Aug 23, 2019 at 1:41 AM Dennis Lee Bieber wrote: > > On Wed, 21 Aug 2019 12:52:44 -0700, Tobiah declaimed the > following: > > > > >I see. What is an example of an iterable that is not reusable? > > > >>> x = range(5) > >>> x > range(0, 5) > >>> > >>> x = range(0, 5) >>> list(x) [0, 1, 2, 3, 4] >>> list(x) [0, 1, 2, 3, 4] >>> list(x) [0, 1, 2, 3, 4] >>> list(x) [0, 1, 2, 3, 4] Perfectly reusable. There are plenty of others that aren't, but that one is. ChrisA From wiwindson at gmail.com Thu Aug 22 12:00:56 2019 From: wiwindson at gmail.com (Windson Yang) Date: Fri, 23 Aug 2019 00:00:56 +0800 Subject: How should we use global variables correctly? Message-ID: I can 'feel' that global variables are evil. I also read lots of articles proves that (http://wiki.c2.com/?GlobalVariablesAreBad). However, I found CPython Lib use quite a lot of `global` keyword. So how should we use `global` keyword correctly? IIUC, it's fine that we use `global` keyword inside the Lib since most of the time the user just import the lib and call the API. In any other situation, we should avoid using it. Am I right? From duram at terra.com.br Thu Aug 22 09:19:21 2019 From: duram at terra.com.br (Daniel) Date: Thu, 22 Aug 2019 10:19:21 -0300 Subject: Tkinter Progress Bar Message-ID: If i have a figure like 13247347347437x23828328382 how to make a progress bar in tkinter that shows the time the pc takes to give the result? --- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus From torriem at gmail.com Thu Aug 22 13:12:40 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 22 Aug 2019 11:12:40 -0600 Subject: How should we use global variables correctly? In-Reply-To: References: Message-ID: On 8/22/19 10:00 AM, Windson Yang wrote: > I can 'feel' that global variables are evil. I also read lots of articles > proves that (http://wiki.c2.com/?GlobalVariablesAreBad). However, I found > CPython Lib use quite a lot of `global` keyword. So how should we use > `global` keyword correctly? IIUC, it's fine that we use `global` keyword > inside the Lib since most of the time the user just import the lib and call > the API. In any other situation, we should avoid using it. Am I right? The "global" keyword only refers to the current module as far as I know. Thus global variables are global only to the current python file, so the damage, as it were, is limited in scope. And it's only required if you plan to write to a global variable from another scope; you can always read from a parent scope if the name hasn't been used by the local scope. I'm sure there are use cases for using the global keyword. It's not evil. It's just not necessary most of the time. I don't think I've ever used the "global" keyword. If I need to share state, or simple configuration information, between modules, I place those variables in their own module file and import them where I need them. From tjreedy at udel.edu Thu Aug 22 13:53:25 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Aug 2019 13:53:25 -0400 Subject: Tkinter Progress Bar In-Reply-To: References: Message-ID: On 8/22/2019 12:12 PM, Dennis Lee Bieber wrote: > On Thu, 22 Aug 2019 15:49:28 +0200, nospam_2019 at efbe.prima.de declaimed the > following: > >> Am 22.08.19 um 15:19 schrieb Daniel: >>> If i have a figure like 13247347347437x23828328382? how to make a >>> progress bar in tkinter that shows the time the pc takes to give the >>> result? That multiplication takes a blink of an eye with python. To time it, see the timeit module. -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 22 13:58:12 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Aug 2019 13:58:12 -0400 Subject: itertools cycle() docs question In-Reply-To: <7fdtlep9qusjnrkfugvus7u0nlelvhv3kb@4ax.com> References: <7fdtlep9qusjnrkfugvus7u0nlelvhv3kb@4ax.com> Message-ID: On 8/22/2019 11:35 AM, Dennis Lee Bieber wrote: > On Wed, 21 Aug 2019 12:52:44 -0700, Tobiah declaimed the > following: > >> >> I see. What is an example of an iterable that is not reusable? Essentially all iterators, which included all generators, which includes the return from all generator functions and all generator expressions and all iter(iterable) expressions. -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 22 14:02:21 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Aug 2019 14:02:21 -0400 Subject: Newbie question about Python syntax In-Reply-To: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> Message-ID: On 8/22/2019 3:34 AM, Paul St George wrote: > I have the Python API for the Map Value Node here: > . > > > All well and good. Now I just want to write a simple line of code such as: > > import bpy > > ... > > >>>print(bpy.types.CompositorNodeMapValue.max[0]) > > If this works, I will do something similar for max, min, offset and then > size. From this and your other responses, you seem to not undertstand some of the concepts explained in the tutorial, in particular class and class instance. Perhaps you should reread the appropriate section(s), and if you don't understand any of the examples, ask about them here. We are familiar with those, but not with CompositorNodeMapValue. -- Terry Jan Reedy From email at paulstgeorge.com Thu Aug 22 16:24:28 2019 From: email at paulstgeorge.com (Paul St George) Date: Thu, 22 Aug 2019 22:24:28 +0200 Subject: Newbie question about Python syntax In-Reply-To: References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> Message-ID: On 22/08/2019 20:02, Terry Reedy wrote: > On 8/22/2019 3:34 AM, Paul St George wrote: >> I have the Python API for the Map Value Node here: >> . >> >> >> All well and good. Now I just want to write a simple line of code such >> as: >> >> import bpy >> >> ... >> >> ?>>>print(bpy.types.CompositorNodeMapValue.max[0]) >> >> If this works, I will do something similar for max, min, offset and >> then size. > > From this and your other responses, you seem to not understand some of > the concepts explained in the tutorial, in particular class and class > instance.? Perhaps you should reread the appropriate section(s), and if > you don't understand any of the examples, ask about them here.? We are > familiar with those, but not with CompositorNodeMapValue. > > Terry, You are right, but it is even worse than you think. I do not have a tutorial so I have no examples to understand. Reading Cameron et al, I have broken the problem down into: do something (probably using the word self) that _gives_ me an instance of CompositorNodeMapValue. Then when I done that, look at some of the attributes (.max, .min, .offset, .size) of the instance. Paul From aeros167 at gmail.com Thu Aug 22 17:21:25 2019 From: aeros167 at gmail.com (Kyle Stanley) Date: Thu, 22 Aug 2019 17:21:25 -0400 Subject: Newbie question about Python syntax In-Reply-To: References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> Message-ID: > You are right, but it is even worse than you think. I do not have a tutorial so I have no examples to understand. The tutorial that Terry was referring to was the one on docs.python.org, here's a couple of links for the sections he was referring to: Full section on classes: https://docs.python.org/3/tutorial/classes.html Section on instantiating objects from classes: https://docs.python.org/3/tutorial/classes.html#class-objects On Thu, Aug 22, 2019 at 4:40 PM Paul St George wrote: > On 22/08/2019 20:02, Terry Reedy wrote: > > On 8/22/2019 3:34 AM, Paul St George wrote: > >> I have the Python API for the Map Value Node here: > >> < > https://docs.blender.org/api/current/bpy.types.CompositorNodeMapValue.html>. > > >> > >> > >> All well and good. Now I just want to write a simple line of code such > >> as: > >> > >> import bpy > >> > >> ... > >> > >> >>>print(bpy.types.CompositorNodeMapValue.max[0]) > >> > >> If this works, I will do something similar for max, min, offset and > >> then size. > > > > From this and your other responses, you seem to not understand some of > > the concepts explained in the tutorial, in particular class and class > > instance. Perhaps you should reread the appropriate section(s), and if > > you don't understand any of the examples, ask about them here. We are > > familiar with those, but not with CompositorNodeMapValue. > > > > > Terry, > You are right, but it is even worse than you think. I do not have a > tutorial so I have no examples to understand. > > Reading Cameron et al, I have broken the problem down into: > do something (probably using the word self) that _gives_ me an instance > of CompositorNodeMapValue. > > Then when I done that, > look at some of the attributes (.max, .min, .offset, .size) of the > instance. > > Paul > > -- > https://mail.python.org/mailman/listinfo/python-list > From nikos63205 at gmail.com Thu Aug 22 17:33:32 2019 From: nikos63205 at gmail.com (Nikos63205) Date: Thu, 22 Aug 2019 17:33:32 -0400 Subject: Broken Message-ID: <5d5f0a2d.1c69fb81.c9904.3410@mx.google.com> I am using python for MM creator pro/relocator G but any time I try to generate Gcode it tells me to update or fix my python but any time I do it and try to generate gcode it says the same thing From cs at cskk.id.au Thu Aug 22 20:17:15 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 23 Aug 2019 10:17:15 +1000 Subject: How should we use global variables correctly? In-Reply-To: References: Message-ID: <20190823001715.GA7291@cskk.homeip.net> On 22Aug2019 11:12, Michael Torrie wrote: >On 8/22/19 10:00 AM, Windson Yang wrote: >> I can 'feel' that global variables are evil. I also read lots of articles >> proves that (http://wiki.c2.com/?GlobalVariablesAreBad). However, I found >> CPython Lib use quite a lot of `global` keyword. So how should we use >> `global` keyword correctly? IIUC, it's fine that we use `global` keyword >> inside the Lib since most of the time the user just import the lib and call >> the API. In any other situation, we should avoid using it. Am I right? > >The "global" keyword only refers to the current module as far as I know. > Thus global variables are global only to the current python file, so >the damage, as it were, is limited in scope. Aye. >And it's only required if >you plan to write to a global variable from another scope; you can >always read from a parent scope if the name hasn't been used by the >local scope. I'm sure there are use cases for using the global keyword. > It's not evil. It's just not necessary most of the time. I don't >think I've ever used the "global" keyword. If I need to share state, or >simple configuration information, between modules, I place those >variables in their own module file and import them where I need them. I've used it a few times. Maybe a handful of times in thousands of lines of code. As Michael says, "you can always read from a parent scope if the name hasn't been used by the local scope". What this means is this: _MODULE_LEVEL_CACHE = {} def factors_of(n): factors = _MODULE_LEVEL_CACHE.get(n) if factors is None: factors = factorise(n) _MODULE_LEVEL_CACHE[n] = factors return factors def factorise(n): ... expensive factorisation algorithm here ... Here we access _MODULE_LEVEL_CACHE directly without bothering with the global keyword. Because the function "factors_of" does not _assign_ to the name _MODULE_LEVEL_CACHE, that name is not local to the function; the outer scopes will be searched in order to find the name. Now, Python decides what variable are local to a function by staticly inspecting the code and seeing which have assignments. So: x = 9 y = 10 z = 11 function foo(x): y = 5 print(x, y, z) Within the "foo" function: - x is local (it is assigned to by the function parameter when you call it) - y is local (it is assigned to in the function body) - z is not local (it is not assigned to); the namespace searching finds it in the module scope Note that in the "factors_of" function we also do not _assign_ to _MODULE_LEVEL_CACHE. We do assign to one of its elements, but that is an access _via_ _MODULE_LEVEL_CACHE, not an assignment to the name itself. So it is nonlocal and found in the module namespace. However, where you might want the use "global" (or its modern friend "nonlocal") is to avoid accidents and to make the globalness obvious. The same example code: x = 9 y = 10 z = 11 function foo(x): y = 5 print(x, y, z) When you use a global, that is usually a very deliberate decision on your part, because using globals is _usually_ undesirable. When all variables are local, side effects are contained within the function and some surprises (== bugs) are prevented. Let's modify "foo": function foo(x): y = 5 z = y * 2 print(x, y, z) Suddenly "z" is a local variable because it is assigned to. In this function it is all very obvious because the function is very short. A longer function might not have this be so obvious. So: was "z" still intended to be global? If yes then you need the global keyword: function foo(x): global z y = 5 z = y * 2 print(x, y, z) And even if we were not assigning to "z", we might still use the "global" statement to make it obvious to the reader that "z" is a global; after all, if it not very visually distinctive - it looks a lot like "x" and "y". So my advice after all of this is: As you thought, globals are to be avoided most of the time. They invite unwanted side effects and also make it harder to write "pure functions", functions with no side effects. Pure functions (most Python functions) are much easier to reuse elsewhere. However, if you have a good case for using a global, always use the "global" statement. It has the following benefits: it makes the globalness obvious to the person reading the code and it avoids a global variable suddenly becoming local if you assign to it. (NB: the "time" of that semantic change is when you change the code, _not_ when the assignment itself happens.) Cheers, Cameron Simpson From rosuav at gmail.com Thu Aug 22 20:20:49 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Aug 2019 10:20:49 +1000 Subject: How should we use global variables correctly? In-Reply-To: <20190823001715.GA7291@cskk.homeip.net> References: <20190823001715.GA7291@cskk.homeip.net> Message-ID: On Fri, Aug 23, 2019 at 10:18 AM Cameron Simpson wrote: > As Michael says, "you can always read from a parent scope if the name > hasn't been used by the local scope". What this means is this: > > _MODULE_LEVEL_CACHE = {} > > def factors_of(n): > factors = _MODULE_LEVEL_CACHE.get(n) > if factors is None: > factors = factorise(n) > _MODULE_LEVEL_CACHE[n] = factors > return factors Note that this is still using a global variable, even though it isn't using the "global" keyword. The two concepts are related but distinct. ChrisA From Richard at Damon-Family.org Thu Aug 22 21:05:43 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 22 Aug 2019 21:05:43 -0400 Subject: How should we use global variables correctly? In-Reply-To: References: Message-ID: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> On 8/22/19 12:00 PM, Windson Yang wrote: > I can 'feel' that global variables are evil. I also read lots of articles > proves that (http://wiki.c2.com/?GlobalVariablesAreBad). However, I found > CPython Lib use quite a lot of `global` keyword. So how should we use > `global` keyword correctly? IIUC, it's fine that we use `global` keyword > inside the Lib since most of the time the user just import the lib and call > the API. In any other situation, we should avoid using it. Am I right? It should be noted that the Python 'global' is much more like the C/C++ file scoped 'static' which is less bad that fully global variables (the extern variable). -- Richard Damon From wiwindson at gmail.com Thu Aug 22 21:22:57 2019 From: wiwindson at gmail.com (Windson Yang) Date: Fri, 23 Aug 2019 09:22:57 +0800 Subject: How should we use global variables correctly? In-Reply-To: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> References: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> Message-ID: Thank you all for the great explanation, I still trying to find some good example to use 'global', In CPython, I found an example use 'global' in cpython/Lib/zipfile.py _crctable = None def _gen_crc(crc): for j in range(8): if crc & 1: crc = (crc >> 1) ^ 0xEDB88320 else: crc >>= 1 return crc def _ZipDecrypter(pwd): key0 = 305419896 key1 = 591751049 key2 = 878082192 global _crctable if _crctable is None: _crctable = list(map(_gen_crc, range(256))) crctable = _crctable _crctable only been used in the _ZipDecrypter function. IIUC, the code can be refactored to def _gen_crc(crc): ...stay the same def _ZipDecrypter(pwd, _crctable=list(map(_gen_crc, range(256)))): key0 = 305419896 key1 = 591751049 key2 = 878082192 crctable = _crctable Which avoid using 'global' keyword. Why we are not doing this? I guess the reason we use 'global' here because we don't want to create `_crctable = list(map(_gen_crc, range(256)))` every time when we run '_ZipDecrypter' function. So we kinda cache _crctable with 'global', am I right? From rosuav at gmail.com Thu Aug 22 21:33:55 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Aug 2019 11:33:55 +1000 Subject: How should we use global variables correctly? In-Reply-To: References: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> Message-ID: On Fri, Aug 23, 2019 at 11:24 AM Windson Yang wrote: > > Thank you all for the great explanation, I still trying to find some good > example to use 'global', In CPython, I found an example use 'global' in > cpython/Lib/zipfile.py > > _crctable = None > def _gen_crc(crc): > for j in range(8): > if crc & 1: > crc = (crc >> 1) ^ 0xEDB88320 > else: > crc >>= 1 > return crc > > def _ZipDecrypter(pwd): > key0 = 305419896 > key1 = 591751049 > key2 = 878082192 > > global _crctable > if _crctable is None: > _crctable = list(map(_gen_crc, range(256))) > crctable = _crctable > > _crctable only been used in the _ZipDecrypter function. IIUC, the code can > be refactored to > > def _gen_crc(crc): > ...stay the same > > def _ZipDecrypter(pwd, _crctable=list(map(_gen_crc, range(256)))): > key0 = 305419896 > key1 = 591751049 > key2 = 878082192 > crctable = _crctable > > Which avoid using 'global' keyword. Why we are not doing this? I guess the > reason we use 'global' here because we don't want to create `_crctable = > list(map(_gen_crc, range(256)))` every time when we run '_ZipDecrypter' > function. So we kinda cache _crctable with 'global', am I right? It's a cache that is made ONLY when it's first needed. If you put it in the function header, it has to be created eagerly as soon as the module is imported. ChrisA From jfong at ms4.hinet.net Thu Aug 22 22:38:54 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 22 Aug 2019 19:38:54 -0700 (PDT) Subject: How to record the console's content in the interpreter? Message-ID: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> Say I like to record everything showing in the console into a file after I start a debug session, and stop it when finished. It's not a console redirection. I still need to see what is going on during the session. --Jach From cs at cskk.id.au Fri Aug 23 00:09:38 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 23 Aug 2019 14:09:38 +1000 Subject: How to record the console's content in the interpreter? In-Reply-To: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> Message-ID: <20190823040938.GA3595@cskk.homeip.net> On 22Aug2019 19:38, Jach Fong wrote: >Say I like to record everything showing in the console into a file >after I start a debug session, and stop it when finished. It's not >a console redirection. I still need to see what is going on during >the session. If you're in a terminal you can run the 'script" command. This starts a new shell inside a session which records itself to the file "typescript" (by default). See "man script" for further details. Cheers, Cameron Simpson From jfong at ms4.hinet.net Fri Aug 23 00:48:33 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 22 Aug 2019 21:48:33 -0700 (PDT) Subject: How to record the console's content in the interpreter? In-Reply-To: References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> Message-ID: <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> Cameron Simpson? 2019?8?23???? UTC+8??12?09?54???? > On 22Aug2019 19:38, Jach Fong wrote: > >Say I like to record everything showing in the console into a file > >after I start a debug session, and stop it when finished. It's not > >a console redirection. I still need to see what is going on during > >the session. > > If you're in a terminal you can run the 'script" command. This starts a > new shell inside a session which records itself to the file "typescript" > (by default). See "man script" for further details. > > Cheers, > Cameron Simpson Mine is Windows:-( No 'script' command? --Jach From wiwindson at gmail.com Fri Aug 23 02:43:36 2019 From: wiwindson at gmail.com (Windson Yang) Date: Fri, 23 Aug 2019 14:43:36 +0800 Subject: How should we use global variables correctly? In-Reply-To: References: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> Message-ID: I also want to know what is the difference between "using 'global variables' in a py module" and "using a variable in class". For example: In global.py: foo = 1 def bar(): global foo return foo + 1 In class.py class Example: def __init__(self): self.foo = 1 def bar() return self.foo + 1 Expect the syntax, why using class variable self.foo would be better (or more common)? I think the 'global' here is relative, foo is global in global.py and self.foo is global in Example class. If the global.py is short and clean enough (didn't have a lot of other class), they are pretty much the same. Or I missed something? Chris Angelico ?2019?8?23??? ??9:34??? > On Fri, Aug 23, 2019 at 11:24 AM Windson Yang wrote: > > > > Thank you all for the great explanation, I still trying to find some good > > example to use 'global', In CPython, I found an example use 'global' in > > cpython/Lib/zipfile.py > > > > _crctable = None > > def _gen_crc(crc): > > for j in range(8): > > if crc & 1: > > crc = (crc >> 1) ^ 0xEDB88320 > > else: > > crc >>= 1 > > return crc > > > > def _ZipDecrypter(pwd): > > key0 = 305419896 > > key1 = 591751049 > > key2 = 878082192 > > > > global _crctable > > if _crctable is None: > > _crctable = list(map(_gen_crc, range(256))) > > crctable = _crctable > > > > _crctable only been used in the _ZipDecrypter function. IIUC, the code > can > > be refactored to > > > > def _gen_crc(crc): > > ...stay the same > > > > def _ZipDecrypter(pwd, _crctable=list(map(_gen_crc, range(256)))): > > key0 = 305419896 > > key1 = 591751049 > > key2 = 878082192 > > crctable = _crctable > > > > Which avoid using 'global' keyword. Why we are not doing this? I guess > the > > reason we use 'global' here because we don't want to create `_crctable = > > list(map(_gen_crc, range(256)))` every time when we run '_ZipDecrypter' > > function. So we kinda cache _crctable with 'global', am I right? > > It's a cache that is made ONLY when it's first needed. If you put it > in the function header, it has to be created eagerly as soon as the > module is imported. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Fri Aug 23 02:54:41 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 23 Aug 2019 16:54:41 +1000 Subject: How to record the console's content in the interpreter? In-Reply-To: <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> References: <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> Message-ID: <20190823065441.GA19355@cskk.homeip.net> On 22Aug2019 21:48, Jach Fong wrote: >Cameron Simpson? 2019?8?23???? UTC+8??12?09?54???? >> On 22Aug2019 19:38, Jach Fong wrote: >> >Say I like to record everything showing in the console into a file >> >after I start a debug session, and stop it when finished. It's not >> >a console redirection. I still need to see what is going on during >> >the session. >> >> If you're in a terminal you can run the 'script" command. This starts a >> new shell inside a session which records itself to the file "typescript" >> (by default). See "man script" for further details. > >Mine is Windows:-( No 'script' command? Maybe not. Cygwin (UNIX emulator) or the Window Linux facility might provide it. Otherwise a Windows person will need to advise you; I can't. Cheers, Cameron Simpson From ml_news at posteo.de Fri Aug 23 02:58:23 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Fri, 23 Aug 2019 08:58:23 +0200 Subject: How to record the console's content in the interpreter? References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> Message-ID: <20190823085823.7199d87d@arcor.com> On Thu, 22 Aug 2019 21:48:33 -0700 (PDT) jfong at ms4.hinet.net wrote: > Cameron Simpson? 2019?8?23???? UTC+8??12?09?54???? > > On 22Aug2019 19:38, Jach Fong wrote: > > >Say I like to record everything showing in the console into a file > > >after I start a debug session, and stop it when finished. It's not > > >a console redirection. I still need to see what is going on during > > >the session. > > > > If you're in a terminal you can run the 'script" command. This > > starts a new shell inside a session which records itself to the > > file "typescript" (by default). See "man script" for further > > details. > > > > Cheers, > > Cameron Simpson > > Mine is Windows:-( No 'script' command? > > --Jach If I understand you correctly you want to save an interactive session!? Then you could use ipython. In ipython the lines get numbererd. If your last line is, for example: In [100] you could do this: save mysave 1-100 in the ipython shell. -- Manfred From frank at chagford.com Fri Aug 23 03:07:27 2019 From: frank at chagford.com (Frank Millman) Date: Fri, 23 Aug 2019 09:07:27 +0200 Subject: How should we use global variables correctly? In-Reply-To: References: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> Message-ID: On 2019-08-23 8:43 AM, Windson Yang wrote: > I also want to know what is the difference between "using 'global > variables' in a py module" and "using a variable in class". For example: > > In global.py: > > foo = 1 > def bar(): > global foo > return foo + 1 > > In class.py > > class Example: > def __init__(self): > self.foo = 1 > def bar() > return self.foo + 1 > > Expect the syntax, why using class variable self.foo would be better (or > more common)? I think the 'global' here is relative, foo is global in > global.py and self.foo is global in Example class. If the global.py is > short and clean enough (didn't have a lot of other class), they are pretty > much the same. Or I missed something? > One difference is that you could have many instances of Example, each with its own value of 'foo', whereas with a global 'foo' there can only be one value of 'foo' for the module. It would make sense to use the 'global' keyword if you have a module with various functions, several of which refer to 'foo', but only one of which changes the value of 'foo'. Frank Millman From frank at chagford.com Fri Aug 23 03:07:27 2019 From: frank at chagford.com (Frank Millman) Date: Fri, 23 Aug 2019 09:07:27 +0200 Subject: How should we use global variables correctly? In-Reply-To: References: <1263d8a7-4204-2a11-de59-7870fa9f8517@Damon-Family.org> Message-ID: On 2019-08-23 8:43 AM, Windson Yang wrote: > I also want to know what is the difference between "using 'global > variables' in a py module" and "using a variable in class". For example: > > In global.py: > > foo = 1 > def bar(): > global foo > return foo + 1 > > In class.py > > class Example: > def __init__(self): > self.foo = 1 > def bar() > return self.foo + 1 > > Expect the syntax, why using class variable self.foo would be better (or > more common)? I think the 'global' here is relative, foo is global in > global.py and self.foo is global in Example class. If the global.py is > short and clean enough (didn't have a lot of other class), they are pretty > much the same. Or I missed something? > One difference is that you could have many instances of Example, each with its own value of 'foo', whereas with a global 'foo' there can only be one value of 'foo' for the module. It would make sense to use the 'global' keyword if you have a module with various functions, several of which refer to 'foo', but only one of which changes the value of 'foo'. Frank Millman From cs at cskk.id.au Fri Aug 23 03:11:01 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 23 Aug 2019 17:11:01 +1000 Subject: How should we use global variables correctly? In-Reply-To: References: Message-ID: <20190823071101.GA24466@cskk.homeip.net> On 23Aug2019 14:43, Windson Yang wrote: >I also want to know what is the difference between "using 'global >variables' in a py module" and "using a variable in class". For example: > >In global.py: > > foo = 1 > def bar(): > global foo > return foo + 1 > >In class.py > > class Example: > def __init__(self): > self.foo = 1 > def bar() > return self.foo + 1 This isn't a class variable. The .foo attribute will be attached to "self", which is an instance of the class, not the class itself. You probably want: class Example2: foo = 1 def __init__(self): pass So what's happening here? When the class is defined, in addition to defining the .__init__ method we also define .foo. These are attributes of the class: there's just one of each. In your code you're setting .foo on "self", so there's one per instance of the class. So in my Example2 there's a foo: print(Example2.foo) works. Compared to a global, this is nicely contained in the class' namespace. But otherwise it is the same: it gets defined just once as the module is imported (which defines the class Example2, which defines Example2.foo). However, it _is_ harder to use as a local by accident. Here: from example_module import Example2 z = 1 def f(): z = 3 Example2.foo = 3 Here, "z" is local to "f" because it is assigned to. Example2.foo is still the one from inside the class - we're not assigning to a function local name, but to a name _accessed_ via Example2. >Expect the syntax, why using class variable self.foo would be better >(or more common)? I think the 'global' here is relative, foo is global in >global.py and self.foo is global in Example class. As mentioned, in your Example class self.foo is an attribute of the instance, not the class. My Example2 class shows how to put it on the class. >If the global.py is >short and clean enough (didn't have a lot of other class), they are pretty >much the same. Or I missed something? Making a class level name has the nice aspect that it has a better conceptual context. Cheers, Cameron Simpson From cs at cskk.id.au Fri Aug 23 03:13:41 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 23 Aug 2019 17:13:41 +1000 Subject: How should we use global variables correctly? In-Reply-To: References: Message-ID: <20190823071341.GA79971@cskk.homeip.net> On 23Aug2019 09:07, Frank Millman wrote: >On 2019-08-23 8:43 AM, Windson Yang wrote: >>In class.py >> >> class Example: >> def __init__(self): >> self.foo = 1 >> def bar() >> return self.foo + 1 >> >>Expect the syntax, why using class variable self.foo would be better (or >>more common)? I think the 'global' here is relative, foo is global in >>global.py and self.foo is global in Example class. If the global.py is >>short and clean enough (didn't have a lot of other class), they are pretty >>much the same. Or I missed something? >> > >One difference is that you could have many instances of Example, each >with its own value of 'foo', whereas with a global 'foo' there can >only be one value of 'foo' for the module. But that is an _instance_ attribute. Which is actually what Windson Yang made. A class attribute is bound to the class, not an instance. The terminology is important. Cheers, Cameron Simpson From jfong at ms4.hinet.net Fri Aug 23 03:42:26 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 23 Aug 2019 00:42:26 -0700 (PDT) Subject: How to record the console's content in the interpreter? In-Reply-To: <20190823085823.7199d87d@arcor.com> References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> Message-ID: Manfred Lotz? 2019?8?23???? UTC+8??2?58?48???? > On Thu, 22 Aug 2019 21:48:33 -0700 (PDT) > jfong at ms4.hinet.net wrote: > > > Cameron Simpson? 2019?8?23???? UTC+8??12?09?54???? > > > On 22Aug2019 19:38, Jach Fong wrote: > > > >Say I like to record everything showing in the console into a file > > > >after I start a debug session, and stop it when finished. It's not > > > >a console redirection. I still need to see what is going on during > > > >the session. > > > > > > If you're in a terminal you can run the 'script" command. This > > > starts a new shell inside a session which records itself to the > > > file "typescript" (by default). See "man script" for further > > > details. > > > > > > Cheers, > > > Cameron Simpson > > > > Mine is Windows:-( No 'script' command? > > > > --Jach > > If I understand you correctly you want to save an interactive session!? > > Then you could use ipython. In ipython the lines get numbererd. If your > last line is, for example: In [100] you could do this: > > save mysave 1-100 > > in the ipython shell. > > -- > Manfred After a quick try on IPython 6.5.0, I saw only the commands I had typed, not include the output of those commands:-( --Jach From wiwindson at gmail.com Fri Aug 23 03:58:58 2019 From: wiwindson at gmail.com (Windson Yang) Date: Fri, 23 Aug 2019 15:58:58 +0800 Subject: How should we use global variables correctly? In-Reply-To: <20190823071341.GA79971@cskk.homeip.net> References: <20190823071341.GA79971@cskk.homeip.net> Message-ID: Thank you all. I agreed with Frank that > It would make sense to use the 'global' keyword if you have a module with various functions, several of which refer to 'foo', but only one of which changes the value of 'foo'. I also found an example in cpython/lib/gettext.py, only 'textdomain function' can change '_current_domain', other functions just refer to it. So, it will be not evil or to use 'global' keyword correctly when there is only one function can change its value? Cameron Simpson ?2019?8?23??? ??3:15??? > On 23Aug2019 09:07, Frank Millman wrote: > >On 2019-08-23 8:43 AM, Windson Yang wrote: > >>In class.py > >> > >> class Example: > >> def __init__(self): > >> self.foo = 1 > >> def bar() > >> return self.foo + 1 > >> > >>Expect the syntax, why using class variable self.foo would be better (or > >>more common)? I think the 'global' here is relative, foo is global in > >>global.py and self.foo is global in Example class. If the global.py is > >>short and clean enough (didn't have a lot of other class), they are > pretty > >>much the same. Or I missed something? > >> > > > >One difference is that you could have many instances of Example, each > >with its own value of 'foo', whereas with a global 'foo' there can > >only be one value of 'foo' for the module. > > But that is an _instance_ attribute. Which is actually what Windson Yang > made. > > A class attribute is bound to the class, not an instance. The > terminology is important. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From joel.goldstick at gmail.com Fri Aug 23 04:22:51 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 23 Aug 2019 04:22:51 -0400 Subject: How should we use global variables correctly? In-Reply-To: References: <20190823071341.GA79971@cskk.homeip.net> Message-ID: On Fri, Aug 23, 2019 at 4:00 AM Windson Yang wrote: > > Thank you all. I agreed with Frank that > > > It would make sense to use the 'global' keyword if you have a module > with various functions, several of which refer to 'foo', but only one of > which changes the value of 'foo'. > > I also found an example in cpython/lib/gettext.py, only 'textdomain > function' can change '_current_domain', other functions just refer to it. > So, it will be not evil or to use 'global' keyword correctly when there is > only one function can change its value? > > Cameron Simpson ?2019?8?23??? ??3:15??? > The problem with deciding that only one function can change the value, is that someone else can change the other functions. So, if you are working alone, it won't be a problem, but once code with globals enters the 'wild' all bets are off. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From pahome.chen at mirlab.org Fri Aug 23 04:42:41 2019 From: pahome.chen at mirlab.org (lampahome) Date: Fri, 23 Aug 2019 16:42:41 +0800 Subject: How to use regex to search string between {}? Message-ID: I want to parse a path string with multiple files and try to figure out a one-line way. If I have path: /home/admin/hello/yo/{h1,h2,h3,h4} What I thought is use regex.search, but the pattern always failed. I use below: import re path = /home/admin/hello/yo/{h1,h2,h3,h4} r = re.search('{.}', path) # r should be ['h1,h2,h3,h4'] but I fail Why always search nothing? From rosuav at gmail.com Fri Aug 23 04:47:30 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Aug 2019 18:47:30 +1000 Subject: How to use regex to search string between {}? In-Reply-To: References: Message-ID: On Fri, Aug 23, 2019 at 6:44 PM lampahome wrote: > > I want to parse a path string with multiple files and try to figure out a > one-line way. > > If I have path: /home/admin/hello/yo/{h1,h2,h3,h4} > > What I thought is use regex.search, but the pattern always failed. > > I use below: > import re > path = /home/admin/hello/yo/{h1,h2,h3,h4} > r = re.search('{.}', path) > # r should be ['h1,h2,h3,h4'] but I fail > > Why always search nothing? Because a dot matches *one single character*. If you want to match multiple characters, you have to say so: >>> re.search("{.*}", "/home/admin/hello/yo/{h1,h2,h3,h4}") ChrisA From ml_news at posteo.de Fri Aug 23 06:07:29 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Fri, 23 Aug 2019 12:07:29 +0200 Subject: How to record the console's content in the interpreter? References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> Message-ID: <20190823120729.2f2d2105@arcor.com> On Fri, 23 Aug 2019 00:42:26 -0700 (PDT) jfong at ms4.hinet.net wrote: > Manfred Lotz? 2019?8?23???? UTC+8??2?58?48???? > > On Thu, 22 Aug 2019 21:48:33 -0700 (PDT) > > jfong at ms4.hinet.net wrote: > > > > > Cameron Simpson? 2019?8?23???? > > > UTC+8??12?09?54???? > > > > On 22Aug2019 19:38, Jach Fong wrote: > > > > >Say I like to record everything showing in the console into a > > > > >file after I start a debug session, and stop it when finished. > > > > >It's not a console redirection. I still need to see what is > > > > >going on during the session. > > > > > > > > If you're in a terminal you can run the 'script" command. This > > > > starts a new shell inside a session which records itself to the > > > > file "typescript" (by default). See "man script" for further > > > > details. > > > > > > > > Cheers, > > > > Cameron Simpson > > > > > > Mine is Windows:-( No 'script' command? > > > > > > --Jach > > > > If I understand you correctly you want to save an interactive > > session!? > > > > Then you could use ipython. In ipython the lines get numbererd. If > > your last line is, for example: In [100] you could do this: > > > > save mysave 1-100 > > > > in the ipython shell. > > > > -- > > Manfred > > After a quick try on IPython 6.5.0, I saw only the commands I had > typed, not include the output of those commands:-( > Sorry, that's true. I found only this. After starting ipython type: %logstart -o Then you get also command output. The log file name is: ipython_log.py But it doesn't seem to show output from print command. -- Manfred From jfong at ms4.hinet.net Fri Aug 23 07:06:44 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 23 Aug 2019 04:06:44 -0700 (PDT) Subject: How to record the console's content in the interpreter? In-Reply-To: <20190823120729.2f2d2105@arcor.com> References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> <20190823120729.2f2d2105@arcor.com> Message-ID: <4ad3aabc-9b6f-415d-95ca-81973d5f3a79@googlegroups.com> Manfred Lotz? 2019?8?23???? UTC+8??6?08?11???? > On Fri, 23 Aug 2019 00:42:26 -0700 (PDT) > jfong at ms4.hinet.net wrote: > > > Manfred Lotz? 2019?8?23???? UTC+8??2?58?48???? > > > On Thu, 22 Aug 2019 21:48:33 -0700 (PDT) > > > jfong at ms4.hinet.net wrote: > > > > > > > Cameron Simpson? 2019?8?23???? > > > > UTC+8??12?09?54???? > > > > > On 22Aug2019 19:38, Jach Fong wrote: > > > > > >Say I like to record everything showing in the console into a > > > > > >file after I start a debug session, and stop it when finished. > > > > > >It's not a console redirection. I still need to see what is > > > > > >going on during the session. > > > > > > > > > > If you're in a terminal you can run the 'script" command. This > > > > > starts a new shell inside a session which records itself to the > > > > > file "typescript" (by default). See "man script" for further > > > > > details. > > > > > > > > > > Cheers, > > > > > Cameron Simpson > > > > > > > > Mine is Windows:-( No 'script' command? > > > > > > > > --Jach > > > > > > If I understand you correctly you want to save an interactive > > > session!? > > > > > > Then you could use ipython. In ipython the lines get numbererd. If > > > your last line is, for example: In [100] you could do this: > > > > > > save mysave 1-100 > > > > > > in the ipython shell. > > > > > > -- > > > Manfred > > > > After a quick try on IPython 6.5.0, I saw only the commands I had > > typed, not include the output of those commands:-( > > > > Sorry, that's true. > > I found only this. After starting ipython type: > > %logstart -o > > Then you get also command output. The log file name is: ipython_log.py > > But it doesn't seem to show output from print command. > > > -- > Manfred You are right, it won't show output from print command, and "print" is the most command used in a module when a response was needed for the user:-( --Jach From tjreedy at udel.edu Fri Aug 23 07:27:27 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Aug 2019 07:27:27 -0400 Subject: How to record the console's content in the interpreter? In-Reply-To: References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> Message-ID: On 8/23/2019 3:42 AM, jfong at ms4.hinet.net wrote: >>>>> Say I like to record everything showing in the console into a file >>>>> after I start a debug session, and stop it when finished. It's not >>>>> a console redirection. I still need to see what is going on during >>>>> the session. > After a quick try on IPython 6.5.0, I saw only the commands I had typed, not include the output of those commands:-( IDLE saves exactly what you see in the window, including with a shell session. One can also select and paste into a new editor window and then save. -- Terry Jan Reedy From email at paulstgeorge.com Fri Aug 23 07:49:43 2019 From: email at paulstgeorge.com (Paul St George) Date: Fri, 23 Aug 2019 13:49:43 +0200 Subject: Newbie question about Python syntax In-Reply-To: References: <34f3139c-eb21-42db-9102-5a520056e559@paulstgeorge.com> Message-ID: On 22/08/2019 23:21, Kyle Stanley wrote: [snip] > > The tutorial that Terry was referring to was the one on docs.python.org, > here's a couple of links for the sections he was referring to: > > Full section on classes: https://docs.python.org/3/tutorial/classes.html > > Section on instantiating objects from classes: > https://docs.python.org/3/tutorial/classes.html#class-objects > [snip] >> Aha, thank you all. Here then, is my first problem. Context: I am using Python to interrogate the value of some thing in Blender (just as someone else might want to use Python to look at an email in a Mail program or an image in Photoshop). Assumptions: So, I want to look at the attribute of an instance of a class called CompositorNodeMapValue. The code in the Python tutorial seems to be for creating an instance of a class, but I assume Blender (in my case) has already created the instance that I want to interrogate. Question: If this is so, should I find the code to get a list of the instances that have been made (maybe using inspect?) and then, when I have its name, the attributes of the one that interests me? Or shall I go into the garden to eat worms? From hongyi.zhao at gmail.com Fri Aug 23 10:36:56 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 23 Aug 2019 14:36:56 +0000 (UTC) Subject: Let the copyfilepath.py to support chinese file path name. Message-ID: Hi, The following is a gedit plugin which provides a way to copy the current file path to the clipboard. https://github.com/willianveiga/gedit-copy-file-path/blob/master/ copyfilepath.py But, I try and find that it doesn't support the path/file names including chinese characters. In this case, it will give messy code like this: dnsmasq/archive/dnsmasq-??? How to fix it? Regards From amirrezaheidarysbu at gmail.com Fri Aug 23 12:38:56 2019 From: amirrezaheidarysbu at gmail.com (Amirreza Heidari) Date: Fri, 23 Aug 2019 09:38:56 -0700 (PDT) Subject: Using the same data for both validation and prediction in Keras Message-ID: <18b82287-61e3-4b69-9c37-f9a0a256e37a@googlegroups.com> I was reading a tutorial for time series prediction by Neural Networks. I found that this code have used the same test data in the following code for validation, and later also for prediction. history = model.fit(train_X, train_y, epochs=50, batch_size=72, validation_data=(test_X, test_y), verbose=2, shuffle=False) Does it mean that the validation and test data are the same, or there is a default percentage to split the data into validation and prediction? From amirrezaheidarysbu at gmail.com Fri Aug 23 12:45:02 2019 From: amirrezaheidarysbu at gmail.com (Amirreza Heidari) Date: Fri, 23 Aug 2019 09:45:02 -0700 (PDT) Subject: How Bidirectional Neural Networks could be used to predict future data while they need future data?! Message-ID: In the following link I see that Bidirectional LSTM is used to predict the future data in time series. I know that a Bidirectional recurrent neural network use both past and future data, and therefore for predicting future data we need future data1! Can anyone explain me how they work when in a time series we are going to predict the future? https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/ From rtomek at ceti.pl Fri Aug 23 13:23:15 2019 From: rtomek at ceti.pl (Tomasz Rola) Date: Fri, 23 Aug 2019 19:23:15 +0200 Subject: How to record the console's content in the interpreter? In-Reply-To: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> Message-ID: <20190823172315.GA20033@tau1.ceti.pl> On Thu, Aug 22, 2019 at 07:38:54PM -0700, jfong at ms4.hinet.net wrote: > Say I like to record everything showing in the console into a file > after I start a debug session, and stop it when finished. It's not a > console redirection. I still need to see what is going on during the > session. > You may be looking for Eshell, but to be sure you have to try, I have no idea how well this works in Windows. After running your stuff in it, all session is present in Emacs' buffer (if I undestand it correctly) and you can do with a buffer however you please (within limitations of Emacs, which are broad), including save to file: Eshell is a shell-like command interpreter implemented in Emacs Lisp. It invokes no external processes except for those requested by the user. It is intended to be an alternative to the IELM (see Emacs Lisp Interaction) REPL for Emacs and with an interface similar to command shells such as bash, zsh, rc, or 4dos. [ https://www.gnu.org/software/emacs/manual/html_mono/eshell.html ] -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From eryksun at gmail.com Fri Aug 23 14:52:51 2019 From: eryksun at gmail.com (eryk sun) Date: Fri, 23 Aug 2019 13:52:51 -0500 Subject: How to record the console's content in the interpreter? In-Reply-To: <4ad3aabc-9b6f-415d-95ca-81973d5f3a79@googlegroups.com> References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> <20190823120729.2f2d2105@arcor.com> <4ad3aabc-9b6f-415d-95ca-81973d5f3a79@googlegroups.com> Message-ID: On 8/23/19, jfong at ms4.hinet.net wrote: > > it won't show output from print command, and "print" is the most > command used in a module when a response was needed ConEmu is an alternate console for Windows that allows logging all console output to a file: https://conemu.github.io/en/AnsiLogFiles.html From michael.stemper at gmail.com Fri Aug 23 15:15:37 2019 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Fri, 23 Aug 2019 14:15:37 -0500 Subject: Style suggestions/critiques In-Reply-To: References: <4dab172d-a430-d717-6798-e8d00602eada@DancesWithMice.info> Message-ID: On 20/08/2019 21.57, DL Neil wrote: > On 21/08/19 9:11 AM, Michael F. Stemper wrote: >> I recently wrote a couple of modules (more to come) to help me >> use the tikz package in TeX/LaTeX. Since it's all to do with >> drawing, I have a lot of points in R^2. Being unimaginative, I >> This all seems reasonably simple and intuitive (to me). However, >> in order to actually do some manipulation, I have stuff like: >> # Unpack the lines >> l1p1,l1p2 = line1 >> l1x1,l1y1 = l1p1 >> l1x2,l1y2 = l1p2 >> l2p1,l2p2 = line2 >> l2x1,l2y1 = l2p1 >> l2x2,l2y2 = l2p2 > Assuming that the code does-stuff with/to lines, eg rotate the line 0.2 > radians about some nominated rotational-center; maybe construct a class, eg > > class Line(): > ????def __init__( self, starting_point, ending_point ): > ??????? self.starting_point = starting_point > ??????? self.ending_point = ending_point > ????def rotate( self, angle, center ): > ??????? ... > > The same could also be said for a Point class. However, if they are > 'only' Cartesian coordinates and no methods ever apply(???), then maybe > named-tuples or a dict? Played briefly with a dict and decided that it was ugly, too. However, the following objects seem nice to me: class Point( ): def __init__( self, x, y ): self.x = float(x) self.y = float(y) class Line( ): def __init__( self, p1, p2 ): self.p1 = p1 self.p2 = p2 def Slope( self ): # Proof of concept only. Won't work on vertical lines return (self.p1.y-self.p2.y)/(self.p1.x-self.p2.x) In use: ^^^ Origin = Point(0,0) ^^^ wayright = Point(7,0) ^^^ xaxis = Line(Origin,wayright) ^^^ identity = Line(Origin,Point(1,1)) ^^^ xaxis.Slope() -0.0 ^^^ identity.Slope() 1.0 ^^^ (I've changed the 3*'>' prompt to 3*'^' to avoid confusing news clients.) This approach eliminates the ad hoc unpacking that I had been doing and made the accesses to particular items more explicit. Using this approach involves slightly more typing than my original approach, which allowed: ^^^ Origin = 0,0 ^^^ wayright = 7,0 But, that's not really much more typing, and it'll help me keep in mind what things are what. My existing code has a function Intersection(line1,line2) that calculates where line1 and line2 intersect (assuming that there is a unique such point). To me, this seems to be the proper pardigm, since it's clear that line1 and line2 are peers in the intersection function. Am I being too fastidious here? Is there any reason that an idiom such as line1.Intersect( line2 ) would be preferable? -- Michael F. Stemper Exodus 22:21 From PythonList at DancesWithMice.info Fri Aug 23 16:09:01 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 24 Aug 2019 08:09:01 +1200 Subject: Let the copyfilepath.py to support chinese file path name. In-Reply-To: References: Message-ID: <105e2d59-55ba-99aa-568c-f71bec8fe28c@DancesWithMice.info> On 24/08/19 2:36 AM, Hongyi Zhao wrote: > Hi, > > The following is a gedit plugin which provides a way to copy the current > file path to the clipboard. > > https://github.com/willianveiga/gedit-copy-file-path/blob/master/ > copyfilepath.py > > But, I try and find that it doesn't support the path/file names including > chinese characters. > > In this case, it will give messy code like this: > > dnsmasq/archive/dnsmasq-??? > > How to fix it? Does "it will give" mean: - this is what is returned from the gtk clipboard, or - this is the fileNM which appears in an errmsg? Please copy-paste the calling code, source data fileNM, and resulting errmsgs/output. NB I only took the quickest look at the code. A first thought is that this code may have originated in Python2 days. In which case there may be pertinent differences between how things were done 'then' (ASCII byte-characters) and how they are done now (Unicode characters). Also, in the Python3 world, many file/pathNM libraries will respond (slightly differently) depending upon whether their input is in (Unicode) characters or bytes. Is it worth experimenting by throwing some test-data at the object? - fileNM as Unicode string - fileNM as bytes - fileNM in (narrow) ASCII - fileNM including Kanji (or...) How does it react differently. A second issue is that whilst Python negotiated a clear-cut difference between Unicode and 'the ?bad, old days'; OpSys and file systems do/did not! (Hence the first question, above) I have run into trouble with (European language) non-ASCII characters originating on a MSFT platform not being properly accepted by 'modern' Python file/path libraries (under Linux - although the OpSys likely doesn't matter). The fileNMs become mangled during the decode() step - to the point of no-repair. In debugging this issue, recommend separating what the clip-board is/not handling, and what the file system might be mangling, ie locate the ACTUAL point of error and separate that from later consequences! -- Regards =dn From PythonList at DancesWithMice.info Fri Aug 23 17:36:12 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 24 Aug 2019 09:36:12 +1200 Subject: Style suggestions/critiques In-Reply-To: References: <4dab172d-a430-d717-6798-e8d00602eada@DancesWithMice.info> Message-ID: <40e09493-2dff-6399-4c8a-772c52707151@DancesWithMice.info> On 24/08/19 7:15 AM, Michael F. Stemper wrote: > On 20/08/2019 21.57, DL Neil wrote: >> On 21/08/19 9:11 AM, Michael F. Stemper wrote: >>> I recently wrote a couple of modules (more to come) to help me >>> use the tikz package in TeX/LaTeX. Since it's all to do with >>> drawing, I have a lot of points in R^2. Being unimaginative, I > >>> This all seems reasonably simple and intuitive (to me). However, >>> in order to actually do some manipulation, I have stuff like: ... > This approach eliminates the ad hoc unpacking that I had been doing > and made the accesses to particular items more explicit. > > Using this approach involves slightly more typing than my original > approach, which allowed: > ^^^ Origin = 0,0 > ^^^ wayright = 7,0 Most programmers subscribe to the belief: that code is read more often than it is written. Of course, the behavioral aspect of writing code so that it can be read, may be less evident... Inevitably, what makes sense to you, may seem obscure to A.N.Other. > But, that's not really much more typing, and it'll help me keep in > mind what things are what. Surely, understanding the "model", is key to a good solution? > My existing code has a function Intersection(line1,line2) that > calculates where line1 and line2 intersect (assuming that there > is a unique such point). To me, this seems to be the proper > pardigm, since it's clear that line1 and line2 are peers in the > intersection function. (To me) You've a good grasp on what is required, because you've realised important (levels of) relationships between the components of the problem. There are both purists and pragmatists in this world, I have to beware "paralysis by analysis"! > Am I being too fastidious here? Is there any reason that an > idiom such as line1.Intersect( line2 ) would be preferable? Let's replace the word "fastidious", which may convey ideas of excessive zeal, with "questioning". Thus: how else will you learn? I'm not going to try to answer - as I've said 'here' before, I'm not an OOP-native, and often pick-up ideas/correction from others with clearer insights... That said, 'looking around' live-code you will find both approaches, even within the PSL. Remember, an object comprises both "data-attributes" and "method-attributes" (such formed a recent discussion, over on the Python-Tutor Discussion List). Accordingly, I'd put "intersection" within the Line object. Thought 1: I find it easier to have the code 'all together' (within the Line class) cf having a separate "helper function" (albeit that likely residing within the same Python module). See also recent discussion 'here', wherein I related from module import-ing a class, but forgetting to also import a 'helper'. (try to be nice to the 'grey hair' - he can't help it!) Thought 2: whilst the (possibly) intersecting lines are "peers", within an English sentence ("subject", "verb", "object"), we would express one as the "subject" and the second as the "object". Accordingly, there is no difficulty is asking the same question in Python: (if/where) do I/self intersect with that other line/slope? Accordingly, something like "find_intersection( self, other_line )" conveys meaning (to me). The fact is, "self" and "other_line" are both of the same object ("is-a" relationship to Line), ie "peers", and the code identifies that! Once again, stating the problem in English (or ?human-language) and then writing it in Python... Back to the philosophical level: always keep 'the big picture' in mind - if you are only coding a couple of lines and to solve a single question, it is literally "throw-away code". Who cares what it looks-like - as long as it works! However, if you intend to add a list of other analyses beyond 'intersection', then build your base-code/base-objects with that in-mind. (please recall earlier comment, that it may/not be worth making Cartesian points into an object!) Small confession/admission/illustration/'object' lesson: I coded a Point object, then later wanted a Vector. "Oh look" says lazy-boy, I could (mis-)use Point - they're both x-y pairs after-all... Later, along came the need for a "translation" function and delta-x, delta-y pairs. You guessed it, I over-over-loaded Point to the point (hah!) where I managed to confuse myself with my own over-clever-ness. That said, it was easy to "re-factor". Thus created a simple x-y base (or "super-class") from which (Cartesian) Point, Vector, Delta (whatever) could be derived/"sub-classed", and then the various methods applicable to each could be separated from each-other. The worst part, was going-through the entire system looking for evidence of my earlier, ?over-clever, misdeeds. (blessings on modern text-editors which will search an entire directory of code at a time) However, thereafter, readability improved and progress accelerated... Whilst OOP can sometimes seem like more work, or more "typing", (or consuming more resources) its central tenet is "re-use"! Yes, one can go 'too far', or 'not far enough'; but what seems reasonable or pragmatic today, may change 'tomorrow'. "Uncle Bob" Martin and sundry other System Architects/philosophers promote the idea of leaving decisions "as late as possible". Certainly, ease of re-factoring makes code restructuring far more Agile today, than was once possible/practical! Closing remarks: If this is a learning-exercise, go for it! However, per another post, this exercise is largely 're-inventing the wheel'. The Python eco-system offers a plethora of 'math' extensions, eg NumPy and SciPy. These become applicable if it takes you less time to read their docs/learn to use, than it would to 'roll your own' functionality. My guess: you'll quickly look at the likes of matplotlib if/when you need to 'show' the results of these analyses graphically... Have fun! -- Regards =dn From cs at cskk.id.au Fri Aug 23 19:23:58 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 24 Aug 2019 09:23:58 +1000 Subject: Newbie question about Python syntax In-Reply-To: References: Message-ID: <20190823232358.GA94429@cskk.homeip.net> On 23Aug2019 13:49, Paul St George wrote: >Context: >I am using Python to interrogate the value of some thing in Blender >(just as someone else might want to use Python to look at an email in >a Mail program or an image in Photoshop). > >Assumptions: >So, I want to look at the attribute of an instance of a class called >CompositorNodeMapValue. The code in the Python tutorial seems to be >for creating an instance of a class, but I assume Blender (in my case) >has already created the instance that I want to interrogate. That would be the expectation. And to interrogate it, you need that instance to hand in a variable. >Question: >If this is so, should I find the code to get a list of the instances >that have been made (maybe using inspect?) and then, when I have its >name, the attributes of the one that interests me? Have you not got one of these handed to you from something? Or are you right at the outside with some "opaque" blender handle or something? (Disclaimer: I've never used Blender.) You can inspect objects with the inspect module. You can also be more direct. Given an object "o", you can do an assortment of things: dir(o) gets a list of its attribute names. help(o) prints out the docstring, somewhat rendered. o.__dict__ is usually a dict mapping attribute names to their values. type(o) gets you its type, so "print(type(o))" or "print(type(o).__name__)" can be handy. A crude probe function (untested): def probe(o): print(o) for attr, value in sorted(o.__dict__.items()): print(" ", attr, type(value).__name__, value) Enjoy, Cameron Simpson (formerly cs at zip.com.au) "Are we alpinists, or are we tourists" followed by "tourists! tourists!" - Kobus Barnard in rec.climbing, on things he's heard firsthand From mhuret at mindspring.com Fri Aug 23 10:33:30 2019 From: mhuret at mindspring.com (Marilynn Huret) Date: Fri, 23 Aug 2019 10:33:30 -0400 (GMT-04:00) Subject: installation 3.7.3 Message-ID: <897930333.2065.1566570811173@wamui-eagle.atl.sa.earthlink.net> Having problems trying to install 3.7.3 with IDLE on a windows 7. When I try to run it, get a message that a .DLL is missing Am reviewing a book for Manning -"hello World" by Sande, third edition? and have tried different install options Can you help? Thank you Marilynn Huret aka mhuret From python at mrabarnett.plus.com Fri Aug 23 20:05:45 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Aug 2019 01:05:45 +0100 Subject: installation 3.7.3 In-Reply-To: <897930333.2065.1566570811173@wamui-eagle.atl.sa.earthlink.net> References: <897930333.2065.1566570811173@wamui-eagle.atl.sa.earthlink.net> Message-ID: <10a73650-a2bd-d5d5-cbd8-416e9c1171c7@mrabarnett.plus.com> On 2019-08-23 15:33, Marilynn Huret wrote: > Having problems trying to install 3.7.3 with IDLE on a windows 7. When I > try to run it, get a message that a .DLL is missing > > Am reviewing a book for Manning -"hello World" by Sande, third edition > and have tried different install options > Can you help? > Which DLL? If it's complaining about this "api-ms-win-crt-runtime-l1-1-0.dll", then you need the Windows Universal C Runtime: http://www.microsoft.com/en-us/download/details.aspx?id=48234 From jfong at ms4.hinet.net Fri Aug 23 23:03:27 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 23 Aug 2019 20:03:27 -0700 (PDT) Subject: How to record the console's content in the interpreter? In-Reply-To: References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> Message-ID: <834520fd-ca82-41bd-a342-255cf18b0800@googlegroups.com> Terry Reedy? 2019?8?23???? UTC+8??7?27?50???? > On 8/23/2019 3:42 AM, jfong at ms4.hinet.net wrote: > > >>>>> Say I like to record everything showing in the console into a file > >>>>> after I start a debug session, and stop it when finished. It's not > >>>>> a console redirection. I still need to see what is going on during > >>>>> the session. > > > After a quick try on IPython 6.5.0, I saw only the commands I had typed, not include the output of those commands:-( > > IDLE saves exactly what you see in the window, including with a shell > session. One can also select and paste into a new editor window and > then save. > > > > -- > Terry Jan Reedy IDLE is the closest one to the command console I currently use. The mouse used in its shell really helps on my requirement:-) Thank you for reminding. --Jach From jfong at ms4.hinet.net Fri Aug 23 23:05:11 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 23 Aug 2019 20:05:11 -0700 (PDT) Subject: How to record the console's content in the interpreter? In-Reply-To: References: <036d12bf-582b-4a1c-a654-063f810be79a@googlegroups.com> <20190823040938.GA3595@cskk.homeip.net> <0ad58eaa-89c0-4e67-bc64-81fdd04c9365@googlegroups.com> <20190823085823.7199d87d@arcor.com> <20190823120729.2f2d2105@arcor.com> <4ad3aabc-9b6f-415d-95ca-81973d5f3a79@googlegroups.com> Message-ID: eryk sun? 2019?8?24???? UTC+8??2?53?56???? > On 8/23/19, jfong at ms4.hinet.net wrote: > > > > it won't show output from print command, and "print" is the most > > command used in a module when a response was needed > > ConEmu is an alternate console for Windows that allows logging all > console output to a file: > > https://conemu.github.io/en/AnsiLogFiles.html Thank you for introducing this alternate console for Windows. I have downloaded the portable version and will give it a try soon. --Jach From ml_news at posteo.de Sat Aug 24 08:12:38 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 24 Aug 2019 14:12:38 +0200 Subject: https://test.pypi.org/ internal server error Message-ID: <20190824141238.214f53ea@arcor.com> I want to exercise how to create a package and upload it to pyi. So, I registered with https://test.pypi.org/. Now, when I click on https://test.pypi.org/manage/account/#account-emails to verify my email address I get an internal server error. Same when I try https://test.pypi.org/manage/account/. What is the proper place to report the problem? -- Manfred From ml_news at posteo.de Sat Aug 24 13:51:42 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 24 Aug 2019 19:51:42 +0200 Subject: https://test.pypi.org/ internal server error References: <20190824141238.214f53ea@arcor.com> Message-ID: <20190824195142.7f2622b7@arcor.com> On Sat, 24 Aug 2019 14:12:38 +0200 Manfred Lotz wrote: > I want to exercise how to create a package and upload it to pyi. So, I > registered with https://test.pypi.org/. > > Now, when I click on > https://test.pypi.org/manage/account/#account-emails to verify my > email address I get an internal server error. > > Same when I try https://test.pypi.org/manage/account/. > > What is the proper place to report the problem? > For the records. In the meantime the internal server error has been fixed. From email at paulstgeorge.com Sat Aug 24 15:52:21 2019 From: email at paulstgeorge.com (Paul St George) Date: Sat, 24 Aug 2019 21:52:21 +0200 Subject: Newbie question about Python syntax In-Reply-To: <20190823232358.GA94429@cskk.homeip.net> References: <20190823232358.GA94429@cskk.homeip.net> Message-ID: On 24/08/2019 01:23, Cameron Simpson wrote: > On 23Aug2019 13:49, Paul St George wrote: >> Context: >> I am using Python to interrogate the value of some thing in Blender >> (just as someone else might want to use Python to look at an email in >> a Mail program or an image in Photoshop). >> >> Assumptions: >> So, I want to look at the attribute of an instance of a class called >> CompositorNodeMapValue. The code in the Python tutorial seems to be >> for creating an instance of a class, but I assume Blender (in my case) >> has already created the instance that I want to interrogate. > > That would be the expectation. And to interrogate it, you need that > instance to hand in a variable. > >> Question: >> If this is so, should I find the code to get a list of the instances >> that have been made (maybe using inspect?) and then, when I have its >> name, the attributes of the one that interests me? > > Have you not got one of these handed to you from something? > > Or are you right at the outside with some "opaque" blender handle or > something? (Disclaimer: I've never used Blender.) Thank you once again. If I understand your question, I am right outside. By this I mean I have not created anything with Python. I have made the Blender model with the UI and am trying to use Python to read the values for the settings used. This has worked for all settings except this Map Value Node. > > You can inspect objects with the inspect module. You can also be more > direct. Given an object "o", you can do an assortment of things: Before I do any of the following, I assume I need to use something like: import struct class CompositorNodeMapValue(o): I have tried this. Nothing happens. Not even an error. It's like waiting for Godot. I am guessing I am in the wrong namespace. I don't know whether it is relevant, but I tried plain dir() and dir(struct) They each returned a list and neither list had mention of CompositorNodeMapValue If I do something like: o = CompositorNodeMapValue() I get: NameError: name 'CompositorNodeMapValue' is not defined > > dir(o) gets a list of its attribute names. > > help(o) prints out the docstring, somewhat rendered. > > o.__dict__ is usually a dict mapping attribute names to their values. > > type(o) gets you its type, so "print(type(o))" or > "print(type(o).__name__)" can be handy. > > A crude probe function (untested): > > ?def probe(o): > ?? print(o) > ?? for attr, value in sorted(o.__dict__.items()): > ???? print(" ", attr, type(value).__name__, value) > > Enjoy, > Cameron Simpson (formerly cs at zip.com.au) > > "Are we alpinists, or are we tourists" followed by "tourists! tourists!" > ?????? - Kobus Barnard in rec.climbing, > ???????? on things he's heard firsthand From barry at barrys-emacs.org Sat Aug 24 16:24:28 2019 From: barry at barrys-emacs.org (Barry) Date: Sat, 24 Aug 2019 21:24:28 +0100 Subject: Newbie question about Python syntax In-Reply-To: References: <20190823232358.GA94429@cskk.homeip.net> Message-ID: <1C81BAB6-A9C4-4CC5-808C-655088EBB8ED@barrys-emacs.org> Have you tried asking on a blender user mailing list for help with this problem? It seems that someone familiar with blender and its python interface should be able to help get you going. Barry > On 24 Aug 2019, at 20:52, Paul St George wrote: > >> On 24/08/2019 01:23, Cameron Simpson wrote: >>> On 23Aug2019 13:49, Paul St George wrote: >>> Context: >>> I am using Python to interrogate the value of some thing in Blender (just as someone else might want to use Python to look at an email in a Mail program or an image in Photoshop). >>> >>> Assumptions: >>> So, I want to look at the attribute of an instance of a class called CompositorNodeMapValue. The code in the Python tutorial seems to be for creating an instance of a class, but I assume Blender (in my case) has already created the instance that I want to interrogate. >> That would be the expectation. And to interrogate it, you need that instance to hand in a variable. >>> Question: >>> If this is so, should I find the code to get a list of the instances that have been made (maybe using inspect?) and then, when I have its name, the attributes of the one that interests me? >> Have you not got one of these handed to you from something? >> Or are you right at the outside with some "opaque" blender handle or something? (Disclaimer: I've never used Blender.) > > Thank you once again. > If I understand your question, I am right outside. By this I mean I have not created anything with Python. I have made the Blender model with the UI and am trying to use Python to read the values for the settings used. This has worked for all settings except this Map Value Node. > >> You can inspect objects with the inspect module. You can also be more direct. Given an object "o", you can do an assortment of things: > > Before I do any of the following, I assume I need to use something like: > > import struct > class CompositorNodeMapValue(o): > > I have tried this. Nothing happens. Not even an error. It's like waiting for Godot. > > I am guessing I am in the wrong namespace. > > I don't know whether it is relevant, but I tried plain > dir() > and > dir(struct) > > They each returned a list and neither list had mention of CompositorNodeMapValue > > If I do something like: > o = CompositorNodeMapValue() > I get: > NameError: name 'CompositorNodeMapValue' is not defined > >> dir(o) gets a list of its attribute names. >> help(o) prints out the docstring, somewhat rendered. >> o.__dict__ is usually a dict mapping attribute names to their values. >> type(o) gets you its type, so "print(type(o))" or "print(type(o).__name__)" can be handy. >> A crude probe function (untested): >> def probe(o): >> print(o) >> for attr, value in sorted(o.__dict__.items()): >> print(" ", attr, type(value).__name__, value) >> Enjoy, >> Cameron Simpson (formerly cs at zip.com.au) >> "Are we alpinists, or are we tourists" followed by "tourists! tourists!" >> - Kobus Barnard in rec.climbing, >> on things he's heard firsthand > > > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Sat Aug 24 20:39:34 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 25 Aug 2019 10:39:34 +1000 Subject: Newbie question about Python syntax In-Reply-To: References: Message-ID: <20190825003934.GA73181@cskk.homeip.net> On 24Aug2019 21:52, Paul St George wrote: >>Have you not got one of these handed to you from something? >> >>Or are you right at the outside with some "opaque" blender handle or >>something? (Disclaimer: I've never used Blender.) > >Thank you once again. >If I understand your question, I am right outside. By this I mean I >have not created anything with Python. I have made the Blender model >with the UI and am trying to use Python to read the values for the >settings used. This has worked for all settings except this Map Value >Node. Hmm. So you have a CompositorNodeMapValue instance? If that is the case you should be able to inspect it as previously described. However, it looks like this is something you construct in order to do some task. A little web searching turns up this stackexchange post: https://blender.stackexchange.com/questions/42579/render-depth-map-to-image-with-python-script/42667 and some example code from an unrelated project: https://github.com/panmari/stanford-shapenet-renderer/blob/master/render_blender.py From the stackexchange post: map = tree.nodes.new(type="CompositorNodeMapValue") # Size is chosen kind of arbitrarily, try out until you're satisfied # with resulting depth map. map.size = [0.08] map.use_min = True map.min = [0] map.use_max = True map.max = [255] "tree" is "bpy.context.scene.node_tree". Aside from "map" being a poor name (it is also a builtin Python function), it seems that one creates one of these to control how some rendering process is done. The class reference page you originally cites then specifies the meaning of the various attributes you might set on one of these objects. Cheers, Cameron Simpson From wiwindson at gmail.com Sat Aug 24 22:54:56 2019 From: wiwindson at gmail.com (Windson Yang) Date: Sun, 25 Aug 2019 10:54:56 +0800 Subject: What make function with huge list so slow Message-ID: I have two functions to calculate Fibonacci numbers. fib_dp use a list to store the calculated number. fib_dp2 just use two variables. def fib_dp(n): if n <= 1: return n dp = [0] * (n+1) dp[0], dp[1] = 0, 1 for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[-1] def fib_dp2(n): if n <= 1: return n pre, now = 0, 1 for i in range(2, (n+1)): pre, now = now, pre+now return now Theoretically, both of their time complexity should be O(n). However, when the input n is so big (like 400000), fib_dp2(400000) can calculate it in 2s but fib_dp(400000) takes *more than 60s* (python3.7.3 and macOS 10.14.6). Why?. At first, I guess the reasons are 1. It took too much time looking up the value in the list (the worse case should be O(1) according to the document). However, the below function fib_dp_tem(400000) can finish in 2s, so looking up value should not be the bottleneck. def fib_dp_look(n): if n <= 1: return n dp = [0] * (n+1) dp[0], dp[1] = 0, 1 for i in range(2, n+1): # change dp[i] to tem, this function is not correct now but it return dp[-1] in 2s tem = dp[i-1] + dp[i-2] return dp[-1] 2. It took too much time setting up the value in the list (the worse case should be O(1) according to the document). Again, the below function fib_dp_set(400000) can finish in 2s, so setting value should not be the bottleneck too. def fib_dp_set(n): if n <= 1: return n dp = [0] * (n+1) dp[0], dp[1] = 0, 1 for i in range(2, n+1): # this function is not correct now but it return dp[-1] in 2s dp[i-1] = i dp[i-2] = i + 1 return dp[-1] 3. python use some kind of cache for 'pre', 'now' variable, (like 'register variable' in C, but I'm not sure how it work in CPython) I also tried to use the dis module but with no luck. Any reason to make fib_dp so much slower than fib_dp2? Please let me know, thank you. Bests, Windson From rosuav at gmail.com Sat Aug 24 23:26:48 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Aug 2019 13:26:48 +1000 Subject: What make function with huge list so slow In-Reply-To: References: Message-ID: On Sun, Aug 25, 2019 at 12:56 PM Windson Yang wrote: > > I have two functions to calculate Fibonacci numbers. fib_dp use a list to > store the calculated number. fib_dp2 just use two variables. > > def fib_dp(n): > if n <= 1: > return n > dp = [0] * (n+1) > dp[0], dp[1] = 0, 1 > for i in range(2, n+1): > dp[i] = dp[i-1] + dp[i-2] > return dp[-1] > > def fib_dp2(n): > if n <= 1: > return n > pre, now = 0, 1 > for i in range(2, (n+1)): > pre, now = now, pre+now > return now > > Theoretically, both of their time complexity should be O(n). However, when > the input n is so big (like 400000), fib_dp2(400000) can calculate it in 2s > but fib_dp(400000) takes *more than 60s* (python3.7.3 and macOS 10.14.6). > Why? Memory allocation can take a long time. Try grabbing the line initializing dp and slapping that into the body of dp2, and then compare their times; that might make all the difference. ChrisA From wiwindson at gmail.com Sat Aug 24 23:43:44 2019 From: wiwindson at gmail.com (Windson Yang) Date: Sun, 25 Aug 2019 11:43:44 +0800 Subject: What make function with huge list so slow In-Reply-To: References: Message-ID: Thank you, Chris. I tried your suggestions. I don't think that is the reason, fib_dp_look() and fib_dp_set() which also allocation a big list can return in 2s. Chris Angelico ?2019?8?25??? ??11:27??? > On Sun, Aug 25, 2019 at 12:56 PM Windson Yang wrote: > > > > I have two functions to calculate Fibonacci numbers. fib_dp use a list to > > store the calculated number. fib_dp2 just use two variables. > > > > def fib_dp(n): > > if n <= 1: > > return n > > dp = [0] * (n+1) > > dp[0], dp[1] = 0, 1 > > for i in range(2, n+1): > > dp[i] = dp[i-1] + dp[i-2] > > return dp[-1] > > > > def fib_dp2(n): > > if n <= 1: > > return n > > pre, now = 0, 1 > > for i in range(2, (n+1)): > > pre, now = now, pre+now > > return now > > > > Theoretically, both of their time complexity should be O(n). However, > when > > the input n is so big (like 400000), fib_dp2(400000) can calculate it in > 2s > > but fib_dp(400000) takes *more than 60s* (python3.7.3 and macOS 10.14.6). > > Why? > > Memory allocation can take a long time. Try grabbing the line > initializing dp and slapping that into the body of dp2, and then > compare their times; that might make all the difference. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Aug 25 00:15:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Aug 2019 14:15:42 +1000 Subject: What make function with huge list so slow In-Reply-To: References: Message-ID: On Sun, Aug 25, 2019 at 1:43 PM Windson Yang wrote: > > Thank you, Chris. I tried your suggestions. I don't think that is the reason, fib_dp_look() and fib_dp_set() which also allocation a big list can return in 2s. (Please don't top-post) Are you running each function more than once, or just running them in succession and seeing how long they take? Show the full code you're using for the timing tests so we can recreate it. ChrisA From wiwindson at gmail.com Sun Aug 25 02:41:36 2019 From: wiwindson at gmail.com (Windson Yang) Date: Sun, 25 Aug 2019 14:41:36 +0800 Subject: What make function with huge list so slow In-Reply-To: References: Message-ID: 'I'm just running them in succession and seeing how long they'. The full code looks like this, this is only an example.py here. and I run 'time python3 example.py' for each function. def fib_dp(n): dp = [0] * (n+1) if n <= 1: return n dp[0], dp[1] = 0, 1 for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[-1] def fib_dp2(n): # add dp here just for calculating memory allocation time dp = [0] * (n+1) if n <= 1: return n pre, now = 0, 1 for i in range(2, (n+1)): pre, now = now, pre+now return now # run the function only once # fib_dp(400000) # took more than 60s # fib_dp2(400000) # took about 2s From alan at csail.mit.edu Sun Aug 25 03:28:13 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 25 Aug 2019 03:28:13 -0400 Subject: What make function with huge list so slow References: Message-ID: <86ftlppuuq.fsf@richard.bawden.org> Windson Yang writes: > 'I'm just running them in succession and seeing how long they'. The full > code looks like this, this is only an example.py here. and I run 'time > python3 example.py' for each function. > > def fib_dp(n): > dp = [0] * (n+1) > if n <= 1: > return n > dp[0], dp[1] = 0, 1 > for i in range(2, n+1): > dp[i] = dp[i-1] + dp[i-2] > return dp[-1] ... > # run the function only once > # fib_dp(400000) # took more than 60s > # fib_dp2(400000) # took about 2s Figure out how much memory fib_dp is holding on to right before it returns the answer. fib(400000) is a _big_ number! And so is fib(399999), and fib(399998), and fib(399997), etc. By the time you're done, you're holding on to quite a huge pile of storage here. Depending on how much physical memory you have, you much actually be swapping before you're done. -- Alan Bawden From wiwindson at gmail.com Sun Aug 25 08:30:09 2019 From: wiwindson at gmail.com (Windson Yang) Date: Sun, 25 Aug 2019 20:30:09 +0800 Subject: What make function with huge list so slow In-Reply-To: <86ftlppuuq.fsf@richard.bawden.org> References: <86ftlppuuq.fsf@richard.bawden.org> Message-ID: > Figure out how much memory fib_dp is holding on to right before it returns > the answer. fib(400000) is a _big_ number! And so is fib(399999), and > fib(399998), and fib(399997), etc. By the time you're done, you're holding > on to quite a huge pile of storage here. Depending on how much physical > memory you have, you much actually be swapping before you're done. > > -- > Alan Bawden > -- > T Thank you Alan. You are right! we use too much memeoy to save the answer in the dp list. Now I get it, thank you so much. From email at paulstgeorge.com Mon Aug 26 06:10:02 2019 From: email at paulstgeorge.com (Paul St George) Date: Mon, 26 Aug 2019 12:10:02 +0200 Subject: Newbie question about Python syntax In-Reply-To: <20190825003934.GA73181@cskk.homeip.net> References: <20190825003934.GA73181@cskk.homeip.net> Message-ID: On 25/08/2019 02:39, Cameron Simpson wrote: > On 24Aug2019 21:52, Paul St George wrote: [snip]> > Aside from "map" being a poor name (it is also a builtin Python > function), it seems that one creates one of these to control how some > rendering process is done. > > The class reference page you originally cites then specifies the meaning > of the various attributes you might set on one of these objects. > > Cheers, > Cameron Simpson Thanks Cameron. As this list has a low noise to signal ratio I cannot thank you enough here. I could have stayed where I belong in Blender Artists, or similar, but those lists tend to just offer solutions and as Douglas Adams almost said knowledge without understanding is almost meaningless. Here I have gained enough understanding (perhaps not to yet make sufficient sense in what I say) but to transfer knowledge from solving one problem to possibly solving many. Thank you for your patience and tolerance, Dr Paul St George -- http://www.paulstgeorge.com http://www.devices-of-wonder.com From pankaj.jangid at gmail.com Mon Aug 26 06:50:31 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Mon, 26 Aug 2019 16:20:31 +0530 Subject: Using the same data for both validation and prediction in Keras References: <18b82287-61e3-4b69-9c37-f9a0a256e37a@googlegroups.com> Message-ID: Amirreza Heidari writes: > I was reading a tutorial for time series prediction by Neural > Networks. I found that this code have used the same test data in the > following code for validation, and later also for prediction. > > history = model.fit(train_X, train_y, epochs=50, batch_size=72, validation_data=(test_X, test_y), verbose=2, shuffle=False) > > Does it mean that the validation and test data are the same, or there is a default percentage to split the data into validation and prediction? As per Prof. Andrew Ng, training, cross-validation and testing should have three different data-sets. If you have a small example set (for example 10,000 or may be 50,000) then you can split the example set into 60:20:20 ratio for train:validation:testing. But if you have a very large data-set (1 million, 10 million) then consider using 1% or may be lesser for validation and testing. -- Pankaj Jangid From mal at europython.eu Tue Aug 27 03:49:49 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 27 Aug 2019 09:49:49 +0200 Subject: EuroPython Society Board 2019/2020 Message-ID: For those of you who were not at EuroPython 2019, we?re happy to announce our new board for the next term: - Anders Hammarquist (Treasurer) - Angel Ramboi - Jakub Musko - Marc-Andr? Lemburg (Chair) - Martin Christen (Vice Chair) - Raquel Dou - Silvia Uberti - Stephane Wirtel Together, we?ll head off into the EuroPython 2020 RFP process next month and then kick off planning next year?s conference. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://www.europython-society.org/post/187300753360/eps-board-20192020 Tweet: https://twitter.com/europythons/status/1166253759044968448 Enjoy, -- EuroPython Society https://ep2019.europython.eu/ https://www.europython-society.org/ From cristi at ieee.org Tue Aug 27 13:01:52 2019 From: cristi at ieee.org (Cristian Cocos) Date: Tue, 27 Aug 2019 13:01:52 -0400 Subject: An "Object" class? Message-ID: I know that "Everything is an object in python" as per https://mail.python.org/pipermail/python-list/2015-June/691689.html. Also, I am more-or-less convinced that there is a generic "class" (aka "type") (meta)class (which would be an object, of course). Is there, however, a generic "object" (meta)class (which would obviously be an object as well as a class)? Christian -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King From cspealma at redhat.com Tue Aug 27 13:39:05 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Tue, 27 Aug 2019 13:39:05 -0400 Subject: An "Object" class? In-Reply-To: References: Message-ID: Yes, it is called `object` and `object` is the base class of ALL other classes, including `type`. In fact, it is the only class which does not itself inherit from anything. On Tue, Aug 27, 2019 at 1:35 PM Cristian Cocos wrote: > I know that "Everything is an object in python" as per > https://mail.python.org/pipermail/python-list/2015-June/691689.html. Also, > I am more-or-less convinced that there is a generic "class" (aka "type") > (meta)class (which would be an object, of course). Is there, however, a > generic "object" (meta)class (which would obviously be an object as well as > a class)? > > Christian > > -- > "People think that I must be a very strange person. This is not correct. I > have the heart of a small boy. It is in a glass jar on my desk." -- Stephen > King > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From cristi at ieee.org Tue Aug 27 14:19:28 2019 From: cristi at ieee.org (Cristian Cocos) Date: Tue, 27 Aug 2019 14:19:28 -0400 Subject: An "Object" class? In-Reply-To: References: Message-ID: Thank you! What would be the names of the *class *class, and of the *function *class please? On Tue, Aug 27, 2019 at 1:39 PM Calvin Spealman wrote: > Yes, it is called `object` and `object` is the base class of ALL other > classes, including `type`. In fact, it is the only class which does not > itself inherit from anything. > > On Tue, Aug 27, 2019 at 1:35 PM Cristian Cocos wrote: > >> I know that "Everything is an object in python" as per >> https://mail.python.org/pipermail/python-list/2015-June/691689.html. >> Also, >> I am more-or-less convinced that there is a generic "class" (aka "type") >> (meta)class (which would be an object, of course). Is there, however, a >> generic "object" (meta)class (which would obviously be an object as well >> as >> a class)? >> >> Christian >> >> -- >> "People think that I must be a very strange person. This is not correct. I >> have the heart of a small boy. It is in a glass jar on my desk." -- >> Stephen >> King >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > [image: https://red.ht/sig] > TRIED. TESTED. TRUSTED. > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King From cspealma at redhat.com Tue Aug 27 14:32:22 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Tue, 27 Aug 2019 14:32:22 -0400 Subject: An "Object" class? In-Reply-To: References: Message-ID: `type` is the "class" class (type and class are more or less synonymous terms in modern Python). You can find many of Python's implementation types in the `types` library, including `FunctionType`, here: https://docs.python.org/3/library/types.html On Tue, Aug 27, 2019 at 2:19 PM Cristian Cocos wrote: > Thank you! What would be the names of the *class *class, and of the > *function > *class please? > > On Tue, Aug 27, 2019 at 1:39 PM Calvin Spealman > wrote: > > > Yes, it is called `object` and `object` is the base class of ALL other > > classes, including `type`. In fact, it is the only class which does not > > itself inherit from anything. > > > > On Tue, Aug 27, 2019 at 1:35 PM Cristian Cocos wrote: > > > >> I know that "Everything is an object in python" as per > >> https://mail.python.org/pipermail/python-list/2015-June/691689.html. > >> Also, > >> I am more-or-less convinced that there is a generic "class" (aka "type") > >> (meta)class (which would be an object, of course). Is there, however, a > >> generic "object" (meta)class (which would obviously be an object as well > >> as > >> a class)? > >> > >> Christian > >> > >> -- > >> "People think that I must be a very strange person. This is not > correct. I > >> have the heart of a small boy. It is in a glass jar on my desk." -- > >> Stephen > >> King > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > > > > -- > > > > CALVIN SPEALMAN > > > > SENIOR QUALITY ENGINEER > > > > cspealma at redhat.com M: +1.336.210.5107 > > [image: https://red.ht/sig] > > TRIED. TESTED. TRUSTED. > > > > > -- > "People think that I must be a very strange person. This is not correct. I > have the heart of a small boy. It is in a glass jar on my desk." -- Stephen > King > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From rosuav at gmail.com Tue Aug 27 14:34:26 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Aug 2019 04:34:26 +1000 Subject: An "Object" class? In-Reply-To: References: Message-ID: On Wed, Aug 28, 2019 at 4:21 AM Cristian Cocos wrote: > > Thank you! What would be the names of the *class *class, and of the *function > *class please? The "class" class is called "type" - or rather, when you use the "class" keyword, you are creating a subclass of "type". There is no built-in name for the type of functions, and you usually don't care; they're simply callable objects, and any object can be made callable by giving it an appropriate method. ChrisA From tjreedy at udel.edu Tue Aug 27 16:59:34 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Aug 2019 16:59:34 -0400 Subject: An "Object" class? In-Reply-To: References: Message-ID: On 8/27/2019 2:19 PM, Cristian Cocos wrote: > Thank you! What would be the names of the *class *class, > and of the *function *class please? Use type(ob) to get the internal name of the class of an object. Built-in classes that users may need to call in python code are bound to the same name in __builtins__, as if __builtins__ were build with class statements. but many are not. >>> type(object) >>> type(type) >>> type(int) >>> type(abs) # built-in function Users can usefully call 'type' but not 'builtin_function_or_method'. >>> def(f): pass >>> type(f) # User-defined function. >>> l = lambda: None # Equivalent lambda expression. >>> type(l) Creating a function by calling 'function' instead of using 'def' or 'lambda' is a super expert endeaver, and the details are CPython specific and subject to change in any version. >>> type(list.__add__) >>> type(list.append) >>> for k, v in vars(list).items(): print(k, type(v)) # 36 lines. To see super classes of a class, use type.mro(cls). The returned list always begins with cls and ends with 'object' >>> mro = type.mro >>> mro(object) [] # As Chris said, baseclass has no superclass. >>> mro(type) [, ] >>> mro(list) [, ] # Nearly all built-in classes return [cls, 'object']. >>> mro(bool) [, , ] # The only exception I can think of. -- Terry Jan Reedy From spencerchief at googlemail.com Wed Aug 28 04:04:46 2019 From: spencerchief at googlemail.com (Spencer Du) Date: Wed, 28 Aug 2019 01:04:46 -0700 (PDT) Subject: How do I decouple these two modules? Message-ID: <1f597d11-754a-46bf-807e-4d946b2a0a94@googlegroups.com> Hi I have code for a GUI and MQTT. How do I make both of these modules decoupled because currently they rely on each other to some extent. GUI.py import logging from datetime import timedelta import time from thespian.actors import * from transitions import Machine import paho.mqtt.client as mqtt import importlib import os.path import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5 import QtWidgets, uic from mqtt import * class MainWindow(QtWidgets.QMainWindow): def __init__(self,parent = None): QMainWindow.__init__(self) super(MainWindow, self).__init__(parent) self.mdi = QMdiArea() self.setCentralWidget(self.mdi) self.setMinimumSize(QSize(800, 600)) self.setWindowTitle("PyQt button example - pythonprogramminglanguage.com") pybutton = QPushButton('Add device', self) pybutton.clicked.connect(self.importbutton) pybutton.move(100, 400) pybutton.resize(150, 32) self.textbox = QLineEdit(self) self.textbox.move(100,350) self.textbox.resize(100, 32) self.fileName_UI = "" def importbutton(self): self.fileName_UI = self.textbox.text() self.loadGUI() def getGUIFilename(self): return self.fileName_UI def loadGUI(self): print("Searching file", self.fileName_UI) try: module = __import__(self.fileName_UI) my_class = getattr(module, "SubWindow") sub = QMdiSubWindow() sub.setWidget(my_class()) sub.setWindowTitle("New GUI: " + self.fileName_UI) self.mdi.addSubWindow(sub) sub.show() print("creating new instance " + self.fileName_UI) client = device("Device") client.run() client.loop_start() # start the loop device_message = self.fileName_UI time.sleep(2) print("Publishing message to topic", "microscope/light_sheet_microscope/UI", " Searching file ", device_message+".py ...") client.publish("microscope/light_sheet_microscope/UI", device_message) time.sleep(2) # wait client.loop_stop() # stop the loop print("File imported") except: print("creating new instance " + self.fileName_UI) client = device("Device") client.run() client.loop_start() # start the loop device_message = self.fileName_UI time.sleep(2) print("Publishing message to topic", "microscope/light_sheet_microscope/UI", " Searching file ", device_message+".py ...") client.publish("microscope/light_sheet_microscope/UI", device_message) time.sleep(2) # wait client.loop_stop() # stop the loop print(device_message + ".py " + "file doesn't exist") if __name__ == "__main__": app = QApplication(sys.argv) mainWin = MainWindow() mainWin.show() publishedMessage = mainWin.getGUIFilename() sys.exit(app.exec_()) MQTT.py import logging from datetime import timedelta import time from thespian.actors import * from transitions import Machine import paho.mqtt.client as mqtt import importlib import os.path import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5 import QtWidgets, uic class device(mqtt.Client): def on_connect(self, mqttc, obj, flags, rc): if rc == 0: print("Connected to broker") else: print("Connection failed") mqttc.subscribe("microscope/light_sheet_microscope/UI") def on_message(self, mqttc, userdata, message): msg = str(message.payload.decode("utf-8")) print("File which you want to import(with .py extension)") print("message topic=", message.topic) print("message qos=", message.qos) print("message retain flag=", message.retain) def run(self): self.connect("broker.hivemq.com", 1883, 60) Thanks Spencer From pankaj.jangid at gmail.com Wed Aug 28 12:59:15 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Wed, 28 Aug 2019 22:29:15 +0530 Subject: Python unit test framework to fire 1000 unique concurrent requests References: <957d406e-32ca-490a-acd8-a320dbb66786@googlegroups.com> Message-ID: vishwatheworld007 at gmail.com writes: > Looking for a unit test framework with below requirements: > 1. Send 1000 unique URL requests in parallel ( Not sequential and not repetitive requests) > 2. Verify HTTP response status code ( eg: 200, 403, 404 etc) of each requests in parallel > 3. Verify Response headers of each URL requests > 4. Login to remote machine ( to which requests is fired) and verify logs > 1st is a load testing. You can use something like Apache JMeter. For other advanced validations use Desktop version of vREST - https://desktop.vrest.io/. Regards. -- Pankaj Jangid From a at d-amo.re Wed Aug 28 14:21:46 2019 From: a at d-amo.re (Andrea D'Amore) Date: Wed, 28 Aug 2019 20:21:46 +0200 Subject: How do I decouple these two modules? In-Reply-To: <1f597d11-754a-46bf-807e-4d946b2a0a94@googlegroups.com> References: <1f597d11-754a-46bf-807e-4d946b2a0a94@googlegroups.com> Message-ID: On Wed, 28 Aug 2019 at 10:04, Spencer Du via Python-list wrote: > I have code for a GUI and MQTT [?] currently they rely on each other to some extent. How? I am failing to see the circular dependency there. -- Andrea From cristi at ieee.org Wed Aug 28 14:34:04 2019 From: cristi at ieee.org (Cristian Cocos) Date: Wed, 28 Aug 2019 14:34:04 -0400 Subject: An "Object" class? In-Reply-To: References: Message-ID: Thank you! I can see that the taxonomy of built-in classes (i.e. the subclass/superclass relations) is not very developed. At the very least I would have loved to see stuff such as int declared as a subClass/subType of float and the like--that is, a class taxonomy in tune with standard mathematical practice, but I am guessing that mathematical kosher-ness had to take a back seat to implementational concerns. Neither does the numbers package bring any order or clarity into this; take for example the following sentence from the standard type hierarchy ( https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy): "There are two types of integers [numbers.Integral]: Integers (int) ... [and] Booleans (bool)" I, for one, cannot help but read this as a subtype declaration, which appears to be the wrong construal. For one, I am not sure that numbers.Integral is a type that is returned by the type() function, regardless of the input argument. Furthermore, it looks to me that no instance of the int type is an instance of the numbers.Integral type (and that is based on the fact that type.mro() function applied to some integer does not list numbers.Integral among the returned values (although this may also be a consequence of the fact that type() never returns numbers.Integral)). Anyway, I am looking forward to your correcting any of the above assertions. C On Tue, Aug 27, 2019 at 5:00 PM Terry Reedy wrote: > On 8/27/2019 2:19 PM, Cristian Cocos wrote: > > Thank you! What would be the names of the *class *class, > > and of the *function *class please? > > Use type(ob) to get the internal name of the class of an object. > Built-in classes that users may need to call in python code are bound to > the same name in __builtins__, as if __builtins__ were build with class > statements. but many are not. > > >>> type(object) > > >>> type(type) > > >>> type(int) > > >>> type(abs) # built-in function > > > Users can usefully call 'type' but not 'builtin_function_or_method'. > > >>> def(f): pass > > >>> type(f) # User-defined function. > > >>> l = lambda: None # Equivalent lambda expression. > >>> type(l) > > > Creating a function by calling 'function' instead of using 'def' or > 'lambda' is a super expert endeaver, and the details are CPython > specific and subject to change in any version. > > >>> type(list.__add__) > > >>> type(list.append) > > >>> for k, v in vars(list).items(): print(k, type(v)) > # 36 lines. > > To see super classes of a class, use type.mro(cls). The returned list > always begins with cls and ends with 'object' > > >>> mro = type.mro > >>> mro(object) > [] # As Chris said, baseclass has no superclass. > >>> mro(type) > [, ] > >>> mro(list) > [, ] > # Nearly all built-in classes return [cls, 'object']. > >>> mro(bool) > [, , ] > # The only exception I can think of. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King From rosuav at gmail.com Wed Aug 28 14:42:25 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Aug 2019 04:42:25 +1000 Subject: An "Object" class? In-Reply-To: References: Message-ID: On Thu, Aug 29, 2019 at 4:35 AM Cristian Cocos wrote: > > Thank you! I can see that the taxonomy of built-in classes (i.e. the > subclass/superclass relations) is not very developed. At the very least I > would have loved to see stuff such as int declared as a subClass/subType > of float and the like--that is, a class taxonomy in tune with standard > mathematical practice, but I am guessing that mathematical kosher-ness had > to take a back seat to implementational concerns. In mathematics, integers are a strict subset of reals, but that doesn't mean that the integer type is a subclass of the float type. Floats in computers are not the same as reals in mathematics; most notably, they are far from infinite in either magnitude or precision. ChrisA From faajabbari at gmail.com Wed Aug 28 18:11:25 2019 From: faajabbari at gmail.com (fateme jbr) Date: Wed, 28 Aug 2019 15:11:25 -0700 Subject: Fwd: installation problem In-Reply-To: References: Message-ID: Dear Python team I downloaded "Windows x86-64 executable installer " form your website. My windows version is 8.1 and it is 64 bit. After installation, I got the message that "Setup was successful", but it didn't lunch to the program. When I found the program in start menu, the fallowing window appeared: [image: Untitled.png] What is the problem? Could you help me to complete the installation please? Best regards From PythonList at DancesWithMice.info Wed Aug 28 18:27:23 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 29 Aug 2019 10:27:23 +1200 Subject: Fwd: installation problem In-Reply-To: References: Message-ID: On 29/08/19 10:11 AM, fateme jbr wrote: > Dear Python team We are a mailing list of enthusiasts with volunteer membership. > I downloaded "Windows x86-64 executable installer > " form your > website. My windows version is 8.1 and it is 64 bit. After installation, I > got the message that "Setup was successful", but it didn't lunch to the > program. > When I found the program in start menu, the fallowing window appeared: > > [image: Untitled.png] Attachments are not permitted by the mailing list. > What is the problem? Could you help me to complete the installation please? Try: Python on Windows FAQ https://docs.python.org/3/faq/windows.html#how-do-i-run-a-python-program-under-windows -- Regards =dn From jsf80238 at gmail.com Wed Aug 28 23:21:01 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 28 Aug 2019 21:21:01 -0600 Subject: How to use regex to search string between {}? In-Reply-To: References: Message-ID: > > If I have path: /home/admin/hello/yo/{h1,h2,h3,h4} > > import re > r = re.search('{.}', path) > # r should be ['h1,h2,h3,h4'] but I fail > > Why always search nothing? > A site like http://www.pyregex.com/ allows you to check your regex with slightly fewer clicks and keystrokes than editing your program. From flebber.crue at gmail.com Wed Aug 28 23:24:50 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 20:24:50 -0700 (PDT) Subject: Compare zip lists where order is important Message-ID: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> Hi Trying to find whats changed in this example. Based around work and team reschuffles. So first I created my current teams and then my shuffled teams. people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] team_number = [1,1,2,2,3,3] shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] shuffle_team_number = [1,1,2,2,3,3] Then combine. teams = list(zip(people,team_number)) shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) Then I am attempting to compare for change. [i for i, j in zip(teams, shuffle_teams) if i != j] #Result [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] #Expecting to see [('Fredricka', 1),('Tim', 2)] What's a working way to go about this? Sayth From flebber.crue at gmail.com Wed Aug 28 23:26:01 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 20:26:01 -0700 (PDT) Subject: How to use regex to search string between {}? In-Reply-To: References: Message-ID: <5b191f46-56eb-4348-bf9a-3a6316f3de6b@googlegroups.com> > > A site like http://www.pyregex.com/ allows you to check your regex with > slightly fewer clicks and keystrokes than editing your program. Thanks Jason From hongyi.zhao at gmail.com Wed Aug 28 23:40:45 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 29 Aug 2019 03:40:45 +0000 (UTC) Subject: if STREAM.isatty(): Message-ID: Hi, I read the following code: https://github.com/shichao-an/homura/blob/master/homura.py On the line 265-266, it said: if STREAM.isatty(): p = (self.progress_template + '\r') % params What's mean by using the above two lines? Can I not use them? Regards From alan at csail.mit.edu Wed Aug 28 23:53:00 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 28 Aug 2019 23:53:00 -0400 Subject: An "Object" class? References: Message-ID: <86a7bspqzn.fsf@richard.bawden.org> Cristian Cocos writes: > Thank you! I can see that the taxonomy of built-in classes (i.e. the > subclass/superclass relations) is not very developed. At the very least I > would have loved to see stuff such as int declared as a subClass/subType > of float and the like--that is, a class taxonomy in tune with standard > mathematical practice, but I am guessing that mathematical kosher-ness had > to take a back seat to implementational concerns. Except that numbers of type `int' are _not_ a subset of numbers of type `float'! Some ints are much larger that the largest float. In fact, both `int' and `float' are subclasses of `numbers.Real'. While it is true that `numbers.Real' does not appear in the list returned by `type.mro(int)', nevertheless `issubclass(int, numbers.Real)' and `isinstance(2, numbers.Real)' are true. `type.mro' tells you something about the _implementation_ of `int' and `float' that you _usually_ shouldn't concern yourself with. Stick to `isinstance' and `issubclass' and everthing looks pretty kosher. -- Alan Bawden From flebber.crue at gmail.com Wed Aug 28 23:53:32 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 20:53:32 -0700 (PDT) Subject: Compare zip lists where order is important In-Reply-To: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> Message-ID: <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > Hi > > Trying to find whats changed in this example. Based around work and team reschuffles. > > So first I created my current teams and then my shuffled teams. > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > team_number = [1,1,2,2,3,3] > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > shuffle_team_number = [1,1,2,2,3,3] > > Then combine. > > teams = list(zip(people,team_number)) > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) > > Then I am attempting to compare for change. > > [i for i, j in zip(teams, shuffle_teams) if i != j] > > #Result > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] > > #Expecting to see > > [('Fredricka', 1),('Tim', 2)] > > What's a working way to go about this? > > Sayth It looks like Tuples are comparing by position changes not content changes. So this fails too set(shuffle_teams) & set(teams) # {('Bill', 1), ('Fred', 3), ('Sally', 2)} From flebber.crue at gmail.com Thu Aug 29 00:03:34 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 21:03:34 -0700 (PDT) Subject: Compare zip lists where order is important In-Reply-To: <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> Message-ID: On Thursday, 29 August 2019 13:53:43 UTC+10, Sayth Renshaw wrote: > On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > > Hi > > > > Trying to find whats changed in this example. Based around work and team reschuffles. > > > > So first I created my current teams and then my shuffled teams. > > > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > > team_number = [1,1,2,2,3,3] > > > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > > shuffle_team_number = [1,1,2,2,3,3] > > > > Then combine. > > > > teams = list(zip(people,team_number)) > > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) > > > > Then I am attempting to compare for change. > > > > [i for i, j in zip(teams, shuffle_teams) if i != j] > > > > #Result > > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] > > > > #Expecting to see > > > > [('Fredricka', 1),('Tim', 2)] > > > > What's a working way to go about this? > > > > Sayth > > It looks like Tuples are comparing by position changes not content changes. > > So this fails too > > set(shuffle_teams) & set(teams) > # {('Bill', 1), ('Fred', 3), ('Sally', 2)} Well this works although its not clear which line is the change. set(teams).symmetric_difference(set(shuffle_teams)) {('Ally', 2), ('Ally', 3), # This is the change Ally changed from 2 to 3 ('Fredricka', 1), # However here this first line is the change. ('Fredricka', 3), ('Tim', 1), ('Tim', 2)} Hints? From flebber.crue at gmail.com Thu Aug 29 00:25:35 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 21:25:35 -0700 (PDT) Subject: [SOLVED] Re: Compare zip lists where order is important In-Reply-To: References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> Message-ID: <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> On Thursday, 29 August 2019 14:03:44 UTC+10, Sayth Renshaw wrote: > On Thursday, 29 August 2019 13:53:43 UTC+10, Sayth Renshaw wrote: > > On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > > > Hi > > > > > > Trying to find whats changed in this example. Based around work and team reschuffles. > > > > > > So first I created my current teams and then my shuffled teams. > > > > > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > > > team_number = [1,1,2,2,3,3] > > > > > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > > > shuffle_team_number = [1,1,2,2,3,3] > > > > > > Then combine. > > > > > > teams = list(zip(people,team_number)) > > > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) > > > > > > Then I am attempting to compare for change. > > > > > > [i for i, j in zip(teams, shuffle_teams) if i != j] > > > > > > #Result > > > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] > > > > > > #Expecting to see > > > > > > [('Fredricka', 1),('Tim', 2)] > > > > > > What's a working way to go about this? > > > > > > Sayth > > > > It looks like Tuples are comparing by position changes not content changes. > > > > So this fails too > > > > set(shuffle_teams) & set(teams) > > # {('Bill', 1), ('Fred', 3), ('Sally', 2)} > > Well this works although its not clear which line is the change. > > set(teams).symmetric_difference(set(shuffle_teams)) > > {('Ally', 2), > ('Ally', 3), # This is the change Ally changed from 2 to 3 > ('Fredricka', 1), # However here this first line is the change. > ('Fredricka', 3), > ('Tim', 1), > ('Tim', 2)} > > Hints? set(shuffle_teams).difference(set(teams)) {('Ally', 3), ('Fredricka', 1), ('Tim', 2)} Sayth From flebber.crue at gmail.com Thu Aug 29 01:33:20 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 28 Aug 2019 22:33:20 -0700 (PDT) Subject: pandas loc on str lower for column comparison Message-ID: Hi I am importing 4 columns into a dataframe from a spreadsheet. My goal is to create a 5th column with TRUE or False if column 4 (str) matches column 3. Trying to leverage this answer https://stackoverflow.com/a/35940955/461887 This is my code import pandas as pd xls = pd.ExcelFile("Melbourne.xlsx") df = xls.parse('Sheet1', skiprows= 4) df1 = df[['UID','Name','New Leader','Current Team', 'New Team']] df1['Difference'] = df1['Current Team'].str.lower().str.replace('s/+',"") == df1['New Team'].str.lower().str.replace('s/+',"") Which gives this error C:\Users\u369811\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy If I update the line to use loc as this I still receive a long error. df1['Difference'] = df1.loc['Current Team'].str.lower().str.replace('s/+',"") == df1.loc['New Team'].str.lower().str.replace('s/+',"") What am I missing? Sayth From Alemug at ethiopianairlines.com Thu Aug 29 00:59:55 2019 From: Alemug at ethiopianairlines.com (Alemu Geletew) Date: Thu, 29 Aug 2019 04:59:55 +0000 Subject: unable to to install paython Message-ID: <98facde3fd554976bf6e968ca474bec4@ethiopianairlines.com> From __peter__ at web.de Thu Aug 29 02:14:47 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Aug 2019 08:14:47 +0200 Subject: [SOLVED] Re: Compare zip lists where order is important References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> Message-ID: Sayth Renshaw wrote: > On Thursday, 29 August 2019 14:03:44 UTC+10, Sayth Renshaw wrote: >> On Thursday, 29 August 2019 13:53:43 UTC+10, Sayth Renshaw wrote: >> > On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: >> > > Hi >> > > >> > > Trying to find whats changed in this example. Based around work and >> > > team reschuffles. >> > > >> > > So first I created my current teams and then my shuffled teams. >> > > >> > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] >> > > team_number = [1,1,2,2,3,3] >> > > >> > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] >> > > shuffle_team_number = [1,1,2,2,3,3] >> > > >> > > Then combine. >> > > >> > > teams = list(zip(people,team_number)) >> > > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) >> > > >> > > Then I am attempting to compare for change. >> > > >> > > [i for i, j in zip(teams, shuffle_teams) if i != j] >> > > >> > > #Result >> > > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] >> > > >> > > #Expecting to see >> > > >> > > [('Fredricka', 1),('Tim', 2)] >> > > >> > > What's a working way to go about this? >> > > >> > > Sayth >> > >> > It looks like Tuples are comparing by position changes not content >> > changes. >> > >> > So this fails too >> > >> > set(shuffle_teams) & set(teams) >> > # {('Bill', 1), ('Fred', 3), ('Sally', 2)} >> >> Well this works although its not clear which line is the change. >> >> set(teams).symmetric_difference(set(shuffle_teams)) >> >> {('Ally', 2), >> ('Ally', 3), # This is the change Ally changed from 2 to 3 >> ('Fredricka', 1), # However here this first line is the change. >> ('Fredricka', 3), >> ('Tim', 1), >> ('Tim', 2)} >> >> Hints? > > set(shuffle_teams).difference(set(teams)) > {('Ally', 3), ('Fredricka', 1), ('Tim', 2)} (0) Sets use the comparison provided by their elements, there is no difference betwen ("Ally", 2) == ("Ally", 3) and "whatever" == 123 (1) If set operations work that means that list order is *not* important (2) a.difference(b), which can also be written as a - b, will find the added pairs, but ignore the removed ones. Is that what you want? From frank at chagford.com Thu Aug 29 02:37:49 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 29 Aug 2019 08:37:49 +0200 Subject: Compare zip lists where order is important In-Reply-To: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> Message-ID: <1645e47d-b832-07a5-fff4-e2689a3413eb@chagford.com> On 2019-08-29 5:24 AM, Sayth Renshaw wrote: > Hi > > Trying to find whats changed in this example. Based around work and team reschuffles. > > So first I created my current teams and then my shuffled teams. > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > team_number = [1,1,2,2,3,3] > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > shuffle_team_number = [1,1,2,2,3,3] > > Then combine. > > teams = list(zip(people,team_number)) > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) > > Then I am attempting to compare for change. > > [i for i, j in zip(teams, shuffle_teams) if i != j] > > #Result > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] > > #Expecting to see > > [('Fredricka', 1),('Tim', 2)] > > What's a working way to go about this? > This would have worked if you sorted your lists first - >>> [i for i, j in zip(sorted(teams), sorted(shuffle_teams)) if i != j] [('Ally', 2), ('Fredricka', 3), ('Tim', 1)] Except you wanted to see the results from shuffle_teams, so instead of 'i for i, j ...', use 'j for i, j ...' - >>> [j for i, j in zip(sorted(teams), sorted(shuffle_teams)) if i != j] [('Ally', 3), ('Fredricka', 1), ('Tim', 2)] Frank Millman From frank at chagford.com Thu Aug 29 02:37:49 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 29 Aug 2019 08:37:49 +0200 Subject: Compare zip lists where order is important In-Reply-To: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> Message-ID: <1645e47d-b832-07a5-fff4-e2689a3413eb@chagford.com> On 2019-08-29 5:24 AM, Sayth Renshaw wrote: > Hi > > Trying to find whats changed in this example. Based around work and team reschuffles. > > So first I created my current teams and then my shuffled teams. > > people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > team_number = [1,1,2,2,3,3] > > shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > shuffle_team_number = [1,1,2,2,3,3] > > Then combine. > > teams = list(zip(people,team_number)) > shuffle_teams = list(zip(shuffle_people, shuffle_team_number)) > > Then I am attempting to compare for change. > > [i for i, j in zip(teams, shuffle_teams) if i != j] > > #Result > [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] > > #Expecting to see > > [('Fredricka', 1),('Tim', 2)] > > What's a working way to go about this? > This would have worked if you sorted your lists first - >>> [i for i, j in zip(sorted(teams), sorted(shuffle_teams)) if i != j] [('Ally', 2), ('Fredricka', 3), ('Tim', 1)] Except you wanted to see the results from shuffle_teams, so instead of 'i for i, j ...', use 'j for i, j ...' - >>> [j for i, j in zip(sorted(teams), sorted(shuffle_teams)) if i != j] [('Ally', 3), ('Fredricka', 1), ('Tim', 2)] Frank Millman From flebber.crue at gmail.com Thu Aug 29 04:38:40 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 29 Aug 2019 01:38:40 -0700 (PDT) Subject: [SOLVED] Re: Compare zip lists where order is important In-Reply-To: References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> Message-ID: <5aad0993-df53-4bd7-becc-1c6a99034008@googlegroups.com> will find the added pairs, but ignore the removed ones. Is that what you want? Yes, I think. I want to find the changed pairs. The people that moved team numbers. Sayth From __peter__ at web.de Thu Aug 29 06:33:19 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Aug 2019 12:33:19 +0200 Subject: [SOLVED] Re: Compare zip lists where order is important References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> <5aad0993-df53-4bd7-becc-1c6a99034008@googlegroups.com> Message-ID: Sayth Renshaw wrote: > will find the added > pairs, but ignore the removed ones. Is that what you want? > > Yes, I think. I want to find the changed pairs. The people that moved team > numbers. To find the people that moved team numbers I would tear the pairs apart. Like: >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] >>> team_number = [1,1,2,2,3,3] >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] >>> shuffle_team_number = [1,1,2,2,3,3] >>> old = dict(zip(people, team_number)) >>> new = dict(zip(shuffle_people, shuffle_team_number)) >>> for name in old.keys() & new.keys(): ... old_team = old[name] ... new_team = new[name] ... if old_team != new_team: ... print(name, "went from", old_team, "to", new_team) ... Tim went from 1 to 2 Fredricka went from 3 to 1 Ally went from 2 to 3 From o1bigtenor at gmail.com Thu Aug 29 07:18:58 2019 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 29 Aug 2019 06:18:58 -0500 Subject: unable to to install paython In-Reply-To: <98facde3fd554976bf6e968ca474bec4@ethiopianairlines.com> References: <98facde3fd554976bf6e968ca474bec4@ethiopianairlines.com> Message-ID: On Thu, Aug 29, 2019 at 12:51 AM Alemu Geletew via Python-list wrote: > Hmmmmmmmmmm - - - - somehow you think that other members of this list can somehow understand what you did do - - - - without you even telling them. As my crystal ball (for future readings and such) hasn't ever worked it would be far more likely that you would get assistance if you would describe what you 'have' done and then it might be possible to guide you to what you could do to achieve what you wish. Regards From rhodri at kynesim.co.uk Thu Aug 29 08:23:07 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 29 Aug 2019 13:23:07 +0100 Subject: if STREAM.isatty(): In-Reply-To: References: Message-ID: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> On 29/08/2019 04:40, Hongyi Zhao wrote: > Hi, > > I read the following code: > > https://github.com/shichao-an/homura/blob/master/homura.py > > On the line 265-266, it said: > > if STREAM.isatty(): > p = (self.progress_template + '\r') % params > > > What's mean by using the above two lines? Can I not use them? If you don't understand them, you definitely shouldn't use them. So let's fix that :-) "isatty()" is a method of the io.IOBase class that checks to see if the stream is connected to a tty, or to use less jargon, if it is interactive. "tty" was I think originally an abbreviation for "teletype", but nowadays it refers to any terminal, anywhere you get a command line prompt. See https://docs.python.org/3/library/io.html#io.IOBase.isatty The next line gives you a cheap and cheerful progress message. I haven't looked at the rest of the code, but I imagine "self.progress_template" gets set somewhere with a string rather like "%d%% complete". What the expression does is add a carriage return character to the end of the string (but *not* a line feed -- remember that, it will be important in a minute), then the % operator formats the string (see https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) using the information in "params". This is easiest to show by example. Suppose "self.progress_template" is "%d%% complete" as I suggested, and "params" is 1. Then "p" becomes the string "1% complete\r" (where \r is the carriage return character). Presumably a little later the code does STREAM.write(p) which will write "1% complete" to the terminal and then put the cursor (the "writing point") back to the start of the line. Since there is no carriage return character, it does *not* move on to a new line. The next time we call this code, say with params = 2, we write out "2% complete" over the top of the previous message, obliterating the old text. The cursor is once again at the start of the line, so we can carry on with "3% complete", "4% complete" and so on. TLDR: these two lines set up (but don't output) a progress message for an interactive stream. -- Rhodri James *-* Kynesim Ltd From hongyi.zhao at gmail.com Thu Aug 29 09:37:01 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 29 Aug 2019 13:37:01 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On Thu, 29 Aug 2019 13:23:07 +0100, Rhodri James wrote: > TLDR: these two lines set up (but don't output) a progress message for > an interactive stream. Thanks a lot for your deeply notes on this. But, if so, when will the ``else ...'' be executed in the original code: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: current_time = time.time() if self._last_time == 0.0: self._last_time = current_time else: interval = current_time - self._last_time if interval < 0.5: return self._last_time = current_time p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() Regards From rhodri at kynesim.co.uk Thu Aug 29 09:51:43 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 29 Aug 2019 14:51:43 +0100 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> On 29/08/2019 14:37, Hongyi Zhao wrote: > On Thu, 29 Aug 2019 13:23:07 +0100, Rhodri James wrote: > >> TLDR: these two lines set up (but don't output) a progress message for >> an interactive stream. > Thanks a lot for your deeply notes on this. But, if so, when will the > ``else ...'' be executed in the original code: When the stream isn't connected to an interactive terminal, obviously. For example, when it's writing to file. -- Rhodri James *-* Kynesim Ltd From eryksun at gmail.com Thu Aug 29 10:16:12 2019 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 29 Aug 2019 09:16:12 -0500 Subject: if STREAM.isatty(): In-Reply-To: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On 8/29/19, Rhodri James wrote: > > "isatty()" is a method of the io.IOBase class that checks to see > if the stream is connected to a tty, or to use less jargon, if it is > interactive. "tty" was I think originally an abbreviation for > "teletype", but nowadays it refers to any terminal, anywhere you > get a command line prompt. In Windows, isatty() is true for any character-type file. This does not necessarily mean an interactive stream. In particular, NUL is a character device: C:\>python -c "import sys;print(sys.stderr.isatty())" 2>NUL True But a pipe is not: C:\>python -c "import sys;print(sys.stderr.isatty())" 2>&1 | more False From piet-l at vanoostrum.org Thu Aug 29 10:33:56 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Thu, 29 Aug 2019 16:33:56 +0200 Subject: pandas loc on str lower for column comparison References: Message-ID: Sayth Renshaw writes: > Hi > > I am importing 4 columns into a dataframe from a spreadsheet. > > My goal is to create a 5th column with TRUE or False if column 4 (str) matches column 3. > > Trying to leverage this answer https://stackoverflow.com/a/35940955/461887 > > This is my code > > import pandas as pd > > xls = pd.ExcelFile("Melbourne.xlsx") > df = xls.parse('Sheet1', skiprows= 4) > df1 = df[['UID','Name','New Leader','Current Team', 'New Team']] > df1['Difference'] = df1['Current > Team'].str.lower().str.replace('s/+',"") == df1['New > Team'].str.lower().str.replace('s/+',"") > > Which gives this error > > C:\Users\u369811\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:6: > SettingWithCopyWarning: > A value is trying to be set on a copy of a slice from a DataFrame. I think what happens is that df1 is not a copy of the subset of df that you want, but it is a VIEW on df instead. This means that df1 shares memory with df (for memory savings reasons). But if you would change this view by adding a column, where should it be put? In df? If so, where? So the correct way to do this is to make df1 a copy rather than a view. df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] And than it should work. Except that the str.replace is wrong for what you want. It just replaces the literal string "s/+" with an empty string instead of white space. This was wrong in the stackoverflow post. To replace whitespace it should be str.replace('\\s+',"", regex=True). But simpler is to use str.strip(): df1['Difference'] = df1['Current Team'].str.lower().str.strip() == df1['New Team'].str.lower().str.strip() -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From piet-l at vanoostrum.org Thu Aug 29 10:49:18 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Thu, 29 Aug 2019 16:49:18 +0200 Subject: pandas loc on str lower for column comparison References: Message-ID: Piet van Oostrum writes: > So the correct way to do this is to make df1 a copy rather than a view. > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] Or maybe even make an explicit copy: df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From hongyi.zhao at gmail.com Thu Aug 29 11:29:28 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 29 Aug 2019 15:29:28 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> Message-ID: On Thu, 29 Aug 2019 14:51:43 +0100, Rhodri James wrote: > When the stream isn't connected to an interactive terminal, obviously. > For example, when it's writing to file. But I cannot see any thing like this in the code. Regards From rhodri at kynesim.co.uk Thu Aug 29 11:42:44 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 29 Aug 2019 16:42:44 +0100 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> Message-ID: <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> On 29/08/2019 16:29, Hongyi Zhao wrote: > On Thu, 29 Aug 2019 14:51:43 +0100, Rhodri James wrote: > >> When the stream isn't connected to an interactive terminal, obviously. >> For example, when it's writing to file. > > But I cannot see any thing like this in the code. I don't understand what's to not to understand. if condition: do_something_because_condition_is_true() else: do_something_because_condition_is_false() is a perfectly normal construction. If you mean something else, please be explicit. -- Rhodri James *-* Kynesim Ltd From cristi at ieee.org Thu Aug 29 12:15:58 2019 From: cristi at ieee.org (Cristian Cocos) Date: Thu, 29 Aug 2019 12:15:58 -0400 Subject: An "Object" class? In-Reply-To: <86a7bspqzn.fsf@richard.bawden.org> References: <86a7bspqzn.fsf@richard.bawden.org> Message-ID: Thank you! For some reason I didn't think of using issubclass and isinstance in my Python types investigation. As you may have already noticed, I am a Python beginner. I also happen to have a Logic and Foundations of Mathematics background, hence I am tempted to investigate Python's type taxonomy from a basic mathematical angle, with an eye to "recovering" basic mathematical notions such as set membership, set inclusion etc. So far, I have been living under the impression that type() is akin to set membership (in a meta-Python approach), hence it should ideally match the results of isinstance(), but that does not happen: >>> type(print) >>> isinstance(print, builtin_function_or_method) Traceback (most recent call last): File "", line 1, in NameError: name 'builtin_function_or_method' is not defined Just curious why builtin_function_or_method doesn't work as an argument of isinstance(). After all, builtin_function_or_method is a type, right? The bottom line is that I am trying to figure out where exactly the world of Python types _diverges from_ what I would expect as a mathematician. It makes it easier for me to learn Python this way. Many thanks, C On Wed, Aug 28, 2019 at 11:56 PM Alan Bawden wrote: > Cristian Cocos writes: > > > Thank you! I can see that the taxonomy of built-in classes (i.e. the > > subclass/superclass relations) is not very developed. At the very least I > > would have loved to see stuff such as int declared as a subClass/subType > > of float and the like--that is, a class taxonomy in tune with standard > > mathematical practice, but I am guessing that mathematical kosher-ness > had > > to take a back seat to implementational concerns. > > Except that numbers of type `int' are _not_ a subset of numbers of > type `float'! Some ints are much larger that the largest float. > > In fact, both `int' and `float' are subclasses of `numbers.Real'. While it > is true that `numbers.Real' does not appear in the list returned by > `type.mro(int)', nevertheless `issubclass(int, numbers.Real)' and > `isinstance(2, numbers.Real)' are true. `type.mro' tells you something > about the _implementation_ of `int' and `float' that you _usually_ > shouldn't > concern yourself with. Stick to `isinstance' and `issubclass' and > everthing looks pretty kosher. > > -- > Alan Bawden > -- > https://mail.python.org/mailman/listinfo/python-list > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King From rmlibre at riseup.net Thu Aug 29 15:25:43 2019 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Thu, 29 Aug 2019 12:25:43 -0700 Subject: Python unit test framework to fire 1000 unique concurrent requests (rmlibre) In-Reply-To: References: Message-ID: <898f4db3f878d3448fbaaf19db33ca3f@riseup.net> If you want to try out some libraries to build your own tests, you could try aiohttp, aiodns, and asyncio. The requests using these libraries are made asynchronously, not completely in parallel, but produce a similar effect at lower cost. Some examples and docs on these can be found here: https://docs.aiohttp.org/en/v2.3.5/ I also recently came across this talk where the author created a server to resolve 100 million requests to a server using asyncio. You can find the talk here: https://www.youtube.com/watch?v=Mj-Pyg4gsPs Also, Raymond Hettinger gave a talk on useful testing modules, which could be helpful in deciding how to create your tests: https://www.youtube.com/watch?v=ARKbfWk4Xyw On 2019-08-29 16:00, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Python unit test framework to fire 1000 unique concurrent > requests (Pankaj Jangid) > 2. Re: How do I decouple these two modules? (Andrea D'Amore) > 3. Re: An "Object" class? (Cristian Cocos) > 4. Re: An "Object" class? (Chris Angelico) > 5. Fwd: installation problem (fateme jbr) > 6. Re: Fwd: installation problem (DL Neil) > 7. Re: How to use regex to search string between {}? (Jason Friedman) > 8. Compare zip lists where order is important (Sayth Renshaw) > 9. Re: How to use regex to search string between {}? (Sayth Renshaw) > 10. if STREAM.isatty(): (Hongyi Zhao) > 11. Re: An "Object" class? (Alan Bawden) > 12. Re: Compare zip lists where order is important (Sayth Renshaw) > 13. Re: Compare zip lists where order is important (Sayth Renshaw) > 14. [SOLVED] Re: Compare zip lists where order is important > (Sayth Renshaw) > 15. pandas loc on str lower for column comparison (Sayth Renshaw) > 16. unable to to install paython (Alemu Geletew) > 17. Re: [SOLVED] Re: Compare zip lists where order is important > (Peter Otten) > 18. Re: Compare zip lists where order is important (Frank Millman) > 19. Re: Compare zip lists where order is important (Frank Millman) > 20. Re: [SOLVED] Re: Compare zip lists where order is important > (Sayth Renshaw) > 21. Re: [SOLVED] Re: Compare zip lists where order is important > (Peter Otten) > 22. Re: unable to to install paython (o1bigtenor) > 23. Re: if STREAM.isatty(): (Rhodri James) > 24. Re: if STREAM.isatty(): (Hongyi Zhao) > 25. Re: if STREAM.isatty(): (Rhodri James) > 26. Re: if STREAM.isatty(): (Eryk Sun) > 27. Re: pandas loc on str lower for column comparison > (Piet van Oostrum) > 28. Re: pandas loc on str lower for column comparison > (Piet van Oostrum) > 29. Re: if STREAM.isatty(): (Hongyi Zhao) > 30. Re: if STREAM.isatty(): (Rhodri James) > 31. Re: unable to to install paython (Dennis Lee Bieber) From hongyi.zhao at gmail.com Thu Aug 29 18:38:42 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 29 Aug 2019 22:38:42 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > I don't understand what's to not to understand. > > if condition: > do_something_because_condition_is_true() > else: > do_something_because_condition_is_false() > > is a perfectly normal construction. If you mean something else, please > be explicit. Let me say it more explicitly: The original code snippet's logic is as follows: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: [do something to reset the new value of p] p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() In order to refresh the tty, the if and else must be run alternatively. i.e., the isatty() must return 0 and 1 periodically. I still understand how the above code will let the isatty() return 0 and 1 in turn? Regards From tjreedy at udel.edu Thu Aug 29 18:45:29 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Aug 2019 18:45:29 -0400 Subject: if STREAM.isatty(): In-Reply-To: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On 8/29/2019 8:23 AM, Rhodri James wrote: > On 29/08/2019 04:40, Hongyi Zhao wrote: >> Hi, >> >> I read the following code: >> >> https://github.com/shichao-an/homura/blob/master/homura.py >> >> On the line 265-266, it said: >> >> ???????? if STREAM.isatty(): >> ???????????? p = (self.progress_template + '\r') % params >> >> >> What's mean by using the above two lines?? Can I not use them? > > If you don't understand them, you definitely shouldn't use them.? So > let's fix that :-) > > "isatty()" is a method of the io.IOBase class that checks to see if the > stream is connected to a tty, or to use less jargon, if it is > interactive.? "tty" was I think originally an abbreviation for > "teletype", but nowadays it refers to any terminal, anywhere you get a > command line prompt.? See > https://docs.python.org/3/library/io.html#io.IOBase.isatty That says "Return True if the stream is interactive (i.e., connected to a terminal/tty device)." AFAIK, the docs do not define 'interactive' or 'terminal/tty device'. The Linux 'isatty(fildes)' man page says "return 1 if fildes is associated with a terminal". I don't know it 'terminal' is defined anywhere. I take 'interactive' as meaning that the stream is one of at least two streams associated with one device such that if the program writes a prompt to an output stream, a response might be received on the corresponding input stream. In python, 'input(prompt)' writes 'prompt' to sys.stdout, reads sys.stdin until '\n' is received, and returns the preceding string. Note that devices differ on whether type-ahead works, and that input calls might never return. When a 'terminal' receives \r, it can ignore it, display something, or act on it by putting the cursor at the beginning of the line if . After moving to the beginning of the line, subsequent chars can overwrite, replace, or be inserted before existing characters, except that \t and \n may get special treatment. The code above assumes 'return' followed by replacement. If that assumption is wrong, as with the original ttys, '\r' instead of '\n' is the wrong choice of terminator. [snip] > which will write "1% complete" to the terminal and then put the cursor > (the "writing point") back to the start of the line.? Since there is no > carriage return character, it does *not* move on to a new line. I presume you meant either 'no newline' or 'just a carriage return' -- Terry Jan Reedy From flebber.crue at gmail.com Thu Aug 29 19:12:01 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 29 Aug 2019 16:12:01 -0700 (PDT) Subject: pandas loc on str lower for column comparison In-Reply-To: References: Message-ID: <025c6f92-57fd-465c-a3d5-20a5aefdaf9c@googlegroups.com> On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote: > Piet van Oostrum > > > So the correct way to do this is to make df1 a copy rather than a view. > > > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] > > Or maybe even make an explicit copy: > > df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() Thank you so much. Sayth From python at mrabarnett.plus.com Thu Aug 29 19:15:20 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 Aug 2019 00:15:20 +0100 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: <0f15bff5-be88-359d-3010-0636a6e44a83@mrabarnett.plus.com> On 2019-08-29 23:38, Hongyi Zhao wrote: > On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > >> I don't understand what's to not to understand. >> >> if condition: >> do_something_because_condition_is_true() >> else: >> do_something_because_condition_is_false() >> >> is a perfectly normal construction. If you mean something else, please >> be explicit. > > Let me say it more explicitly: > > The original code snippet's logic is as follows: > > if STREAM.isatty(): > p = (self.progress_template + '\r') % params > else: > [do something to reset the new value of p] > p = (self.progress_template + '\n') % params > STREAM.write(p) > STREAM.flush() > > > In order to refresh the tty, the if and else must be run alternatively. > i.e., the isatty() must return 0 and 1 periodically. > > I still understand how the above code will let the isatty() return 0 and > 1 in turn? > No. Either it's outputting to a TTY, or it isn't. If it detects that it's outputting to a TTY, it'll make the progress messages overwrite each other on the same line. This looks better on an interactive terminal than printing many lines and scrolling the display. If it detects that it's _not_ outputting to a TTY (probably a file), it'll write the progress messages one after another. This makes more sense in, say, a log file. From cs at cskk.id.au Thu Aug 29 19:22:45 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 30 Aug 2019 09:22:45 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: Message-ID: <20190829232245.GA84014@cskk.homeip.net> On 29Aug2019 22:38, Hongyi Zhao wrote: >On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: >The original code snippet's logic is as follows: > > if STREAM.isatty(): > p = (self.progress_template + '\r') % params > else: > [do something to reset the new value of p] > p = (self.progress_template + '\n') % params > STREAM.write(p) > STREAM.flush() > > >In order to refresh the tty, the if and else must be run alternatively. >i.e., the isatty() must return 0 and 1 periodically. > >I still understand how the above code will let the isatty() return 0 and >1 in turn? No, merely that the test is done every time this code runs. It will normally always return the same value. What you describe above is two distinct implementations of progress reporting, chosen accordin to the nature of the output stream. If the output stream is a terminal, it always writes a progress string and a carriage return, which will return the cursor to the start of the line. Notably, this never scrolls the display. The next call will overwrite what happened before. Otherwise, it writes the progress string and a newline on the premise that the output is a normal text file, such as a log file. So it just wants to write normal lines of text. Cheers, Cameron Simpson From tjreedy at udel.edu Thu Aug 29 19:24:42 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Aug 2019 19:24:42 -0400 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On 8/29/2019 10:16 AM, Eryk Sun wrote: > On 8/29/19, Rhodri James wrote: >> >> "isatty()" is a method of the io.IOBase class that checks to see >> if the stream is connected to a tty, or to use less jargon, if it is >> interactive. "tty" was I think originally an abbreviation for >> "teletype", but nowadays it refers to any terminal, anywhere you >> get a command line prompt. > > In Windows, isatty() is true for any character-type file. Does that mean one that can either send or receive data a character at a time, as opposed to a block at a time? > This does > not necessarily mean an interactive stream. In particular, NUL is a > character device: > > C:\>python -c "import sys;print(sys.stderr.isatty())" 2>NUL > True Aha. So this is why https://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html follows the doc for isatty, which says 'associated with a terminal device', with an information section that contradicts that with "The isatty() function does not necessarily indicate that a human being is available for interaction via fildes. It is quite possible that non-terminal devices are connected to the communications line." > But a pipe is not: > > C:\>python -c "import sys;print(sys.stderr.isatty())" 2>&1 | more > False What makes a pipe on Windows not a character file? Is data sent between processes a block at a time? Are posix pipes different? https://stackoverflow.com/questions/1312922/detect-if-stdin-is-a-terminal-or-pipe notes that 'cat | python' does not launch the REPL' and asks how to detect if connected to a pipe (or not a terminal). I presume the system in not Windows. The answers include both isatty and a stat call. For CPython, the answer is in the code. On Windows, I got the following with one 'Enter' after 'NUL' --- C:\Users\Terry>python 0>> --- It appears that Python sees NUL as a tty, as you said, and the first read indicated EndOfFile, nearly the same as entering ^Z. I don't understand the following. --- C:\Users\Terry>python -c "print('hello\n') | python hello Traceback (most recent call last): File "", line 1, in NameError: name 'python' is not defined --- This illustrates that pipe input is not seen as a tty as python exits without a prompt. --- C:\Users\Terry>py -c "print('''print('alpha')''')" | py alpha C:\Users\Terry> --- -- Terry Jan Reedy From flebber.crue at gmail.com Thu Aug 29 19:20:46 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 29 Aug 2019 16:20:46 -0700 (PDT) Subject: [SOLVED] Re: Compare zip lists where order is important In-Reply-To: References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> <5aad0993-df53-4bd7-becc-1c6a99034008@googlegroups.com> Message-ID: <2bf8af17-65c7-4f44-b340-11b252c8ed30@googlegroups.com> On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote: > Sayth Renshaw wrote: > > > will find the added > > pairs, but ignore the removed ones. Is that what you want? > > > > Yes, I think. I want to find the changed pairs. The people that moved team > > numbers. > > To find the people that moved team numbers I would tear the pairs apart. > Like: > > >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > >>> team_number = [1,1,2,2,3,3] > >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > >>> shuffle_team_number = [1,1,2,2,3,3] > >>> old = dict(zip(people, team_number)) > >>> new = dict(zip(shuffle_people, shuffle_team_number)) > >>> for name in old.keys() & new.keys(): > ... old_team = old[name] > ... new_team = new[name] > ... if old_team != new_team: > ... print(name, "went from", old_team, "to", new_team) > ... > Tim went from 1 to 2 > Fredricka went from 3 to 1 > Ally went from 2 to 3 The reason I opted away from Dictionaries is if there was a team with people with same name. Then the keys would be the same. So if Sally left and team 2 had one Tim move in and a new Tim start. shuffle_people = ["Fredricka","Bill","Tim","Tim","Ally","Fred"] shuffle_team_number = [1,1,2,2,3,3] becomes {'Fredricka': 1, 'Bill': 1, 'Tim': 2, 'Ally': 3, 'Fred': 3} This still appears to work but is wrong. for name in old.keys()& new.keys(): old_team = old[name] new_team = new[name] if old_team != new_team: print(name, "went from", old_team, "to", new_team) Ally went from 2 to 3 Tim went from 1 to 2 Fredricka went from 3 to 1 But I guess in reality I would use a UID and then look up the UID in a list or database. Cheers Sayth From __peter__ at web.de Thu Aug 29 19:29:48 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Aug 2019 01:29:48 +0200 Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: Hongyi Zhao wrote: > On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > >> I don't understand what's to not to understand. >> >> if condition: >> do_something_because_condition_is_true() >> else: >> do_something_because_condition_is_false() >> >> is a perfectly normal construction. If you mean something else, please >> be explicit. > > Let me say it more explicitly: > > The original code snippet's logic is as follows: > > if STREAM.isatty(): > p = (self.progress_template + '\r') % params > else: > [do something to reset the new value of p] > p = (self.progress_template + '\n') % params > STREAM.write(p) > STREAM.flush() > > > In order to refresh the tty, the if and else must be run alternatively. > i.e., the isatty() must return 0 and 1 periodically. > > I still understand how the above code will let the isatty() return 0 and > 1 in turn? Perhaps a simple example can help? $ cat checktty.py import sys stream = sys.stdout if stream.isatty(): message = "tty" else: message = "no tty" print(message, file=stream) When you run the script it prints to the terminal: $ python3 checktty.py tty But when you redirect to a pipe or into a file: $ python3 checktty.py | cat no tty $ python3 checktty.py > tmp.txt $ cat tmp.txt no tty From __peter__ at web.de Thu Aug 29 19:34:05 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Aug 2019 01:34:05 +0200 Subject: [SOLVED] Re: Compare zip lists where order is important References: <7e435a5f-be7f-4f64-bd1e-d8eb2f18a40c@googlegroups.com> <26c18b09-8079-4b07-83cb-d18c9a748855@googlegroups.com> <2f0d4eda-2e7e-4995-b5da-3cb3e15bd24c@googlegroups.com> <5aad0993-df53-4bd7-becc-1c6a99034008@googlegroups.com> <2bf8af17-65c7-4f44-b340-11b252c8ed30@googlegroups.com> Message-ID: Sayth Renshaw wrote: > On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote: >> Sayth Renshaw wrote: >> >> > will find the added >> > pairs, but ignore the removed ones. Is that what you want? >> > >> > Yes, I think. I want to find the changed pairs. The people that moved >> > team numbers. >> >> To find the people that moved team numbers I would tear the pairs apart. >> Like: >> >> >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] >> >>> team_number = [1,1,2,2,3,3] >> >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] >> >>> shuffle_team_number = [1,1,2,2,3,3] >> >>> old = dict(zip(people, team_number)) >> >>> new = dict(zip(shuffle_people, shuffle_team_number)) >> >>> for name in old.keys() & new.keys(): >> ... old_team = old[name] >> ... new_team = new[name] >> ... if old_team != new_team: >> ... print(name, "went from", old_team, "to", new_team) >> ... >> Tim went from 1 to 2 >> Fredricka went from 3 to 1 >> Ally went from 2 to 3 > > The reason I opted away from Dictionaries is if there was a team with > people with same name. Then the keys would be the same. > > So if Sally left and team 2 had one Tim move in and a new Tim start. > shuffle_people = ["Fredricka","Bill","Tim","Tim","Ally","Fred"] > shuffle_team_number = [1,1,2,2,3,3] > > becomes > {'Fredricka': 1, 'Bill': 1, 'Tim': 2, 'Ally': 3, 'Fred': 3} > > This still appears to work but is wrong. > > for name in old.keys()& new.keys(): > old_team = old[name] > new_team = new[name] > if old_team != new_team: > print(name, "went from", old_team, "to", new_team) > Ally went from 2 to 3 > Tim went from 1 to 2 > Fredricka went from 3 to 1 > > But I guess in reality I would use a UID and then look up the UID in a > list or database. It doesn't matter how you calculate the team changes; you always have to ensure unique players. From flebber.crue at gmail.com Thu Aug 29 19:36:30 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 29 Aug 2019 16:36:30 -0700 (PDT) Subject: pandas loc on str lower for column comparison In-Reply-To: References: Message-ID: On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote: > Piet van Oostrum writes: > > > So the correct way to do this is to make df1 a copy rather than a view. > > > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] > > Or maybe even make an explicit copy: > > df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() > -- > Piet van Oostrum > WWW: http://piet.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] I have tried both df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip() and df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip() But on both occasions I receive this error. # KeyError: 'the label [Current Team] is not in the [index]' if I test df1 before trying to create the new column it works just fine. Sayth From eryksun at gmail.com Fri Aug 30 03:10:00 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 30 Aug 2019 02:10:00 -0500 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On 8/29/19, Terry Reedy wrote: > On 8/29/2019 10:16 AM, Eryk Sun wrote: > >> In Windows, isatty() is true for any character-type file. > > Does that mean one that can either send or receive data a character at a > time, as opposed to a block at a time? Yes, any number of bytes can be written to a character device, whereas a block device will require some fixed number of bytes such as a 512-byte disk sector. WINAPI GetFileType classifies files for all of the following NT device types as FILE_TYPE_CHAR (akin to Unix S_IFCHR): FILE_DEVICE_CONSOLE FILE_DEVICE_NULL FILE_DEVICE_SERIAL_PORT FILE_DEVICE_PARALLEL_PORT FILE_DEVICE_KEYBOARD FILE_DEVICE_MOUSE FILE_DEVICE_MODEM FILE_DEVICE_PRINTER FILE_DEVICE_SCREEN FILE_DEVICE_SOUND FILE_DEVICE_CONSOLE is for the ConDrv console device, which was added in Windows 8. In previous versions, GetFileType special cases console pseudohandles. GetFileType classifies files for all of the following NT device types as FILE_TYPE_DISK (akin to Unix S_IFBLK): FILE_DEVICE_DISK FILE_DEVICE_VIRTUAL_DISK FILE_DEVICE_CD_ROM FILE_DEVICE_DISK_FILE_SYSTEM FILE_DEVICE_CD_ROM_FILE_SYSTEM FILE_DEVICE_DFS FILE_DEVICE_DATALINK FILE_DEVICE_CONTROLLER > Aha. So this is why > https://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html > follows the doc for isatty, which says 'associated with a terminal > device', with an information section that contradicts that with > "The isatty() function does not necessarily indicate that a human being > is available for interaction via fildes. It is quite possible that > non-terminal devices are connected to the communications line." As far as I know, only the Windows CRT classifies any character device as a TTY. Linux doesn't. "/dev/null" is a character device, but not a TTY. I think the CRT's _isatty implementation is wrong, though I'm not certain what the right answer looks like. Windows doesn't have any notion of a tty/pty terminal. I suppose it can just check for a console. For older versions of Windows that would be based on checking for a console pseudohandle. In Windows 8+, we can query NtQueryVolumeInformationFile: FileFsDeviceInformation to check for FILE_DEVICE_CONSOLE. (It would be useful if they exposed this in the Windows API, maybe as GetVolumeInformationByHandleEx, like what they did for GetFileInformationByHandleEx.) > What makes a pipe on Windows not a character file? Is data sent between > processes a block at a time? Are posix pipes different? FILE_TYPE_PIPE (akin to Unix S_IFIFO) is a type that accesses a section of shared memory that's used as an inter-process communication channel. Requesting a read on an empty pipe blocks until at least one byte is available. Requesting a write on a pipe blocks until there's available space for the write to complete, which may require multiple reads at the other end. (Note that Windows also classifies sockets as 'pipes', but Unix has a dedicated S_IFSOCK type for sockets.) A pipe channel can be inbound (client-write, server-read), outbound (server-write, client-read), or duplex (read-write on both ends). Anonymous pipes are in duplex mode but they're opened with access on each end that makes them effectively inbound mode. Windows also supports message-mode pipes, which handles each write as a message. A message-mode pipe can be configured to be read in either byte mode or message mode. (Pipes in most Unix systems do not support duplex and message modes.) In principle, a pipe can be used as the IPC channel for an interactive terminal. For example, MSYS2 does this with specially named pipes that its isatty() function special cases as a TTYs. But in general we expect pipes to be non-interactive, and for performance we default to full buffering with pipes instead of line buffering. Full buffering is incompatible with interactive usage. > I don't understand the following. > --- > C:\Users\Terry>python -c "print('hello\n') | python > hello > > Traceback (most recent call last): > File "", line 1, in > NameError: name 'python' is not defined The command line is missing the closing double quote around "print('hello\n')". In this case, CMD acts as if the whole statement is quoted, so the vertical bar is not interpreted as a pipe to a `python` command. Let's print the command line for the python.exe process in order to demonstrate this: C:\>python -c "import win32api;print(win32api.GetCommandLine()) | python python -c "import win32api;print(win32api.GetCommandLine()) | python Traceback (most recent call last): File "", line 1, in NameError: name 'python' is not defined From eryksun at gmail.com Fri Aug 30 03:31:52 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 30 Aug 2019 02:31:52 -0500 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: On 8/30/19, Eryk Sun wrote: > > GetFileType classifies files for all of the following NT device types > as FILE_TYPE_DISK (akin to Unix S_IFBLK): To clarify, file-system files and directories in a mounted file system on such as device are akin to Unix S_IFREG and S_IFDIR. Their file type is FILE_TYPE_DISK, but this is simply based on the underlying device type. If it's a file-system file, then GetFileAttributesW will succeed. FILE_TYPE_DISK is only akin to S_IFBLK when we open a volume or disk device directly, such as "//./C:" or "//./PhysicalDrive0". From greg.ewing at canterbury.ac.nz Fri Aug 30 03:42:52 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Aug 2019 19:42:52 +1200 Subject: An "Object" class? In-Reply-To: References: <86a7bspqzn.fsf@richard.bawden.org> Message-ID: Cristian Cocos wrote: >>>>type(print) > > > >>>>isinstance(print, builtin_function_or_method) > > Traceback (most recent call last): > File "", line 1, in > NameError: name 'builtin_function_or_method' is not defined > > Just curious why builtin_function_or_method doesn't work as an argument of > isinstance(). Because the type object in question is not bound to the name 'builtin_function_or_method' in the builtin namespace. There is a way to get at it, though: >>> import types >>> types.BuiltinFunctionType >>> isinstance(print, types.BuiltinFunctionType) True When it comes to objects that form part of the interpreter's internal machinery, the names shown when you print their types are often just suggestive and aren't meant to be taken literally. Most of them are available in the 'types' module, however, possibly under different names. The reasons for all this are buried in a lot of messy history. > The bottom line is that I am trying to figure out where exactly the world > of Python types _diverges from_ what I would expect as a mathematician. It > makes it easier for me to learn Python this way. I'm not sure that focusing on classes as mathematical sets is all that useful. In Python, what class an object belongs to isn't usually very important. Much more relevant is how the object *behaves*. We call this "duck typing" -- if it walks like a duck and quacks like a duck then it might as well be a duck, even if it doesn't belong to a class called "Duck". This is why Python doesn't have e.g. an elaborate tower of numeric types as is seen in some other languages. It just isn't necessary for getting things done, and Python, being a very pragmatic language, is all about getting things done. -- Greg From hongyi.zhao at gmail.com Fri Aug 30 03:49:11 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Aug 2019 07:49:11 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, 30 Aug 2019 01:29:48 +0200, Peter Otten wrote: > Perhaps a simple example can help? > > $ cat checktty.py import sys > > stream = sys.stdout > > if stream.isatty(): > message = "tty" > else: > message = "no tty" > print(message, file=stream) > > When you run the script it prints to the terminal: > > $ python3 checktty.py tty > > But when you redirect to a pipe or into a file: > > $ python3 checktty.py | cat no tty > > $ python3 checktty.py > tmp.txt $ cat tmp.txt no tty But, see my example: $ cat check-isatty.py import sys import time if sys.stderr.isatty(): p = 'tty ' + '\r' else: p = 'no tty ' + '\n' sys.stderr.write(p) sys.stderr.flush() time.sleep(1.0) I run both of the following commands: $ python check-isatty.py $ python check-isatty.py | cat Both will output `tty'. So still I cannot figure out the issue. Regards From rosuav at gmail.com Fri Aug 30 03:53:02 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Aug 2019 17:53:02 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, Aug 30, 2019 at 5:51 PM Hongyi Zhao wrote: > > On Fri, 30 Aug 2019 01:29:48 +0200, Peter Otten wrote: > > > Perhaps a simple example can help? > > > > $ cat checktty.py import sys > > > > stream = sys.stdout > > > > if stream.isatty(): > > message = "tty" > > else: > > message = "no tty" > > print(message, file=stream) > > > > When you run the script it prints to the terminal: > > > > $ python3 checktty.py tty > > > > But when you redirect to a pipe or into a file: > > > > $ python3 checktty.py | cat no tty > > > > $ python3 checktty.py > tmp.txt $ cat tmp.txt no tty > > > But, see my example: > > $ cat check-isatty.py > import sys > import time > > if sys.stderr.isatty(): > p = 'tty ' + '\r' > else: > p = 'no tty ' + '\n' > > sys.stderr.write(p) > sys.stderr.flush() > time.sleep(1.0) > > > I run both of the following commands: > > $ python check-isatty.py > $ python check-isatty.py | cat > > Both will output `tty'. So still I cannot figure out the issue. > That's because sys.stderr is never changing in your example here. Try checking whether sys.stdout is a TTY instead. (Also, why the sleep? Seems unnecessary.) ChrisA From hongyi.zhao at gmail.com Fri Aug 30 04:33:31 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Aug 2019 08:33:31 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > I don't understand what's to not to understand. > > if condition: > do_something_because_condition_is_true() > else: > do_something_because_condition_is_false() > > is a perfectly normal construction. If you mean something else, please > be explicit. I've read some more thing on the python 3 's print, seems for the isatty () discussed here is completely can done with using it by something like: print(p, end='\r', flush=True) Regards From rosuav at gmail.com Fri Aug 30 04:42:51 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Aug 2019 18:42:51 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, Aug 30, 2019 at 6:36 PM Hongyi Zhao wrote: > > On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > > > I don't understand what's to not to understand. > > > > if condition: > > do_something_because_condition_is_true() > > else: > > do_something_because_condition_is_false() > > > > is a perfectly normal construction. If you mean something else, please > > be explicit. > > I've read some more thing on the python 3 's print, seems for the isatty > () discussed here is completely can done with using it by something like: > > print(p, end='\r', flush=True) > No, it can't. That will still do the same thing whether you're outputting to a file or a console. The whole point of isatty() is to log *differently* in those cases. There is no magic here. It is simply asking a question, and then making a decision based on the answer. ChrisA From lukasz at langa.pl Fri Aug 30 05:09:37 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Fri, 30 Aug 2019 11:09:37 +0200 Subject: [RELEASE] ACTION REQUIRED: Python 3.8.0b4 now available for testing Message-ID: It's time for the last beta release of Python 3.8. Go find it at: https://www.python.org/downloads/release/python-380b4/ This release is the last of four planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. The next pre-release of Python 3.8 will be 3.8.0c1, the first release candidate, currently scheduled for 2019-09-30. Call to action We strongly encourage maintainers of third-party Python projects to test with 3.8 during the beta phase and report issues found to the Python bug tracker as soon as possible. Please note this is the last beta release, there is not much time left to identify and fix issues before the release of 3.8.0. If you were hesitating trying it out before, now is the time. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (2019-09-30). Our goal is have no ABI changes after beta 3 and no code changes after 3.8.0c1, the release candidate. To achieve that, it will be extremely important to get as much exposure for 3.8 as possible during the beta phase. That beta phase is coming to an end. Please test now. Please keep in mind that this is a preview release and its use is not recommended for production environments. Acknowledgments Many developers worked hard for the past four weeks to squash remaining bugs, some requiring non-obvious decisions. Many thanks to the most active, namely Raymond Hettinger, Steve Dower, Victor Stinner, Terry Jan Reedy, Serhiy Storchaka, Pablo Galindo Salgado, Tal Einat, Zackery Spytz, Ronald Oussoren, Neil Schemenauer, Inada Naoki, Christian Heimes, and Andrew Svetlov. 3.8.0 would not reach the Last Beta without you. Thank you! - ? -------------- 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 hongyi.zhao at gmail.com Fri Aug 30 06:56:45 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Aug 2019 10:56:45 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: > That's because sys.stderr is never changing in your example here. Try > checking whether sys.stdout is a TTY instead. OMG, thanks a lot, this does the trick. > > (Also, why the sleep? Seems unnecessary.) Because without using sleep, the stuff on screen will display very shortly and then disappear. Is this not your testing result? From hongyi.zhao at gmail.com Fri Aug 30 07:05:18 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Aug 2019 11:05:18 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, 30 Aug 2019 18:42:51 +1000, Chris Angelico wrote: > There is no magic here. It is simply asking a question, and then making > a decision based on the answer. What's your mean by saying this? Sorry for my poor English. From cristi at ieee.org Fri Aug 30 12:18:02 2019 From: cristi at ieee.org (Cristian Cocos) Date: Fri, 30 Aug 2019 12:18:02 -0400 Subject: An "Object" class? In-Reply-To: References: <86a7bspqzn.fsf@richard.bawden.org> Message-ID: Thank you! Will give the "types" module a whirl. Otherwise, the whole idea behind building a rigorous taxonomical hierarchy ("taxonomy") is to provide a simpler management of the wealth of features objects have. And that is because entities belonging to the same taxonomical class ("clade") have common features, and also inherit the features of the taxonomical parent. A kosher type hierarchy (or class taxonomy) is thus meant to answer precisely your concern about entity/object behavior. Now, it may be that this was not the intention of Python developers when they came up with the breakdown of the class of objects into types/classes, in which case the term "type" and derivatives (subtype, supertype etc.) used in this context is nothing but a regrettable misnomer. Then maybe I should re-direct my quest away from studying the type hierarchy, toward asking for built-in-object inheritance: Is there a diagram of built-in-object inheritance available anywhere? Many thanks for the clarifications, C On Fri, Aug 30, 2019 at 3:47 AM Gregory Ewing wrote: > Cristian Cocos wrote: > > >>>>type(print) > > > > > > > >>>>isinstance(print, builtin_function_or_method) > > > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'builtin_function_or_method' is not defined > > > > Just curious why builtin_function_or_method doesn't work as an argument > of > > isinstance(). > > Because the type object in question is not bound to the name > 'builtin_function_or_method' in the builtin namespace. There > is a way to get at it, though: > > >>> import types > >>> types.BuiltinFunctionType > > >>> isinstance(print, types.BuiltinFunctionType) > True > > When it comes to objects that form part of the interpreter's > internal machinery, the names shown when you print their types > are often just suggestive and aren't meant to be taken literally. > Most of them are available in the 'types' module, however, > possibly under different names. The reasons for all this are > buried in a lot of messy history. > > > The bottom line is that I am trying to figure out where exactly the world > > of Python types _diverges from_ what I would expect as a mathematician. > It > > makes it easier for me to learn Python this way. > > I'm not sure that focusing on classes as mathematical sets is all > that useful. In Python, what class an object belongs to isn't > usually very important. Much more relevant is how the object > *behaves*. We call this "duck typing" -- if it walks like a duck > and quacks like a duck then it might as well be a duck, even if > it doesn't belong to a class called "Duck". > > This is why Python doesn't have e.g. an elaborate tower of > numeric types as is seen in some other languages. It just isn't > necessary for getting things done, and Python, being a very > pragmatic language, is all about getting things done. > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King From torriem at gmail.com Fri Aug 30 12:25:10 2019 From: torriem at gmail.com (Michael Torrie) Date: Fri, 30 Aug 2019 10:25:10 -0600 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, Aug 30, 2019, 05:02 Hongyi Zhao On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: > > (Also, why the sleep? Seems unnecessary.) > > Because without using sleep, the stuff on screen will display very > shortly and then disappear. Is this not your testing result? No it is not. What kind of terminal are you using? From rosuav at gmail.com Fri Aug 30 12:49:48 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Aug 2019 02:49:48 +1000 Subject: An "Object" class? In-Reply-To: References: <86a7bspqzn.fsf@richard.bawden.org> Message-ID: On Sat, Aug 31, 2019 at 2:19 AM Cristian Cocos wrote: > > Thank you! Will give the "types" module a whirl. > > Otherwise, the whole idea behind building a rigorous taxonomical hierarchy > ("taxonomy") is to provide a simpler management of the wealth of features > objects have. And that is because entities belonging to the same > taxonomical class ("clade") have common features, and also inherit the > features of the taxonomical parent. A kosher type hierarchy (or class > taxonomy) is thus meant to answer precisely your concern about > entity/object behavior. Now, it may be that this was not the intention of > Python developers when they came up with the breakdown of the class of > objects into types/classes, in which case the term "type" and derivatives > (subtype, supertype etc.) used in this context is nothing but a regrettable > misnomer. Then maybe I should re-direct my quest away from studying the > type hierarchy, toward asking for built-in-object inheritance: Is there a > diagram of built-in-object inheritance available anywhere? > Even in biology, taxonomy has its limitations. For instance, you might assert that all birds can fly, and therefore that all members of a subclass of birds can fly; but the Emu would like to have a word with you. Or you might posit that all mammals give birth to live young, but then Platypus would give you a taste of its spur. [1] In software design, the same kinds of exceptions do occur. By and large, principles like "anywhere that you could use the superclass, you can equivalently use a subclass of it" will hold true, but there are good reasons to go against them sometimes. So if you're looking for absolute hard-and-fast taxonomic rules about Python types, you won't find them... but you CAN expect things to generally follow rules like LSP. That means that, for instance, any operation valid on an instance of the vanilla 'object' type can be done on literally any object in Python, and anything you can do with the 'type' type can be done with any Python class. Notably, since "type" is a subclass of "object", this means that you can manipulate types the same way that you manipulate anything else. As to a diagram of built-in objects... this might be of some help: https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy It's not fully comprehensive, but it hopefully will have some useful information. Another neat trick is that all types have a __subclasses__() method, so you can sometimes build up your hierarchy that way: >>> LookupError.__subclasses__() [, , ] Start from 'object' and delve from there. And when you hit 'type' in your exploration, you'll learn something about re-entrant hierarchies and how descriptors work :) ChrisA [1] One valid counter-argument here is that Australia is just plain weird. I've lived here all my life, and it's certainly true. From rosuav at gmail.com Fri Aug 30 12:50:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Aug 2019 02:50:45 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Sat, Aug 31, 2019 at 2:26 AM Michael Torrie wrote: > > On Fri, Aug 30, 2019, 05:02 Hongyi Zhao > > On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: > > > (Also, why the sleep? Seems unnecessary.) > > > > Because without using sleep, the stuff on screen will display very > > shortly and then disappear. Is this not your testing result? > > > No it is not. What kind of terminal are you using? Probably a Windows computer and just double-clicking on the program to make it do stuff. Recommendation: If that's the case, get an actual terminal. Learn to use it. ChrisA From tjreedy at udel.edu Fri Aug 30 13:34:04 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Aug 2019 13:34:04 -0400 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> Message-ID: Eric, thank you for the detailed answer. I stashed it away for future review ;-). On 8/30/2019 3:10 AM, Eryk Sun wrote: > On 8/29/19, Terry Reedy wrote: >> On 8/29/2019 10:16 AM, Eryk Sun wrote: >> >>> In Windows, isatty() is true for any character-type file. >> >> Does that mean one that can either send or receive data a character at a >> time, as opposed to a block at a time? > > Yes, any number of bytes can be written to a character device, whereas > a block device will require some fixed number of bytes such as a > 512-byte disk sector. > > WINAPI GetFileType classifies files for all of the following NT device > types as FILE_TYPE_CHAR (akin to Unix S_IFCHR): > > FILE_DEVICE_CONSOLE > FILE_DEVICE_NULL > FILE_DEVICE_SERIAL_PORT > FILE_DEVICE_PARALLEL_PORT > FILE_DEVICE_KEYBOARD > FILE_DEVICE_MOUSE > FILE_DEVICE_MODEM > FILE_DEVICE_PRINTER > FILE_DEVICE_SCREEN > FILE_DEVICE_SOUND > > FILE_DEVICE_CONSOLE is for the ConDrv console device, which was added > in Windows 8. In previous versions, GetFileType special cases console > pseudohandles. > > GetFileType classifies files for all of the following NT device types > as FILE_TYPE_DISK (akin to Unix S_IFBLK): > > FILE_DEVICE_DISK > FILE_DEVICE_VIRTUAL_DISK > FILE_DEVICE_CD_ROM > FILE_DEVICE_DISK_FILE_SYSTEM > FILE_DEVICE_CD_ROM_FILE_SYSTEM > FILE_DEVICE_DFS > FILE_DEVICE_DATALINK > FILE_DEVICE_CONTROLLER > >> Aha. So this is why >> https://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html >> follows the doc for isatty, which says 'associated with a terminal >> device', with an information section that contradicts that with >> "The isatty() function does not necessarily indicate that a human being >> is available for interaction via fildes. It is quite possible that >> non-terminal devices are connected to the communications line." > > As far as I know, only the Windows CRT classifies any character device > as a TTY. Linux doesn't. "/dev/null" is a character device, but not a > TTY. > > I think the CRT's _isatty implementation is wrong, though I'm not > certain what the right answer looks like. Windows doesn't have any > notion of a tty/pty terminal. I suppose it can just check for a > console. For older versions of Windows that would be based on checking > for a console pseudohandle. In Windows 8+, we can query > NtQueryVolumeInformationFile: FileFsDeviceInformation to check for > FILE_DEVICE_CONSOLE. (It would be useful if they exposed this in the > Windows API, maybe as GetVolumeInformationByHandleEx, like what they > did for GetFileInformationByHandleEx.) > >> What makes a pipe on Windows not a character file? Is data sent between >> processes a block at a time? Are posix pipes different? > > FILE_TYPE_PIPE (akin to Unix S_IFIFO) is a type that accesses a > section of shared memory that's used as an inter-process communication > channel. Requesting a read on an empty pipe blocks until at least one > byte is available. Requesting a write on a pipe blocks until there's > available space for the write to complete, which may require multiple > reads at the other end. (Note that Windows also classifies sockets as > 'pipes', but Unix has a dedicated S_IFSOCK type for sockets.) > > A pipe channel can be inbound (client-write, server-read), outbound > (server-write, client-read), or duplex (read-write on both ends). > Anonymous pipes are in duplex mode but they're opened with access on > each end that makes them effectively inbound mode. Windows also > supports message-mode pipes, which handles each write as a message. A > message-mode pipe can be configured to be read in either byte mode or > message mode. (Pipes in most Unix systems do not support duplex and > message modes.) > > In principle, a pipe can be used as the IPC channel for an interactive > terminal. For example, MSYS2 does this with specially named pipes that > its isatty() function special cases as a TTYs. But in general we > expect pipes to be non-interactive, and for performance we default to > full buffering with pipes instead of line buffering. Full buffering is > incompatible with interactive usage. > >> I don't understand the following. >> --- >> C:\Users\Terry>python -c "print('hello\n') | python >> hello >> >> Traceback (most recent call last): >> File "", line 1, in >> NameError: name 'python' is not defined > > The command line is missing the closing double quote around > "print('hello\n')". In this case, CMD acts as if the whole statement > is quoted, so the vertical bar is not interpreted as a pipe to a > `python` command. Let's print the command line for the python.exe > process in order to demonstrate this: > > C:\>python -c "import win32api;print(win32api.GetCommandLine()) | python > python -c "import win32api;print(win32api.GetCommandLine()) | python > Traceback (most recent call last): > File "", line 1, in > NameError: name 'python' is not defined > -- Terry Jan Reedy From eryksun at gmail.com Fri Aug 30 15:38:27 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 30 Aug 2019 14:38:27 -0500 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On 8/30/19, Chris Angelico wrote: > On Sat, Aug 31, 2019 at 2:26 AM Michael Torrie wrote: >> On Fri, Aug 30, 2019, 05:02 Hongyi Zhao > >>> Because without using sleep, the stuff on screen will display very >>> shortly and then disappear. Is this not your testing result? >> >> No it is not. What kind of terminal are you using? > > Probably a Windows computer and just double-clicking on the program to > make it do stuff. > > Recommendation: If that's the case, get an actual terminal. Learn to use > it. Or simply run python.exe from another console process that keeps the console alive (it's reference counted), which is typically cmd.exe or powershell.exe. Or have the script spawn a process that keeps the console alive (e.g. subprocess.Popen('cmd')). Or configure .py files to use the py.exe launcher and change the shebang to `#!python3 -i` when testing a script, which runs the REPL after the script terminates. From rosuav at gmail.com Fri Aug 30 15:56:46 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Aug 2019 05:56:46 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Sat, Aug 31, 2019 at 5:40 AM Eryk Sun wrote: > > On 8/30/19, Chris Angelico wrote: > > On Sat, Aug 31, 2019 at 2:26 AM Michael Torrie wrote: > >> On Fri, Aug 30, 2019, 05:02 Hongyi Zhao >> > >>> Because without using sleep, the stuff on screen will display very > >>> shortly and then disappear. Is this not your testing result? > >> > >> No it is not. What kind of terminal are you using? > > > > Probably a Windows computer and just double-clicking on the program to > > make it do stuff. > > > > Recommendation: If that's the case, get an actual terminal. Learn to use > > it. > > Or simply run python.exe from another console process that keeps the > console alive (it's reference counted), which is typically cmd.exe or > powershell.exe. Not sure what you mean by "reference counted", but yes, if you start python.exe as a child of some shell such as cmd.exe, then the terminal that cmd.exe is running in will remain. That is the most normal way to do things. Of course, most of us use a shell that's a tad more powerful than cmd.exe, but the effect is the same regardless. ChrisA From tascioglu.tansu at gmail.com Fri Aug 30 16:26:00 2019 From: tascioglu.tansu at gmail.com (tascioglu.tansu at gmail.com) Date: Fri, 30 Aug 2019 13:26:00 -0700 (PDT) Subject: multiple lines in one line Message-ID: <753c9db5-f66d-4579-91ef-fc8ada156b0f@googlegroups.com> Hello,I working on some file operations with python.I have 2 text file which is consist of lines such as apple_pie 0.3434 0.6767 0.2312 and other text file has apple 0.2334 0.3412 0.123 pie 0.976 0.75654 0.2312 I want to append lines like apple_pie 0.3434 0.6767 0.2312 0.2334 0.3412 0.123(values for apple) 0.976 0.75654 0.2312(values for pie) in one line. does anybody know how to do it ?Thanks... From PythonList at DancesWithMice.info Fri Aug 30 17:14:04 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 31 Aug 2019 09:14:04 +1200 Subject: multiple lines in one line In-Reply-To: <753c9db5-f66d-4579-91ef-fc8ada156b0f@googlegroups.com> References: <753c9db5-f66d-4579-91ef-fc8ada156b0f@googlegroups.com> Message-ID: <6e4668f6-6d0b-4ed3-e23d-9a8bd97ef963@DancesWithMice.info> On 31/08/19 8:26 AM, tascioglu.tansu at gmail.com wrote: > Hello,I working on some file operations with python.I have 2 text file which is consist of lines such as apple_pie 0.3434 0.6767 0.2312 and other text file has apple 0.2334 0.3412 0.123 > pie 0.976 0.75654 0.2312 > I want to append lines like apple_pie 0.3434 0.6767 0.2312 0.2334 0.3412 0.123(values for apple) 0.976 0.75654 0.2312(values for pie) in one line. does anybody know how to do it ?Thanks... This is a very broad question. Is it a homework assignment? First find a consistent relationship between the three words: "apple_pie", "apple", and "pie" - is the first always a combination of the others? ... always separated by an under-score/under-line? ...always in the same sequence of words? Are the two files sorted in a 1:1 relationship, ie so that the nth-record from one 'matches' the nth-record from the other - or is record-matching part of the problem? To solve any ComSc problem think about how it can be split into sub-problems. The analogy that is often used, talks about peeling-back the successive layers of an onion. Reduce the size of the problem being considered, until each sub-problem is small-enough for you to (understand how to) solve. Below, are several functions addressing possible sub-problems. Solving one sub-problem can then feed its 'answer' into solving a 'larger' problem... Possibly useful functions: - take a string and split it into 'first word' and 'rest of line' - take a two-word string and split it into the two separate words - take a two-part record and given the two independent words, split it, and return its two components (plus, building sub-problem solutions as Python functions enables us to thoroughly test each function separately - to ensure it 'does the job', before moving-on to the next, ie before things become ever-more complex and testing 'the whole thing' reveals an error without giving ideas as to 'when/where' things went-wrong!) If you come back to us, please add more data examples (otherwise the answer becomes: find( "apple" )!), plus sample code showing the progress you've made to-date... -- Regards =dn From eryksun at gmail.com Fri Aug 30 17:40:58 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 30 Aug 2019 16:40:58 -0500 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On 8/30/19, Chris Angelico wrote: > On Sat, Aug 31, 2019 at 5:40 AM Eryk Sun wrote: > >> Or simply run python.exe from another console process that keeps the >> console alive (it's reference counted), which is typically cmd.exe or >> powershell.exe. > > Not sure what you mean by "reference counted" In Windows 8+, a process attaches to a console by opening "\Device\ConDrv\Connect" as a connection to an instance of the console host process, conhost.exe. This handle is stored internally as "ConsoleHandle" (in its PEB->ProcessParameters). The console API uses this handle for functions that don't operate on a stream, such as GetConsoleTitle. Every open instance of this "Connect" file that connects a process to a console is a reference on the console that keeps it alive. And every handle for a kernel File object is a counted reference on the object. Thus if we call DuplicateHandle to duplicate the connection handle to another process that's not technically 'attached' to the console, then even if we close all processes attached to the console, the console will not be destroyed until the duplicate handle for the connection is closed. Other console files that have this property are "CON" (i.e. "\Device\ConDrv\Console"), "CONIN$" (i.e. "\Device\ConDrv\CurrentIn") and "CONOUT$" (i.e. "\Device\ConDrv\CurrentOut"). When opened, these files reference the active input or output stream of the currently attached console, and they keep the console alive. However, they only work for I/O when we're attached to the referenced console, so this property isn't really useful. Attaching to a console via WINAPI AttachConsole requires the PID of a process that's already attached to the console (and thus keeping it alive). On the other hand, by default a console process starts with its StandardInput handle set to a generic console input file (i.e. "\Device\ConDrv\Input") and its StandardOutput and StandardError handles set to a generic console output file (i.e. "\Device\ConDrv\Output"). These generic files work with any console connection, and they do not keep a console alive. The implementation details of the console are completely different prior to Windows 8, and not all behaviors are consistent with the above description. But Windows 7 is almost at end of life. > Of course, most of us use a shell that's a tad more powerful than > cmd.exe, but the effect is the same regardless. Yes, CMD is not a great shell, and PowerShell is tedious (IMO). We can use bash.exe from MSYS2 or Git instead. But stick to the normal console interface (i.e. run bash.exe directly), or use winpty if you need to run Windows Python. The MSYS2 terminal interface (mintty) is based on named pipes. Its build of Python special cases these pipes, but they're just pipes to the Windows build, so isatty() is false and it defaults to full buffering. Also, the REPL of the Windows build depends on the system console for line editing and history, so even if we force interactive mode via `python -i`, the UI is horrible without a console. From rosuav at gmail.com Fri Aug 30 17:50:21 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Aug 2019 07:50:21 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Sat, Aug 31, 2019 at 7:42 AM Eryk Sun wrote: > > On 8/30/19, Chris Angelico wrote: > > On Sat, Aug 31, 2019 at 5:40 AM Eryk Sun wrote: > > > >> Or simply run python.exe from another console process that keeps the > >> console alive (it's reference counted), which is typically cmd.exe or > >> powershell.exe. > > > > Not sure what you mean by "reference counted" > > In Windows 8+, a process attaches to a console by opening > "\Device\ConDrv\Connect" as a connection to an instance of the console > host process, conhost.exe. This handle is stored internally as > "ConsoleHandle" (in its PEB->ProcessParameters). The console API uses > this handle for functions that don't operate on a stream, such as > GetConsoleTitle. > [chomp more details] Huh. I kinda just assumed that, since cmd.exe was still running, the console would continue to be in use. I guess technically it's a lot more complicated than that, but still, to the average user, the difference won't be visible. > > Of course, most of us use a shell that's a tad more powerful than > > cmd.exe, but the effect is the same regardless. > > Yes, CMD is not a great shell, and PowerShell is tedious (IMO). We can > use bash.exe from MSYS2 or Git instead. But stick to the normal > console interface (i.e. run bash.exe directly), or use winpty if you > need to run Windows Python. The MSYS2 terminal interface (mintty) is > based on named pipes. Its build of Python special cases these pipes, > but they're just pipes to the Windows build, so isatty() is false and > it defaults to full buffering. Also, the REPL of the Windows build > depends on the system console for line editing and history, so even if > we force interactive mode via `python -i`, the UI is horrible without > a console. And that's why the pseudo-tty system is vital to making things make sense. On Unix-like platforms, a tool like ssh can connect a program to something that it perceives as a TTY, and then take the contents elsewhere. It's a consistent system that works with any program. Oh, and, well, GNU Readline is just a smidge better than the default Windows line editing, too... ChrisA From piet-l at vanoostrum.org Fri Aug 30 18:22:49 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sat, 31 Aug 2019 00:22:49 +0200 Subject: pandas loc on str lower for column comparison References: Message-ID: Sayth Renshaw writes: > > I have tried both > > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] > df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == > df1.loc['New Team'].str.lower().str.strip() > > and > > df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() > df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == > df1.loc['New Team'].str.lower().str.strip() > > But on both occasions I receive this error. > > # KeyError: 'the label [Current Team] is not in the [index]' > > if I test df1 before trying to create the new column it works just fine. > > Sayth What does df1.info() produce? Which versions of numpy, scipy and pandas are you using? It would be helpful if you could make a copy of the original .xlsx file available. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From eryksun at gmail.com Fri Aug 30 18:56:45 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 30 Aug 2019 17:56:45 -0500 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On 8/30/19, Chris Angelico wrote: > On Sat, Aug 31, 2019 at 7:42 AM Eryk Sun wrote: > >> In Windows 8+, a process attaches to a console by opening >> "\Device\ConDrv\Connect" as a connection to an instance of the console >> host process, conhost.exe. This handle is stored internally as >> "ConsoleHandle" (in its PEB->ProcessParameters). The console API uses >> this handle for functions that don't operate on a stream, such as >> GetConsoleTitle. >> [chomp more details] > > Huh. I kinda just assumed that, since cmd.exe was still running, the > console would continue to be in use. I guess technically it's a lot > more complicated than that, but still, to the average user, the > difference won't be visible. I was just clarifying the implementation details of what kind of reference is used to keep a console alive in Windows 8+. To me the details are useful to flesh out a picture of how things work, so that I know what to look for when they fail to work. For the average user and average use case, all that we need to know is that at least one process has to be attached to the console to keep it alive. > And that's why the pseudo-tty system is vital to making things make > sense. On Unix-like platforms, a tool like ssh can connect a program > to something that it perceives as a TTY, and then take the contents > elsewhere. It's a consistent system that works with any program. Windows 10 has pseudoconsole support. I think the new Windows terminal that's available in preview builds is based on this, but I haven't experimented with it yet. Note that the console host process (conhost.exe) is still in the loop. It works in this case as a headless subsystem server (i.e. it doesn't create a window) that sits in between the application and the terminal. The application<->ConHost interface is still mediated in the kernel via the ConDrv console device. But ConDrv is kept relatively simple. Most of the console subsystem is implemented in the user-mode ConHost server process (in coordination with the session subsystem process, CSRSS). The terminal communicates with ConHost using a pair of pipes for I/O that stream UTF-8 text with inline virtual-terminal sequences. > Oh, and, well, GNU Readline is just a smidge better than the default > Windows line editing, too... There's pyreadline in Windows, which uses ctypes to access the console at a low level in order to emulate GNU Readline. PowerShell has a similar PSRreadline library that's enabled by default. It can be configured to use Emacs or Vi mode, but it defaults to Windows mode, which emulates the console's builtin line editing. From cs at cskk.id.au Fri Aug 30 18:57:55 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 31 Aug 2019 08:57:55 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: Message-ID: <20190830225755.GA11771@cskk.homeip.net> On 30Aug2019 10:25, Michael Torrie wrote: >On Fri, Aug 30, 2019, 05:02 Hongyi Zhao > On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: >> > (Also, why the sleep? Seems unnecessary.) >> >> Because without using sleep, the stuff on screen will display very >> shortly and then disappear. Is this not your testing result? > >No it is not. What kind of terminal are you using? Note that testing this stuff in a regular terminal will us the \r version. Which leaves the cursor at the left end of the progress display. Where it will be overwritten by your prompt, depending on the shell. So what he describes is entirely possible on UNIX. Cheers, Cameron Simpson From rosuav at gmail.com Fri Aug 30 19:07:12 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Aug 2019 09:07:12 +1000 Subject: if STREAM.isatty(): In-Reply-To: References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Sat, Aug 31, 2019 at 8:58 AM Eryk Sun wrote: > > On 8/30/19, Chris Angelico wrote: > > On Sat, Aug 31, 2019 at 7:42 AM Eryk Sun wrote: > > > >> In Windows 8+, a process attaches to a console by opening > >> "\Device\ConDrv\Connect" as a connection to an instance of the console > >> host process, conhost.exe. This handle is stored internally as > >> "ConsoleHandle" (in its PEB->ProcessParameters). The console API uses > >> this handle for functions that don't operate on a stream, such as > >> GetConsoleTitle. > >> [chomp more details] > > > > Huh. I kinda just assumed that, since cmd.exe was still running, the > > console would continue to be in use. I guess technically it's a lot > > more complicated than that, but still, to the average user, the > > difference won't be visible. > > I was just clarifying the implementation details of what kind of > reference is used to keep a console alive in Windows 8+. To me the > details are useful to flesh out a picture of how things work, so that > I know what to look for when they fail to work. For the average user > and average use case, all that we need to know is that at least one > process has to be attached to the console to keep it alive. Yes, and I appreciate the info from the perspective of curiosity! Even though it won't make a difference most of the time, it's still cool to know. ChrisA From cs at cskk.id.au Fri Aug 30 19:11:22 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 31 Aug 2019 09:11:22 +1000 Subject: if STREAM.isatty(): In-Reply-To: <20190830225755.GA11771@cskk.homeip.net> References: <20190830225755.GA11771@cskk.homeip.net> Message-ID: <20190830231122.GA45485@cskk.homeip.net> On 31Aug2019 08:57, Cameron Simpson wrote: >On 30Aug2019 10:25, Michael Torrie wrote: >>On Fri, Aug 30, 2019, 05:02 Hongyi Zhao >>On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: >>>> (Also, why the sleep? Seems unnecessary.) >>> >>>Because without using sleep, the stuff on screen will display very >>>shortly and then disappear. Is this not your testing result? >> >>No it is not. What kind of terminal are you using? > >Note that testing this stuff in a regular terminal will us the \r >version. Which leaves the cursor at the left end of the progress >display. Where it will be overwritten by your prompt, depending on the >shell. > >So what he describes is entirely possible on UNIX. And just further to this. It is more common to write his one-line update not as: progress_status+'\r' as he has it, which leaves the cursor at the left ready to overwrite things, but as: '\r' + progress_status which backs up to the start of the line, writes the status, and leaves the cursor at the end. The latter has the advantage that any subsequent output (egthe shell prompt after the programmke exits) will not overwrite the status string. Cheers, Cameron Simpson From hongyi.zhao at gmail.com Fri Aug 30 19:56:46 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 30 Aug 2019 23:56:46 +0000 (UTC) Subject: if STREAM.isatty(): References: <413b4f52-e79c-00dc-e125-bf0b4364541d@kynesim.co.uk> <2e0a8015-f053-40d0-b3a8-7d5fd393c2f5@kynesim.co.uk> <1c557fe8-dbb6-383c-285a-363e86047084@kynesim.co.uk> Message-ID: On Fri, 30 Aug 2019 10:25:10 -0600, Michael Torrie wrote: > No it is not. What kind of terminal are you using? I use Debian 9 with gnome desktop and the default gnome terminal. From hongyi.zhao at gmail.com Fri Aug 30 20:05:46 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Sat, 31 Aug 2019 00:05:46 +0000 (UTC) Subject: if STREAM.isatty(): References: <20190830225755.GA11771@cskk.homeip.net> <20190830231122.GA45485@cskk.homeip.net> Message-ID: On Sat, 31 Aug 2019 09:11:22 +1000, Cameron Simpson wrote: > '\r' + progress_status > > which backs up to the start of the line, writes the status, and leaves > the cursor at the end. > > The latter has the advantage that any subsequent output (egthe shell > prompt after the programmke exits) will not overwrite the status string. Thanks a lot for your revision, it makes the status more clear on using this trick. From jasonanyilian at gmail.com Sat Aug 31 02:31:55 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Fri, 30 Aug 2019 23:31:55 -0700 (PDT) Subject: Python Editor for mobile Message-ID: <2f024408-5dce-49e7-8dbf-778f095714a0@googlegroups.com> Are there any good editors on Apple that don't cost money and already has matplotlib, numpy, and other modules already installed? From greg.ewing at canterbury.ac.nz Sat Aug 31 03:07:42 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 31 Aug 2019 19:07:42 +1200 Subject: An "Object" class? In-Reply-To: References: <86a7bspqzn.fsf@richard.bawden.org> Message-ID: Cristian Cocos wrote: > And that is because entities belonging to the same > taxonomical class ("clade") have common features, and also inherit the > features of the taxonomical parent. I think the notion you're after is what is known in the Python world as a "protocol". This is an informal collection of methods and behaviours that an object can conform to, which makes it usable in certain ways. Some fundamental ones include the sequence protocol, the mapping protocol, and the iterator protocol. I'm not aware of a diagram, but the "Built-In Types" section of the Library Reference describes all the major protocols and lists the types that belong to them. Originally these protocols did not have any formal embodiment. Nowadays Python has ABCs (Abstract Base Classes) which provides a way to formalise them. You may also find it instructive to look at the docs for the collections.abc module. Note that ABCs a bit weird, because you can register a class as belonging to an ABC, so that isinstance() and issubclass() will behave as though the class inherits from the ABC even though it doesn't. For example, >>> import collections.abc >>> issubclass(list, collections.abc.Sequence) True >>> list.__mro__ (, ) Unfortunately this means there is no easy way to find all the ABCs that a given class is a member of, so you'll have to rely on documentation to build the taxonomy that you're after. Also, there is no requirement for a class implementing a given protocol to be registered with a corresponding ABC. Most of the built-in ones are, but there are plenty of classes out in the wild that aren't. So there isn't any foolproof way for a program to ask an object a question like "are you a sequence". -- Greg From ml_news at posteo.de Sat Aug 31 08:22:05 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 31 Aug 2019 14:22:05 +0200 Subject: open, close Message-ID: <20190831142205.668cc583@arcor.com> Hi there, This is a beginner question. I learned that with open("foo.txt") as f: lines = f.readlines() using the with-construct is the recommended way to deal with files making sure that close() always happens. However, I also could do: lines = open("foo.txt").readlines() I have to admit that I'm not sure if in case something bad happens a close() is done implicitly as in the first example. Could I use the latter as a substitute for the with-construct? What are the recommendations of the experts? -- Thanks, Manfred From max at zettlmeissl.de Sat Aug 31 09:20:41 2019 From: max at zettlmeissl.de (=?UTF-8?Q?Max_Zettlmei=C3=9Fl?=) Date: Sat, 31 Aug 2019 15:20:41 +0200 Subject: open, close In-Reply-To: <20190831142205.668cc583@arcor.com> References: <20190831142205.668cc583@arcor.com> Message-ID: On Sat, Aug 31, 2019 at 2:22 PM Manfred Lotz wrote: > > Could I use the latter as a substitute for the with-construct? > You can't use the second statement as a proper substitute for the first one. With the context manager, it is ensured that the file is closed. It's more or less equal to a "finally" clause which closes the file descriptor. So as long as the Python runtime environment functions properly, it will be closed. Your second statement on the other hand, is more or less equivalent to: f = open("foo.txt") lines = f.readlines() Close won't be called. From piet-l at vanoostrum.org Sat Aug 31 09:43:41 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sat, 31 Aug 2019 15:43:41 +0200 Subject: open, close References: <20190831142205.668cc583@arcor.com> Message-ID: Max Zettlmei?l writes: > On Sat, Aug 31, 2019 at 2:22 PM Manfred Lotz wrote: >> >> Could I use the latter as a substitute for the with-construct? >> > > You can't use the second statement as a proper substitute for the first one. > > With the context manager, it is ensured that the file is closed. It's > more or less equal to a "finally" clause which closes the file > descriptor. > So as long as the Python runtime environment functions properly, it > will be closed. > > Your second statement on the other hand, is more or less equivalent to: > > f = open("foo.txt") > lines = f.readlines() > > Close won't be called. There is a difference here with the construct that the OP mentioned: lines = open("foo.txt").readlines() In that case the file COULD be closed, but there is no guarantee. It depends on garbage collection. In your case the file will not be closed as long as there is still a reference to it (as in f). When f disappears and all copies of it as well, the file COULD be closed similarly. On the other hand, the with statement guarantees that the file will be closed, so it is the preferred method. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From grant.b.edwards at gmail.com Sat Aug 31 10:36:26 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 31 Aug 2019 14:36:26 -0000 (UTC) Subject: open, close References: <20190831142205.668cc583@arcor.com> Message-ID: On 2019-08-31, Manfred Lotz wrote: > Hi there, > This is a beginner question. > > I learned that > > with open("foo.txt") as f: > lines = f.readlines() > > using the with-construct is the recommended way to deal with files > making sure that close() always happens. More importantly, it makes sure that close() always happens at a particular point. It gets closed when the block after with [...]: exits. > lines = open("foo.txt").readlines() In that example, close() will very probably happen sometime soon when the system notices that there are no remaining references to the file-object. In the general case, it's not wise to depend on that for large complex programs. For small throw-away scripts it's fine if you know the program will terminate soon and that having the file open until then isn't an issue. For example, if the program is something trivial like this import sys lines = open(sys.argv[1]).readlines() sys.stdout.write("there are %d lines\n" % len(lines)) then it's fine. The file will get closed when the program exits. -- Grant From __peter__ at web.de Sat Aug 31 10:37:23 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 31 Aug 2019 16:37:23 +0200 Subject: open, close References: <20190831142205.668cc583@arcor.com> Message-ID: Manfred Lotz wrote: > Hi there, > This is a beginner question. > > I learned that > > with open("foo.txt") as f: > lines = f.readlines() > > using the with-construct is the recommended way to deal with files > making sure that close() always happens. > > However, I also could do: > > lines = open("foo.txt").readlines() > > I have to admit that I'm not sure if in case something bad happens a > close() is done implicitly as in the first example. > > > Could I use the latter as a substitute for the with-construct? What are > the recommendations of the experts? Always using with open(...) ... is a good habit to get into. If you need to read all lines of a file very often write a helper function: def readlines(filename): with open(filename) as f: return f.readlines() That way you can write lines = readlines("foo.txt") which saves even more typing and still closes the file deterministically. From ml_news at posteo.de Sat Aug 31 10:41:36 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 31 Aug 2019 16:41:36 +0200 Subject: open, close References: <20190831142205.668cc583@arcor.com> Message-ID: <20190831164136.68d0ea41@arcor.com> On Sat, 31 Aug 2019 15:43:41 +0200 Piet van Oostrum wrote: > Max Zettlmei?l writes: > > > On Sat, Aug 31, 2019 at 2:22 PM Manfred Lotz > > wrote: > >> > >> Could I use the latter as a substitute for the with-construct? > >> > > > > You can't use the second statement as a proper substitute for the > > first one. > > > > With the context manager, it is ensured that the file is closed. > > It's more or less equal to a "finally" clause which closes the file > > descriptor. > > So as long as the Python runtime environment functions properly, it > > will be closed. > > > > Your second statement on the other hand, is more or less equivalent > > to: > > > > f = open("foo.txt") > > lines = f.readlines() > > > > Close won't be called. > > There is a difference here with the construct that the OP mentioned: > > lines = open("foo.txt").readlines() > > In that case the file COULD be closed, but there is no guarantee. It > depends on garbage collection. In your case the file will not be > closed as long as there is still a reference to it (as in f). When f > disappears and all copies of it as well, the file COULD be closed > similarly. > When you say COULD this sounds like it is a matter of luck. My thinking was that USUALLY the file will be closed after the statement because then the file handle goes out of scope. However, I understand now that in contrary to `with...` there is no guarantee. > On the other hand, the with statement guarantees that the file will > be closed, so it is the preferred method. > Thanks. So, I take that I'm better off to use 'with...'. -- Manfred From ml_news at posteo.de Sat Aug 31 10:48:51 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 31 Aug 2019 16:48:51 +0200 Subject: open, close References: <20190831142205.668cc583@arcor.com> Message-ID: <20190831164851.3d87197c@arcor.com> On Sat, 31 Aug 2019 16:37:23 +0200 Peter Otten <__peter__ at web.de> wrote: > Manfred Lotz wrote: > > > Hi there, > > This is a beginner question. > > > > I learned that > > > > with open("foo.txt") as f: > > lines = f.readlines() > > > > using the with-construct is the recommended way to deal with files > > making sure that close() always happens. > > > > However, I also could do: > > > > lines = open("foo.txt").readlines() > > > > I have to admit that I'm not sure if in case something bad happens a > > close() is done implicitly as in the first example. > > > > > > Could I use the latter as a substitute for the with-construct? What > > are the recommendations of the experts? > > Always using > > with open(...) ... > > is a good habit to get into. As a Python beginner I started to use with open.. in all cases but was tempted to use the even shorter one-line way of reading a file. So, I will continue to use with open... ALWAYS as good habits are very helpful in life. :-) > if you need to read all lines of a file > very often write a helper function: > > def readlines(filename): > with open(filename) as f: > return f.readlines() > > That way you can write > > lines = readlines("foo.txt") > > which saves even more typing and still closes the file > deterministically. > Good idea. Thanks to all for your help. -- Manfred From piet-l at vanoostrum.org Sat Aug 31 15:19:19 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sat, 31 Aug 2019 21:19:19 +0200 Subject: pandas loc on str lower for column comparison References: Message-ID: Sayth Renshaw writes: > But on both occasions I receive this error. > > # KeyError: 'the label [Current Team] is not in the [index]' > > if I test df1 before trying to create the new column it works just fine. > What do you mean by testing df1? And could it be that 'Current Team' is spelled differently in the assignment than in the construction of df1? For example a difference in spaces, like a triling space or a breaking vs. non-breaking space? Please check that both are exactly the same. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From flebber.crue at gmail.com Sat Aug 31 20:37:36 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 31 Aug 2019 17:37:36 -0700 (PDT) Subject: pandas loc on str lower for column comparison In-Reply-To: References: Message-ID: <05e75ce6-34f3-41c3-a04e-3a900b98488a@googlegroups.com> On Sunday, 1 September 2019 05:19:34 UTC+10, Piet van Oostrum wrote: > Sayth Renshaw writes: > > > But on both occasions I receive this error. > > > > # KeyError: 'the label [Current Team] is not in the [index]' > > > > if I test df1 before trying to create the new column it works just fine. > > > What do you mean by testing df1? > > And could it be that 'Current Team' is spelled differently in the assignment than in the construction of df1? For example a difference in spaces, like a triling space or a breaking vs. non-breaking space? Please check that both are exactly the same. > > -- > Piet van Oostrum > WWW: http://piet.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] Hi Version info 1.1.0 #scipy 0.23.4 #pandas RangeIndex: 35 entries, 0 to 34 Data columns (total 5 columns): UID 35 non-null object Name 35 non-null object New Leader 35 non-null object Current Team 35 non-null object New Team 35 non-null object dtypes: object(5) memory usage: 1.4+ KB I had to anonymise the sheet. But same structure. tested produces same errors. import pandas as pd import scipy print(scipy.version.version) print(pd.__version__) xls = pd.ExcelFile("Melbourne-anon.xlsx") df = xls.parse('Sheet1', skiprows= 4) # df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] # print(df['Current Team'] == df1['Current Team']) df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')] # df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip() # df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip() df1.info() From jasonanyilian at gmail.com Sat Aug 31 22:11:40 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Sat, 31 Aug 2019 19:11:40 -0700 (PDT) Subject: Pygal bar colors Message-ID: <161737cd-2cd1-4b26-9242-96615295ec36@googlegroups.com> How do you change the color of the bar in pygal? I want to change it from red to blue. Help! From cs at cskk.id.au Sat Aug 31 22:33:54 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 1 Sep 2019 12:33:54 +1000 Subject: Pygal bar colors In-Reply-To: <161737cd-2cd1-4b26-9242-96615295ec36@googlegroups.com> References: <161737cd-2cd1-4b26-9242-96615295ec36@googlegroups.com> Message-ID: <20190901023354.GA77181@cskk.homeip.net> On 31Aug2019 19:11, CrazyVideoGamez wrote: >How do you change the color of the bar in pygal? >I want to change it from red to blue. Help! http://www.pygal.org/en/stable/documentation/custom_styles.html You _did_ look at the documentation didn't you? This took me about a minute to find, and I've never used pygal. Cheers, Cameron Simpson From arifsamana at gmail.com Fri Aug 30 08:25:22 2019 From: arifsamana at gmail.com (Mohammad Arif Samana) Date: Fri, 30 Aug 2019 17:25:22 +0500 Subject: Python 3.7.4 on win 7 Message-ID: Dear sir, I am installing the above version of python on my pc with win7 as my operating system. But I am constantly receiving error messages. What could be the problem and remedy for that. Kindly update me as I am facing problems for my studies. Also brief me about Anaconda3. Its not installing on window 7, is there any bugs. Arif Samana From ekopalypse at gmail.com Fri Aug 30 12:01:47 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Fri, 30 Aug 2019 18:01:47 +0200 Subject: Using exec with embedded python interpreter 3.7 Message-ID: Hello, I'm creating a notepad++ plugin which hosts an embedded python interpreter by using cffi to build the dll. So far so good. One obstacle I've found is that I'm not able to use exec(help(object)) in order to get the wanted info from the object. The error I get is: Traceback (most recent call last): File "", line 131, in run_code File "", line 1, in File "D:\...\Python\Python37_64\Lib\_sitebuiltins.py", line 103, in __call__ return pydoc.help(*args, **kwds) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1895, in __call__ self.help(request) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1954, in help else: doc(request, 'Help on %s:', output=self._output) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1674, in doc pager(render_doc(thing, title, forceload)) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1451, in pager pager(text) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1576, in plainpager sys.stdout.write(plain(_escape_stdout(text))) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1528, in _escape_stdout return text.encode(encoding, 'backslashreplace').decode(encoding) TypeError: encode() argument 1 must be str, not method If I encase the object with quotes then I do get the info that no documentation is found for that object. 1. It doesn't feel right to encase the object with quotes. I don't have to do this using the standard python interpreter shell. What did I miss? 2. If it is needed to use the encased way, why don't it show the help info? The object class contains the module, class and functions doc strings, what did I miss here? Thank you Eren From av69583 at gmail.com Sat Aug 31 04:54:01 2019 From: av69583 at gmail.com (Akash verma) Date: Sat, 31 Aug 2019 14:24:01 +0530 Subject: "Edit With Python" option missing Message-ID: "Edit With Python" option missing from message context when right clicked with mouse . I am facing many problems with it. From kishore.gowdaman at soprasteria.com Sat Aug 31 05:13:07 2019 From: kishore.gowdaman at soprasteria.com (G Kishore) Date: Sat, 31 Aug 2019 09:13:07 +0000 Subject: 'python' is not recognized as an internal or external command Message-ID: Hi Team, I was installing python in my new windows 10 machine and cpuld able to access python from command window when the location is where I have installed python. The same I have tried to enter the command from Desktop location but "'python' is not recognized as an internal or external command," error is thrown. Done the path variable in the environmental variables as the location where python is installed. Thanks Kishore From yuxuan.dong at outlook.com Sat Aug 31 05:00:23 2019 From: yuxuan.dong at outlook.com (YuXuan Dong) Date: Sat, 31 Aug 2019 09:00:23 +0000 Subject: Message-ID: <24CE63C5-B57A-4DEC-8110-7E2520830784@outlook.com> From yuxuan.dong at outlook.com Sat Aug 31 05:16:55 2019 From: yuxuan.dong at outlook.com (YuXuan Dong) Date: Sat, 31 Aug 2019 09:16:55 +0000 Subject: Problem while integrating unittest with setuptools Message-ID: <010F3B60-6AE1-420F-94BA-63C3CC3723A8@contoso.com> Hi, everybody: I met a problem while I ran `python setup.py test`: unittest.case.SkipTest: No module named 'winreg' I ran the command in MacOS and my project is written for only UNIX-like systems. I don't use any Windows-specified API. How dose `winreg` come here? In my `setup.py`: test_suite="test" In my `test/test.py`: import unittest class TestAll(unittest.TestCase): def testall(self): return None I'm working on this for the whole day, searched for every keywords I can think of with Google but can't find why or how. Could you help me? Thanks. -- YX. D. From ekopalypse at gmail.com Sat Aug 31 08:16:31 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 31 Aug 2019 05:16:31 -0700 (PDT) Subject: Using exec with embedded python interpreter 3.7 Message-ID: <3526187c-0128-4705-ab87-f103fb848d45@googlegroups.com> I've already sent this through mail yesterday but it doesn't appear here, maybe because of the help word in the content. Please execute in case it appears a second time. Hello, I'm creating a notepad++ plugin which hosts an embedded python interpreter by using cffi to build the dll. So far so good. One obstacle I've found is that I'm not able to use exec(help(object)) in order to get the wanted info from the object. The error I get is: Traceback (most recent call last): File "", line 131, in run_code File "", line 1, in File "D:\...\Python\Python37_64\Lib\_sitebuiltins.py", line 103, in __call__ return pydoc.help(*args, **kwds) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1895, in __call__ self.help(request) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1954, in help else: doc(request, 'Help on %s:', output=self._output) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1674, in doc pager(render_doc(thing, title, forceload)) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1451, in pager pager(text) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1576, in plainpager sys.stdout.write(plain(_escape_stdout(text))) File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1528, in _escape_stdout return text.encode(encoding, 'backslashreplace').decode(encoding) TypeError: encode() argument 1 must be str, not method If I encase the object with quotes then I do get the info that no documentation is found for that object. 1. It doesn't feel right to encase the object with quotes. I don't have to do this using the standard python interpreter shell. What did I miss? 2. If it is needed to use the encased way, why don't it show the help info? The object class contains the module, class and functions doc strings, what did I miss here? Thank you Eren From petersutton2009 at gmail.com Sat Aug 31 09:36:50 2019 From: petersutton2009 at gmail.com (Peter Sutton) Date: Sat, 31 Aug 2019 14:36:50 +0100 Subject: Async subprocess context manager Message-ID: Hi all, First time posting! I need an async context manager that ensures a Process has finished before it `__exit__()`s, either by graceful or forceful termination, and regardless of cancellation. I've put my code at the bottom. I'm relatively new to asyncio, so I'm looking for feedback on any aspect of the code. Not only correctness, but things like if I'm handling cancellation correctly or is the a more idiomatic way to go back this? Thanks, Peter. ``` from __future__ import annotations import asyncio import time from contextlib import asynccontextmanager from typing import AsyncIterator, Optional @asynccontextmanager async def terminating(proc: asyncio.subprocess.Process, timeout: float) \ -> AsyncIterator[asyncio.subprocess.Process]: try: yield proc finally: try: proc.terminate() except ProcessLookupError: pass else: start = time.time() while True: remaining = timeout - (time.time() - start) try: await asyncio.wait_for(proc.wait(), remaining) except asyncio.CancelledError: is_done = False is_cancelled = True except asyncio.TimeoutError: is_done = False is_cancelled = False break else: print('Terminated') is_done = True is_cancelled = False break if not is_done: try: proc.kill() except ProcessLookupError: pass else: while True: try: proc.wait() except asyncio.CancelledError: is_cancelled = True else: print('Killed') break if is_cancelled: raise asyncio.CancelledError() async def test(sleep: float) -> None: proc = await asyncio.create_subprocess_shell('sleep 10') async with terminating(proc, 1): await asyncio.sleep(sleep) async def main(): await test(1) task = asyncio.create_task(test(1)) task.cancel() try: await task except asyncio.CancelledError: pass asyncio.run(main()) ``` From yashikaparb2523 at gmail.com Sat Aug 31 11:11:22 2019 From: yashikaparb2523 at gmail.com (best web site) Date: Sat, 31 Aug 2019 07:11:22 -0800 Subject: problem occurring in operating python , after typing only 5-6 programs only is causing problem it has stoped working Message-ID: <5d6a7825.1c69fb81.d1719.cdbf@mx.google.com> Sent from Mail for Windows 10 From saqilali761 at gmail.com Sat Aug 31 12:22:38 2019 From: saqilali761 at gmail.com (ABID NAZIR) Date: Sat, 31 Aug 2019 21:22:38 +0500 Subject: it is not working Message-ID: From zaknishu26 at outlook.com Sat Aug 31 12:39:35 2019 From: zaknishu26 at outlook.com (mohd zak) Date: Sat, 31 Aug 2019 16:39:35 +0000 Subject: ssl certificate issue while installing Django on y windows 64 bit os Message-ID: Sent from Mail for Windows 10 From artemibozadji at mail.ru Sat Aug 31 14:30:58 2019 From: artemibozadji at mail.ru (=?UTF-8?B?0JDQoNCi0IHQnCDQkdCe0JfQkNCU0JbQmA==?=) Date: Sat, 31 Aug 2019 21:30:58 +0300 Subject: =?UTF-8?B?UFlUSE9OIERJRE5UIERFVEVDVEVE?= Message-ID: <1567276258.150346035@f117.i.mail.ru> Traceback (most recent call last): File "", line 1, in NameError: name 'python' is not defined and more? C:\Users\VeNoMD>python -v import _frozen_importlib # frozen import _imp # builtin import '_thread' # import '_warnings' # import '_weakref' # # installing zipimport hook import 'zipimport' # # installed zipimport hook import '_frozen_importlib_external' # import '_io' # import 'marshal' # import 'nt' # import _thread # previously loaded ('_thread') import '_thread' # import _weakref # previously loaded ('_weakref') import '_weakref' # import 'winreg' # # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\__pycache__\__init__.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\__init__.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\encodings\\__pycache__\\__init__.cpython-37.pyc' # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\codecs.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\codecs.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\codecs.cpython-37.pyc' import '_codecs' # import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x031B8E90> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\__pycache__\aliases.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\aliases.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\encodings\\__pycache__\\aliases.cpython-37.pyc' import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x031D00D0> import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x031B8770> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\__pycache__\utf_8.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\utf_8.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\encodings\\__pycache__\\utf_8.cpython-37.pyc' import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x031DAF70> import '_signal' # # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\__pycache__\latin_1.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\encodings\latin_1.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\encodings\\__pycache__\\latin_1.cpython-37.pyc' import 'encodings.latin_1' # <_frozen_importlib_external.SourceFileLoader object at 0x031DF1D0> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\io.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\io.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\io.cpython-37.pyc' # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\abc.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\abc.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\abc.cpython-37.pyc' import '_abc' # import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x031DF430> import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x031DF290> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\site.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\site.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\site.cpython-37.pyc' # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\os.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\os.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\os.cpython-37.pyc' # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\stat.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\stat.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\stat.cpython-37.pyc' import '_stat' # import 'stat' # <_frozen_importlib_external.SourceFileLoader object at 0x032F1E50> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\ntpath.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\ntpath.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\ntpath.cpython-37.pyc' # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\genericpath.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\genericpath.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\genericpath.cpython-37.pyc' import 'genericpath' # <_frozen_importlib_external.SourceFileLoader object at 0x032F6FD0> import 'ntpath' # <_frozen_importlib_external.SourceFileLoader object at 0x032F1F50> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\_collections_abc.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\_collections_abc.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\_collections_abc.cpython-37.pyc' import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x032FF3D0> import 'os' # <_frozen_importlib_external.SourceFileLoader object at 0x031EA790> # C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\__pycache__\_sitebuiltins.cpython-37.pyc matches C:\Users\VeNoMD\AppData\Local\Programs\Python\Python37-32\lib\_sitebuiltins.py # code object from 'C:\\Users\\VeNoMD\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\__pycache__\\_sitebuiltins.cpython-37.pyc' import '_sitebuiltins' # <_frozen_importlib_external.SourceFileLoader object at 0x031EAC50> import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x031DFC50> Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import 'atexit' # >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?????????, ????? ??????? artemibozadji at mail.ru From flebber.crue at gmail.com Sat Aug 31 20:48:42 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 31 Aug 2019 17:48:42 -0700 (PDT) Subject: pandas loc on str lower for column comparison In-Reply-To: <05e75ce6-34f3-41c3-a04e-3a900b98488a@googlegroups.com> References: <05e75ce6-34f3-41c3-a04e-3a900b98488a@googlegroups.com> Message-ID: <812057cd-9f21-462c-b071-2e8f8d23bd12@googlegroups.com> I've created a share doc same structure anon data from my google drive. https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing Sayth From max at zettlmeissl.de Sat Aug 31 10:12:15 2019 From: max at zettlmeissl.de (=?UTF-8?Q?Max_Zettlmei=C3=9Fl?=) Date: Sat, 31 Aug 2019 16:12:15 +0200 Subject: open, close In-Reply-To: References: <20190831142205.668cc583@arcor.com> Message-ID: On Sat, Aug 31, 2019 at 3:43 PM Piet van Oostrum wrote: > > There is a difference here with the construct that the OP mentioned: > > lines = open("foo.txt").readlines() > > In that case the file COULD be closed, but there is no guarantee. It depends on garbage collection. > In your case the file will not be closed as long as there is still a reference to it (as in f). When f disappears and all copies of it as well, the file COULD be closed similarly. > Yes, that is correct. I thought about mentioning the garbage collection and the extra binding for f, but eventually it does not change the conclusion. The garbage collection is just too unpredictable to rely upon in any scenario where you would deal with many open descriptors in a short period of time e.g. when opening and processing files in a loop. It is not easy to generalise from such simple examples. After all, if all the program does is process one file and shut down afterwards, this would not be an aspect to worry about.