From Markus.Elfring at web.de Sat Jun 1 09:33:43 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sat, 1 Jun 2019 15:33:43 +0200 Subject: Checking refusal of a network connection In-Reply-To: <20190531231738.GA92303@cskk.homeip.net> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: > Also, it can be very useful to strace the client process, eg: Do you find the following background information more helpful for the desired clarification of unexpected software behaviour? elfring at Sonne:~/Projekte/Python> LANG=C strace -e trace=network /usr/bin/python3 socket-send_json_data.py --server_id localhost --server_port 37351 Using Python version: 3.7.2 ? socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 3 socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4 connect(4, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0 sendto(4, "\2\0\0\0\r\0\0\0\6\0\0\0hosts\0", 18, MSG_NOSIGNAL, NULL, 0) = 18 recvmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="hosts\0", iov_len=6}, {iov_base="\310O\3\0\0\0\0\0", iov_len=8}], msg_iovlen=2, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=20, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 14 connect(3, {sa_family=AF_INET, sin_port=htons(37351), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused) Traceback ?: ? File "socket-send_json_data.py", line 17, in send_data so.connect((args.server_id, args.server_port)) ConnectionRefusedError: [Errno 111] Connection refused +++ exited with 1 +++ > You can also strace the running service process: I do not observe additional function calls for the TCP client connection attempt here. > Also, on the service side it isn't enough to create the service socket, > you also need to do an accept IIRC. This should be performed by my implementation of the C++ function ?setup?. Regards, Markus From Markus.Elfring at web.de Sat Jun 1 13:15:28 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sat, 1 Jun 2019 19:15:28 +0200 Subject: Checking refusal of a network connection In-Reply-To: References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: >> connect(3, {sa_family=AF_INET, sin_port=htons(37351), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused) > > Without seeing the code, I'd be suspicious of that difference. I would expect that the IPv4 address from such a connection attempt would be automatically converted to a IPv6 loopback address. Unfortunately, the direct specification ?? socket-send_json_data.py --server_id ::1 ?? does not work at the moment because of the error message ?socket.gaierror: [Errno -9] Address family for hostname not supported?. Regards, Markus From hjp-python at hjp.at Sat Jun 1 13:32:09 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2019 19:32:09 +0200 Subject: Checking refusal of a network connection In-Reply-To: References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: <20190601173209.t25f35m5wk4lj6si@hjp.at> On 2019-06-01 19:15:28 +0200, Markus Elfring wrote: > >> connect(3, {sa_family=AF_INET, sin_port=htons(37351), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused) > > Without seeing the code, I'd be suspicious of that difference. > > I would expect that the IPv4 address from such a connection attempt > would be automatically converted to a IPv6 loopback address. You haven't said which OS you are using, but as far as I know this expectation will be frustrated at least on Linux: There ::1 and 127.0.0.1 are distinct addresses. If you want to accept connections on both, you have to listen on both (or on ::, which does accept connections on all IP addresees - IPv6 and IPv4). 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 torriem at gmail.com Sat Jun 1 13:45:44 2019 From: torriem at gmail.com (Michael Torrie) Date: Sat, 1 Jun 2019 11:45:44 -0600 Subject: Checking refusal of a network connection In-Reply-To: References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: On 06/01/2019 11:15 AM, Markus Elfring wrote: >>> connect(3, {sa_family=AF_INET, sin_port=htons(37351), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused) >> >> Without seeing the code, I'd be suspicious of that difference. > > I would expect that the IPv4 address from such a connection attempt > would be automatically converted to a IPv6 loopback address. How would this conversion take place? Localhost is 127.0.0.1. Localhost6 is ::1. They are different and you cannot route between the two. What I can see is that your server binds to localhost6 and your client is trying to connect to localhost. > Unfortunately, the direct specification ?? socket-send_json_data.py --server_id ::1 ?? > does not work at the moment because of the error message ?socket.gaierror: [Errno -9] > Address family for hostname not supported?. No idea on that one. From hjp-python at hjp.at Sat Jun 1 13:55:31 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2019 19:55:31 +0200 Subject: PEP 594 cgi & cgitb removal In-Reply-To: References: <871s0peoio.fsf@nightsong.com> <20190523124635.hphiagslwrbdjnz7@gthmcloud> <09e6f2c4-e8d3-903f-630f-b1803ca55b6c@gmail.com> Message-ID: <20190601175531.lmcf7ihjulovdmxd@hjp.at> On 2019-05-25 23:45:06 +0200, Roel Schroeven wrote: > Jon Ribbens via Python-list schreef op 25/05/2019 om 21:00: > > On 2019-05-25, Michael Torrie wrote: > > > On 05/24/2019 04:27 AM, Jon Ribbens via Python-list wrote: > > > > Sorry, in what sense do you mean "Serverless is CGI"? > > > > > > > > As far as I can tell, it's just a script to automatically upload > > > > bits of code into various cloud providers, none of which use CGI. > > > > > > Not really. Serverless just means stateless web-based remote procedure > > > calls. This is by definition what CGI is. > > > > No, it isn't. CGI is a specific API and method of calling a program > > in order to serve a web request. It isn't a shorthand for "any > > web-based remote procedure call". > > More specifically, with CGI the webserver starts a new process for every > single request. That's bad enough for a light C program, but it's certainly > not a good idea to start a whole new Python process for every request. At > least not for any production website or web service that serves any real > amount of traffic. I strongly disagree with this. A minimal Python script using the cgi package takes between 50 and 80 milliseconds on my (not very fast) private server. Assuming a script which does anything useful takes about 100 milliseconds, that's still a) a shorter response time than a lot of websites with persistent servers have b) fast enough not be a bottleneck on the vast majority of web sites. Yes, you cannot run Facebook on CGI, but most websites aren't Facebook. I doubt we have even one website which gets close to 10 requests to dynamic content per second. Much less 10 requests per second per core. I don't use CGI very much these days (and when I do, I use Perl - old habits die hard), but performance isn't the reason. 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 hjp-python at hjp.at Sat Jun 1 14:12:07 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2019 20:12:07 +0200 Subject: Handling an connection error with Twython In-Reply-To: <87imtypxi7.fsf@munus.decebal.nl> References: <87y32wq1hz.fsf@munus.decebal.nl> <2e4f24a1-0806-96a9-3cc9-0f418043f82a@mrabarnett.plus.com> <87tvdkpfks.fsf@munus.decebal.nl> <346feeprknvm8225vugcm01nm2th7ncvgh@4ax.com> <87mujcp8d6.fsf@munus.decebal.nl> <87imtypxi7.fsf@munus.decebal.nl> Message-ID: <20190601181207.yznln7jvitpktjfu@hjp.at> On 2019-05-25 13:46:40 +0200, Cecil Westerhof wrote: > Just changing the while loop to a for loop did not make sense to me, > but this does. I now have: > max_tries = 5 > for current_try in range(1, max_tries): > try: > posted = twitter.update_status(status = message, > in_reply_to_status_id = message_id, > trim_user = True) > return posted['id'] > except TwythonError as e: > if not 'Temporary failure in name resolution' in e.msg: > raise > timed_message('Failed on try: {0} of {1}'.format(current_try, max_tries)) > if current_try == max_tries: ^^^^^^^^^^^^^^^^^^^^^^^^ This will never be true because the loop will exit before current_try reaches max_tries. > print('Could not get a connection to the internet: exiting') > deinit(2) Also you don't seem to stop here (unless deinit raises an exception) > time.sleep(60) > raise RuntimeError('Should not get here') ^^^^^^^^^^^^^^^^^^^^^ So if you can't get a status update you will reach this point. 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 Markus.Elfring at web.de Sat Jun 1 14:22:39 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sat, 1 Jun 2019 20:22:39 +0200 Subject: Checking refusal of a network connection In-Reply-To: <20190601173209.t25f35m5wk4lj6si@hjp.at> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> <20190601173209.t25f35m5wk4lj6si@hjp.at> Message-ID: <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> >> I would expect that the IPv4 address from such a connection attempt >> would be automatically converted to a IPv6 loopback address. > > You haven't said which OS you are using, but as far as I know this > expectation will be frustrated at least on Linux: There ::1 and > 127.0.0.1 are distinct addresses. How does this view fit to information from the Linux programmer's manual? See also: command ?man 7 ipv6? Regards, Markus From hjp-python at hjp.at Sat Jun 1 14:30:11 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 1 Jun 2019 20:30:11 +0200 Subject: Checking refusal of a network connection In-Reply-To: <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> <20190601173209.t25f35m5wk4lj6si@hjp.at> <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> Message-ID: <20190601183011.n2ylb64f2eelbwmj@hjp.at> On 2019-06-01 20:22:39 +0200, Markus Elfring wrote: > >> I would expect that the IPv4 address from such a connection attempt > >> would be automatically converted to a IPv6 loopback address. > > > > You haven't said which OS you are using, but as far as I know this > > expectation will be frustrated at least on Linux: There ::1 and > > 127.0.0.1 are distinct addresses. > > How does this view fit to information from the Linux programmer's manual? > See also: command ?man 7 ipv6? Which specific information in that man page contradicts what what I wrote? If you think of | IPv4 connections can be handled with the v6 API by using the | v4-mapped-on-v6 address type; thus a program needs to support only | this API type to support both protocols. please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1. So you still need to bind to two addresses. 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 Markus.Elfring at web.de Sat Jun 1 14:44:29 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sat, 1 Jun 2019 20:44:29 +0200 Subject: Checking refusal of a network connection In-Reply-To: <20190601183011.n2ylb64f2eelbwmj@hjp.at> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> <20190601173209.t25f35m5wk4lj6si@hjp.at> <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> <20190601183011.n2ylb64f2eelbwmj@hjp.at> Message-ID: <91576c05-1edc-ce85-e51b-cbb35e9a3a24@web.de> > Which specific information in that man page contradicts what I wrote? We can agree that the mentioned IP addresses are distinct. But the corresponding functionality should be equivalent. > If you think of > > | IPv4 connections can be handled with the v6 API by using the > | v4-mapped-on-v6 address type; thus a program needs to support only > | this API type to support both protocols. > > please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1. I find another information like ?This is handled transparently by the address handling functions in the C library.? also interesting. > So you still need to bind to two addresses. I am unsure about this conclusion. Under which circumstances will the Python programming interfaces support the direct usage of the identification ?::1?? Regards, Markus From younes.boutriq at gmail.com Sat Jun 1 14:52:31 2019 From: younes.boutriq at gmail.com (Barb Cr33k) Date: Sat, 1 Jun 2019 11:52:31 -0700 (PDT) Subject: Getter is not returning the data it should be Message-ID: <17a743bd-193b-4b6f-832f-b755abfb8149@googlegroups.com> I have a parent Class that has a setter that returns queryFiltre value and a getter that is supposed to pass the queryFiltre value to my child Class. queryFiltre Should return an SQL query like "SELECT * FROM Report WHERE GA_RPM > 0 and CAMPAIGN LIKE '%TT%'... ". The print() in the setter returns a SQL query, but the print() of the getter when called in the child Class returns something like " ". What's wrong with my code? Please bear with me as I'm still learning and oop is still an abstract concept in my head. I've added comments in the code so you can see what happens where: class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin): def __init__(self, parent, log): gridlib.Grid.__init__(self, parent, -1) ########### DATABASE CONNECT self.path =os.path.dirname(os.path.realpath(__file__)) self.dbfile = os.path.join(self.path , "report.db") self.db_conn = sqlite3.connect(self.dbfile) self.theCursor = self.db_conn.cursor() ########### SETTING FILE CONNECT self.configFile = os.path.join(self.path , "config.ini") self.config = configparser.ConfigParser() self.config.read(self.configFile) ########### Calling th Getter and Setter self.queryFiltre = self.setQueryFiltre(self) self.getQueryFiltre() ########### Setter def setQueryFiltre(self,queryFiltre): if self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "true": network = "" elif self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "false": network = " and CAMPAIGN LIKE '%TB%'" elif self.config.get('Network', 'outbrain') == "true" and self.config.get('Network', 'tb') == "false": network = " and CAMPAIGN LIKE '%OB%'" else: network = "" queryFiltre = "SELECT * FROM Report WHERE GA_RPM > 0 " + network + " and STATUS = '1' ORDER BY CLICKS DESC" ########### The print below returns the right value of queryFiltre print(queryFiltre) return queryFiltre ########### Getter def getQueryFiltre(queryFiltre): queryFiltre = queryFiltre return queryFiltre class TestFrame(wx.Frame): def __init__(self, parent, log): wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800)) self.grid = SimpleGrid(self, log) ########### Calling the Getter of the parent Class self.queryFiltre = self.grid.getQueryFiltre() ########### DATABASE CONNECT self.path =os.path.dirname(os.path.realpath(__file__)) self.dbfile = os.path.join(self.path , "report.db") self.db_conn = sqlite3.connect(self.dbfile) self.theCursor = self.db_conn.cursor() ########### The print below returns a bad value, something like : <__main__.SimpleGrid object at 0x042AF2B0> print(self.queryFiltre) You'll notice also that I've added the script to define the path and to connect to the db in both classes, is there a way to do it only once in the first Class? Thank you, From Cecil at decebal.nl Sat Jun 1 15:12:28 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 01 Jun 2019 21:12:28 +0200 Subject: Handling an connection error with Twython References: <87y32wq1hz.fsf@munus.decebal.nl> <2e4f24a1-0806-96a9-3cc9-0f418043f82a@mrabarnett.plus.com> <87tvdkpfks.fsf@munus.decebal.nl> <346feeprknvm8225vugcm01nm2th7ncvgh@4ax.com> <87mujcp8d6.fsf@munus.decebal.nl> <87imtypxi7.fsf@munus.decebal.nl> <20190601181207.yznln7jvitpktjfu@hjp.at> Message-ID: <877ea5i0gz.fsf@munus.decebal.nl> "Peter J. Holzer" writes: > On 2019-05-25 13:46:40 +0200, Cecil Westerhof wrote: >> Just changing the while loop to a for loop did not make sense to me, >> but this does. I now have: >> max_tries = 5 >> for current_try in range(1, max_tries): >> try: >> posted = twitter.update_status(status = message, >> in_reply_to_status_id = message_id, >> trim_user = True) >> return posted['id'] >> except TwythonError as e: >> if not 'Temporary failure in name resolution' in e.msg: >> raise >> timed_message('Failed on try: {0} of {1}'.format(current_try, max_tries)) >> if current_try == max_tries: > ^^^^^^^^^^^^^^^^^^^^^^^^ > This will never be true because the loop will exit > before current_try reaches max_tries. >> print('Could not get a connection to the internet: exiting') >> deinit(2) > Also you don't seem to stop here (unless deinit raises > an exception) > >> time.sleep(60) >> raise RuntimeError('Should not get here') > ^^^^^^^^^^^^^^^^^^^^^ > So if you can't get a status update you will reach this point. Oops, you are completely right. :'-( The for should be: for current_try in range(1, max_tries + 1): A bit silly of me. The function deinit does some deinitialisation and after that an exit with the value it receives. (Default it uses 0.) So you never return from this call. Should have made that clear. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Markus.Elfring at web.de Sat Jun 1 16:20:43 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sat, 1 Jun 2019 22:20:43 +0200 Subject: Checking refusal of a network connection In-Reply-To: <20190531231738.GA92303@cskk.homeip.net> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: <4e2f2237-358c-c504-a8a0-a523b0e27262@web.de> > It looks like the service isn't listening at the time the so.connect is called. * I get an other impression from the programs ?/usr/bin/netstat? and ?/usr/bin/ss?. * The data transmission seems to work also for my small script ?socket-send_test_data1.tcl? (even when the identification ?::1? was passed as a command parameter). Regards, Markus From PythonList at DancesWithMice.info Sat Jun 1 16:22:43 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 2 Jun 2019 08:22:43 +1200 Subject: Getter is not returning the data it should be In-Reply-To: <17a743bd-193b-4b6f-832f-b755abfb8149@googlegroups.com> References: <17a743bd-193b-4b6f-832f-b755abfb8149@googlegroups.com> Message-ID: Bonjour Barb, Please allow me to answer your question, somewhat, backwards:- There is a principle in program design known as "separation of concerns". If you look at the class SimpleGrid and consider that the bulk of its code lies after the first comment, how would you summarise (in English) its actions? Does the answer contain the word "database" more often than any word relating to wxPython? - Might it simplify matters if the functions related to those two words were separated? Thus, let's look at the overall objective in the manner of OOP. There is a data-source (or two) and an output screen/frame/grid. Let's go completely 'purist' and create an object for each one. - As soon as the 'database' (or query) object is created, does it answer the "both classes" question, below? What is the need for separate (database) "getter" and "setter" methods? Once the query text has been built, why not query the DB immediately? Please review "getQueryFiltre". Again, summarise (in English) exactly what you think/want this method to do. - If the two separate methods are required, and they both appear in a 'database' object, then make the query an attribute of that object (self) and you won't need to pass the query as a result/parameter. - However, in Python we don't need to do that anyway because if setQueryFiltre set self.queryFiltre (instead of returning it) the calling-code would be able to access db.queryFiltre without any need for a "getter" (this Python idiom is quite different to many other programming languages, eg Java!) Once the DB and screen operations have been separated: (a) you will be able to test the DB code-operations independently and ensure the correct data is being retrieved for each usual- and special-case; and (b) you will no longer receive the quite mystifying SimpleGrid errmsg (from wxPython) when you are expecting something data-related to be returned! On 2/06/19 6:52 AM, Barb Cr33k wrote: > I have a parent Class that has a setter that returns queryFiltre value and a getter that is supposed to pass the queryFiltre value to my child Class. queryFiltre Should return an SQL query like "SELECT * FROM Report WHERE GA_RPM > 0 and CAMPAIGN LIKE '%TT%'... ". > > The print() in the setter returns a SQL query, but the print() of the getter when called in the child Class returns something like " ". > > What's wrong with my code? Please bear with me as I'm still learning and oop is still an abstract concept in my head. > > I've added comments in the code so you can see what happens where: > > > > class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin): > def __init__(self, parent, log): > gridlib.Grid.__init__(self, parent, -1) > > > ########### DATABASE CONNECT > self.path =os.path.dirname(os.path.realpath(__file__)) > self.dbfile = os.path.join(self.path , "report.db") > self.db_conn = sqlite3.connect(self.dbfile) > self.theCursor = self.db_conn.cursor() > ########### SETTING FILE CONNECT > self.configFile = os.path.join(self.path , "config.ini") > self.config = configparser.ConfigParser() > self.config.read(self.configFile) > > ########### Calling th Getter and Setter > self.queryFiltre = self.setQueryFiltre(self) > self.getQueryFiltre() > > ########### Setter > def setQueryFiltre(self,queryFiltre): > > if self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "true": > network = "" > elif self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "false": > network = " and CAMPAIGN LIKE '%TB%'" > elif self.config.get('Network', 'outbrain') == "true" and self.config.get('Network', 'tb') == "false": > network = " and CAMPAIGN LIKE '%OB%'" > else: > network = "" > > queryFiltre = "SELECT * FROM Report WHERE GA_RPM > 0 " + network + " and STATUS = '1' ORDER BY CLICKS DESC" > > ########### The print below returns the right value of queryFiltre > print(queryFiltre) > > return queryFiltre > > ########### Getter > def getQueryFiltre(queryFiltre): > queryFiltre = queryFiltre > return queryFiltre > > > class TestFrame(wx.Frame): > def __init__(self, parent, log): > wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800)) > self.grid = SimpleGrid(self, log) > > ########### Calling the Getter of the parent Class > self.queryFiltre = self.grid.getQueryFiltre() > > ########### DATABASE CONNECT > self.path =os.path.dirname(os.path.realpath(__file__)) > self.dbfile = os.path.join(self.path , "report.db") > self.db_conn = sqlite3.connect(self.dbfile) > self.theCursor = self.db_conn.cursor() > > ########### The print below returns a bad value, something like : <__main__.SimpleGrid object at 0x042AF2B0> > print(self.queryFiltre) > > > You'll notice also that I've added the script to define the path and to connect to the db in both classes, is there a way to do it only once in the first Class? > > Thank you, > -- Regards =dn From mfranke at inet.tu-berlin.de Sat Jun 1 09:32:23 2019 From: mfranke at inet.tu-berlin.de (Max Franke) Date: Sat, 1 Jun 2019 15:32:23 +0200 Subject: Socket.py SSM support Message-ID: <9B3C8CE7-AF61-4BF8-A752-91039D4C59DC@inet.tu-berlin.de> Hi, as of right now there appears to be a lack of setsockoptions required to enable SSM, MCAST_JOIN_SOURCE_GROUP or something a kin to that in particular. Is there currently any effort to add those options or any other workaround to make SSM work in python natively? Best regards Max From hjp-python at hjp.at Sat Jun 1 18:43:33 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 2 Jun 2019 00:43:33 +0200 Subject: Checking refusal of a network connection In-Reply-To: <91576c05-1edc-ce85-e51b-cbb35e9a3a24@web.de> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> <20190601173209.t25f35m5wk4lj6si@hjp.at> <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> <20190601183011.n2ylb64f2eelbwmj@hjp.at> <91576c05-1edc-ce85-e51b-cbb35e9a3a24@web.de> Message-ID: <20190601224333.bdpv7wvthd4qgncd@hjp.at> On 2019-06-01 20:44:29 +0200, Markus Elfring wrote: > > Which specific information in that man page contradicts what I wrote? > > We can agree that the mentioned IP addresses are distinct. > But the corresponding functionality should be equivalent. > > > > If you think of > > > > | IPv4 connections can be handled with the v6 API by using the > > | v4-mapped-on-v6 address type; thus a program needs to support only > > | this API type to support both protocols. > > > > please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1. Oops, that should have been ::ffff:7f00:1. > I find another information like ?This is handled transparently by > the address handling functions in the C library.? also interesting. "Handled transparently" means that an ipv6 server can handle connections from ipv4 clients without doing anything special. They just appear to come from a specific IPv6 address range. It doesn't mean the OS performs random address translations according to user's expectations of "equivalence". > > So you still need to bind to two addresses. > > I am unsure about this conclusion. Well, we don't study theology here. We don't have to theorize (no pun intended), we can experiment. Why don't you just try it out? > Under which circumstances will the Python programming interfaces > support the direct usage of the identification ?::1?? I'm not sure I understand the question. They do. 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 cs at cskk.id.au Sat Jun 1 19:14:45 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Jun 2019 09:14:45 +1000 Subject: Checking refusal of a network connection In-Reply-To: References: Message-ID: <20190601231445.GA29274@cskk.homeip.net> On 01Jun2019 12:57, Dennis Lee Bieber wrote: >On Sat, 1 Jun 2019 15:33:43 +0200, Markus Elfring >declaimed the following: > > I don't know "strace" (I'd likely be running WireShark to capture all >traffic for investigation). Sure, but that means you need to winnow it from any other traffic. The advantage of strace is that it watches the programme itself, and shows (in this case) the network system calls. It is great for seeing what the programme is doing/trying to do at the basic level. And, like wireshark, language independent - all runtimes have to go through the OS to get stuff done. I've debugged third party java apps this way because the issue was a basic one like this. >>connect(4, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0 > >>connect(3, {sa_family=AF_INET, sin_port=htons(37351), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused) > > Without seeing the code, I'd be suspicious of that difference. The >latter is asking for a TCP/UDP family connection, whereas the first is a >UNIX domain socket. To my knowledge they are not compatible types. They're certainly distinct address spaces. In other regards they're pretty compatible - you listen/connect the same way. A UNIX socket is just IPC within the kernel instead of over the network. However, the former connect is to the OS name service (hostname lookup - it will mediate to the /etc/hosts file, DNS, NIS or whatever other name services may be set up). The latter is his connection attempt to his service. So this difference is expected and on the surface it looks correct. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sat Jun 1 19:52:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 2 Jun 2019 11:52:59 +1200 Subject: How to concatenate strings with iteration in a loop? In-Reply-To: References: <6173af87-62e6-4c37-a5f2-a70619c040b9@googlegroups.com> <4c26feee-ff54-313c-9798-e99c32797139@chagford.com> Message-ID: On 21/05/19 8:40 PM, Paul Moore wrote: > On Tue, 21 May 2019 at 09:25, Frank Millman wrote: >> >> On 2019-05-21 9:42 AM, Madhavan Bomidi wrote: >>> Hi, >>> >>> I need to create an array as below: >>> >>> tempStr = year+','+mon+','+day+','+str("{:6.4f}".format(UTCHrs[k]))+','+ \ >>> str("{:9.7f}".format(AExt[k,0]))+','+str({:9.7f}".format(AExt[k,1]))+','+ \ >>> str("{:9.7f}".format(AExt[k,2]))+','+str("{:9.7f}".format(AExt[k,3]))+','+ \ >>> str("{:9.7f}".format(AExt[k,4]))+','+str("{:9.7f}".format(AExt[k,5]))+','+ \ >>> str("{:9.7f}".format(AExt[k,6]))+','+str("{:9.7f}".format(AExt[k,7]))+','+ \ >>> str("{:9.7f}".format(AExt[k,8]))+','+str("{:9.7f}".format(AExt[k,9])) >>> >>> >>> k is a row index >>> >>> Can some one suggest me how I can iterate the column index along with row index to concatenate the string as per the above format? >>> >>> Thanks in advance >>> >> >> The following (untested) assumes that you are using a reasonably >> up-to-date Python that has the 'f' format operator. >> >> tempStr = f'{year},{mon},{day},{UTCHrs[k]:6.4f}' >> for col in range(10): >> tempStr += f',{AExt[k, col]:9.7f}' >> > > As a minor performance note (not really important with only 10 items, > but better to get into good habits from the start): > > temp = [f'{year},{mon},{day},{UTCHrs[k]:6.4f}'] > for col in range(10): > temp.append(f',{AExt[k, col]:9.7f}') > > tempStr = ''.join(tempStr) > > Repeated concatenation of immutable strings (which is what Python has) > is O(N**2) in the number of chunks added because of the need to > repeatedly copy the string. A more pythonic approach might be to eschew the "k is a row index" and resultant range(), by gathering the temperature readings into a list/tuple (tuple unpacking at read-step or zip(), as appropriate). The point of which (hah!) is to get rid of "pointers", and replace the 'algebra' with more readable code. The collection can then be processed into the string using .append() and/or .join(), perhaps with a list comprehension/generator... -- Regards =dn From jfong at ms4.hinet.net Sat Jun 1 21:28:33 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 1 Jun 2019 18:28:33 -0700 (PDT) Subject: tkinter.tix "Control" widget don't work with StringVar? Message-ID: Below is a simplified version of the sample script downloaded from its package. When run it, the entry field display '0' instead of 'P&W'. PS. I am using Python 3.4.4, Windows 32bit ----test0.py---- 1 from tkinter import tix as Tix 2 3 root = Tix.Tk() 4 5 demo_maker = Tix.StringVar() 6 demo_maker.set('P&W') 7 8 c = Tix.Control(root, label='Engine Maker: ', 9 variable=demo_maker, 10 options='entry.width 10 label.width 20 label.anchor e') 11 c.pack(side=Tix.TOP, anchor=Tix.W) 12 13 root.mainloop() -------- I run it under pdb, try to figure out where the problem is: D:\Works\Python>py -m pdb test0.py > d:\works\python\test0.py(1)() -> from tkinter import tix as Tix (Pdb) tbreak 13 Breakpoint 1 at d:\works\python\test0.py:13 (Pdb) cont Deleted breakpoint 1 at d:\works\python\test0.py:13 > d:\works\python\test0.py(13)() -> root.mainloop() (Pdb) !c['value'] '0' (Pdb) !demo_maker.get() 'P&W' (Pdb) quit If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', value='P&W',", the result is very interest: D:\Works\Python>py -m pdb test0.py > d:\works\python\test0.py(1)() -> from tkinter import tix as Tix (Pdb) tbreak 13 Breakpoint 1 at d:\works\python\test0.py:13 (Pdb) cont Deleted breakpoint 1 at d:\works\python\test0.py:13 > d:\works\python\test0.py(13)() -> root.mainloop() (Pdb) !c['value'] '0' (Pdb) !demo_maker.get() '0' (Pdb) quit Anyone can help? --Jach From tjreedy at udel.edu Sat Jun 1 22:06:37 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 1 Jun 2019 22:06:37 -0400 Subject: tkinter.tix "Control" widget don't work with StringVar? In-Reply-To: References: Message-ID: On 6/1/2019 9:28 PM, jfong at ms4.hinet.net wrote: > Below is a simplified version of the sample script downloaded from its package. > When run it, the entry field display '0' instead of 'P&W'. > PS. I am using Python 3.4.4, Windows 32bit > > ----test0.py---- > 1 from tkinter import tix as Tix > 2 > 3 root = Tix.Tk() > 4 > 5 demo_maker = Tix.StringVar() > 6 demo_maker.set('P&W') > 7 > 8 c = Tix.Control(root, label='Engine Maker: ', > 9 variable=demo_maker, > 10 options='entry.width 10 label.width 20 label.anchor e') > 11 c.pack(side=Tix.TOP, anchor=Tix.W) > 12 > 13 root.mainloop() > -------- Line numbers interfere with copy and paste. Control or Spinbox controls a number that can be increased or decreased with the arrows. You can use a number string like '33' or Intvar or Floatvar. Note that tix is unmaintained, deprecated, and generally not advised for new code (or new users). -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Jun 1 22:15:13 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 2 Jun 2019 03:15:13 +0100 Subject: tkinter.tix "Control" widget don't work with StringVar? In-Reply-To: References: Message-ID: On 2019-06-02 02:28, jfong at ms4.hinet.net wrote: > Below is a simplified version of the sample script downloaded from its package. > When run it, the entry field display '0' instead of 'P&W'. > PS. I am using Python 3.4.4, Windows 32bit > > ----test0.py---- > 1 from tkinter import tix as Tix > 2 > 3 root = Tix.Tk() > 4 > 5 demo_maker = Tix.StringVar() > 6 demo_maker.set('P&W') > 7 > 8 c = Tix.Control(root, label='Engine Maker: ', > 9 variable=demo_maker, > 10 options='entry.width 10 label.width 20 label.anchor e') > 11 c.pack(side=Tix.TOP, anchor=Tix.W) > 12 > 13 root.mainloop() > -------- > > I run it under pdb, try to figure out where the problem is: > > D:\Works\Python>py -m pdb test0.py >> d:\works\python\test0.py(1)() > -> from tkinter import tix as Tix > (Pdb) tbreak 13 > Breakpoint 1 at d:\works\python\test0.py:13 > (Pdb) cont > Deleted breakpoint 1 at d:\works\python\test0.py:13 >> d:\works\python\test0.py(13)() > -> root.mainloop() > (Pdb) !c['value'] > '0' > (Pdb) !demo_maker.get() > 'P&W' > (Pdb) quit > > If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', value='P&W',", the result is very interest: > > D:\Works\Python>py -m pdb test0.py >> d:\works\python\test0.py(1)() > -> from tkinter import tix as Tix > (Pdb) tbreak 13 > Breakpoint 1 at d:\works\python\test0.py:13 > (Pdb) cont > Deleted breakpoint 1 at d:\works\python\test0.py:13 >> d:\works\python\test0.py(13)() > -> root.mainloop() > (Pdb) !c['value'] > '0' > (Pdb) !demo_maker.get() > '0' > (Pdb) quit > > Anyone can help? > From the documentation: """class tkinter.tix.Control The Control widget is also known as the SpinBox widget. The user can adjust the value by pressing the two arrow buttons or by entering the value directly into the entry. The new value will be checked against the user-defined upper and lower limits.""" In other words, the widget that you're using is for entering a _number_; you can click the up and down buttons to change its value. You usually use it with tix.IntVar. You're using it with tix.StringVar, which is for strings, and because it's unable to interpret the value as a number, it's pretending that it's 0 instead. You can, however, set it to, say, '1', or '01', and the widget will then show the number 1. From jfong at ms4.hinet.net Sat Jun 1 22:44:14 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 1 Jun 2019 19:44:14 -0700 (PDT) Subject: tkinter.tix "Control" widget don't work with StringVar? In-Reply-To: References: Message-ID: <6a1f2602-365b-4a2e-92af-432b02b0943a@googlegroups.com> MRAB? 2019?6?2???? UTC+8??10?18?36???? > On 2019-06-02 02:28, jfong at ms4.hinet.net wrote: > > Below is a simplified version of the sample script downloaded from its package. > > When run it, the entry field display '0' instead of 'P&W'. > > PS. I am using Python 3.4.4, Windows 32bit > > > > ----test0.py---- > > 1 from tkinter import tix as Tix > > 2 > > 3 root = Tix.Tk() > > 4 > > 5 demo_maker = Tix.StringVar() > > 6 demo_maker.set('P&W') > > 7 > > 8 c = Tix.Control(root, label='Engine Maker: ', > > 9 variable=demo_maker, > > 10 options='entry.width 10 label.width 20 label.anchor e') > > 11 c.pack(side=Tix.TOP, anchor=Tix.W) > > 12 > > 13 root.mainloop() > > -------- > > > > I run it under pdb, try to figure out where the problem is: > > > > D:\Works\Python>py -m pdb test0.py > >> d:\works\python\test0.py(1)() > > -> from tkinter import tix as Tix > > (Pdb) tbreak 13 > > Breakpoint 1 at d:\works\python\test0.py:13 > > (Pdb) cont > > Deleted breakpoint 1 at d:\works\python\test0.py:13 > >> d:\works\python\test0.py(13)() > > -> root.mainloop() > > (Pdb) !c['value'] > > '0' > > (Pdb) !demo_maker.get() > > 'P&W' > > (Pdb) quit > > > > If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', value='P&W',", the result is very interest: > > > > D:\Works\Python>py -m pdb test0.py > >> d:\works\python\test0.py(1)() > > -> from tkinter import tix as Tix > > (Pdb) tbreak 13 > > Breakpoint 1 at d:\works\python\test0.py:13 > > (Pdb) cont > > Deleted breakpoint 1 at d:\works\python\test0.py:13 > >> d:\works\python\test0.py(13)() > > -> root.mainloop() > > (Pdb) !c['value'] > > '0' > > (Pdb) !demo_maker.get() > > '0' > > (Pdb) quit > > > > Anyone can help? > > > From the documentation: > > """class tkinter.tix.Control > The Control widget is also known as the SpinBox widget. The user can > adjust the value by pressing the two arrow buttons or by entering the > value directly into the entry. The new value will be checked against the > user-defined upper and lower limits.""" > > In other words, the widget that you're using is for entering a _number_; > you can click the up and down buttons to change its value. You usually > use it with tix.IntVar. > > You're using it with tix.StringVar, which is for strings, and because > it's unable to interpret the value as a number, it's pretending that > it's 0 instead. You can, however, set it to, say, '1', or '01', and the > widget will then show the number 1. >From the documents, it sounds that this widget was designed for number only. But the original example Control.py from https://svn.python.org/projects/stackless/trunk/Demo/tix/samples/ works on string either by changing its button command. The only thing bothers me is that why it fails at the start-up? and I can't figure out the reason:-( From Markus.Elfring at web.de Sun Jun 2 01:14:39 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sun, 2 Jun 2019 07:14:39 +0200 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: <20190601224333.bdpv7wvthd4qgncd@hjp.at> References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> <20190601173209.t25f35m5wk4lj6si@hjp.at> <4c6d667f-bc3c-9d59-a33c-d2dfc5d86a36@web.de> <20190601183011.n2ylb64f2eelbwmj@hjp.at> <91576c05-1edc-ce85-e51b-cbb35e9a3a24@web.de> <20190601224333.bdpv7wvthd4qgncd@hjp.at> Message-ID: > "Handled transparently" means that an ipv6 server can handle connections > from ipv4 clients without doing anything special. It is nice if this conversion is working. > They just appear to come from a specific IPv6 address range. I got expected connections by my small script ?socket-send_test_data1.tcl?. >> Under which circumstances will the Python programming interfaces >> support the direct usage of the identification ?::1?? > > I'm not sure I understand the question. They do. How would like to explain the error message ?socket.gaierror: [Errno -9] Address family for hostname not supported? on my Linux test system then? Regards, Markus From cs at cskk.id.au Sun Jun 2 01:55:41 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Jun 2019 15:55:41 +1000 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: References: Message-ID: <20190602055541.GA23756@cskk.homeip.net> On 02Jun2019 07:14, Markus Elfring wrote: >> "Handled transparently" means that an ipv6 server can handle connections >> from ipv4 clients without doing anything special. > >It is nice if this conversion is working. > > >> They just appear to come from a specific IPv6 address range. > >I got expected connections by my small script ?socket-send_test_data1.tcl?. > > >>> Under which circumstances will the Python programming interfaces >>> support the direct usage of the identification ?::1?? >> >> I'm not sure I understand the question. They do. > >How would like to explain the error message ?socket.gaierror: [Errno -9] >Address family for hostname not supported? on my Linux test system >then? Can you supply a tiny standalone piece of code demonstrating this error please? I've dug through the thread and can't see one. Cheers, Cameron Simpson From __peter__ at web.de Sun Jun 2 03:03:12 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 02 Jun 2019 09:03:12 +0200 Subject: How to concatenate strings with iteration in a loop? References: <6173af87-62e6-4c37-a5f2-a70619c040b9@googlegroups.com> <4c26feee-ff54-313c-9798-e99c32797139@chagford.com> Message-ID: DL Neil wrote: > On 21/05/19 8:40 PM, Paul Moore wrote: >> On Tue, 21 May 2019 at 09:25, Frank Millman wrote: >>> >>> On 2019-05-21 9:42 AM, Madhavan Bomidi wrote: >>>> Hi, >>>> >>>> I need to create an array as below: >>>> >>>> tempStr = >>>> year+','+mon+','+day+','+str("{:6.4f}".format(UTCHrs[k]))+','+ \ >>>> str("{:9.7f}".format(AExt[k,0]))+','+str({:9.7f}".format(AExt[k,1]))+','+ >>>> \ >>>> str("{:9.7f}".format(AExt[k,2]))+','+str("{:9.7f}".format(AExt[k,3]))+','+ >>>> \ >>>> str("{:9.7f}".format(AExt[k,4]))+','+str("{:9.7f}".format(AExt[k,5]))+','+ >>>> \ >>>> str("{:9.7f}".format(AExt[k,6]))+','+str("{:9.7f}".format(AExt[k,7]))+','+ >>>> \ str("{:9.7f}".format(AExt[k,8]))+','+str("{:9.7f}".format(AExt[k,9])) >>>> >>>> >>>> k is a row index >>>> >>>> Can some one suggest me how I can iterate the column index along with >>>> row index to concatenate the string as per the above format? >>>> >>>> Thanks in advance >>>> >>> >>> The following (untested) assumes that you are using a reasonably >>> up-to-date Python that has the 'f' format operator. >>> >>> tempStr = f'{year},{mon},{day},{UTCHrs[k]:6.4f}' >>> for col in range(10): >>> tempStr += f',{AExt[k, col]:9.7f}' >>> >> >> As a minor performance note (not really important with only 10 items, >> but better to get into good habits from the start): >> >> temp = [f'{year},{mon},{day},{UTCHrs[k]:6.4f}'] >> for col in range(10): >> temp.append(f',{AExt[k, col]:9.7f}') >> >> tempStr = ''.join(tempStr) >> >> Repeated concatenation of immutable strings (which is what Python has) >> is O(N**2) in the number of chunks added because of the need to >> repeatedly copy the string. > > > A more pythonic approach might be to eschew the "k is a row index" and > resultant range(), by gathering the temperature readings into a > list/tuple (tuple unpacking at read-step or zip(), as appropriate). The > point of which (hah!) is to get rid of "pointers", and replace the > 'algebra' with more readable code. > > The collection can then be processed into the string using .append() > and/or .join(), perhaps with a list comprehension/generator... One way: temp_str = ",".join( itertools.chain( (year, mon, day, f"{UTCHrs[k]:6.4f}"), (f"{x:9.7f}" for x in AExt[k]) ) ) This assumes that the magic number 10 is actually len(AExt[k]). From Markus.Elfring at web.de Sun Jun 2 03:15:28 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sun, 2 Jun 2019 09:15:28 +0200 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: <20190602055541.GA23756@cskk.homeip.net> References: <20190602055541.GA23756@cskk.homeip.net> Message-ID: <5db2d9f1-449a-6bcb-5cf5-b77e62a8410b@web.de> >> How would like to explain the error message ?socket.gaierror: [Errno -9] >> Address family for hostname not supported? on my Linux test system then? > > Can you supply a tiny standalone piece of code demonstrating this error please? The following script part would be relevant. ? def send_data(x): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as so: global args so.connect((args.server_id, args.server_port)) ? If the address family ?AF_INET6? was passed instead, the identification ?::1? can work also as a command parameter. The data transmission seems to succeed by my script ?socket-send_json_data2.py? then. Regards, Markus From Markus.Elfring at web.de Sun Jun 2 03:15:28 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Sun, 2 Jun 2019 09:15:28 +0200 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: <20190602055541.GA23756@cskk.homeip.net> References: <20190602055541.GA23756@cskk.homeip.net> Message-ID: <097e77b3-eb54-f626-8e58-d25b08c245a0@web.de> >> How would like to explain the error message ?socket.gaierror: [Errno -9] >> Address family for hostname not supported? on my Linux test system then? > > Can you supply a tiny standalone piece of code demonstrating this error please? The following script part would be relevant. ? def send_data(x): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as so: global args so.connect((args.server_id, args.server_port)) ? If the address family ?AF_INET6? was passed instead, the identification ?::1? can work also as a command parameter. The data transmission seems to succeed by my script ?socket-send_json_data2.py? then. Regards, Markus From rosuav at gmail.com Sun Jun 2 03:49:07 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Jun 2019 17:49:07 +1000 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: <5db2d9f1-449a-6bcb-5cf5-b77e62a8410b@web.de> References: <20190602055541.GA23756@cskk.homeip.net> <5db2d9f1-449a-6bcb-5cf5-b77e62a8410b@web.de> Message-ID: On Sun, Jun 2, 2019 at 5:17 PM Markus Elfring wrote: > > >> How would like to explain the error message ?socket.gaierror: [Errno -9] > >> Address family for hostname not supported? on my Linux test system then? > > > > Can you supply a tiny standalone piece of code demonstrating this error please? > > The following script part would be relevant. > > ? > def send_data(x): > with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as so: > global args > so.connect((args.server_id, args.server_port)) > ? > > > If the address family ?AF_INET6? was passed instead, the identification ?::1? > can work also as a command parameter. > The data transmission seems to succeed by my script ?socket-send_json_data2.py? then. > May I recommend using this function instead? It'll be easier to handle both IPv4 and IPv6: https://docs.python.org/3/library/socket.html#socket.create_connection ChrisA From cs at cskk.id.au Sun Jun 2 04:09:37 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Jun 2019 18:09:37 +1000 Subject: Checking support for network connections from Python client to IPv6 server In-Reply-To: References: Message-ID: <20190602080937.GA60578@cskk.homeip.net> On 02Jun2019 17:49, Chris Angelico wrote: >On Sun, Jun 2, 2019 at 5:17 PM Markus Elfring wrote: >> >> How would like to explain the error message ?socket.gaierror: >> >> [Errno -9] >> >> Address family for hostname not supported? on my Linux test system then? >> > >> > Can you supply a tiny standalone piece of code demonstrating this error please? >> >> The following script part would be relevant. >> >> ? >> def send_data(x): >> with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as so: >> global args >> so.connect((args.server_id, args.server_port)) >> ? >> >> If the address family ?AF_INET6? was passed instead, the identification ?::1? >> can work also as a command parameter. >> The data transmission seems to succeed by my script ?socket-send_json_data2.py? then. >> > >May I recommend using this function instead? It'll be easier to handle >both IPv4 and IPv6: > >https://docs.python.org/3/library/socket.html#socket.create_connection I think I'm with Chris here: by using AF_INET you're saying "IPv4 only please". "::1" is not an IPv4 address. hence your error. It's not called "AF_INET4" because it predates IPv6. The function Chris has suggested to you tries both IPv4 and IPv6. Cheers, Cameron Simpson From wiwindson at gmail.com Sun Jun 2 22:02:06 2019 From: wiwindson at gmail.com (Windson Yang) Date: Mon, 3 Jun 2019 10:02:06 +0800 Subject: Questions about the IO modules and C-api Message-ID: I have some questions about the IO modules. 1. My script: f = open('myfile, 'a+b') f.close() I added a printf statement at the beginning of _io_open_impl , the output is: _io_open _io_open _io_open _io_open _io_open Why this function has been called more than one time? I expect this function only let us call the `open()` system call once. 2. I'm not familiar with the C, How the c-api like PyObject_CallMethodObjArgs(self->raw, _PyIO_str_write, memobj, NULL) works? I guess this function will finally call the `write()` system call but I don't know why it would work. I found `self->raw` is an empty PyObject and `_PyIO_str_write` is a global variable which is NULL. Why an empty PyObject have a write method? Why we didn't just use `write()` system call directly? Thank you so much :D Best, Windson From tjol at tjol.eu Mon Jun 3 02:15:28 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 3 Jun 2019 08:15:28 +0200 Subject: Questions about the IO modules and C-api In-Reply-To: References: Message-ID: <3414ccbd-c6ab-e799-df62-019ef4cfbd1c@tjol.eu> On 03/06/2019 04:02, Windson Yang wrote: > I have some questions about the IO modules. > > 1. My script: > > f = open('myfile, 'a+b') > f.close() > > I added a printf statement at the beginning of _io_open_impl > , > the output is: Is this the output of running `python your_script.py`? If it is, it may include calls to _io.open made during Python startup. Maybe you can add a line to print out which file is being opened each time as well (this is a bit tricky). Or you could add print() calls at the start and end of your script to see what's happening during, what before, and what after your script. > 2. I'm not familiar with the C, How the c-api like > PyObject_CallMethodObjArgs(self->raw, > _PyIO_str_write, memobj, NULL) > > works? If you haven't yet, I suggest you read the Python C API tutorial [1] and consult the C API reference [2]. FWIW, the write call is ultimately here [3] via here [4]. [1] https://docs.python.org/3/extending/index.html [2] https://docs.python.org/3/c-api/index.html [3] https://github.com/python/cpython/blob/b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184/Python/fileutils.c#L1586 [4] https://github.com/python/cpython/blob/master/Modules/_io/fileio.c#L854 > > I guess this function will finally call the `write()` system call but I > don't know why it would work. I found `self->raw` is an empty PyObject and > `_PyIO_str_write` is a global variable which is NULL. Why an empty > PyObject have a write method? Why we didn't just use `write()` system call > directly? Oh, but it's not NULL, is it? https://github.com/python/cpython/blob/331a6a56e9a9c72f3e4605987fabdaec72677702/Modules/_io/_iomodule.c#L761 I don't believe self->raw is "empty" either. It's initialized by _io.open, isn't it? As for why go through the python method rather than calling something in C directly, that would be in order to allow BufferedWriter to be used with different types of IO classes, not just files. -- Thomas From eryksun at gmail.com Mon Jun 3 08:29:54 2019 From: eryksun at gmail.com (eryk sun) Date: Mon, 3 Jun 2019 07:29:54 -0500 Subject: Questions about the IO modules and C-api In-Reply-To: References: Message-ID: On 6/2/19, Windson Yang wrote: > > f = open('myfile, 'a+b') This is missing the closing quote around 'myfile'. > I added a printf statement at the beginning of _io_open_impl Repeatedly rebuilding the interpreter sounds like a frustrating learning experience, IMO. Use a debugger such as gdb in Linux or cdb, WinDbg or Visual Studio in Windows. > 2. I'm not familiar with the C, IMO, start with a good book or tutorial on C. > I found `self->raw` is an empty PyObject and > `_PyIO_str_write` is a global variable which is NULL. Why an empty > PyObject have a write method? The macro that defines _PyIO_str_write was already pointed out to you by Thomas. A C programmer should know to look for a macro definition, and someone experienced with the Python 3 C API should know to look in the module initialization function PyInit_. Consider that in terms of learning Python internals, you may be putting the cart before the horse as they say. Let's inspect these values in the console debugger (cdb) in Windows, which is not the greatest debugging experience, but it works. Below I have the debugger attached to an interactive Python 3.8 session with a breakpoint set on _bufferedwriter_raw_write: >>> f = open(filename, 'wb', buffering=10) >>> n = f.write(b'spam' * 3) Breakpoint hit: python38!_bufferedwriter_raw_write: 00007ffd`1950ff50 4c8bdc mov r11,rsp Let's see what self->raw is. 0:000> ?? self->raw->ob_type->tp_name char * 0x00007ffd`197dd378 "_io.FileIO" It's the FileIO object that we can reference in Python as the `raw` attribute of the buffered writer. Next check the value of _PyIO_str_write. 0:000> ?? ((PyASCIIObject *)_PyIO_str_write)->state struct +0x000 interned : 0y01 +0x000 kind : 0y001 +0x000 compact : 0y1 +0x000 ascii : 0y1 +0x000 ready : 0y1 This is a compact ASCII string, meaning that it's a char string that immediately follows the object. Use pointer arithmetic and cast to `char *`: 0:000> ?? (char *)(((PyASCIIObject *)_PyIO_str_write) + 1) char * 0x0000014c`823b4560 "write" So we're calling the write method of our raw object, i.e. f.raw.write. > Why we didn't just use `write()` system call directly? The raw layer is a necessary abstraction in the I/O stack. For a concrete example, consider the raw I/O type io._WindowsConsoleIO. For writing, it transcodes from UTF-8 to UTF-16LE and calls the wide-character function WriteConsoleW. For reading, it calls ReadConsoleW and transcodes from UTF-16LE to UTF-8. From Markus.Elfring at web.de Mon Jun 3 08:54:29 2019 From: Markus.Elfring at web.de (Markus Elfring) Date: Mon, 3 Jun 2019 14:54:29 +0200 Subject: Checking refusal of a network connection In-Reply-To: References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: > How would this conversion take place? Localhost is 127.0.0.1. > Localhost6 is ::1. They are different My configuration file ?/etc/hosts? provides the following information as usual. ?? ::1 localhost ipv6-localhost ipv6-loopback ?? > and you cannot route between the two. I got other expectations for the corresponding software behaviour. > What I can see is that your server binds to localhost6 and your client > is trying to connect to localhost. I am curious to clarify the circumstances further if such a combination can also work finally. If my software test client would pass the IPv6 address family for a connection, both processes would use the same network protocol version. Regards, Markus From bernd.lentes at helmholtz-muenchen.de Mon Jun 3 11:05:52 2019 From: bernd.lentes at helmholtz-muenchen.de (Lentes, Bernd) Date: Mon, 3 Jun 2019 17:05:52 +0200 (CEST) Subject: new to python - like to write a script with the libvirt-python 5.3.0 package Message-ID: <1165347818.1423645.1559574352079.JavaMail.zimbra@helmholtz-muenchen.de> Hello dear Python-community, i'm pretty new to Python. I made a seminar two weeks ago and like to write now a script because if i don't i will have forgotten everything in a few weeks. If this is the wrong place to ask my question please tell me where is the appropriate one. I'm a Sysadmin, not a software developer. We are running a two-node High Availibility cluster on SLES 12 SP4 with virtual machines on it. I wrote a shellscript to create consistent images of the virtual machines each night, using the bash and virsh (the libvirt shell). Script is running fairly fine, but i need to extend it. I'm thinking of rewriting it in python, i think that would be a good practise. Inside the script i'm using things like "virsh start, virsh shutdown, virsh snaphot-list, virsh snapshot, virsh snapshot-delete, virsh domblklist, virsh blockcommit, virsh list, virsh define ..." Can i use all the possibilities i have in virsh in that libvirt-package ? I'm also creating logfiles, deleting files, sending e-Mails, redirecting stdout and stderr. This shouldn't be a problem in Python ? Thanks. Bernd -- Bernd Lentes Systemadministration Institut f?r Entwicklungsgenetik Geb?ude 35.34 - Raum 208 HelmholtzZentrum m?nchen bernd.lentes at helmholtz-muenchen.de phone: +49 89 3187 1241 phone: +49 89 3187 3827 fax: +49 89 3187 2294 http://www.helmholtz-muenchen.de/idg wer Fehler macht kann etwas lernen wer nichts macht kann auch nichts lernen Helmholtz Zentrum Muenchen Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH) Ingolstaedter Landstr. 1 85764 Neuherberg www.helmholtz-muenchen.de Stellv. Aufsichtsratsvorsitzender: MinDirig. Dr. Manfred Wolter Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Heinrich Bassler, Kerstin Guenther Registergericht: Amtsgericht Muenchen HRB 6466 USt-IdNr: DE 129521671 From eileen at themaii.org Mon Jun 3 15:18:36 2019 From: eileen at themaii.org (eileen at themaii.org) Date: Mon, 3 Jun 2019 12:18:36 -0700 (PDT) Subject: Trying to test SelectDateWidget as SelectMonthDayWidget on command line Message-ID: <352fb673-328d-4284-bbfa-4be1b2bdff47@googlegroups.com> Hi, I'm a newbie and I want to change the Django SelectDateWidget to SelectMonthDayWidget because I can't use the year in my application. I had been getting another error (which I don't recall right now) on the statement that started 'html['month']' so, I decided to convert it to command line to get a better picture of what's going on. Unfotunately, now I get: Traceback (most recent call last): File "SelectMDWidget.py", line 34, in class SelectMonthDayWidget(month,day_ok): TypeError: Error when calling the metaclass bases unicode() argument 2 must be string, not tuple What am I doing wrong? I'm passing the class two strings... """ HTML Widget classes """ from __future__ import unicode_literals import copy import re from itertools import chain from django.conf import settings from django.forms.widgets import Widget, Select from django.templatetags.static import static from django.utils import formats from django.utils.dates import MONTHS from django.utils.formats import get_format from django.utils.safestring import mark_safe from django.utils.six.moves import range from django.utils.translation import ugettext_lazy, gettext_lazy as _ from django.utils.deprecation import ( RemovedInDjango20Warning, RenameMethodsBase, ) from django.utils.encoding import ( force_str, force_text, python_2_unicode_compatible, ) __all__ = ('SelectMonthDayWidget', ) day_ok = u'' month = u'' class SelectMonthDayWidget(month,day_ok): """ A Widget that splits date input into three boxes. > > This also serves as an example of a Widget that has more than one HTML > element and hence implements value_from_datadict. > """ [snip] In other words, you're asking it to do: class SelectMonthDayWidget(u'', u''): .... From formisc at gmail.com Tue Jun 4 01:41:56 2019 From: formisc at gmail.com (Andrew Z) Date: Tue, 4 Jun 2019 01:41:56 -0400 Subject: Pandas- yahoo finance Message-ID: Hello, Do i get it right that yahoo finance is no longer available as a data source for pandas? From grant.b.edwards at gmail.com Tue Jun 4 11:17:51 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 4 Jun 2019 15:17:51 -0000 (UTC) Subject: Fw: Download issues for Python References: Message-ID: On 2019-06-04, tom milikic wrote: > [...] > > It states that this is missing from my computer -: > > api-ms-win-crt-runtime-l1-1-0.dl [You left off the second 'l'. Precision is very important when dealing with software problems.] You can often the answer just by Googling the error message: https://www.google.com/search?q=python+install+missing+api-ms-win-crt-runtime-l1-1-0.dll&oq=python+install+missing+api-ms-win-crt-runtime-l1-1-0.dll -- Grant Edwards grant.b.edwards Yow! I'm thinking about at DIGITAL READ-OUT systems gmail.com and computer-generated IMAGE FORMATIONS ... From hjp-python at hjp.at Tue Jun 4 11:26:16 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 4 Jun 2019 17:26:16 +0200 Subject: Checking refusal of a network connection In-Reply-To: References: <274a7e1f-fc0d-0744-af06-bb861af8e30c@web.de> <20190531231738.GA92303@cskk.homeip.net> Message-ID: <20190604152616.isakx673udmzlwdi@hjp.at> On 2019-06-03 14:54:29 +0200, Markus Elfring wrote: > > How would this conversion take place? Localhost is 127.0.0.1. > > Localhost6 is ::1. They are different > > My configuration file ?/etc/hosts? provides the following information > as usual. > > ?? > ::1 localhost ipv6-localhost ipv6-loopback > ?? The name doesn't matter on the TCP/IP level it is only used to get the correct IP address(es). The line above looks like something from Debian or Ubuntu. If so, you'll have another line 127.0.0.1 localhost localhost.localdomain above, So if you pass the name "localhost" to socket.connect, it will check /etc/hosts (and possibly DNS and other data sources) and get back a list of IP addresses, ['127.0.0.1', '::1'] in this case (the order may be different). It will then try to connect to each of these IP addresses in turn. But if you pass it an IP address (like '::1'), it will connect only to the IP address you gave it. It won't try to find out if there is a name associated with that address and whether this name is also associated with other addresses and try to connect to those. And the address ::1 is clearly distinct from the address 127.0.0.1, even if the name "localhost" refers to both and both are bound to the same interface. This is not unusual. If you do a DNS lookup on yahoo.com. you will see that that name refers to 6 IPv4 and 6 IPv6 addresses - 12 different addresses for the same name. OTOH I frequently run several webservers on the same host and when I can, I give them different IP addresses, too. I think the maximum I've had was over 50 IP addresses on the same (physical) interface. Naturally when you connect to 192.0.2.23 you don't want to get connected to the webserver listening on 192.0.2.42 just because that's the same interface. > > and you cannot route between the two. > > I got other expectations for the corresponding software behaviour. You might have to adjust your expectations. > > What I can see is that your server binds to localhost6 and your client > > is trying to connect to localhost. > > I am curious to clarify the circumstances further if such a combination > can also work finally. Users generally use names, not IP addresses. When you connect to Google, you use the URL https://google.com, not https://172.217.23.238 or https://[2a00:1450:4014:80d::200e]. The server listens on both addresses, the client will try both addresses if IPv6 is available, or only the IPv4 address if IPv6 isn't available. (Not sure if this answers your question since I'm not sure what your question is) > If my software test client would pass the IPv6 address family for a > connection, both processes would use the same network protocol > version. Yes. 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 lukasz at langa.pl Tue Jun 4 18:44:04 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Wed, 5 Jun 2019 00:44:04 +0200 Subject: [RELEASE] Python 3.8.0b1 is now available for testing Message-ID: <2FEBF8A0-7D2D-4BB8-BE37-6B0E6D9F75B8@langa.pl> The time has come for Python 3.8.0b1: https://www.python.org/downloads/release/python-380b1/ This release is the first 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.0b2, currently scheduled for 2019-07-01. 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. 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.0rc1, 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. Please keep in mind that this is a preview release and its use is not recommended for production environments. A new challenger has appeared! With the release of Python 3.8.0b1, development started on Python 3.9. The ?master? branch in the cpython repository now tracks development of 3.9 while Python 3.8 received its own branch, called simply ?3.8?. Acknowledgments As you might expect, creating new branches triggers a lot of changes in configuration for all sorts of tooling that we?re using. Additionally, the inevitable deadline for new features caused a flurry of activity that tested the buildbots to the max. The revert hammer got used more than once. I would not be able to make this release available alone. Many thanks to the fearless duo of Pablo Galindo Salgado and Victor Stinner for spending tens of hours during the past week working on getting the buildbots green for release. Seriously, that took a lot of effort. We are all so lucky to have you both. Thanks to Andrew Svetlov for his swift fixes to asyncio and to Yury Selivanov for code reviews, even when jetlagged. Thanks to Julien Palard for untangling the documentation configs. Thank you to Zachary Ware for help with buildbot and CI configuration. Thanks to Mariatta for helping with the bots. Thank you to Steve Dower for delivering the Windows installers. Most importantly though, huge thanks to Ned Deily who not only helped me understand the scope of this special release but also did some of the grunt work involved. Last but not least, thanks to you for making this release more meaty than I expected. There?s plenty of super exciting changes in there. Just take a look at ?What?s New ?! One more thing Hey, fellow Core Developer, Beta 2 is in four weeks. If your important new feature got reverted last minute, or you decided not to merge due to inadequate time, I have a one time offer for you (restrictions apply). If you: find a second core developer champion for your change; and in tandem you finish your change complete with tests and documentation before Beta 2 then I will let it in. I?m asking for a champion because it?s too late now for changes with hasty design or code review. And as I said, restrictions apply. For instance, at this point changes to existing APIs are unlikely to be accepted. Don?t start new work with 3.8 in mind. 3.9 is going to come sooner than you think! - ? -------------- 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 fczwtyds at gmail.com Wed Jun 5 11:57:03 2019 From: fczwtyds at gmail.com (Fc Zwtyds) Date: Wed, 5 Jun 2019 23:57:03 +0800 Subject: How to use ssh-agent in windows in python? References: <20190531230133.GA67454@cskk.homeip.net> Message-ID: ? 2019-06-01 7:01, Cameron Simpson ??: > On 31May2019 21:51, Fc Zwtyds wrote: >>> ? 2019-05-30 6:41, Cameron Simpson ??: >>>> The you could just use os.system() to run the other commands, >>>> because the environment now has the necessary environment settings. > [...] >> >> ?Under your guidance, the python code using ssh-agent ssh-add has been >> running successfully. In addition to the code you wrote to me, I also >> refer to man ssh-agent and subprocess: Subprocess management. I now >> know the importance of environment variables. > > Excellent. I'm glad to hear it. > >> BTW, this program is for visit youtube. > > I am curious, how do you use the ssh commands to access youtube? I > though it was an HTTP only service. > > Cheers, > Cameron Simpson Sorry, I have not encountered very difficult problems, I will not come here to ask for help. It is because of your help that I will not be trapped by this problem for more time. Just like accessing google, without the help of ssh, you can't access youtube, you should know now. Thank you again for your selfless help. From rshepard at appl-ecosys.com Wed Jun 5 16:45:14 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 5 Jun 2019 13:45:14 -0700 (PDT) Subject: tkinter: tk.grid columnspan Message-ID: In one row of a grid layout I have these two input widgets: self.inputs['name'] = LabelInput( self, 'Site Name', input_var=tk.StringVar(), ) self.inputs['name'].grid(sticky=tk.W, row=0, column=0) self.inputs['description'] = LabelInput( self, 'Site Description', input_var=tk.StringVar(), ) self.inputs['description'].grid(row=0, column=1, columnspan=2) I want the second one (description) to be wider and thought the columnspan option would do the job. It does not. I've read several web pages on the tk.grid without seeing the proper way of making a stringvar wider than a single grid cell. Please teach me how to make a tk.StingVar cover two columns in a grid layout. TIA, Rich From tjreedy at udel.edu Wed Jun 5 17:19:10 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Jun 2019 17:19:10 -0400 Subject: tkinter: tk.grid columnspan In-Reply-To: References: Message-ID: On 6/5/2019 4:45 PM, Rich Shepard wrote: > In one row of a grid layout I have these two input widgets: > > ????self.inputs['name'] = LabelInput( > ??????????? self, 'Site Name', > ??????????? input_var=tk.StringVar(), > ??????????? ) > ??????? self.inputs['name'].grid(sticky=tk.W, row=0, column=0) > > ??????? self.inputs['description'] = LabelInput( > ??????????? self, 'Site Description', > ??????????? input_var=tk.StringVar(), > ??????? ) > ??????? self.inputs['description'].grid(row=0, column=1, columnspan=2) > > I want the second one (description) to be wider and thought the columnspan > option would do the job. It does not. I've read several web pages on the > tk.grid without seeing the proper way of making a stringvar wider than a > single grid cell. > > Please teach me how to make a tk.StingVar cover two columns in a grid > layout. Unless you specifiy otherwise through expand and weight options, grid columns are the minimum width required for the widest minimum width of any widget in the column. The columnspan makes the minimum width of 'description' the minimum width of column 1 plus the minimum width of column 2. With nothing else in columns 1 and 2, it has no effect. Try reading the grid page at http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html if you can get it to load. (I did a couple of days ago, but not today.) -- Terry Jan Reedy From rshepard at appl-ecosys.com Wed Jun 5 17:38:48 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 5 Jun 2019 14:38:48 -0700 (PDT) Subject: tkinter: tk.grid columnspan In-Reply-To: References: Message-ID: On Wed, 5 Jun 2019, Terry Reedy wrote: > Unless you specifiy otherwise through expand and weight options, grid > columns are the minimum width required for the widest minimum width of any > widget in the column. > The columnspan makes the minimum width of 'description' the minimum width > of column 1 plus the minimum width of column 2. With nothing else in > columns 1 and 2, it has no effect. Terry, If I understand you correctly, when a user wants to insert a new row they'll see the odd spacing of the frame, but when they enter a long string for the description it will adjust the size and expand to the left. Alternatively, when a use selects a row from the database table the retrieved data will fill the description entry widget so column 2's width will be wider. Is this correct? Thanks, Rich From rshepard at appl-ecosys.com Wed Jun 5 22:55:19 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 5 Jun 2019 19:55:19 -0700 (PDT) Subject: tkinter: tk.grid columnspan In-Reply-To: <8rlgfehd2imejm8a5d11ola2oqcklnrem8@4ax.com> References: <8rlgfehd2imejm8a5d11ola2oqcklnrem8@4ax.com> Message-ID: On Wed, 5 Jun 2019, Dennis Lee Bieber wrote: > With only those two fields as the only thing defined in the grid > sizer, than there are only two columns in the grid, and nothing in which > to "span" a field. Dennis, Makes sense to me. > My antique Tkinter book is in storage a mile away, so I can't verify if > my understanding is correct. https://effbot.org/tkinterbook/grid.htm sort > of reinforces that, in that the example with spanning defines four(0..3) > columns in use, with the image using the 3rd&4th columns (2..3) and the > checkbox spanning the first two columns (0..1) Yes, I read that. > wxPython has: I've used wxPython for years and decided that for my new projects I'd use tkinter. I have the impression it is easier when users run MacOS and Windoze rather than linux. Perhaps not, but there are aspects of wxPython that wore me out. I find tkinter easier to read and write, but I'm still at the very bottom of the learning curve. Regards, Rich From tjreedy at udel.edu Thu Jun 6 00:30:02 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Jun 2019 00:30:02 -0400 Subject: tkinter: tk.grid columnspan In-Reply-To: References: <8rlgfehd2imejm8a5d11ola2oqcklnrem8@4ax.com> Message-ID: On 6/5/2019 10:55 PM, Rich Shepard wrote: > I've used wxPython for years and decided that for my new projects I'd use > tkinter. I have the impression it is easier when users run MacOS and > Windoze > rather than linux. Perhaps not, but there are aspects of wxPython that wore > me out. I find tkinter easier to read and write, but I'm still at the very > bottom of the learning curve. If you use IDLE, it is easy to experiment with tkinter, because the IDLE execution process runs a hidden tkinter update loop. Enter a statement adding or changing a widget, and it takes effect immediately. -- Terry Jan Reedy From rshepard at appl-ecosys.com Thu Jun 6 08:46:55 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 6 Jun 2019 05:46:55 -0700 (PDT) Subject: tkinter: tk.grid columnspan [RESOLVED] In-Reply-To: References: <8rlgfehd2imejm8a5d11ola2oqcklnrem8@4ax.com> Message-ID: On Thu, 6 Jun 2019, Terry Reedy wrote: > If you use IDLE, it is easy to experiment with tkinter, because the IDLE > execution process runs a hidden tkinter update loop. Enter a statement > adding or changing a widget, and it takes effect immediately. Terry, I use emacs. I did not provide the code for the full dialog box. The last widget is tk.Text for a comment. Adding 'columnspan=4' to the grid options makes the layout correct. The Entry widget will expand to accommodate entered text. Thanks, everyone, Rich From softlogicseo at gmail.com Thu Jun 6 09:05:13 2019 From: softlogicseo at gmail.com (softlogicseo at gmail.com) Date: Thu, 6 Jun 2019 06:05:13 -0700 (PDT) Subject: Python Training in Chennai Message-ID: <02788e64-85ed-47f9-91a8-b958b233be56@googlegroups.com> Python is easier to code and is highly applicable in forming both simple and high-end applications. This amazing benefit makes Python very famous in the IT industry. There is also an increase in the usage of Python in web development. URL : https://www.slajobs.com/python-training-institute-in-chennai/ From nidhijan8750 at gmail.com Fri Jun 7 01:33:23 2019 From: nidhijan8750 at gmail.com (nidhi singh) Date: Thu, 6 Jun 2019 22:33:23 -0700 Subject: it is not working .....how to unstalll it Message-ID: I?m protected online with Avast Free Antivirus. Get it here ? it?s free forever. <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From shreya.mm.joshi at gmail.com Fri Jun 7 03:46:14 2019 From: shreya.mm.joshi at gmail.com (Shreya Joshi) Date: Fri, 7 Jun 2019 13:16:14 +0530 Subject: No option available for saving files Message-ID: <5cfa1648.1c69fb81.fbea8.742e@mx.google.com> Hi ma?am/sir, I?ve started using python Shell 3.6.8-32 bit executable installer on windows OS. But there is no option to save or open a new file. This gives an output after every line. But, I want to work on longer codes to execute programs. Am I using the right interface? Please help. Here is a screenshot? Sent from Mail for Windows 10 From cspealma at redhat.com Fri Jun 7 10:51:36 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Fri, 7 Jun 2019 10:51:36 -0400 Subject: No option available for saving files In-Reply-To: <5cfa1648.1c69fb81.fbea8.742e@mx.google.com> References: <5cfa1648.1c69fb81.fbea8.742e@mx.google.com> Message-ID: The python shell is good for experimenting and testing some things out, but you are right it isn't for writing programs you actually re-use and run later. You can use any text editor you want, Visual Studio Code and Sublime Text are both popular, but anything will do at all. There is also a simple editor with integration for running Python included in the Python Windows installer, called IDLE. You should be able to find that in your start menu. On Fri, Jun 7, 2019 at 4:24 AM Shreya Joshi wrote: > Hi ma?am/sir, > I?ve started using python Shell 3.6.8-32 bit executable installer on > windows OS. But there is no option to save or open a new file. This gives > an output after every line. But, I want to work on longer codes to execute > programs. > > Am I using the right interface? Please help. > Here is a screenshot? > > Sent from Mail for Windows 10 > > -- > 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 rshepard at appl-ecosys.com Fri Jun 7 12:26:30 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 09:26:30 -0700 (PDT) Subject: Python3-3.7.3: cannot run pdb Message-ID: Running python3-3.7.3 on Slackware-14.2. I'm trying to debug a module using pdb but failing with all attempts. For example, using breakpoint() at the line where I want to stop the running module and examine each line's execution, the program runs to completion and shows there's a syntax error: $ python3 geochem.py File "geochem.py", line 35 boxchoices = ttk.Combobox(self, textvariable=med, ^ SyntaxError: invalid syntax Importing pdb and inserting pdb.set_trace() produces the same output. invoking pdb from the command line produces a full back trace: $ python3 -m pdb geochem.py Traceback (most recent call last): File "/usr/lib/python3.7/pdb.py", line 1701, in main pdb._runscript(mainpyfile) File "/usr/lib/python3.7/pdb.py", line 1570, in _runscript self.run(statement) File "/usr/lib/python3.7/bdb.py", line 585, in run exec(cmd, globals, locals) File "", line 1, in File "/home/rshepard/development/openEDMS/views/geochem.py", line 35 boxchoices = ttk.Combobox(self, textvariable=med, ^ SyntaxError: invalid syntax I don't understand the source of the syntax error and I'm not able to allow pdb to step through the code. Your advice appreciated, Rich From __peter__ at web.de Fri Jun 7 12:41:18 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Jun 2019 18:41:18 +0200 Subject: Python3-3.7.3: cannot run pdb References: Message-ID: Rich Shepard wrote: > Running python3-3.7.3 on Slackware-14.2. > > I'm trying to debug a module using pdb but failing with all attempts. For > example, using breakpoint() at the line where I want to stop the running > module and examine each line's execution, the program runs to completion > and shows there's a syntax error: > > $ python3 geochem.py > File "geochem.py", line 35 > boxchoices = ttk.Combobox(self, textvariable=med, > ^ > SyntaxError: invalid syntax > > Importing pdb and inserting pdb.set_trace() produces the same output. > > invoking pdb from the command line produces a full back trace: > > $ python3 -m pdb geochem.py > Traceback (most recent call last): > File "/usr/lib/python3.7/pdb.py", line 1701, in main > pdb._runscript(mainpyfile) > File "/usr/lib/python3.7/pdb.py", line 1570, in _runscript > self.run(statement) > File "/usr/lib/python3.7/bdb.py", line 585, in run > exec(cmd, globals, locals) > File "", line 1, in > File "/home/rshepard/development/openEDMS/views/geochem.py", line 35 > boxchoices = ttk.Combobox(self, textvariable=med, > ^ > SyntaxError: invalid syntax > > I don't understand the source of the syntax error and I'm not able to > allow pdb to step through the code. You need to fix all syntax errors before you can run the script, with or without pdb. The syntax error you are seeing is typically caused by unclosed parentheses in a line preceding the one shown by the compiler, e. g. >>> x = 2 * (3 + 4 ... foo = 42 File "", line 2 foo = 42 ^ SyntaxError: invalid syntax From python at mrabarnett.plus.com Fri Jun 7 12:44:15 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 7 Jun 2019 17:44:15 +0100 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: Message-ID: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> On 2019-06-07 17:26, Rich Shepard wrote: > Running python3-3.7.3 on Slackware-14.2. > > I'm trying to debug a module using pdb but failing with all attempts. For > example, using breakpoint() at the line where I want to stop the running > module and examine each line's execution, the program runs to completion and > shows there's a syntax error: > > $ python3 geochem.py > File "geochem.py", line 35 > boxchoices = ttk.Combobox(self, textvariable=med, > ^ > SyntaxError: invalid syntax > > Importing pdb and inserting pdb.set_trace() produces the same output. > > invoking pdb from the command line produces a full back trace: > > $ python3 -m pdb geochem.py > Traceback (most recent call last): > File "/usr/lib/python3.7/pdb.py", line 1701, in main > pdb._runscript(mainpyfile) > File "/usr/lib/python3.7/pdb.py", line 1570, in _runscript > self.run(statement) > File "/usr/lib/python3.7/bdb.py", line 585, in run > exec(cmd, globals, locals) > File "", line 1, in > File "/home/rshepard/development/openEDMS/views/geochem.py", line 35 > boxchoices = ttk.Combobox(self, textvariable=med, > ^ > SyntaxError: invalid syntax > > I don't understand the source of the syntax error and I'm not able to allow > pdb to step through the code. > > Your advice appreciated, > It's possible that the error is actually on the previous line and that it thinks that what's on line 35 is a continuation of what's on line 34, but it isn't. From rshepard at appl-ecosys.com Fri Jun 7 13:28:31 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 10:28:31 -0700 (PDT) Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: Message-ID: On Fri, 7 Jun 2019, Peter Otten wrote: > You need to fix all syntax errors before you can run the script, with or > without pdb. Peter, I thought the debugger would show me the location of the syntax error. > The syntax error you are seeing is typically caused by unclosed > parentheses in a line preceding the one shown by the compiler, e. g. Yes, I know that and have looked for it unsuccessfully. Will post preceeding lines in response to MRAB's response. Regards, Rich From rshepard at appl-ecosys.com Fri Jun 7 13:31:38 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 10:31:38 -0700 (PDT) Subject: Python3-3.7.3: cannot run pdb In-Reply-To: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> References: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> Message-ID: On Fri, 7 Jun 2019, MRAB wrote: > It's possible that the error is actually on the previous line and that it > thinks that what's on line 35 is a continuation of what's on line 34, but > it isn't. MRAB, If that's the case I'm missing seeing the error. Here are the lines prior to and including line 36: def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) # A dict to keep track of input widgets self.inputs = {} # line 0 self.inputs['name'] = LabelInput( self, 'Site Name', input_var=tk.StringVar(), ) self.inputs['name'].grid(sticky=tk.W, row=0, column=0) self.inputs['date'] = LabelInput( self, 'Sample Date', input_var=tk.StringVar(), ) self.inputs['date'].grid(row=0, column=1) self.inputs['medium'] = LabelInput( self, 'Medium', med = tk.StringVar() boxchoices = ttk.Combobox(self, textvariable=med, values=['Storm water', 'Surface water', 'Ground water', 'Sediments', 'Soils']) ) emacs shows all parentheses are paired. I hope that fresh eyeballs see what I keep missing. Regards, Rich From rhodri at kynesim.co.uk Fri Jun 7 13:36:14 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 7 Jun 2019 18:36:14 +0100 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: Message-ID: On 07/06/2019 18:28, Rich Shepard wrote: > On Fri, 7 Jun 2019, Peter Otten wrote: > >> You need to fix all syntax errors before you can run the script, with or >> without pdb. > > Peter, > > I thought the debugger would show me the location of the syntax error. The syntax error causes Python to halt before it has finished compiling your program into byte code. There is nothing to run pdb on! -- Rhodri James *-* Kynesim Ltd From daniloco at acm.org Fri Jun 7 13:42:43 2019 From: daniloco at acm.org (Danilo Coccia) Date: Fri, 7 Jun 2019 19:42:43 +0200 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> Message-ID: <3eb09b06-244b-90a1-3b0a-b311a3876417@acm.org> Il 07/06/2019 19:31, Rich Shepard ha scritto: > On Fri, 7 Jun 2019, MRAB wrote: > >> It's possible that the error is actually on the previous line and that it >> thinks that what's on line 35 is a continuation of what's on line 34, but >> it isn't. > > MRAB, > > If that's the case I'm missing seeing the error. Here are the lines > prior to > and including line 36: > > def __init__(self, parent, *args, **kwargs): > ??????? super().__init__(parent, *args, **kwargs) > ??????? # A dict to keep track of input widgets > ??????? self.inputs = {} > > ??????? # line 0 > ??????? self.inputs['name'] = LabelInput( > ??????????? self, 'Site Name', > ??????????? input_var=tk.StringVar(), > ??????????? ) > ??????? self.inputs['name'].grid(sticky=tk.W, row=0, column=0) > > ??????? self.inputs['date'] = LabelInput( > ??????????? self, 'Sample Date', > ??????????? input_var=tk.StringVar(), > ??????? ) > ??????? self.inputs['date'].grid(row=0, column=1) > > ??????? self.inputs['medium'] = LabelInput( > ??????????? self, 'Medium', > ??????????? med = tk.StringVar() ^^^ Missing a comma here! > ??????????? boxchoices = ttk.Combobox(self, textvariable=med, > ??????????????????????????????????? values=['Storm water', 'Surface water', > ??????????????????????????????????????????? 'Ground water', 'Sediments', > 'Soils']) > ??????? ) > > emacs shows all parentheses are paired. I hope that fresh eyeballs see what > I keep missing. > > Regards, > > Rich > From rshepard at appl-ecosys.com Fri Jun 7 13:53:16 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 10:53:16 -0700 (PDT) Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: Message-ID: On Fri, 7 Jun 2019, Rhodri James wrote: > The syntax error causes Python to halt before it has finished compiling > your program into byte code. There is nothing to run pdb on! Okay. That certainly makes sense. It's been a very long time since I did any Python coding. Regards, Rich From python at mrabarnett.plus.com Fri Jun 7 13:56:46 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 7 Jun 2019 18:56:46 +0100 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> Message-ID: <8d8432a3-7b75-99d4-eb21-f872675480d8@mrabarnett.plus.com> On 2019-06-07 18:31, Rich Shepard wrote: > On Fri, 7 Jun 2019, MRAB wrote: > >> It's possible that the error is actually on the previous line and that it >> thinks that what's on line 35 is a continuation of what's on line 34, but >> it isn't. > > MRAB, > > If that's the case I'm missing seeing the error. Here are the lines prior to > and including line 36: > > def __init__(self, parent, *args, **kwargs): > super().__init__(parent, *args, **kwargs) > # A dict to keep track of input widgets > self.inputs = {} > > # line 0 > self.inputs['name'] = LabelInput( > self, 'Site Name', > input_var=tk.StringVar(), > ) > self.inputs['name'].grid(sticky=tk.W, row=0, column=0) > > self.inputs['date'] = LabelInput( > self, 'Sample Date', > input_var=tk.StringVar(), > ) > self.inputs['date'].grid(row=0, column=1) > > self.inputs['medium'] = LabelInput( Rememnber that these lines are an argument list. > self, 'Medium', > med = tk.StringVar() ^ Missing comma. > boxchoices = ttk.Combobox(self, textvariable=med, > values=['Storm water', 'Surface water', > 'Ground water', 'Sediments', 'Soils']) > ) > > emacs shows all parentheses are paired. I hope that fresh eyeballs see what > I keep missing. > From rshepard at appl-ecosys.com Fri Jun 7 13:57:49 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 10:57:49 -0700 (PDT) Subject: Python3-3.7.3: cannot run pdb In-Reply-To: <3eb09b06-244b-90a1-3b0a-b311a3876417@acm.org> References: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> <3eb09b06-244b-90a1-3b0a-b311a3876417@acm.org> Message-ID: On Fri, 7 Jun 2019, Danilo Coccia wrote: >> ??????? self.inputs['medium'] = LabelInput( >> ??????????? self, 'Medium', >> ??????????? med = tk.StringVar() > ^^^ > Missing a comma here! Thanks, Danilo! When we write the code we too often see what we expect to see and not what's actually there. Fresh eyes to the rescue once again. Regards, Rich From rshepard at appl-ecosys.com Fri Jun 7 14:43:48 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 11:43:48 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument Message-ID: I understand positional and keyword arguments and the syntax for the ttk.Checkbutton as described on . $ python3 geochem.py File "geochem.py", line 60 ttk.Checkbutton(text='Censored?', variable=input_var), ^ SyntaxError: positional argument follows keyword argument I've provided only keyword arguments to the call to the ttk.Checkbutton widget and am not seeing the positional argument that follows. Please show me what I miss seeing here: self.inputs['nondetect'] = LabelInput( self, 'Censored?', #input_var = tk.BooleanVar(), input_var = tk.IntVar, ttk.Checkbutton(text='Censored?', variable=input_var), ) It does not matter if the variable holding the checkbutton's state is an IntVar or a BooleanVar, the same syntax error is generated. Commenting out all widgets prior to this one makes no difference so the error must be local. Yes? Please explain where the positional argument is located. Regards, Rich From rhodri at kynesim.co.uk Fri Jun 7 14:50:39 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 7 Jun 2019 19:50:39 +0100 Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: <757d57a0-087a-c14c-f19a-f33a97f7ea64@kynesim.co.uk> On 07/06/2019 19:43, Rich Shepard wrote: > I understand positional and keyword arguments and the syntax for the > ttk.Checkbutton as described on > . > > $ python3 geochem.py > ? File "geochem.py", line 60 > ??? ttk.Checkbutton(text='Censored?', variable=input_var), > ??? ^ > SyntaxError: positional argument follows keyword argument > > I've provided only keyword arguments to the call to the ttk.Checkbutton > widget and am not seeing the positional argument that follows. Please show > me what I miss seeing here: Context is everything! > self.inputs['nondetect'] = LabelInput( > ??????????? self, 'Censored?', > ??????????? #input_var = tk.BooleanVar(), > ??????????? input_var = tk.IntVar, > ??????????? ttk.Checkbutton(text='Censored?', variable=input_var), > ) Now we can see that Python isn't complaining about the arguments to tth.Checkbutton. The call to ttk.Checkbutton() is itself a positional argument in the call to LabelInput, coming after the keyword argument "input_var = tk.IntVar". -- Rhodri James *-* Kynesim Ltd From abrault at mapgears.com Fri Jun 7 14:48:46 2019 From: abrault at mapgears.com (Alexandre Brault) Date: Fri, 7 Jun 2019 14:48:46 -0400 Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: <1d02dc83-2b81-a801-0886-92fd3050b102@mapgears.com> On 2019-06-07 2:43 p.m., Rich Shepard wrote: > I understand positional and keyword arguments and the syntax for the > ttk.Checkbutton as described on > . > > $ python3 geochem.py > ? File "geochem.py", line 60 > ??? ttk.Checkbutton(text='Censored?', variable=input_var), > ??? ^ > SyntaxError: positional argument follows keyword argument > > I've provided only keyword arguments to the call to the ttk.Checkbutton > widget and am not seeing the positional argument that follows. Please > show > me what I miss seeing here: > > self.inputs['nondetect'] = LabelInput( > ??????????? self, 'Censored?', > ??????????? #input_var = tk.BooleanVar(), > ??????????? input_var = tk.IntVar, > ??????????? ttk.Checkbutton(text='Censored?', variable=input_var), > ) > > It does not matter if the variable holding the checkbutton's state is an > IntVar or a BooleanVar, the same syntax error is generated. Commenting > out > all widgets prior to this one makes no difference so the error must be > local. Yes? > > Please explain where the positional argument is located. > > Regards, > > Rich The positional argument in question is not one you passed to the ttk.Checkbutton call, but the ttk.Checkbutton itself that you're passing to LabelInput as a positional argument after the input_var keyword argument Alex From rosuav at gmail.com Fri Jun 7 15:02:47 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Jun 2019 05:02:47 +1000 Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On Sat, Jun 8, 2019 at 4:45 AM Rich Shepard wrote: > I've provided only keyword arguments to the call to the ttk.Checkbutton > widget and am not seeing the positional argument that follows. Please show > me what I miss seeing here: > > self.inputs['nondetect'] = LabelInput( > self, 'Censored?', > #input_var = tk.BooleanVar(), > input_var = tk.IntVar, > ttk.Checkbutton(text='Censored?', variable=input_var), > ) > General principle: When you see a syntax error, look *before* that point (reading top-to-bottom, left-to-right, same as the parser does). Often, the problem is prior to the point where it was actually discovered. Specific point: It looks like perhaps you're trying to assign in the middle of a function call. That doesn't do what you think it does, but on sufficiently-recent versions of Python, you can do this with "input_var := tk.IntVar". That might be the easiest solution. ChrisA From rshepard at appl-ecosys.com Fri Jun 7 15:52:07 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 12:52:07 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: <1d02dc83-2b81-a801-0886-92fd3050b102@mapgears.com> References: <1d02dc83-2b81-a801-0886-92fd3050b102@mapgears.com> Message-ID: On Fri, 7 Jun 2019, Alexandre Brault wrote: > The positional argument in question is not one you passed to the > ttk.Checkbutton call, but the ttk.Checkbutton itself that you're passing > to LabelInput as a positional argument after the input_var keyword > argument Alex, Got it, thanks. Now to figure out the proper way of writing the widget. Regards, Rich From rshepard at appl-ecosys.com Fri Jun 7 15:53:09 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 12:53:09 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: <757d57a0-087a-c14c-f19a-f33a97f7ea64@kynesim.co.uk> References: <757d57a0-087a-c14c-f19a-f33a97f7ea64@kynesim.co.uk> Message-ID: On Fri, 7 Jun 2019, Rhodri James wrote: > Now we can see that Python isn't complaining about the arguments to > tth.Checkbutton. The call to ttk.Checkbutton() is itself a positional > argument in the call to LabelInput, coming after the keyword argument > "input_var = tk.IntVar". Thank you Rhodri. More reading is now the next thing I do. Regards, Rich From rshepard at appl-ecosys.com Fri Jun 7 15:55:46 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 12:55:46 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On Sat, 8 Jun 2019, Chris Angelico wrote: > General principle: When you see a syntax error, look *before* that point > (reading top-to-bottom, left-to-right, same as the parser does). Often, > the problem is prior to the point where it was actually discovered. Chris, This is why I commented out all widgets prior to the ttk.Checkbutton. If the error was earlier the error would not have appeared. > Specific point: It looks like perhaps you're trying to assign in the > middle of a function call. That doesn't do what you think it does, but on > sufficiently-recent versions of Python, you can do this with "input_var := > tk.IntVar". That might be the easiest solution. Yes, I need to use a diffrent syntax for Checkbuttons and Radiobuttons than for other widgets. Back to my reference book for more study. Regards, Rich From rosuav at gmail.com Fri Jun 7 16:05:00 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Jun 2019 06:05:00 +1000 Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On Sat, Jun 8, 2019 at 6:01 AM Rich Shepard wrote: > > On Sat, 8 Jun 2019, Chris Angelico wrote: > > > General principle: When you see a syntax error, look *before* that point > > (reading top-to-bottom, left-to-right, same as the parser does). Often, > > the problem is prior to the point where it was actually discovered. > > Chris, > > This is why I commented out all widgets prior to the ttk.Checkbutton. If the > error was earlier the error would not have appeared. Right, but the problem was actually in the LabelInput call, not the Checkbutton itself. ChrisA From tjreedy at udel.edu Fri Jun 7 16:30:03 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Jun 2019 16:30:03 -0400 Subject: No option available for saving files In-Reply-To: References: <5cfa1648.1c69fb81.fbea8.742e@mx.google.com> Message-ID: On 6/7/2019 10:51 AM, Calvin Spealman wrote: > The python shell is good for experimenting and testing some things out, but > you are right it isn't for writing programs you actually re-use and run > later. You can use any text editor you want, Visual Studio Code and Sublime > Text are both popular, but anything will do at all. There is also a simple > editor with integration for running Python included in the Python Windows > installer, called IDLE. You should be able to find that in your start menu. > > On Fri, Jun 7, 2019 at 4:24 AM Shreya Joshi > wrote: > >> Hi ma?am/sir, >> I?ve started using python Shell 3.6.8-32 bit executable installer on >> windows OS. But there is no option to save or open a new file. This gives >> an output after every line. But, I want to work on longer codes to execute >> programs. >> >> Am I using the right interface? Please help. An interactive shell is for experimentation a statement at a time. You need an editor for longer code. IDLE has both. You can save its Shell session to a file for later review or extraction of code that worked. >> Here is a screenshot? This is a text only mailing list with no attachments allowed, certainly no images. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jun 7 16:44:15 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Jun 2019 16:44:15 -0400 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: Message-ID: On 6/7/2019 12:26 PM, Rich Shepard wrote: > Running python3-3.7.3 on Slackware-14.2. > $ python3 geochem.py > ? File "geochem.py", line 35 > ??? boxchoices = ttk.Combobox(self, textvariable=med, > ???????????? ^ > SyntaxError: invalid syntax An addendum to previous comments solving the issue. In 3.8.0b1, you would see the caret at the beginning of the word, rather than at the end. ... > boxchoices = ttk.Combobox(self, textvariable=med, > ^ This gives a better hint that the error is due to something before the 'b', or rather that the parser was expecting something other than a letter (beginning of name character). One should therefore imagine that there was no preceeding \n and that the initial character, in this case, was at the end of the previous line. The error here is basically the same as >>> b b File "", line 1 b b ^ SyntaxError: invalid syntax -- Terry Jan Reedy From rshepard at appl-ecosys.com Fri Jun 7 16:49:32 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 13:49:32 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On Sat, 8 Jun 2019, Chris Angelico wrote: > Right, but the problem was actually in the LabelInput call, not the > Checkbutton itself. ChrisA, That's what I found and fixed. Now working on a slightly different issue with a ttk.Combobox. Carpe weekend, Rich From tjreedy at udel.edu Fri Jun 7 17:00:17 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Jun 2019 17:00:17 -0400 Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On 6/7/2019 2:43 PM, Rich Shepard wrote: > I understand positional and keyword arguments and the syntax for the > ttk.Checkbutton as described on > . > > $ python3 geochem.py > ? File "geochem.py", line 60 > ??? ttk.Checkbutton(text='Censored?', variable=input_var), > ??? ^ > SyntaxError: positional argument follows keyword argument > > I've provided only keyword arguments to the call to the ttk.Checkbutton > widget and am not seeing the positional argument that follows. Please show > me what I miss seeing here: > > self.inputs['nondetect'] = LabelInput( > ??????????? self, 'Censored?', > ??????????? #input_var = tk.BooleanVar(), > ??????????? input_var = tk.IntVar, An additional error is the missing ()s. This would make input_var refer to the class, not an instance thereof. > ??????????? ttk.Checkbutton(text='Censored?', variable=input_var), > ) -- Terry Jan Reedy From rshepard at appl-ecosys.com Fri Jun 7 17:33:08 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 7 Jun 2019 14:33:08 -0700 (PDT) Subject: SyntaxError: positional argument follows keyword argument In-Reply-To: References: Message-ID: On Fri, 7 Jun 2019, Terry Reedy wrote: > An additional error is the missing ()s. This would make input_var refer to > the class, not an instance thereof. Oops! I completely missed that. Thanks, Terry, Rich From daniloco at acm.org Fri Jun 7 13:42:43 2019 From: daniloco at acm.org (Danilo Coccia) Date: Fri, 7 Jun 2019 19:42:43 +0200 Subject: Python3-3.7.3: cannot run pdb In-Reply-To: References: <7abb9c71-1310-c2fe-f6d1-7893a9ceac56@mrabarnett.plus.com> Message-ID: <3eb09b06-244b-90a1-3b0a-b311a3876417@acm.org> Il 07/06/2019 19:31, Rich Shepard ha scritto: > On Fri, 7 Jun 2019, MRAB wrote: > >> It's possible that the error is actually on the previous line and that it >> thinks that what's on line 35 is a continuation of what's on line 34, but >> it isn't. > > MRAB, > > If that's the case I'm missing seeing the error. Here are the lines > prior to > and including line 36: > > def __init__(self, parent, *args, **kwargs): > ??????? super().__init__(parent, *args, **kwargs) > ??????? # A dict to keep track of input widgets > ??????? self.inputs = {} > > ??????? # line 0 > ??????? self.inputs['name'] = LabelInput( > ??????????? self, 'Site Name', > ??????????? input_var=tk.StringVar(), > ??????????? ) > ??????? self.inputs['name'].grid(sticky=tk.W, row=0, column=0) > > ??????? self.inputs['date'] = LabelInput( > ??????????? self, 'Sample Date', > ??????????? input_var=tk.StringVar(), > ??????? ) > ??????? self.inputs['date'].grid(row=0, column=1) > > ??????? self.inputs['medium'] = LabelInput( > ??????????? self, 'Medium', > ??????????? med = tk.StringVar() ^^^ Missing a comma here! > ??????????? boxchoices = ttk.Combobox(self, textvariable=med, > ??????????????????????????????????? values=['Storm water', 'Surface water', > ??????????????????????????????????????????? 'Ground water', 'Sediments', > 'Soils']) > ??????? ) > > emacs shows all parentheses are paired. I hope that fresh eyeballs see what > I keep missing. > > Regards, > > Rich > From rshepard at appl-ecosys.com Sat Jun 8 12:32:09 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 8 Jun 2019 09:32:09 -0700 (PDT) Subject: Center ttk.Checkbox in grid column Message-ID: A data input form (screenshot attached) has two ttk.Checkbutton widgets. I've read the manual page for this widget and interpret the justify style as applying to only multiline text descriptors of the checkbutton. Is there a way to center the entire widget within the grid column? TIA, Rich From rshepard at appl-ecosys.com Sat Jun 8 13:37:36 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 8 Jun 2019 10:37:36 -0700 (PDT) Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: On Sat, 8 Jun 2019, Rich Shepard wrote: > A data input form (screenshot attached) has two ttk.Checkbutton widgets. Looks like the screenshot image was clipped off the message. Is there a widget option for the ttk.Checkbox that horizontally and vertically centers the button and label text in the column width? Rich From python at mrabarnett.plus.com Sat Jun 8 14:38:31 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 8 Jun 2019 19:38:31 +0100 Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: On 2019-06-08 18:37, Rich Shepard wrote: > On Sat, 8 Jun 2019, Rich Shepard wrote: > >> A data input form (screenshot attached) has two ttk.Checkbutton widgets. > > Looks like the screenshot image was clipped off the message. Is there a > widget option for the ttk.Checkbox that horizontally and vertically centers > the button and label text in the column width? > Attachments sent to this list are removed automatically. In answer to your question, widgets are centred by default; you have to tell it if you _don't_ want a widget centred horizontally or centred vertically. From rshepard at appl-ecosys.com Sat Jun 8 15:01:23 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 8 Jun 2019 12:01:23 -0700 (PDT) Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: On Sat, 8 Jun 2019, MRAB wrote: > In answer to your question, widgets are centred by default; you have to > tell it if you _don't_ want a widget centred horizontally or centred > vertically. That's what I thought but the little box and button label don't look centered but left justified. Thanks, Rich From python at mrabarnett.plus.com Sat Jun 8 15:44:30 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 8 Jun 2019 20:44:30 +0100 Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: <9295721f-a6c0-c2d4-6b44-c305772781ac@mrabarnett.plus.com> On 2019-06-08 20:01, Rich Shepard wrote: > On Sat, 8 Jun 2019, MRAB wrote: > >> In answer to your question, widgets are centred by default; you have to >> tell it if you _don't_ want a widget centred horizontally or centred >> vertically. > > That's what I thought but the little box and button label don't look > centered but left justified. > A workaround is to pack the widget in a tk.Frame and then put the frame in the grid cell. From rshepard at appl-ecosys.com Sat Jun 8 17:04:26 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 8 Jun 2019 14:04:26 -0700 (PDT) Subject: Center ttk.Checkbox in grid column In-Reply-To: <9295721f-a6c0-c2d4-6b44-c305772781ac@mrabarnett.plus.com> References: <9295721f-a6c0-c2d4-6b44-c305772781ac@mrabarnett.plus.com> Message-ID: On Sat, 8 Jun 2019, MRAB wrote: > A workaround is to pack the widget in a tk.Frame and then put the frame in > the grid cell. Okay. For now I'll leave it as-is and wait for feedback from users (if any) when the application is up and running. Thanks again, Rich From tjreedy at udel.edu Sat Jun 8 18:22:25 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 8 Jun 2019 18:22:25 -0400 Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: On 6/8/2019 12:32 PM, Rich Shepard wrote: > Is there a way to center the entire widget within the grid column? This is supposed to be the default. I managed to get them right-justified somehow, but the following works for me on Windows to get two centered widgets. import tkinter as tk from tkinter import ttk r = tk.Tk() c1 = ttk.Checkbutton(r, text='box1') c2 = ttk.Label(r, text='box2') r.columnconfigure((0,1), minsize=100, weight=1) c1.grid(row=0, column=0) c2.grid(row=0, column=1) -- Terry Jan Reedy From rshepard at appl-ecosys.com Sat Jun 8 19:15:38 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 8 Jun 2019 16:15:38 -0700 (PDT) Subject: Center ttk.Checkbox in grid column In-Reply-To: References: Message-ID: On Sat, 8 Jun 2019, Terry Reedy wrote: > This is supposed to be the default. I managed to get them right-justified > somehow, but the following works for me on Windows to get two centered > widgets. > > import tkinter as tk > from tkinter import ttk > r = tk.Tk() > c1 = ttk.Checkbutton(r, text='box1') > c2 = ttk.Label(r, text='box2') > r.columnconfigure((0,1), minsize=100, weight=1) > c1.grid(row=0, column=0) > c2.grid(row=0, column=1) Thanks, Terry. Rich From pahome.chen at mirlab.org Mon Jun 10 06:18:07 2019 From: pahome.chen at mirlab.org (lampahome) Date: Mon, 10 Jun 2019 18:18:07 +0800 Subject: FDs will be closed after exception automatically in python2.7? Message-ID: as title, I confused will fd will be close after exception automatically? Like: try: fd=open("file","w+") fd.get() //any useless function of fd except Exception: print 'hi' From hjp-python at hjp.at Mon Jun 10 06:47:22 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 10 Jun 2019 12:47:22 +0200 Subject: FDs will be closed after exception automatically in python2.7? In-Reply-To: References: Message-ID: <20190610104722.dnaoeej322jb6jkz@hjp.at> On 2019-06-10 18:18:07 +0800, lampahome wrote: > as title, > > I confused will fd will be close after exception automatically? > > Like: > try: > fd=open("file","w+") > fd.get() //any useless function of fd > except Exception: > print 'hi' Please try to preserve indentation when sending code to the list. Indentation is part of the Python syntax and if you smash everything to the left margin your program is not only hard to read but syntactically wrong. To answer your question: No, an exception will not automatically close open file descriptors (which file descriptors should it close and why?). However, while handling an exception the variable holding the file descriptor may go out of scope (for example if you leave a "with" block[1] or return from a function). In that case the file descriptor will be closed (in the case of a with block immediately, otherwise when the garbage collector gets around to it). hp [1] Don't know if those exist in Python 2.x. You should upgrade to 3.x anyway. -- _ | 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 cs at cskk.id.au Mon Jun 10 07:36:58 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 10 Jun 2019 21:36:58 +1000 Subject: FDs will be closed after exception automatically in python2.7? In-Reply-To: <20190610104722.dnaoeej322jb6jkz@hjp.at> References: <20190610104722.dnaoeej322jb6jkz@hjp.at> Message-ID: <20190610113658.GA97839@cskk.homeip.net> On 10Jun2019 12:47, Peter J. Holzer wrote: >On 2019-06-10 18:18:07 +0800, lampahome wrote: >> I confused will fd will be close after exception automatically? >> >> Like: >> try: >> fd=open("file","w+") >> fd.get() //any useless function of fd >> except Exception: >> print 'hi' > >Please try to preserve indentation when sending code to the list. >Indentation is part of the Python syntax and if you smash everything to >the left margin your program is not only hard to read but syntactically >wrong. > >To answer your question: > >No, an exception will not automatically close open file descriptors >(which file descriptors should it close and why?). > >However, while handling an exception the variable holding the file >descriptor may go out of scope (for example if you leave a "with" >block[1] or return from a function). In that case the file descriptor >will be closed (in the case of a with block immediately, otherwise when >the garbage collector gets around to it). We want to be more precise here. By using the term "file descriptor" above you've conflated 2 things: the Python file object and the OS file descriptor. They're different things with different behaviours. What you get from "open()" is a python "file object". And what the OP is getting in his example code is also a file object. And as you say, when all references to that are removed (variable goes out of scope), the Python interpreter will close the file. So far so good. However the term "file descriptor", at least in POSIX (UNIX and Linux), is _not_ the same as a Python "file object". Instead, it is the integer you get from a OS level file open such as returned by os.open(). It is _not_ managed by the Python interpreter and does not get closed when nobody references it, because it is not an object. Now, for the OP's edification: when you use Python's open() function you get a file object, which includes a reference to the _underlying_ OS level file descriptor. When that object get recovered _it_ will close the file descriptor as part of the close operation. However, if you do an OS level file open which returns _just_ the file descriptor, this does not happen because there's no object cleanup and nothing to close the descriptor, because nothing is managing it. Example code: #!/usr/bin/python import os def open_and_fail(): fd = os.open('/dev/null',os.O_RDONLY) raise RuntimeError("blam") try: open_and_fail() except RuntimeError: pass os.system("lsof -p "+str(os.getpid())) Here's some code which does an OS level open, getting a fie descriptor. The opening function raises an exception. After we've caught it, we run "lsof" on our own process. here's it on my Mac: [~]fleet*1> /usr/bin/python fd.py COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Python 97417 cameron cwd DIR 1,5 9214 934731 /Users/cameron Python 97417 cameron txt REG 1,5 25152 199261280 /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python Python 97417 cameron txt REG 1,5 2633024 199261275 /System/Library/Frameworks/Python.framework/Versions/2.7/Python Python 97417 cameron txt REG 1,5 52832 199261366 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_locale.so Python 97417 cameron txt REG 1,5 643792 199264919 /usr/lib/dyld Python 97417 cameron txt REG 1,5 560200432 200219840 /private/var/db/dyld/dyld_shared_cache_x86_64 Python 97417 cameron 0u CHR 16,47 0t1529 1991 /dev/ttys047 Python 97417 cameron 1u CHR 16,47 0t1529 1991 /dev/ttys047 Python 97417 cameron 2u CHR 16,47 0t1529 1991 /dev/ttys047 Python 97417 cameron 3r CHR 3,2 0t0 305 /dev/null See the last line. That is file descriptor 3, attached to /dev/null. It is still open. When your programme exits the OS will clean this up, but until then the _descriptor_ remains open. If you rewrote this with plain Python "open("/dev/null")" instead of the os.open you would not see the file descriptor lying around because the close of the _file object_ would have cleaned up the related OS file descriptor. Cheers, Cameron Simpson From torriem at gmail.com Mon Jun 10 10:48:30 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 10 Jun 2019 08:48:30 -0600 Subject: FDs will be closed after exception automatically in python2.7? In-Reply-To: References: Message-ID: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> On 06/10/2019 04:18 AM, lampahome wrote: > as title, > > I confused will fd will be close after exception automatically? > Like: > try: > fd=open("file","w+") > fd.get() //any useless function of fd > except Exception: > print 'hi' No. What if you want to work with the fd object after dealing with the exception? Probably you should be using Python 3, which uses a print() function. But even in Python 2.7, the recommended way to do this is like this: fd = open("file","w+") with fd: fd.get() After the "with" block exits, the fd object is automatically closed. This happens regardless of whether an exception occurred within the with block or not. You may use try and except within the with block. Normally I wouldn't bother, though. Be careful about catching exceptions. In most cases, it is not appropriate in my opinion to "except Exception" which will catch *all* exceptions including syntax errors in your code. Only catch exceptions that your code is specifically equipped to deal with (expecting). For example, if a user provides a file name, and you open it, you may want to catch the FileNotFound exception, in order to inform the user and prompt for a new file name. Exceptions that your code is not expecting and cannot handle should be left alone to bubble up and be caught somewhere else, or crash the program with a traceback, which will aid in debugging. From darcy at VybeNetworks.com Mon Jun 10 11:11:14 2019 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 10 Jun 2019 11:11:14 -0400 Subject: FDs will be closed after exception automatically in python2.7? In-Reply-To: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> References: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> Message-ID: <420857b6-6e13-48af-9b26-135d21e4584b@VybeNetworks.com> On 2019-06-10 10:48, Michael Torrie wrote: > Probably you should be using Python 3, which uses a print() function. > But even in Python 2.7, the recommended way to do this is like this: > > fd = open("file","w+") > with fd: There is still a small window there if there are asynchronous events happening. Use this instead: with open("file","w+") as fd: *rest of good advice elided.* -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From ariskokaliarisa at gmail.com Mon Jun 10 13:28:52 2019 From: ariskokaliarisa at gmail.com (aris) Date: Mon, 10 Jun 2019 20:28:52 +0300 Subject: can not use pycharm Message-ID: <5cfe9354.1c69fb81.fd035.1747@mx.google.com> Hello,this is my first time trying to learn coding and programming and I wanted to start with python.Though,when I download pycharm, I go to configure>settings>project interpreter and i can not put a project interpreter( I have download python version 3) .What should I do?thank you for your time. --- ???? ?? e-mail ????????? ??? ???? ??? ?? ????????? Avast antivirus. https://www.avast.com/antivirus From alan at csail.mit.edu Mon Jun 10 15:46:00 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 10 Jun 2019 15:46:00 -0400 Subject: FDs will be closed after exception automatically in python2.7? References: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> <420857b6-6e13-48af-9b26-135d21e4584b@VybeNetworks.com> Message-ID: <86blz5ql53.fsf@richard.bawden.org> D'Arcy Cain writes: > On 2019-06-10 10:48, Michael Torrie wrote: > > fd = open("file","w+") > > with fd: > > There is still a small window there if there are asynchronous events > happening. Use this instead: > > with open("file","w+") as fd: That makes the window smaller, but it doesn't actually eliminate it. Look at the generated byte code. In both cases the call to open() is over and the open file is created _before_ the SETUP_WITH instruction is executed. -- Alan Bawden From darcy at VybeNetworks.com Mon Jun 10 19:54:15 2019 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 10 Jun 2019 19:54:15 -0400 Subject: FDs will be closed after exception automatically in python2.7? In-Reply-To: <86blz5ql53.fsf@richard.bawden.org> References: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> <420857b6-6e13-48af-9b26-135d21e4584b@VybeNetworks.com> <86blz5ql53.fsf@richard.bawden.org> Message-ID: <7c6d9d8e-00df-2bec-a2fd-dd659edbfec5@VybeNetworks.com> On 2019-06-10 15:46, Alan Bawden wrote: > D'Arcy Cain writes: >> with open("file","w+") as fd: > > That makes the window smaller, but it doesn't actually eliminate it. Look > at the generated byte code. In both cases the call to open() is over and > the open file is created _before_ the SETUP_WITH instruction is executed. Am I correct in assuming that the window is there for process interrupts but not threads? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From info at egenix.com Tue Jun 11 03:54:13 2019 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 11 Jun 2019 09:54:13 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_12.06.2019?= Message-ID: <5e545db0-eb69-b40c-1b22-1ffe1672400a@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 12.06.2019, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2019-06-12 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Detlef Lannert "Data classes in Python 3.7" Marc-Andre Lemburg "Unfacify ? Gesichtserkennung mit Python" Charlie Clark "Do you love your database enough?" Christian Liguda "Using Python in an e-mail based reporting workflow" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm' in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte per Meetup https://www.meetup.com/Python-Meeting-Dusseldorf/ oder formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jun 11 2019) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From robin at reportlab.com Tue Jun 11 10:23:52 2019 From: robin at reportlab.com (Robin Becker) Date: Tue, 11 Jun 2019 15:23:52 +0100 Subject: pysftp / paramiko problem Message-ID: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. I am using the pysftp wrapper around paramiko. The following script fails def main(): import pysftp with pysftp.Connection('ftp.remote.com', username='me', password='xxxxxx') as sftp: print('top level') print(sftp.listdir()) print(sftp.normalize(u'XXXX')) print('direct list of XXXX') print(sftp.listdir(u'XXXX')) with sftp.cd(u'XXXX'): print(sftp.listdir()) if __name__ == '__main__': main() when run the program prints [u'XXXX'] and then fails at the normalize command. > $ python tsftp.py > top level > [u'XXXX'] > Traceback (most recent call last): > File "tsftp.py", line 13, in > main() > File "tsftp.py", line 6, in main > print(sftp.normalize(u'XXXX')) > File "/home/rptlab/devel/env/lib/python2.7/site-packages/pysftp/__init__.py", line 640, in normalize > return self._sftp.normalize(remotepath) > File "/home/rptlab/devel/env/lib/python2.7/site-packages/paramiko/sftp_client.py", line 632, in normalize > t, msg = self._request(CMD_REALPATH, path) > File "/home/rptlab/devel/env/lib/python2.7/site-packages/paramiko/sftp_client.py", line 813, in _request > return self._read_response(num) > File "/home/rptlab/devel/env/lib/python2.7/site-packages/paramiko/sftp_client.py", line 865, in _read_response > self._convert_status(msg) > File "/home/rptlab/devel/env/lib/python2.7/site-packages/paramiko/sftp_client.py", line 894, in _convert_status > raise IOError(errno.ENOENT, text) > IOError: [Errno 2] No such file. I tried other commands, but it seems any attempt to cd to the XXXX directory fails. Using sftp in the shell directly I needed to add HostKeyAlgorithms=+ssh-dss for this host. Any pointers to what the problem could be? -- Robin Becker From madhavanbomidi at gmail.com Tue Jun 11 12:52:42 2019 From: madhavanbomidi at gmail.com (madhavanbomidi at gmail.com) Date: Tue, 11 Jun 2019 09:52:42 -0700 (PDT) Subject: Why I am getting IndexError: tuple index out of range when converting a float value to a string? Message-ID: I wrote the following lines of code: xm = np.nanmean(x[indx],axis=None,dtype=float) xsd = np.nanstd(x[indx],axis=None,dtype=float) type(xm) # np.float64 type(xsd # np.float64 print(xm) # 0.5414720812182742 print(xsd) # 0.15748041033663002 print(str("{6.5f}".format(xm))) I get the following error: IndexError: tuple index out of range Can someone suggest me why I am getting this error and how to overcome this? Thanks in advance From rgaddi at highlandtechnology.invalid Tue Jun 11 13:04:59 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 11 Jun 2019 10:04:59 -0700 Subject: Why I am getting IndexError: tuple index out of range when converting a float value to a string? In-Reply-To: References: Message-ID: On 6/11/19 9:52 AM, madhavanbomidi at gmail.com wrote: > I wrote the following lines of code: > > xm = np.nanmean(x[indx],axis=None,dtype=float) > xsd = np.nanstd(x[indx],axis=None,dtype=float) > > type(xm) # np.float64 > type(xsd # np.float64 > > print(xm) # 0.5414720812182742 > print(xsd) # 0.15748041033663002 > > print(str("{6.5f}".format(xm))) > > I get the following error: > > IndexError: tuple index out of range > > Can someone suggest me why I am getting this error and how to overcome this? > > Thanks in advance > print(str("{:6.5f}".format(xm))) You want to apply the format 6.5f to the autoindexed element. You could also explicitly index the 1st element (#0) as {0:6.5f}. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From tjreedy at udel.edu Tue Jun 11 16:11:55 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Jun 2019 16:11:55 -0400 Subject: Why I am getting IndexError: tuple index out of range when converting a float value to a string? In-Reply-To: References: Message-ID: On 6/11/2019 1:04 PM, Rob Gaddi wrote: > On 6/11/19 9:52 AM, madhavanbomidi at gmail.com wrote: >> I wrote the following lines of code: >> >> xm = np.nanmean(x[indx],axis=None,dtype=float) >> xsd = np.nanstd(x[indx],axis=None,dtype=float) >> >> type(xm)??? # np.float64 >> type(xsd??? # np.float64 >> >> print(xm)????? # 0.5414720812182742 >> print(xsd)???? # 0.15748041033663002 >> >> print(str("{6.5f}".format(xm))) >> >> I get the following error: >> >> IndexError: tuple index out of range >> >> Can someone suggest me why I am getting this error and how to overcome >> this? Show us the full traceback after expanding and reducing the example to the minimum needed to exhibit the problem. > print(str("{:6.5f}".format(xm))) > > You want to apply the format 6.5f to the autoindexed element. Which works fine as it is. >>> xm = 3.0 >>> print(str("{:6.5f}".format(xm))) 3.00000 > You could also explicitly index the 1st element (#0) as {0:6.5f}. He could, but it makes no difference for the print statement above. Applying str to an str is redundant, as it applying it to a print argument. >>> print("{0:6.5f}".format(xm)) 3.00000 -- Terry Jan Reedy From alan at csail.mit.edu Tue Jun 11 16:55:02 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 11 Jun 2019 16:55:02 -0400 Subject: FDs will be closed after exception automatically in python2.7? References: <41abb57a-b0ff-fc39-d495-59bb970d5ca3@gmail.com> <420857b6-6e13-48af-9b26-135d21e4584b@VybeNetworks.com> <86blz5ql53.fsf@richard.bawden.org> <7c6d9d8e-00df-2bec-a2fd-dd659edbfec5@VybeNetworks.com> Message-ID: <865zpbrgex.fsf@richard.bawden.org> D'Arcy Cain writes: > On 2019-06-10 15:46, Alan Bawden wrote: > > D'Arcy Cain writes: > >> with open("file","w+") as fd: > > > > That makes the window smaller, but it doesn't actually eliminate it. Look > > at the generated byte code. In both cases the call to open() is over and > > the open file is created _before_ the SETUP_WITH instruction is executed. > > Am I correct in assuming that the window is there for process interrupts > but not threads? I believe that _either_ a signal handler invocation _or_ a thread switch might happen immediately before the SETUP_WITH instruction, so there is a window in either case. You probably do have less to worry about in the thread switch case, because eventually the thread will resume where it left off (there being no way to kill a thread). In the interrupt case it is possible that a KeyboardInterrupt will kill your thread right before the SETUP_WITH, and then the stream's __exit__ method will never be called. But you don't have much to worry about in that case either because the ONLY reference to the stream is on the top of the stack, so after the thread is unwound the stream will become garbage, and then the garbage collector will close it. But my point was that replacing: f = open(...) with f: with with open(...) as f: doesn't fully close _any_ timing windows, it's just clearer to write it that way. -- Alan Bawden From dieter at handshake.de Wed Jun 12 00:59:17 2019 From: dieter at handshake.de (dieter) Date: Wed, 12 Jun 2019 06:59:17 +0200 Subject: pysftp / paramiko problem References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> Message-ID: <8736kfz9ei.fsf@handshake.de> Robin Becker writes: > I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. > > I am using the pysftp wrapper around paramiko. > > The following script fails > > def main(): > import pysftp > with pysftp.Connection('ftp.remote.com', username='me', password='xxxxxx') as sftp: > print('top level') > print(sftp.listdir()) > print(sftp.normalize(u'XXXX')) >From the "sftp" documentation: | normalize(self, remotepath) | Return the expanded path, w.r.t the server, of a given path. This | can be used to resolve symlinks or determine what the server believes | to be the :attr:`.pwd`, by passing '.' as remotepath. This suggests that your observation could be explained by "u'XXXX'" being a broken symlink. From robin at reportlab.com Wed Jun 12 03:05:05 2019 From: robin at reportlab.com (Robin Becker) Date: Wed, 12 Jun 2019 08:05:05 +0100 Subject: pysftp / paramiko problem In-Reply-To: <8736kfz9ei.fsf@handshake.de> References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> Message-ID: <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> On 12/06/2019 05:59, dieter wrote: > Robin Becker writes: >> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. >> >> I am using the pysftp wrapper around paramiko. >> >> The following script fails >> >> def main(): >> import pysftp >> with pysftp.Connection('ftp.remote.com', username='me', password='xxxxxx') as sftp: >> print('top level') >> print(sftp.listdir()) >> print(sftp.normalize(u'XXXX')) > > From the "sftp" documentation: > > | normalize(self, remotepath) > | Return the expanded path, w.r.t the server, of a given path. This > | can be used to resolve symlinks or determine what the server believes > | to be the :attr:`.pwd`, by passing '.' as remotepath. > > This suggests that your observation could be explained > by "u'XXXX'" being a broken symlink. > Well with real sftp I can cd to that path so if it is a symlink it goes somewhere. With pysftp I am unable to chdir or cd into it. With a bit of difficulty I can use subprocess + sshpass + sftp to do the required transfer. -- Robin Becker From rishika21sen at gmail.com Wed Jun 12 07:12:34 2019 From: rishika21sen at gmail.com (Rishika Sen) Date: Wed, 12 Jun 2019 04:12:34 -0700 (PDT) Subject: Why am a getting wrong prediction when combining two list of samples, which individually gives correct prediction? Message-ID: <608afe1c-072c-4977-8619-093385d3629c@googlegroups.com> So I am coding in Python. I have to set of samples. Set1 contains samples of class A and the other set, Set2 contains samples of class B. When I am predicting set1 and set2 individually, the classification is perfect. Now when I am merging the two sets for prediction into one set, the prediction gives the wrong result for the samples in Set2, i.e., predicting the samples of set 2 to be in class A. However, samples belonging to Set1 are predicted to be in class A in the merged set. Why is this happening? model.add(Dense(newshape[1]+1, activation='relu', input_shape=(newshape[1],))) model.add(Dropout(0.5)) model.add(Dense(500, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(250, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(100, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(50, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['binary_accuracy']) model.fit(X_train, y_train,validation_data=(X_test, y_test),validation_split=0.2, epochs=500, batch_size=25, verbose=0) From pkpearson at nowhere.invalid Wed Jun 12 11:28:55 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 12 Jun 2019 15:28:55 GMT Subject: Why am a getting wrong prediction when combining two list of samples, which individually gives correct prediction? References: <608afe1c-072c-4977-8619-093385d3629c@googlegroups.com> Message-ID: On Wed, 12 Jun 2019 04:12:34 -0700 (PDT), Rishika Sen wrote: > So I am coding in Python. I have to set of samples. Set1 contains > samples of class A and the other set, Set2 contains samples of class > B. When I am predicting set1 and set2 individually, the classification > is perfect. Now when I am merging the two sets for prediction into one > set, the prediction gives the wrong result for the samples in Set2, > i.e., predicting the samples of set 2 to be in class A. However, > samples belonging to Set1 are predicted to be in class A in the merged > set. Why is this happening? > > model.add(Dense(newshape[1]+1, activation='relu', input_shape=(newshape[1],))) > model.add(Dropout(0.5)) > model.add(Dense(500, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(250, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(100, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(50, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(1, activation='sigmoid')) > model.compile(loss='binary_crossentropy', > optimizer='adam', > metrics=['binary_accuracy']) > model.fit(X_train, y_train,validation_data=(X_test, y_test), > validation_split=0.2, epochs=500, batch_size=25, verbose=0) This is really a question about some model-fitting package that you're using, not about Python. And you don't even tell us which model-fitting package it is. Please share more information. Are you expecting that any model-fitting process that works individually on Set1 and Set2 must work on the union of the two sets? 'Cause I don't think it works that way. -- To email me, substitute nowhere->runbox, invalid->com. From dieter at handshake.de Thu Jun 13 00:56:55 2019 From: dieter at handshake.de (dieter) Date: Thu, 13 Jun 2019 06:56:55 +0200 Subject: pysftp / paramiko problem References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> Message-ID: <87h88udqw8.fsf@handshake.de> Robin Becker writes: > On 12/06/2019 05:59, dieter wrote: >> Robin Becker writes: >>> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. > ... > Well with real sftp I can cd to that path so if it is a symlink it goes somewhere. > > With pysftp I am unable to chdir or cd into it. With a bit of > difficulty I can use subprocess + sshpass + sftp to do the required > transfer. Maybe, the problem is the "u" prefix. Can you try your script with Python 3 or encode the unicode into a native ``str``? From robin at reportlab.com Thu Jun 13 09:57:21 2019 From: robin at reportlab.com (Robin Becker) Date: Thu, 13 Jun 2019 14:57:21 +0100 Subject: pysftp / paramiko problem In-Reply-To: <87h88udqw8.fsf@handshake.de> References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> <87h88udqw8.fsf@handshake.de> Message-ID: <5f950cd0-3f6b-d601-f39a-f2d032073073@chamonix.reportlab.co.uk> On 13/06/2019 05:56, dieter wrote: > Robin Becker writes: >> On 12/06/2019 05:59, dieter wrote: >>> Robin Becker writes: >>>> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. >> ... >> Well with real sftp I can cd to that path so if it is a symlink it goes somewhere. >> >> With pysftp I am unable to chdir or cd into it. With a bit of >> difficulty I can use subprocess + sshpass + sftp to do the required >> transfer. > > Maybe, the problem is the "u" prefix. > Can you try your script with Python 3 or encode the unicode > into a native ``str``? > no same happens in a fresh python 3.6 environment > $ cat - > tsftp.py > def main(): > import pysftp > with pysftp.Connection('ftp.remote.com', username='me', password='ucl20 11') as sftp: > print('top level') > print(sftp.listdir()) > print(sftp.normalize('XXXX')) > > if __name__ == '__main__': > main() > (tpy3) rptlab at app1:~/tmp/tpy3 > $ python tsftp.py > top level > ['XXXX'] > Traceback (most recent call last): > File "tsftp.py", line 9, in > main() > File "tsftp.py", line 6, in main > print(sftp.normalize('XXXX')) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", line 640, in normalize > return self._sftp.normalize(remotepath) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 632, in normalize > t, msg = self._request(CMD_REALPATH, path) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 813, in _request > return self._read_response(num) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 865, in _read_response > self._convert_status(msg) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 894, in _convert_status > raise IOError(errno.ENOENT, text) > FileNotFoundError: [Errno 2] No such file. this is what real sftp does > (tpy3) rptlab at app1:~/tmp/tpy3 > $ sshpass -p ucl2011 sftp me at ftp.remote.com > Connected to ftp.remote.com. > sftp> cd XXXX > sftp> pwd > Remote working directory: /XXXX > sftp> ls > OLD GR ........ > ZZZZZ.pdf > sftp> ^D > (tpy3) rptlab at app1:~/tmp/tpy3 -- Robin Becker From python at mrabarnett.plus.com Thu Jun 13 13:23:52 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Jun 2019 18:23:52 +0100 Subject: pysftp / paramiko problem In-Reply-To: <5f950cd0-3f6b-d601-f39a-f2d032073073@chamonix.reportlab.co.uk> References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> <87h88udqw8.fsf@handshake.de> <5f950cd0-3f6b-d601-f39a-f2d032073073@chamonix.reportlab.co.uk> Message-ID: On 2019-06-13 14:57, Robin Becker wrote: > On 13/06/2019 05:56, dieter wrote: >> Robin Becker writes: >>> On 12/06/2019 05:59, dieter wrote: >>>> Robin Becker writes: >>>>> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only. >>> ... >>> Well with real sftp I can cd to that path so if it is a symlink it goes somewhere. >>> >>> With pysftp I am unable to chdir or cd into it. With a bit of >>> difficulty I can use subprocess + sshpass + sftp to do the required >>> transfer. >> >> Maybe, the problem is the "u" prefix. >> Can you try your script with Python 3 or encode the unicode >> into a native ``str``? >> > no same happens in a fresh python 3.6 environment > >> $ cat - > tsftp.py >> def main(): >> import pysftp >> with pysftp.Connection('ftp.remote.com', username='me', password='ucl20 11') as sftp: >> print('top level') >> print(sftp.listdir()) >> print(sftp.normalize('XXXX')) >> >> if __name__ == '__main__': >> main() >> (tpy3) rptlab at app1:~/tmp/tpy3 >> $ python tsftp.py >> top level >> ['XXXX'] >> Traceback (most recent call last): >> File "tsftp.py", line 9, in >> main() >> File "tsftp.py", line 6, in main >> print(sftp.normalize('XXXX')) >> File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", line 640, in normalize >> return self._sftp.normalize(remotepath) >> File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 632, in normalize >> t, msg = self._request(CMD_REALPATH, path) >> File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 813, in _request >> return self._read_response(num) >> File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 865, in _read_response >> self._convert_status(msg) >> File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 894, in _convert_status >> raise IOError(errno.ENOENT, text) >> FileNotFoundError: [Errno 2] No such file. > > this is what real sftp does > >> (tpy3) rptlab at app1:~/tmp/tpy3 >> $ sshpass -p ucl2011 sftp me at ftp.remote.com >> Connected to ftp.remote.com. >> sftp> cd XXXX >> sftp> pwd >> Remote working directory: /XXXX >> sftp> ls >> OLD GR ........ >> ZZZZZ.pdf >> sftp> ^D >> (tpy3) rptlab at app1:~/tmp/tpy3 > What does: sftp.normalize('.') return? From cs at cskk.id.au Thu Jun 13 19:02:46 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 14 Jun 2019 09:02:46 +1000 Subject: The trailing comma bites! You have a new tuple. Message-ID: <20190613230246.GA14824@cskk.homeip.net> Just venting :-( I've just wasted a surprising amount of time on a simple mistake. Former code: task = IngestTask(..., logical_dirpath=join(source_dir, subdir, rpath), ...) During a reworking it became this: logical_dirpath = join( source_dir, subdir, rpath ), task = IngestTask(..., logical_dirpath=logical_dirpath, ...) Typing badness ensues. In a subsequent function call far far away. Grumble, Cameron Simpson From cseberino at gmail.com Thu Jun 13 19:49:48 2019 From: cseberino at gmail.com (Christian Seberino) Date: Thu, 13 Jun 2019 16:49:48 -0700 (PDT) Subject: How control a GUI for an unrelated application from a Python script? Message-ID: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> I have a third party GUI that manages some hardware. I want to control the hardware from a Python script. This seems to mean I need to somehow have Python code that imitates a human doing the necessary actions on the GUI (selecting menu options, pressing buttons, etc.) Is this possible / easy / doable? Thanks! Chris From rosuav at gmail.com Thu Jun 13 20:00:38 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Jun 2019 10:00:38 +1000 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: On Fri, Jun 14, 2019 at 9:51 AM Christian Seberino wrote: > > I have a third party GUI that manages some hardware. > > I want to control the hardware from a Python script. > > This seems to mean I need to somehow have Python code > that imitates a human doing the necessary > actions on the GUI (selecting menu options, pressing buttons, etc.) > > Is this possible / easy / doable? > Possible? Yes. Easy? Probably not. So I would recommend first seeing if there's any sort of command-line tool, or command-line invocation for the GUI tool (some programs will open a GUI if given no arguments, but you can provide args to make them do stuff straight away). Once you've exhausted all options of easy automation, yes, you CAN have a program manipulate a GUI. It's fiddly, though. ChrisA From torriem at gmail.com Thu Jun 13 21:34:54 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Jun 2019 19:34:54 -0600 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: On 06/13/2019 05:49 PM, Christian Seberino wrote: > I have a third party GUI that manages some hardware. > > I want to control the hardware from a Python script. > > This seems to mean I need to somehow have Python code > that imitates a human doing the necessary > actions on the GUI (selecting menu options, pressing buttons, etc.) > > Is this possible Maybe. > / easy No. > doable? Maybe. It's kind of the old "if you have to ask" sort of question. There are ways of programatically driving other applications' user interfaces. You haven't said what OS you are using. We used to use an application called AutoIt to drive GUI programs. You can send clicks, keystrokes, and work with certain controls (read values, set values, etc), at least if they are standard win32 widgets. More and more applications draw their own controls these days rather than use win32 widgets, which wouldn't be usable for that kind of modification. As far as modifying a running GUI to add functionality, the answer to that is probably "very difficult" to "impossible." If the GUI itself is just a frontend for command-line tools or even libraries that interact with the hardware, then you probably could develop your own GUI from scratch. This is one reason why free and open source software wins. It's just that much more flexible to manipulate and make to do cool new things. From thinmanj at gmail.com Thu Jun 13 22:00:22 2019 From: thinmanj at gmail.com (=?UTF-8?Q?Julio_O=C3=B1a?=) Date: Thu, 13 Jun 2019 22:00:22 -0400 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: try https://pypi.org/project/PyAutoIt/ Regards Julio El jue., 13 de jun. de 2019 a la(s) 21:37, Michael Torrie (torriem at gmail.com) escribi?: > > On 06/13/2019 05:49 PM, Christian Seberino wrote: > > I have a third party GUI that manages some hardware. > > > > I want to control the hardware from a Python script. > > > > This seems to mean I need to somehow have Python code > > that imitates a human doing the necessary > > actions on the GUI (selecting menu options, pressing buttons, etc.) > > > > Is this possible > > Maybe. > > > / easy > No. > > > doable? > > Maybe. > > It's kind of the old "if you have to ask" sort of question. > > There are ways of programatically driving other applications' user > interfaces. You haven't said what OS you are using. We used to use an > application called AutoIt to drive GUI programs. You can send clicks, > keystrokes, and work with certain controls (read values, set values, > etc), at least if they are standard win32 widgets. More and more > applications draw their own controls these days rather than use win32 > widgets, which wouldn't be usable for that kind of modification. > > As far as modifying a running GUI to add functionality, the answer to > that is probably "very difficult" to "impossible." If the GUI itself is > just a frontend for command-line tools or even libraries that interact > with the hardware, then you probably could develop your own GUI from > scratch. > > This is one reason why free and open source software wins. It's just > that much more flexible to manipulate and make to do cool new things. > -- > https://mail.python.org/mailman/listinfo/python-list From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Thu Jun 13 23:56:22 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 14 Jun 2019 04:56:22 +0100 Subject: Dataframe with two groups of cols. Message-ID: Hi! How do I create a pandas dataframe with two (or more) groups of cols.? Ex.: G1 G2 C1 C2 C3 C1 C2 C3 Rows of values ... I then should be able to access for example df['G2']['C3'][] Thanks. From mal at europython.eu Fri Jun 14 05:50:33 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 14 Jun 2019 11:50:33 +0200 Subject: EuroPython 2019: Warning - Spoiler alert! Message-ID: Usually, we try to have something as surprise for our attendees every year. However, for this year?s conference, we have decided to give our attendees something to play with and this needs a little more preparation than a bottle or a beach towel. Drum roll? crowd screaming? and here it is: we?re please to present the... EuroPython 2019 PewPew Game Console ----------------------------------- * https://ep2019.europython.eu/events/pewpew-workshops/ * The device was created and designed by Radomir Dopieralski, a long time EuroPython regular and enthusiastic Python device and robotics builder. The PewPew is a simplified game console, programmable with CircuitPython, a variant of MicroPython. It comes with a 64 LED display and a set of small buttons to drive the console. We will have one device per attendee with training or conference ticket and plan to give them out together with the badges. Free Workshops -------------- To teach you how to program the consoles and help with any questions you may have, we have arranged a special workshop room on the training days Monday and Tuesday, where Radomir and his team will run workshops focusing on the PewPew. You will learn how to write small programs and games. Our hope is that you will take this knowledge home and spread the word about how much fun Python is ? especially for younger users. The workshops are free for EuroPython conference or training ticket holders, but please see our notes on catering on the training days. Help us run the workshops ------------------------- Since Radomir needs help with running the workshops, we are reaching out to you with this blog post. If you are interested in embedded Python, hardware hacking, game development and similar topics, we invite you to come help us running those workshops. This is a great opportunity to meet with Python developers and learn together, and we?re sure you will have great fun while helping other attendees. Whether it?s just lending a hand getting things working, or running a whole workshop ? it?s up to you, either way we will greatly appreciate your help. Please sign up using our mentor form. Many thanks ! https://docs.google.com/forms/d/e/1FAIpQLSefU0VMGA7QVO6DgO_9faHQ_Z4XcsfpRZ2koALOP63kN-UeGA/viewform More information will be available on the PewPew workshop page: https://ep2019.europython.eu/events/pewpew-workshops/ Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185584014022/europython-2019-warning-spoiler-alert Tweet: https://twitter.com/europython/status/1139464940627136512 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From tjol at tjol.eu Fri Jun 14 05:43:18 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 14 Jun 2019 11:43:18 +0200 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: On 14/06/2019 01.49, Christian Seberino wrote: > I have a third party GUI that manages some hardware. > > I want to control the hardware from a Python script. Forget about the GUI, see if you can control your device without it. See how well the device is documented. Maybe there's an API? If not for Python, maybe for C? If not, maybe it's easy to write your own driver in Python? Writing a driver for a simple message-based wire protocol is not very hard, and may be easier than reliably controlling somebody else's GUI with a script. > > This seems to mean I need to somehow have Python code > that imitates a human doing the necessary > actions on the GUI (selecting menu options, pressing buttons, etc.) > > Is this possible / easy / doable? > > Thanks! > > Chris From chaz at chaz6.com Fri Jun 14 07:27:37 2019 From: chaz at chaz6.com (Chris Hills) Date: Fri, 14 Jun 2019 12:27:37 +0100 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: On 6/14/2019 12:49 AM, Christian Seberino wrote: > I have a third party GUI that manages some hardware. > > I want to control the hardware from a Python script. > > This seems to mean I need to somehow have Python code > that imitates a human doing the necessary > actions on the GUI (selecting menu options, pressing buttons, etc.) > > Is this possible / easy / doable? > > Thanks! > > Chris > Hi Chris THere are two approaches for this. If the appication is inheritenty controllable, e.g. through COM, then you can use win32com. Alternatively, you can go down the route of "Robotic Process Automation" using something like https://github.com/OakwoodAI/Automagica Hope this helps, Chris Hills From johann.spies at gmail.com Fri Jun 14 07:36:04 2019 From: johann.spies at gmail.com (Johann Spies) Date: Fri, 14 Jun 2019 13:36:04 +0200 Subject: can not use pycharm In-Reply-To: <5cfe9354.1c69fb81.fd035.1747@mx.google.com> References: <5cfe9354.1c69fb81.fd035.1747@mx.google.com> Message-ID: On Mon, 10 Jun 2019 at 19:46, aris wrote: > > > Hello,this is my first time trying to learn coding and programming and I > wanted to start with python.Though,when I download pycharm, I go to > configure>settings>project interpreter and i can not put a project > interpreter( I have download python version 3) .What should I do?thank you > for your time.Because experiencing your loyal love is better than life > itself, > > Pycharm can be complicated to start with. If you have problems getting started, try out others like Spyder3 and Atom - or emacs and vim :) Johann From robin at reportlab.com Fri Jun 14 10:18:54 2019 From: robin at reportlab.com (Robin Becker) Date: Fri, 14 Jun 2019 15:18:54 +0100 Subject: pysftp / paramiko problem In-Reply-To: References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> <87h88udqw8.fsf@handshake.de> <5f950cd0-3f6b-d601-f39a-f2d032073073@chamonix.reportlab.co.uk> Message-ID: On 13/06/2019 18:23, MRAB wrote: ......... >> > What does: > > sftp.normalize('.') > > return? It returns '/'. sftp.chdir('XXXX') and that also fails in paramiko as it seems to use CMD_REALPATH to do that. > File "tsftp.py", line 7, in main > print(sftp.chdir('XXXX')) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", line 524, in chdir > self._sftp.chdir(remotepath) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 662, in chdir > self._cwd = b(self.normalize(path)) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 632, in normalize > t, msg = self._request(CMD_REALPATH, path) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 813, in _request > return self._read_response(num) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 865, in _read_response > self._convert_status(msg) > File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 894, in _convert_status > raise IOError(errno.ENOENT, text) > FileNotFoundError: [Errno 2] No such file. -- Robin Becker From robin at reportlab.com Fri Jun 14 10:48:31 2019 From: robin at reportlab.com (Robin Becker) Date: Fri, 14 Jun 2019 15:48:31 +0100 Subject: pysftp / paramiko problem In-Reply-To: References: <4f926a45-6f69-1747-84fc-288a417173d2@chamonix.reportlab.co.uk> <8736kfz9ei.fsf@handshake.de> <3fc01816-3573-cc22-f7fc-f346f409e9c5@chamonix.reportlab.co.uk> <87h88udqw8.fsf@handshake.de> <5f950cd0-3f6b-d601-f39a-f2d032073073@chamonix.reportlab.co.uk> Message-ID: ....... I tried an experiment with a remote server that I control and pysftp works perfectly there. A difference that I know of is that this server is using ubuntu 18.04 and we don't use passwords, but a private_key. Also this server is using the openssh internal sftp. I believe the failing server is using an earlier version of openssh or OS as it wants to use ssh-dss which is now considered unsafe (I believe). -- Robin Becker From infneurodcr.mtz at infomed.sld.cu Fri Jun 14 09:39:09 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Fri, 14 Jun 2019 09:39:09 -0400 Subject: can not use pycharm In-Reply-To: <5cfe9354.1c69fb81.fd035.1747@mx.google.com> References: <5cfe9354.1c69fb81.fd035.1747@mx.google.com> Message-ID: <26394bc0-2d68-7ea7-345c-bb93e2510566@infomed.sld.cu> El 10/06/19 a las 13:28, aris escribi?: > > Hello,this is my first time trying to learn coding and programming and I wanted to start with python.Though,when I download pycharm, I go to configure>settings>project interpreter and i can not put a project interpreter( I have download python version 3) .What should I do?thank you for your time. > > Hi Aris: You must go to: File -> Settings and below of "Version Control" you find like this: Project:"project name" -> Project Interpreter and the top at your right hand you find litle button and you can add (configure) an interpreter: Virtualenv Enviroment, Conda Env., System Interpreter, Pipenv Env.., etc. You must use the last (at least a version after mars of the last year ), because include the pipenv support. I hope that can help you. PD Before all, you must have already installed pipenv in your system. -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From python at bdurham.com Fri Jun 14 11:23:00 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 14 Jun 2019 09:23:00 -0600 Subject: What's the latest best practice on Python project directory layouts? Message-ID: <3537e5e6-8088-4197-bffb-8aa703fa64be@www.fastmail.com> I have a collection of command line scripts that share a collection of common modules. This code collection is for internal use and will run under a single version of Python 3.6+ and a single OS. My understanding of best practice is to organize this collection of Python files into a folder structure like this: # common files .gitignore readme.md requirements.txt setup.py <--- what is the advantage of this file for internally distributed code bases? # app specific package folders app-1 __init__.py (optional; if needed) __main__.py app-1-module-1.py app-1-module-2.py app-1-module-N.py app-2 __init__.py (optional; if needed) __main__.py app-2-module-1.py app-2-module-2.py app-2-module-N.py # modules shared across multiple apps common common-module-1.py common-module-2.py common-module-N.py # tests - place at package level with sub-packages for each package -OR- underneath each app package? tests app-1 test_app-1-module-1.py test_app-1-module-2.py test_app-1-module-N.py app-2 test_app-2-module-1.py test_app-2-module-2.py test_app-2-module-N.py # virtual env folder placed at same level as packages ??? venv And execute each app via the following ... python -m app-1 Questions 1. Does the above structure sound reasonable? 2. Where to place virtual env files and what to call this folder? venv, .env, etc? 3. Where to put tests (pytest)? In a tests folder or under each package? 4. Use a src folder or not? If so, where to put above files relative to the src folder? Malcolm From cseberino at gmail.com Fri Jun 14 11:49:04 2019 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 14 Jun 2019 08:49:04 -0700 (PDT) Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> Message-ID: <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> Thanks for all the help. I'll definitely try to bypass the GUI first if possible. This is on Windows 7 so maybe AutoIt will do the trick if can't avoid the GUI. Thanks again everyone. From rgaddi at highlandtechnology.invalid Fri Jun 14 12:27:24 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 14 Jun 2019 09:27:24 -0700 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> Message-ID: On 6/14/19 8:49 AM, Christian Seberino wrote: > Thanks for all the help. I'll definitely try to bypass the GUI first if possible. This is on Windows 7 so maybe AutoIt will do the trick if can't avoid the GUI. Thanks again everyone. > Out of curiosity, what hardware? -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Fri Jun 14 13:31:26 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 14 Jun 2019 18:31:26 +0100 Subject: Dataframe with two groups of cols. [RESOLVED] References: Message-ID: ?s 04:56 de 14/06/19, Paulo da Silva escreveu: > Hi! > > How do I create a pandas dataframe with two (or more) groups of cols.? > > Ex.: > > G1 G2 > C1 C2 C3 C1 C2 C3 > Rows of values ... > > I then should be able to access for example > df['G2']['C3'][] > > > Thanks. > After digging a lot :-) , and for those who may be interested, I found one way: In [21]: d1 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),columns=['C1', 'C2', 'C3']) In [22]: d2 = pd.DataFrame(np.array([[10, 2, 3], [10, 5, 6], [10, 8, 9]]),columns=['C1', 'C2', 'C3']) In [23]: d=pd.concat([d1,d2],keys=['G1','G2'],axis=1) In [24]: d Out[24]: G1 G2 C1 C2 C3 C1 C2 C3 0 1 2 3 10 2 3 1 4 5 6 10 5 6 2 7 8 9 10 8 9 In [25]: d['G2']['C1'] Out[25]: 0 10 1 10 2 10 Name: C1, dtype: int64 In [26]: From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Fri Jun 14 14:06:39 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Fri, 14 Jun 2019 19:06:39 +0100 Subject: Dataframe with two groups of cols. [RESOLVED] References: Message-ID: ?s 18:31 de 14/06/19, Paulo da Silva escreveu: > ?s 04:56 de 14/06/19, Paulo da Silva escreveu: ... > > After digging a lot :-) , and for those who may be interested, I found > one way: > > In [21]: d1 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, > 9]]),columns=['C1', 'C2', 'C3']) > > In [22]: d2 = pd.DataFrame(np.array([[10, 2, 3], [10, 5, 6], [10, 8, > 9]]),columns=['C1', 'C2', 'C3']) > > In [23]: d=pd.concat([d1,d2],keys=['G1','G2'],axis=1) > > In [24]: d > Out[24]: > G1 G2 > C1 C2 C3 C1 C2 C3 > 0 1 2 3 10 2 3 > 1 4 5 6 10 5 6 > 2 7 8 9 10 8 9 > > In [25]: d['G2']['C1'] > Out[25]: > 0 10 > 1 10 > 2 10 > Name: C1, dtype: int64 > > In [26]: > And I noticed that things are yet more flexible ... For ex. we can add further data In [12]: d['G3','C1']=['v1','v2','v3'] In [13]: d Out[13]: G1 G2 G3 C1 C2 C3 C1 C2 C3 C1 0 1 2 3 10 2 3 v1 1 4 5 6 10 5 6 v2 2 7 8 9 10 8 9 v3 ... but starting with an empty dataframe does not work! In [3]: df=pd.DataFrame() In [4]: df['G1','c1']=[1,2,3] In [5]: df Out[5]: (G1, c1) 0 1 1 2 2 3 In [6]: From cseberino at gmail.com Fri Jun 14 14:14:17 2019 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 14 Jun 2019 11:14:17 -0700 (PDT) Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> Message-ID: <0eff3bb7-d39e-4556-a307-2ea9908b2990@googlegroups.com> > Out of curiosity, what hardware? Texas Instruments ADS1675REF card From rgaddi at highlandtechnology.invalid Fri Jun 14 14:42:02 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 14 Jun 2019 11:42:02 -0700 Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: <0eff3bb7-d39e-4556-a307-2ea9908b2990@googlegroups.com> References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> <0eff3bb7-d39e-4556-a307-2ea9908b2990@googlegroups.com> Message-ID: On 6/14/19 11:14 AM, Christian Seberino wrote: > >> Out of curiosity, what hardware? > > Texas Instruments ADS1675REF card > Condolences. TI is a world-leader in giving every eval board its own complicated, proprietary digital interface, then not documenting it because "You can just use the provided software" that hasn't been updated since 2001 and doesn't actually let you test the thing you need to. The underlying FPGA board that it's built on has its own page at https://opalkelly.com/products/xem3010/ with an SDK. That may turn out to be your best way in. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From cseberino at gmail.com Fri Jun 14 14:56:00 2019 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 14 Jun 2019 11:56:00 -0700 (PDT) Subject: How control a GUI for an unrelated application from a Python script? In-Reply-To: References: <02e1265c-a998-48c2-9acc-32a9f726817b@googlegroups.com> <76a9f9f7-e55b-4779-9312-b79e6819b2b5@googlegroups.com> <0eff3bb7-d39e-4556-a307-2ea9908b2990@googlegroups.com> Message-ID: <8291ad53-9c75-4ed2-963c-9643b5899ff0@googlegroups.com> On Friday, June 14, 2019 at 1:42:17 PM UTC-5, Rob Gaddi wrote: > Condolences. TI is a world-leader in giving every eval board its own > complicated, proprietary digital interface, then not documenting it > because "You can just use the provided software" that hasn't been > updated since 2001 and doesn't actually let you test the thing you need to. > > The underlying FPGA board that it's built on has its own page at > https://opalkelly.com/products/xem3010/ with an SDK. That may turn out > to be your best way in. You don't know how right you are. It gets even better....Since they don't update their Windows GUI apps...10 years later it won't run on the latest Windows. I had to set up a Windows 7 machine to run their @#$# software!!! ;) This is the dreaded GUI app ... http://www.ti.com/tool/ADCPRO (That Opal Kelly code is very nice but isn't designed to support all the TI boards the FPGA plugs into. Believe me I tried that route. ;) From cs at cskk.id.au Fri Jun 14 21:15:14 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 15 Jun 2019 11:15:14 +1000 Subject: What's the latest best practice on Python project directory layouts? In-Reply-To: <3537e5e6-8088-4197-bffb-8aa703fa64be@www.fastmail.com> References: <3537e5e6-8088-4197-bffb-8aa703fa64be@www.fastmail.com> Message-ID: <20190615011514.GA50760@cskk.homeip.net> On 14Jun2019 09:23, Malcolm Greene wrote: >I have a collection of command line scripts that share a collection of common modules. This code collection is for internal use and will run under a single version of Python 3.6+ and a single OS. My understanding of best practice is to organize this collection of Python files into a folder structure like this: > ># common files >.gitignore >readme.md >requirements.txt >setup.py <--- what is the advantage of this file for internally distributed code bases? > ># app specific package folders >app-1 > __init__.py (optional; if needed) > __main__.py > app-1-module-1.py > app-1-module-2.py > app-1-module-N.py > >app-2 > __init__.py (optional; if needed) > __main__.py > app-2-module-1.py > app-2-module-2.py > app-2-module-N.py > ># modules shared across multiple apps >common > common-module-1.py > common-module-2.py > common-module-N.py > ># tests - place at package level with sub-packages for each package -OR- underneath each app package? >tests > app-1 > test_app-1-module-1.py > test_app-1-module-2.py > test_app-1-module-N.py > app-2 > test_app-2-module-1.py > test_app-2-module-2.py > test_app-2-module-N.py > ># virtual env folder placed at same level as packages ??? >venv > > >And execute each app via the following ... > >python -m app-1 > >Questions > >1. Does the above structure sound reasonable? Yes. Though I like to get them out of the top directory, details below. >2. Where to place virtual env files and what to call this folder? venv, .env, etc? I use "venv" myself. >3. Where to put tests (pytest)? In a tests folder or under each package? Personally, I'd do it however you would do them if the apps and the common modules were standalone. I use a foo_tests.py beside my foo.py module file myself, but a naming scheme adhering to the discoverability of your test running tool would also be a good choice. >4. Use a src folder or not? If so, where to put above files relative to >the src folder? Well, yeah. Always a subdirectory, I hate littering the top level. Here is how I lay out a project, based on my current one (nonPython bits elided): project/ bin/ lib/python/all-modules-here venv/ Various points: - I dislike using Python's "search for modules in the current directory"; I would _always_ rather set $PYTHONPATH for specific control. - The lib/python depth is to accomodate lib/other-languages according to the mix in the project. Some context: I'm making a full stack app for a client at present. The client's code is like this: lib/python/clientname/appname/*.py It happens that all the "common" code is in the appname subdirectory because it is self contained, but were it not it would be in lib/python/clientname/*.py or possibly lib/python/clientname/util/*.py (or "common" if you prefer). One important aspect of this is that it lets me keep the client code away from conflicts with other library names, so the "clientname" module path component is important for this, _and_ it better labels the purpose of the module. So the environment setup looks like this: project=/path/to/project # or $(dirname "$0") if $0 is useful PYTHONPATH=$project/lib/python PATH=$project/bin:$project/venv/bin:$PATH export PYTHONPATH PATH and the app is run: python -m clientname.appname args... The app does relative imports for itself: from .util import SomeAppClass and would import common code absolutely: from clientname.util import SomeCommonClass In my current project I've actually got a small shell script which does the environment setup above and invokes the python app (or various other utility tasks like "init the database" etc). I find this approach generally useful. Anyway, this might inform what choices you make. Happy to elaborate on specifics, though they get more personal and idiosyncratic the more fine grained we get. Cheers, Cameron Simpson From mail.python.org at marco.sulla.e4ward.com Sun Jun 16 09:45:42 2019 From: mail.python.org at marco.sulla.e4ward.com (Marco Sulla) Date: Sun, 16 Jun 2019 15:45:42 +0200 Subject: Why Python has no equivalent of JDBC of Java? In-Reply-To: References: <5CE3EEB50200001B0002C199@smtp1.astron.nl> Message-ID: On Tue, 21 May 2019 at 01:20, Michael Torrie wrote: > On 05/20/2019 04:23 PM, Andrew Z wrote: > I assume > Nope, it requires the instantclient and, on Linux only, also the installclient-devel package. And a bunch of obscure and terrible settings, like LD_LIBRARY_PATH... On Tue, 21 May 2019 at 03:42, Chris Angelico wrote: > From the sound of > things, the choice of database back end has already been made, and the > Python script just has to cope. Otherwise, PostgreSQL would be an > entirely better alternative. > Yes it's that the problem. Well I love Postgres, but IMHO the big disadvantages over Oracle are two: BLOBs and performance. On Tue, 21 May 2019 at 15:14, Paul Moore wrote: > Because a commercial product like Oracle doesn't document > those protocols, open-source reimplementations are hard, if not > impossible. > IMHO this is the more logical answer to my doubts. On Tue, 21 May 2019 at 18:17, Dennis Lee Bieber wrote: > It wouldn't surprise me to find that they include the JDBC > driver layer for Oracle database in the Java package} It would surprise _me_. Oracle did not even uploaded ojdbc to the maven repository... On Sun, 26 May 2019 at 15:37, Bischoop wrote: > On 2019-05-19, Marco Sulla wrote: > >blablabla > >blablablalbla > >blablalblalbalblabla > > There's no perfect language mate, in some one is easier in other not, > normal surprised you notice it so late. I discovered it two years and an half ago, when I started to program in Java too. Sorry if I didn't had the time to post but I'm working. And sorry again, I don't know the whole basics of every programming language in the world. I only programmed in Python 2 and 3, Cython, C, C++, Fortran, Qt, PHP, Visual Basic .NET, LabView and Javascript. On Sun, 26 May 2019 at 19:53, Christian Gollwitzer wrote: > Python closer to the metal than Java? This is nonsense. > Well, it seems to me the majority of python db drivers uses Cython, Python C API or external C libraries. So in this particular case Python *could* be more performant than Java. I don't know, you should do some benchmark with different queries, different in nature, complexity and number of rows retrieved, on the same db, accessed once with Java and once with Python. The problem is benchmarking Java not so easy as Python. It's very boring. From hjp-python at hjp.at Sun Jun 16 11:03:52 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 16 Jun 2019 17:03:52 +0200 Subject: Why Python has no equivalent of JDBC of Java? In-Reply-To: References: <5CE3EEB50200001B0002C199@smtp1.astron.nl> Message-ID: <20190616150352.ybwrlpqyunlcgcf4@hjp.at> On 2019-06-16 15:45:42 +0200, Marco Sulla via Python-list wrote: > On Tue, 21 May 2019 at 01:20, Michael Torrie wrote: > > On 05/20/2019 04:23 PM, Andrew Z wrote: > > I assume > > It would have helped if you also quoted what Andrew assumed, not just that he assumed something. For the record, he assumed that JDBC also needs a native driver but that this is automatically installed. (the assumption was wrong) > Nope, it requires the instantclient and, on Linux only, also the > installclient-devel package. And a bunch of obscure and terrible settings, > like LD_LIBRARY_PATH... If "it" means the Oracle JDBC driver, then it doesn't require those things, which I think was your original point. Anything which uses the Oracle native driver (Python's cx_Oracle, Perl's DBD:Oracle, etc.) needs these things, which makes setting them up more complicated. The fact is that Oracle chose to write a pure-Java implementation of their driver which is really easy to install (although it might have some limitations) but they did no such thing for other languages - plus their license terms make it hard to bundle their driver, so everybody needs to go through the "install instantclient, configure instantclient, install language-specific drivers" dance (which btw is much easier now than it was before instantclient) So that's the answer to your question: Because Oracle made it so. > On Tue, 21 May 2019 at 03:42, Chris Angelico wrote: > > From the sound of things, the choice of database back end has > > already been made, and the Python script just has to cope. > > Otherwise, PostgreSQL would be an entirely better alternative. > > > > Yes it's that the problem. > Well I love Postgres, but IMHO the big disadvantages over Oracle are two: > BLOBs and performance. Interesting. I think PostgreSQL's bytea type is much easier to work with than Oracle's BLOBs, and they cover my needs (they have a 1 GB size limit, but so far I haven't run into that). PostgreSQL also has LOs, which seem to be even more awkward to use than Oracle's BLOBs, but I haven't actually used them so I might be wrong. And over the years I got the impression that PostgreSQL's performance is at least comparable to that of Oracle - at least for "normal" databases, not something like RAC (which I never used because we couldn't afford it anyway). One of our databases was recently migrated to PostgreSQL and the guy who mostly works with it was quite enthusiastic about the speed (but there might have been other changes like new hardware ...). > On Tue, 21 May 2019 at 15:14, Paul Moore wrote: > > Because a commercial product like Oracle doesn't document > > those protocols, open-source reimplementations are hard, if not > > impossible. > > > > IMHO this is the more logical answer to my doubts. Oracle is also well-known for employing an army of lawyers, so the technical difficulties might just be the beginning. [...] > On Sun, 26 May 2019 at 19:53, Christian Gollwitzer wrote: > > Python closer to the metal than Java? This is nonsense. > > > > Well, it seems to me the majority of python db drivers uses Cython, > Python C API or external C libraries. Which I would take as an indication that Python is "further from the metal". Python isn't really suited for the job so you have to switch to a lower-level (closer to the metal) language to implement it. > So in this particular case Python *could* be more performant than > Java. Performance is only very indirectly related to being close to the metal. 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 rajpara.jaydip1084 at gmail.com Wed Jun 12 01:42:29 2019 From: rajpara.jaydip1084 at gmail.com (jaydip rajpara) Date: Wed, 12 Jun 2019 11:12:29 +0530 Subject: installing of python Message-ID: this pic of my c drive after installing python 3.7.2. No python folder generated From jorgconforte at hotmail.com Wed Jun 12 10:37:48 2019 From: jorgconforte at hotmail.com (Jorge Conrado Conforte) Date: Wed, 12 Jun 2019 14:37:48 +0000 Subject: How to create a RGB color Table Message-ID: HI, Please someone could help me. How can I create a new color table with the values of r g and b that I have. I use the Mataplolib color tables. However, I would like to use a new color table with the respective r g b values that I have. Thank you. [https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png] Livre de v?rus. www.avg.com. From lokallu6 at gmail.com Wed Jun 12 12:02:21 2019 From: lokallu6 at gmail.com (Lokallu Maltorin) Date: Thu, 13 Jun 2019 01:02:21 +0900 Subject: error 0xc0000374 during installation Message-ID: Hi there, I always get a 0xc0000374 error when I try to install Python on my PC. I am using a flash installed win 7 Pro x64, with all available win-update installed including SP1 and convenience-rollup. I found 1. python -m pip worked but "python not responding" error always show up at last and .exe file never being generated 2. pip.exe do not appear in the Script folder, and "pip" in command prompt return "not recognized" I am unable to use some packages because there are no .exe generated. Can you please help? Thanks in advance. Lokallu From luciano at ramalho.org Wed Jun 12 15:13:41 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Wed, 12 Jun 2019 16:13:41 -0300 Subject: Is there an archive of this list with permanent URLs to each message? Message-ID: Hello! When I wrote Fluent Python a few years ago I provided my readers with hundreds of links to my sources, including several links to messages in the python-list archive. Now as I prepare the 2nd edition I notice all my links to this list are broken. Apparently mailman rebuilds the archives and changes the ids of the messages. Is there an archive of python-list that preserves each message with a permanent URL? Thanks! Luciano PS. For the curious, here is an instance of the problem. The message currently at: https://mail.python.org/pipermail/python-list/2009-February/525280.html Used to be at this URL: https://mail.python.org/pipermail/python-list/2009-February/538048.html -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From dm780193 at gmail.com Thu Jun 13 01:20:29 2019 From: dm780193 at gmail.com (David Martin) Date: Wed, 12 Jun 2019 22:20:29 -0700 Subject: problem about the installation Message-ID: Hello there! My computer windows is 8 and the operating system is 32-bit operating system, based upon x64 processor but I got a problem during installation, could you please assist me about this? I appreciate your efforts in advance. Thanks Yours sincerely YarDel Daudy Virus-free. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From marselle.grace at outlook.com Thu Jun 13 12:08:03 2019 From: marselle.grace at outlook.com (Marselle Grace) Date: Thu, 13 Jun 2019 16:08:03 +0000 Subject: Issue with the program Message-ID: Hello, I downloaded the Python program today, as well as the separate IDE pyCharm today and on pyCharm I tried setting up Python as the interpreter, as the tutorial I am following stated, however it says that it is invalid and every time I try to input any code, a window for Python setup appears and tells me to Modify, Repair, or Uninstall Python, however none of those are applicable in this situation. I?m a beginner programmer and I?m not sure if the issue is with Python, pyCharm, or just user error and I would greatly appreciate some assistance in figuring this out. Thank you. Sent from Mail for Windows 10 From clinchris13 at gmail.com Thu Jun 13 13:09:29 2019 From: clinchris13 at gmail.com (clinchris13) Date: Thu, 13 Jun 2019 22:39:29 +0530 Subject: there is an errar it is nit opening Message-ID: <000001d5220a$c5031ab0$4f095010$@com> From clinchris13 at gmail.com Thu Jun 13 13:09:45 2019 From: clinchris13 at gmail.com (clinchris13) Date: Thu, 13 Jun 2019 22:39:45 +0530 Subject: there is an errar it is nit opening Message-ID: <000001d5220a$ce95f890$6bc1e9b0$@com> From karan.170987 at gmail.com Thu Jun 13 13:13:45 2019 From: karan.170987 at gmail.com (Karan Aggarwal) Date: Thu, 13 Jun 2019 22:43:45 +0530 Subject: Please solve my problem Message-ID: Respected Sir, I am a reserach scholar in image processing. Sir i started the work on deep learning and machine learning. For this, i installed many times tensorflow on python. but it gave me error always. please resolve my issue sothat i can work further. Sir, please help me out. Thanks -- With Regards, Karan Aggarwal Ph.: 9466822528, 8059931278 From praveendevan1942 at gmail.com Fri Jun 14 04:00:28 2019 From: praveendevan1942 at gmail.com (praveendevan) Date: Fri, 14 Jun 2019 01:00:28 -0700 Subject: how to learn python language Message-ID: <5d034d2d.1c69fb81.452af.9fd7@mx.google.com> Sent from Mail for Windows 10 From hassanhamayun49 at gmail.com Fri Jun 14 05:32:22 2019 From: hassanhamayun49 at gmail.com (Hassan Hamayun) Date: Fri, 14 Jun 2019 02:32:22 -0700 Subject: Facing an error while install python Message-ID: When i Install python i face an error i attach the screenshot with it. [image: Untitled.png] Thanks & Best Regaed *Hassan Hamayun* From injamul253 at gmail.com Fri Jun 14 05:32:58 2019 From: injamul253 at gmail.com (INJAMUL HOQUE) Date: Fri, 14 Jun 2019 15:02:58 +0530 Subject: Coding problem Message-ID: From dglsx37 at yahoo.com Fri Jun 14 11:09:27 2019 From: dglsx37 at yahoo.com (Douglas Beard) Date: Fri, 14 Jun 2019 15:09:27 +0000 (UTC) Subject: Subprocess References: <2018529384.1513401.1560524967170.ref@mail.yahoo.com> Message-ID: <2018529384.1513401.1560524967170@mail.yahoo.com> Error: IDLE's Subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall is blocking the connection.python has been working fine until today. I used the python repair but no luck. it does not seem my firewall is blocking. please help From wiwindson at gmail.com Sat Jun 15 00:52:43 2019 From: wiwindson at gmail.com (Windson Yang) Date: Sat, 15 Jun 2019 12:52:43 +0800 Subject: Understand workflow about reading and writing files in Python Message-ID: I'm trying to understand the workflow of how python read/writes files with buffer. I drew a diagram for it. I will be appreciated if someone can review the diagram :D [image: ???? 2019-06-15 ??12.50.57.png] From nishakolekar23 at gmail.com Sat Jun 15 05:26:31 2019 From: nishakolekar23 at gmail.com (Nisha Kolekar) Date: Sat, 15 Jun 2019 14:56:31 +0530 Subject: api msi.python .dll missing Message-ID: Hello, My Python36 library deleted so i cannot reinstal python3.6.8amd64 on my windows8.1 64bit OS. Any command to remove complete python from OS through command prompt From xuan.alan at 163.com Sun Jun 16 03:53:32 2019 From: xuan.alan at 163.com (=?GBK?B?0Pu66A==?=) Date: Sun, 16 Jun 2019 15:53:32 +0800 (CST) Subject: problem encountered Message-ID: <62249ad4.80f0.16b5f46edd4.Coremail.xuan.alan@163.com> Hi, After installation, in cmd window, I can not run any command successfully. I copied screens as below, could you pls help? Very appreciate for your help! Could you pls help answering how to fix this issue? Thx again! Best Regards, Alan From emaxservicesltd at gmail.com Sun Jun 16 18:45:36 2019 From: emaxservicesltd at gmail.com (EMAX ENGRG SERVICES LTD) Date: Sun, 16 Jun 2019 23:45:36 +0100 Subject: Cannot install python on my system Message-ID: <5d06c691.1c69fb81.80243.4df3@mx.google.com> Sent from Mail for Windows 10 Sir, Please I have difficulties installing python on my system. After downloading the extension, yet it would not take me to sequence of agreeing to license and terms. I am looking forward to hearing from you/ Best regards. From arj.python at gmail.com Mon Jun 17 04:14:08 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 17 Jun 2019 12:14:08 +0400 Subject: UG blog's contact advocate@python.org no longer working? Message-ID: Greetings, here: https://wiki.python.org/moin/StartingYourUsersGroup it is written: Also, please consider posting news from your user group on the Python User Group Blog ! and on that page, the contact email is: Just drop an email to advocate at python.org and I'll set you up. and my mail delivery service returned: Your message wasn't delivered to *advocate at python.org*because the address couldn't be found, or is unable to receive mail. Any ideas about this issue? Thanks! -- Abdur-Rahmaan Janhangeer Mauritius From flori.gue at t-online.de Mon Jun 17 04:27:02 2019 From: flori.gue at t-online.de (flori.gue at t-online.de) Date: Mon, 17 Jun 2019 10:27:02 +0200 (CEST) Subject: Installing python into Blender 2.79 Message-ID: <1560760022789.4928104.fc1b28971cfd1b8341fb5300e88acb277c3de102@spica.telekom.de> Hallo Python, I want to import DWG- or FBX-data from AutoCAD Architecture 2015 into Blender. I downloaded Python 3.7.3 into Windows 10 Prof., but I cannot find the python-program and do not know the path to bind python into blender. Please could you help and tell me how to bring python into Blender? Thank you fpr your help in advance. With best regards, Guenter ? From p.f.moore at gmail.com Mon Jun 17 05:36:52 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 17 Jun 2019 10:36:52 +0100 Subject: installing of python In-Reply-To: References: Message-ID: (a) By default if you're using a user install, Python is installed to %LOCALAPPDATA%\Programs\Python. (b) This list is text-only, so the screenshot didn't appear - I'm therefore only guessing what your issue is here. (c) Does the command py -V work? That should run Python and give the version number. (d) If you did a default install, Python is not added to your user PATH so you need to use the "py" launcher as I showed in (c) above. If you want Python adding to PATH, you need to specify that when installing (or manually add it to your PATH afterwards). Paul On Mon, 17 Jun 2019 at 10:31, jaydip rajpara wrote: > > this pic of my c drive after installing python 3.7.2. No python folder > generated > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:14:34 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:14:34 -0500 Subject: python 2 to 3 conversion Message-ID: Hi, Is there a place where there is a full list of incompatibilities between python 2 and python 3 is available and how to fix them? I'm looking for a way to fix following code, which runs perfectly with python 2 (and make it work with both python 2 and python 3): if bytes[0:16].tostring() != '': I know there are automated tools that can help you do the upgrade, but automated tools can do only so much.... And I am not sure if they can just add python 3 code and include version check. Thank you. From ikorot01 at gmail.com Mon Jun 17 09:17:02 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:17:02 -0500 Subject: Cannot install python on my system In-Reply-To: <5d06c691.1c69fb81.80243.4df3@mx.google.com> References: <5d06c691.1c69fb81.80243.4df3@mx.google.com> Message-ID: Hi, On Mon, Jun 17, 2019 at 5:18 AM EMAX ENGRG SERVICES LTD wrote: > > > > Sent from Mail for Windows 10 > Sir, > Please I have difficulties installing python on my system. After downloading the extension, yet it would not take me to sequence of agreeing to license and terms. I am looking forward to hearing from you/ Unfortunately I can't log in to you system to help you - I don't have credentials. Lucking that - can you give more information? Thank you. > > Best regards. > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:19:28 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:19:28 -0500 Subject: problem encountered In-Reply-To: <62249ad4.80f0.16b5f46edd4.Coremail.xuan.alan@163.com> References: <62249ad4.80f0.16b5f46edd4.Coremail.xuan.alan@163.com> Message-ID: Hi, On Mon, Jun 17, 2019 at 5:14 AM ?? wrote: > > Hi, > > > After installation, in cmd window, I can not run any command successfully. I copied screens as below, could you pls help? > Very appreciate for your help! I hope you can read my message. This list does not support an attachments - it is available for blind people as well. Can you copy and paste what is happening in the message body? Thank you. > > > > > Could you pls help answering how to fix this issue? Thx again! > > > Best Regards, > Alan > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:20:29 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:20:29 -0500 Subject: Coding problem In-Reply-To: References: Message-ID: On Mon, Jun 17, 2019 at 5:03 AM INJAMUL HOQUE wrote: > > Reading problem... > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:22:15 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:22:15 -0500 Subject: Facing an error while install python In-Reply-To: References: Message-ID: Hi, On Mon, Jun 17, 2019 at 4:59 AM Hassan Hamayun wrote: > > When i Install python i face an error i attach the screenshot with it. Sorry attachments not supported - some blind people are reading the list and provide support. Can you describe what happened and/or copy'n'paste the error? Thank you. > [image: Untitled.png] > > Thanks & Best Regaed > > *Hassan Hamayun* > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Jun 17 08:22:14 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Jun 2019 22:22:14 +1000 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: On Mon, Jun 17, 2019 at 10:15 PM Igor Korot wrote: > > Hi, > Is there a place where there is a full list of incompatibilities between > python 2 and python 3 is available and how to fix them? > > I'm looking for a way to fix following code, which runs perfectly with python 2 > (and make it work with both python 2 and python 3): > > if bytes[0:16].tostring() != '': > > I know there are automated tools that can help you do the upgrade, but > automated tools can do only so much.... > > And I am not sure if they can just add python 3 code and include version check. If "bytes" here refers to a byte string, and not to the actual type called "bytes" (the same as "str" in Py2), the way I'd do it is: if bytes[:16] != b"": However, I have no idea what your .tostring() method is, since it doesn't seem to be a method on the Py2 str object, nor of the bytearray object (my next guess). So further details/context would be needed. I would strongly recommend requiring either Python 2.7 or Python 3.5+. There should be no need to support Python 2.6 or older, and if you restrict your Py3 support to 3.5 and better, you can take advantage of a number of syntactic compatibilities - u"text" and b"ASCII bytes" will work on both, and b"x %d y" % 1234 will have equivalent functionality. Features like that will make it much easier to code to the common subset. ChrisA From ikorot01 at gmail.com Mon Jun 17 09:23:36 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:23:36 -0500 Subject: how to learn python language In-Reply-To: <5d034d2d.1c69fb81.452af.9fd7@mx.google.com> References: <5d034d2d.1c69fb81.452af.9fd7@mx.google.com> Message-ID: Hi, On Mon, Jun 17, 2019 at 4:55 AM praveendevan wrote: > > The best way is to get to class that teaches it. Then you will learn how to do things proper way. Thank you. > > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:29:02 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:29:02 -0500 Subject: there is an errar it is nit opening In-Reply-To: <000001d5220a$ce95f890$6bc1e9b0$@com> References: <000001d5220a$ce95f890$6bc1e9b0$@com> Message-ID: Hi, On Mon, Jun 17, 2019 at 4:51 AM clinchris13 wrote: > > There is an error in you post - I can't see anything... Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:31:05 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:31:05 -0500 Subject: Issue with the program In-Reply-To: References: Message-ID: Hi, On Mon, Jun 17, 2019 at 4:47 AM Marselle Grace wrote: > > > Hello, I downloaded the Python program today, as well as the separate IDE pyCharm today and on pyCharm I tried setting up Python as the interpreter, as the tutorial I am following stated, however it says that it is invalid and every time I try to input any code, a window for Python setup appears and tells me to Modify, Repair, or Uninstall Python, however none of those are applicable in this situation. I?m a beginner programmer and I?m not sure if the issue is with Python, pyCharm, or just user error and I would greatly appreciate some assistance in figuring this out. Thank you. Which tutorial you are using? At what step exactly the error comes up? Thank you. > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:33:37 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:33:37 -0500 Subject: there is an errar it is nit opening In-Reply-To: <000001d5220a$c5031ab0$4f095010$@com> References: <000001d5220a$c5031ab0$4f095010$@com> Message-ID: Hi, On Mon, Jun 17, 2019 at 4:35 AM clinchris13 wrote: > > There is an error in this message - I can't read it. Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:35:47 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:35:47 -0500 Subject: Please solve my problem In-Reply-To: References: Message-ID: Hi, On Mon, Jun 17, 2019 at 4:39 AM Karan Aggarwal wrote: > > Respected Sir, > > I am a reserach scholar in image processing. > Sir i started the work on deep learning and machine learning. > For this, i installed many times tensorflow on python. > but it gave me error always. What error did you receive? Thank you. > please resolve my issue sothat i can work further. > Sir, please help me out. > > Thanks > > > -- > > > With Regards, > > Karan Aggarwal > Ph.: 9466822528, 8059931278 > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:38:20 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:38:20 -0500 Subject: api msi.python .dll missing In-Reply-To: References: Message-ID: Hi, On Mon, Jun 17, 2019 at 4:43 AM Nisha Kolekar wrote: > > Hello, > My Python36 library deleted so i cannot reinstal python3.6.8amd64 on my > windows8.1 64bit OS. > Any command to remove complete python from OS through command prompt Can you remove the python completely and install from scratch? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:39:57 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:39:57 -0500 Subject: problem about the installation In-Reply-To: References: Message-ID: Hi, On Mon, Jun 17, 2019 at 4:43 AM David Martin wrote: > > Hello there! > > > My computer windows is 8 and the operating system is 32-bit operating > system, based upon x64 processor but I got a problem during installation, > could you please assist me about this? > I appreciate your efforts in advance. Sorry this is python list and we can't help you with the Windows install. Please contact you manufacturer. Thank you. > Thanks > > > > > Yours sincerely > YarDel Daudy > > > > Virus-free. > www.avast.com > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Mon Jun 17 09:46:16 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 08:46:16 -0500 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: Hi, Chris, On Mon, Jun 17, 2019 at 7:31 AM Chris Angelico wrote: > > On Mon, Jun 17, 2019 at 10:15 PM Igor Korot wrote: > > > > Hi, > > Is there a place where there is a full list of incompatibilities between > > python 2 and python 3 is available and how to fix them? > > > > I'm looking for a way to fix following code, which runs perfectly with python 2 > > (and make it work with both python 2 and python 3): > > > > if bytes[0:16].tostring() != '': > > > > I know there are automated tools that can help you do the upgrade, but > > automated tools can do only so much.... > > > > And I am not sure if they can just add python 3 code and include version check. > > If "bytes" here refers to a byte string, and not to the actual type > called "bytes" (the same as "str" in Py2), the way I'd do it is: > > if bytes[:16] != b"": > > However, I have no idea what your .tostring() method is, since it > doesn't seem to be a method on the Py2 str object, nor of the > bytearray object (my next guess). So further details/context would be > needed. bytes = array.array('B', open(path, "rb").read()) count = len(bytes) This is where bytes come from - sorry about that. So, how do I write the code compatible with both python 2 and python 3 in this case? Thank you. > > I would strongly recommend requiring either Python 2.7 or Python 3.5+. > There should be no need to support Python 2.6 or older, and if you > restrict your Py3 support to 3.5 and better, you can take advantage of > a number of syntactic compatibilities - u"text" and b"ASCII bytes" > will work on both, and b"x %d y" % 1234 will have equivalent > functionality. Features like that will make it much easier to code to > the common subset. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From tjol at tjol.eu Mon Jun 17 08:30:55 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 17 Jun 2019 14:30:55 +0200 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: On 17/06/2019 15.14, Igor Korot wrote: > Hi, > Is there a place where there is a full list of incompatibilities between > python 2 and python 3 is available and how to fix them? ?What?s new in Python 3.0? is a good starting point https://docs.python.org/3/whatsnew/3.0.html It doesn?t list all standard library changes, but it has the most important ones. Obviously it can't include anything that third-party modules do. The main incompatibility is obviously strings, and there various modules have adopted different strategies for the transition. > > I'm looking for a way to fix following code, which runs perfectly with python 2 > (and make it work with both python 2 and python 3): > > if bytes[0:16].tostring() != '': No idea what this is supposed to do as you didn't say what ?bytes? was. I could imagine that the tostring() method returns a bytes rather than a str? Also, ?bytes? is the name of a built-in type in Python3. You don't want to use that as a variable name any more! (You can, though) > I know there are automated tools that can help you do the upgrade, but > automated tools can do only so much.... By many accounts, 2to3 doesn't work very well in the real world, at least not any more. > > And I am not sure if they can just add python 3 code and include version check. > > Thank you. From rosuav at gmail.com Mon Jun 17 08:51:47 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Jun 2019 22:51:47 +1000 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: On Mon, Jun 17, 2019 at 10:45 PM Igor Korot wrote: > > Hi, Chris, > > On Mon, Jun 17, 2019 at 7:31 AM Chris Angelico wrote: > > > > On Mon, Jun 17, 2019 at 10:15 PM Igor Korot wrote: > > > > > > Hi, > > > Is there a place where there is a full list of incompatibilities between > > > python 2 and python 3 is available and how to fix them? > > > > > > I'm looking for a way to fix following code, which runs perfectly with python 2 > > > (and make it work with both python 2 and python 3): > > > > > > if bytes[0:16].tostring() != '': > > > > > > I know there are automated tools that can help you do the upgrade, but > > > automated tools can do only so much.... > > > > > > And I am not sure if they can just add python 3 code and include version check. > > > > If "bytes" here refers to a byte string, and not to the actual type > > called "bytes" (the same as "str" in Py2), the way I'd do it is: > > > > if bytes[:16] != b"": > > > > However, I have no idea what your .tostring() method is, since it > > doesn't seem to be a method on the Py2 str object, nor of the > > bytearray object (my next guess). So further details/context would be > > needed. > > bytes = array.array('B', open(path, "rb").read()) > count = len(bytes) > > This is where bytes come from - sorry about that. > > So, how do I write the code compatible with both python 2 and python 3 > in this case? Where's the incompatibility coming from? I tried this very simple example, and it seems fine. Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import array >>> b = array.array("B", b"asdfqwerzxcv") >>> b[:4] array('B', [97, 115, 100, 102]) >>> b[:4].tostring() 'asdf' Python 3.9.0a0 (heads/master:19a1e1eb86, Jun 5 2019, 09:02:06) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import array >>> b = array.array("B", b"asdfqwerzxcv") >>> b[:4] array('B', [97, 115, 100, 102]) >>> b[:4].tostring() b'asdf' Either way, tostring() is giving you back a byte string, which you can easily compare to any byte string literal eg b"test string". Can you show more code, and where the actual failure (exception or wrong result) is coming from? ChrisA From rosuav at gmail.com Mon Jun 17 08:53:30 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Jun 2019 22:53:30 +1000 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: On Mon, Jun 17, 2019 at 10:50 PM Thomas Jollans wrote: > > On 17/06/2019 15.14, Igor Korot wrote: > > Hi, > > Is there a place where there is a full list of incompatibilities between > > python 2 and python 3 is available and how to fix them? > > ?What?s new in Python 3.0? is a good starting point > > https://docs.python.org/3/whatsnew/3.0.html > > It doesn?t list all standard library changes, but it has the most > important ones. Obviously it can't include anything that third-party > modules do. > > The main incompatibility is obviously strings, and there various modules > have adopted different strategies for the transition. Unfortunately starting there means ignoring all the compatibilities that were implemented in more recent versions. Notably, Python 3.3 introduced u"..." literals, and 3.5 allows you to use percent interpolation with bytes as well as text. So those kinds of differences are no longer significant. ChrisA From ikorot01 at gmail.com Mon Jun 17 10:16:39 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 09:16:39 -0500 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: Hi, Chris et al, On Mon, Jun 17, 2019 at 8:00 AM Chris Angelico wrote: > > On Mon, Jun 17, 2019 at 10:50 PM Thomas Jollans wrote: > > > > On 17/06/2019 15.14, Igor Korot wrote: > > > Hi, > > > Is there a place where there is a full list of incompatibilities between > > > python 2 and python 3 is available and how to fix them? > > > > ?What?s new in Python 3.0? is a good starting point > > > > https://docs.python.org/3/whatsnew/3.0.html > > > > It doesn?t list all standard library changes, but it has the most > > important ones. Obviously it can't include anything that third-party > > modules do. > > > > The main incompatibility is obviously strings, and there various modules > > have adopted different strategies for the transition. > > Unfortunately starting there means ignoring all the compatibilities > that were implemented in more recent versions. Notably, Python 3.3 > introduced u"..." literals, and 3.5 allows you to use percent > interpolation with bytes as well as text. So those kinds of > differences are no longer significant. > > ChrisA This is what I have in my script (reproduction steps): igor at IgorReinCloud ~/dbhandler/libdbwindow/res/gui $ python Python 3.6.5 (default, Oct 5 2018, 14:32:41) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import array >>> bytes = array.array('B', open("bold.png", "rb").read()) >>> bytes[0:16].tostring() b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR' >>> if bytes[0:16].tostring() != '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR': ... print("Failed") ... Failed >>> Do I just need to add "b" in front of the string to make it work with both? Or I need to check version call? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From rhodri at kynesim.co.uk Mon Jun 17 09:53:25 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 17 Jun 2019 14:53:25 +0100 Subject: Coding problem In-Reply-To: References: Message-ID: <1b6caf25-a4e4-cb21-b8cc-dd4ff49fc63f@kynesim.co.uk> On 14/06/2019 10:32, INJAMUL HOQUE wrote: ...nothing. I'm afraid your email had no content when it reached us. If you included a screen shot, I'm afraid it was automatically removed before it reached us. -- Rhodri James *-* Kynesim Ltd From skip.montanaro at gmail.com Mon Jun 17 10:27:17 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 17 Jun 2019 09:27:17 -0500 Subject: Is there an archive of this list with permanent URLs to each message? In-Reply-To: References: Message-ID: > Hello! When I wrote Fluent Python a few years ago I provided my > readers with hundreds of links to my sources, including several links > to messages in the python-list archive. > > Now as I prepare the 2nd edition I notice all my links to this list > are broken. Apparently mailman rebuilds the archives and changes the > ids of the messages. > > Is there an archive of python-list that preserves each message with a > permanent URL? This list hasn't yet been moved to Mailman 3. I believe once it is, permalinks will be more permanent. You might want to drop an email to postmaster at python.org to see if migration will happen in the near future. I know several other lists were recently migrated (python-dev and python-ideas come to mind). Skip From grant.b.edwards at gmail.com Mon Jun 17 10:29:59 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 17 Jun 2019 14:29:59 -0000 (UTC) Subject: python 2 to 3 conversion References: Message-ID: On 2019-06-17, Igor Korot wrote: > So, how do I write the code compatible with both python 2 and python 3 > in this case? Writing 2/3 compatible code that deals with bytes is difficult. For example: Python 2.7.15 (default, Sep 12 2018, 15:19:18) >>> bytes(5) '5' >>> b'1234'[0] '1' Python 3.7.3 (default, May 20 2019, 15:21:07) >>> bytes(5) b'\x00\x00\x00\x00\x00' >>> b'1234'[0] 49 Differences like those mean you can't really use the bytes type/class or indexing of bytes objects in code that needs to be 2/3 compatible. I tried writing a bytes class for 2.7, but gave up. In anything dealing with bytes, trying to be compatible with 2 and 3 is a lot of work, and I usually don't bother. -- Grant Edwards grant.b.edwards Yow! I guess you guys got at BIG MUSCLES from doing too gmail.com much STUDYING! From rosuav at gmail.com Mon Jun 17 10:52:13 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Jun 2019 00:52:13 +1000 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: On Mon, Jun 17, 2019 at 11:15 PM Igor Korot wrote: > > Hi, Chris et al, > > On Mon, Jun 17, 2019 at 8:00 AM Chris Angelico wrote: > > > > On Mon, Jun 17, 2019 at 10:50 PM Thomas Jollans wrote: > > > > > > On 17/06/2019 15.14, Igor Korot wrote: > > > > Hi, > > > > Is there a place where there is a full list of incompatibilities between > > > > python 2 and python 3 is available and how to fix them? > > > > > > ?What?s new in Python 3.0? is a good starting point > > > > > > https://docs.python.org/3/whatsnew/3.0.html > > > > > > It doesn?t list all standard library changes, but it has the most > > > important ones. Obviously it can't include anything that third-party > > > modules do. > > > > > > The main incompatibility is obviously strings, and there various modules > > > have adopted different strategies for the transition. > > > > Unfortunately starting there means ignoring all the compatibilities > > that were implemented in more recent versions. Notably, Python 3.3 > > introduced u"..." literals, and 3.5 allows you to use percent > > interpolation with bytes as well as text. So those kinds of > > differences are no longer significant. > > > > ChrisA > > This is what I have in my script (reproduction steps): > > igor at IgorReinCloud ~/dbhandler/libdbwindow/res/gui $ python > Python 3.6.5 (default, Oct 5 2018, 14:32:41) > [GCC 7.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import array > >>> bytes = array.array('B', open("bold.png", "rb").read()) > >>> bytes[0:16].tostring() > b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR' > >>> if bytes[0:16].tostring() != '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR': > ... print("Failed") > ... > Failed > >>> > > Do I just need to add "b" in front of the string to make it work with both? > Or I need to check version call? > Yep, all you need to do is compare against a byte string. That should be the only change needed. Currently, you're checking against a byte string in Py2, and a text string in Py3; but the b"..." prefix will make them consistent. ChrisA From Joseph.Schachner at Teledyne.com Mon Jun 17 10:58:33 2019 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 17 Jun 2019 14:58:33 +0000 Subject: Python-list Digest, Vol 189, Issue 17 In-Reply-To: References: Message-ID: <171d7244f36d4184accaee0d18a0d6c1@Teledyne.com> Please see https://docs.python.org/2/library/colorsys.html And follow the links in there, read the FAQ. You'll find that python represents RGB values in three numeric values. Very simple. I believe scale is 0.0 to 1.0. --- Joseph S. -----Original Message----- From: Python-list On Behalf Of python-list-request at python.org Sent: Monday, June 17, 2019 10:28 AM To: python-list at python.org Subject: Python-list Digest, Vol 189, Issue 17 ---External Email--- 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..." From ikorot01 at gmail.com Mon Jun 17 11:00:42 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Jun 2019 10:00:42 -0500 Subject: python 2 to 3 conversion In-Reply-To: References: Message-ID: Hi, Chris, On Mon, Jun 17, 2019 at 9:55 AM Chris Angelico wrote: > > On Mon, Jun 17, 2019 at 11:15 PM Igor Korot wrote: > > > > Hi, Chris et al, > > > > On Mon, Jun 17, 2019 at 8:00 AM Chris Angelico wrote: > > > > > > On Mon, Jun 17, 2019 at 10:50 PM Thomas Jollans wrote: > > > > > > > > On 17/06/2019 15.14, Igor Korot wrote: > > > > > Hi, > > > > > Is there a place where there is a full list of incompatibilities between > > > > > python 2 and python 3 is available and how to fix them? > > > > > > > > ?What?s new in Python 3.0? is a good starting point > > > > > > > > https://docs.python.org/3/whatsnew/3.0.html > > > > > > > > It doesn?t list all standard library changes, but it has the most > > > > important ones. Obviously it can't include anything that third-party > > > > modules do. > > > > > > > > The main incompatibility is obviously strings, and there various modules > > > > have adopted different strategies for the transition. > > > > > > Unfortunately starting there means ignoring all the compatibilities > > > that were implemented in more recent versions. Notably, Python 3.3 > > > introduced u"..." literals, and 3.5 allows you to use percent > > > interpolation with bytes as well as text. So those kinds of > > > differences are no longer significant. > > > > > > ChrisA > > > > This is what I have in my script (reproduction steps): > > > > igor at IgorReinCloud ~/dbhandler/libdbwindow/res/gui $ python > > Python 3.6.5 (default, Oct 5 2018, 14:32:41) > > [GCC 7.3.0] on linux > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import array > > >>> bytes = array.array('B', open("bold.png", "rb").read()) > > >>> bytes[0:16].tostring() > > b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR' > > >>> if bytes[0:16].tostring() != '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR': > > ... print("Failed") > > ... > > Failed > > >>> > > > > Do I just need to add "b" in front of the string to make it work with both? > > Or I need to check version call? > > > > Yep, all you need to do is compare against a byte string. That should > be the only change needed. Currently, you're checking against a byte > string in Py2, and a text string in Py3; but the b"..." prefix will > make them consistent. Thank you. I will try to test it tonight pulling my python 2 install. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Mon Jun 17 11:36:38 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Jun 2019 11:36:38 -0400 Subject: Subprocess In-Reply-To: <2018529384.1513401.1560524967170@mail.yahoo.com> References: <2018529384.1513401.1560524967170.ref@mail.yahoo.com> <2018529384.1513401.1560524967170@mail.yahoo.com> Message-ID: On 6/14/2019 11:09 AM, Douglas Beard via Python-list wrote: > Error: IDLE's Subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall is blocking the connection.python has been working fine until today. I used the python repair but no luck. it does not seem my firewall is blocking. please help https://docs.python.org/3/library/idle.html#startup-failure gives several possible IDLE startup failure reasons and things to check -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 17 11:37:25 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Jun 2019 11:37:25 -0400 Subject: Understand workflow about reading and writing files in Python In-Reply-To: References: Message-ID: On 6/15/2019 12:52 AM, Windson Yang wrote: > I'm trying to understand the workflow of how python read/writes files with > buffer. I drew a diagram for it. I will be appreciated if someone can > review the diagram :D > > [image: ???? 2019-06-15 ??12.50.57.png] Text only list, no attachments. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 17 11:41:11 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Jun 2019 11:41:11 -0400 Subject: Cannot install python on my system In-Reply-To: <5d06c691.1c69fb81.80243.4df3@mx.google.com> References: <5d06c691.1c69fb81.80243.4df3@mx.google.com> Message-ID: On 6/16/2019 6:45 PM, EMAX ENGRG SERVICES LTD wrote: > Please I have difficulties installing python on my system. After downloading the extension, yet it would not take me to sequence of agreeing to license and terms. You need to be much more detailed and specific as to what you did and what happened. -- Terry Jan Reedy From uri at speedy.net Mon Jun 17 11:56:48 2019 From: uri at speedy.net (=?UTF-8?B?15DXldeo15k=?=) Date: Mon, 17 Jun 2019 18:56:48 +0300 Subject: Python-list Digest, Vol 189, Issue 17 In-Reply-To: <171d7244f36d4184accaee0d18a0d6c1@Teledyne.com> References: <171d7244f36d4184accaee0d18a0d6c1@Teledyne.com> Message-ID: Please don't reply to digest. ???? uri at speedy.net On Mon, Jun 17, 2019 at 6:01 PM Schachner, Joseph < Joseph.Schachner at teledyne.com> wrote: > Please see https://docs.python.org/2/library/colorsys.html > > And follow the links in there, read the FAQ. > > You'll find that python represents RGB values in three numeric values. > Very simple. I believe scale is 0.0 to 1.0. > > --- Joseph S. > > -----Original Message----- > From: Python-list teledyne.com at python.org> On Behalf Of python-list-request at python.org > Sent: Monday, June 17, 2019 10:28 AM > To: python-list at python.org > Subject: Python-list Digest, Vol 189, Issue 17 > > ---External Email--- > > 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..." > -- > https://mail.python.org/mailman/listinfo/python-list > From vlastimil.brom at gmail.com Mon Jun 17 15:11:57 2019 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 17 Jun 2019 21:11:57 +0200 Subject: How to create a RGB color Table In-Reply-To: References: Message-ID: po 17. 6. 2019 v 11:30 odes?latel Jorge Conrado Conforte napsal: > > HI, > > Please someone could help me. How can I create a new color table with the values of r g and b that I have. I use the Mataplolib color tables. However, I would like to use a new color table with the respective r g b values that I have. > > Thank you. > >... Hi, I am not sure, this is exactly what you are looking for, but there seems to be a similar topic covered in matplotlib docs: https://matplotlib.org/3.1.0/tutorials/colors/colormap-manipulation.html#creating-listed-colormaps It seems, you can just pass the multidimensional sequence to ListedColormap from matplotlib.colors There needs to be an alpha value too - i.e. RGBA hth, vbr From jfong at ms4.hinet.net Mon Jun 17 21:39:32 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 17 Jun 2019 18:39:32 -0700 (PDT) Subject: Which curses version should I use under Windows Message-ID: As many others had encountered, when I import the curses module under Windows, I got ImportError: No module named '_curses' Search "curses" on the Pypi returns plenty of related packages. Which one should I use? Is this package still valid on usage? Any comment will be appreciated. --Jach From python at mrabarnett.plus.com Mon Jun 17 22:07:57 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Jun 2019 03:07:57 +0100 Subject: Which curses version should I use under Windows In-Reply-To: References: Message-ID: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> On 2019-06-18 02:39, jfong at ms4.hinet.net wrote: > As many others had encountered, when I import the curses module under Windows, I got > > ImportError: No module named '_curses' > > Search "curses" on the Pypi returns plenty of related packages. Which one should I use? Is this package still valid on usage? Any comment will be appreciated. > I'd probably go for "windows-curses". Seems to install OK. From jfong at ms4.hinet.net Mon Jun 17 22:54:34 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 17 Jun 2019 19:54:34 -0700 (PDT) Subject: Which curses version should I use under Windows In-Reply-To: References: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> Message-ID: <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> MRAB? 2019?6?18???? UTC+8??10?08?23???? > On 2019-06-18 02:39, jfong at ms4.hinet.net wrote: > > As many others had encountered, when I import the curses module under Windows, I got > > > > ImportError: No module named '_curses' > > > > Search "curses" on the Pypi returns plenty of related packages. Which one should I use? Is this package still valid on usage? Any comment will be appreciated. > > > I'd probably go for "windows-curses". Seems to install OK. Thank you for your prompt reply. I got the following error: c:\Works\Python34>pip install windows-curses DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 w on't be maintained after March 2019 (cf PEP 429). Collecting windows-curses ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) ERROR: No matching distribution found for windows-curses What to do? From tjreedy at udel.edu Mon Jun 17 23:02:36 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Jun 2019 23:02:36 -0400 Subject: Which curses version should I use under Windows In-Reply-To: <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> References: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> Message-ID: On 6/17/2019 10:54 PM, jfong at ms4.hinet.net wrote: > c:\Works\Python34>pip install windows-curses > DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 w > on't be maintained after March 2019 (cf PEP 429). > Collecting windows-curses > ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) > ERROR: No matching distribution found for windows-curses > > What to do? What is says, use a newer python. It is quite possible that there is not 3.4 package for windows-curses. Look it up on pypi.org. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 17 23:07:46 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Jun 2019 23:07:46 -0400 Subject: Subprocess In-Reply-To: References: <2018529384.1513401.1560524967170.ref@mail.yahoo.com> <2018529384.1513401.1560524967170@mail.yahoo.com> Message-ID: On 6/17/2019 11:36 AM, Terry Reedy wrote: > On 6/14/2019 11:09 AM, Douglas Beard via Python-list wrote: >> Error: IDLE's Subprocess didn't make connection. Either IDLE can't >> start a subprocess or personal firewall is blocking the >> connection.python has been working fine until today. I used the python >> repair but no luck. it does not seem my firewall is blocking. please help > > https://docs.python.org/3/library/idle.html#startup-failure > gives several possible IDLE startup failure reasons and things to check I added this reverence to the error message. -- Terry Jan Reedy From arj.python at gmail.com Mon Jun 17 23:50:31 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 18 Jun 2019 07:50:31 +0400 Subject: Please solve my problem In-Reply-To: References: Message-ID: If you have a 32bit pc it won't install. Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From jfong at ms4.hinet.net Mon Jun 17 23:57:38 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 17 Jun 2019 20:57:38 -0700 (PDT) Subject: Which curses version should I use under Windows In-Reply-To: References: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> Message-ID: <23b36b77-1661-449d-a967-f6a75cc23200@googlegroups.com> Terry Reedy? 2019?6?18???? UTC+8??11?03?00???? > On 6/17/2019 10:54 PM, jfong at ms4.hinet.net wrote: > > > c:\Works\Python34>pip install windows-curses > > DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 w > > on't be maintained after March 2019 (cf PEP 429). > > Collecting windows-curses > > ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) > > ERROR: No matching distribution found for windows-curses > > > > What to do? > > What is says, use a newer python. > > It is quite possible that there is not 3.4 package for windows-curses. > Look it up on pypi.org. > > -- > Terry Jan Reedy You are right, there is no package for Python 3.4. In the project description: '''Adds support for the standard Python curses module on Windows. Based on https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. Uses the PDCurses curses implementation.''' Do I have to install the curses package mentioned there before install/use windows-curses? How to use this windows-curses? still "import curses"? I am so confused! From python at mrabarnett.plus.com Tue Jun 18 06:12:31 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Jun 2019 11:12:31 +0100 Subject: Which curses version should I use under Windows In-Reply-To: <23b36b77-1661-449d-a967-f6a75cc23200@googlegroups.com> References: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> <23b36b77-1661-449d-a967-f6a75cc23200@googlegroups.com> Message-ID: On 2019-06-18 04:57, jfong at ms4.hinet.net wrote: > Terry Reedy? 2019?6?18???? UTC+8??11?03?00???? >> On 6/17/2019 10:54 PM, jfong at ms4.hinet.net wrote: >> >> > c:\Works\Python34>pip install windows-curses >> > DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 w >> > on't be maintained after March 2019 (cf PEP 429). >> > Collecting windows-curses >> > ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) >> > ERROR: No matching distribution found for windows-curses >> > >> > What to do? >> >> What is says, use a newer python. >> >> It is quite possible that there is not 3.4 package for windows-curses. >> Look it up on pypi.org. >> >> -- >> Terry Jan Reedy > > You are right, there is no package for Python 3.4. > > In the project description: > > '''Adds support for the standard Python curses module on Windows. Based on https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. Uses the PDCurses curses implementation.''' > > Do I have to install the curses package mentioned there before install/use windows-curses? How to use this windows-curses? still "import curses"? I am so confused! > 1. Install a more recent version of Python. Python 3.7 is the current version. (Python 3.4 is no longer supported.) 2. Install windows-curses using pip for that version of Python. That's it! From jfong at ms4.hinet.net Tue Jun 18 07:19:37 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 18 Jun 2019 04:19:37 -0700 (PDT) Subject: Which curses version should I use under Windows In-Reply-To: References: <3a1f082e-5153-a3e6-d282-17367db86012@mrabarnett.plus.com> <8c293104-1fed-4431-a3a2-1dca01902a49@googlegroups.com> <23b36b77-1661-449d-a967-f6a75cc23200@googlegroups.com> Message-ID: MRAB? 2019?6?18???? UTC+8??6?12?50???? > On 2019-06-18 04:57, jfong at ms4.hinet.net wrote: > > Terry Reedy? 2019?6?18???? UTC+8??11?03?00???? > >> On 6/17/2019 10:54 PM, jfong at ms4.hinet.net wrote: > >> > >> > c:\Works\Python34>pip install windows-curses > >> > DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 w > >> > on't be maintained after March 2019 (cf PEP 429). > >> > Collecting windows-curses > >> > ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) > >> > ERROR: No matching distribution found for windows-curses > >> > > >> > What to do? > >> > >> What is says, use a newer python. > >> > >> It is quite possible that there is not 3.4 package for windows-curses. > >> Look it up on pypi.org. > >> > >> -- > >> Terry Jan Reedy > > > > You are right, there is no package for Python 3.4. > > > > In the project description: > > > > '''Adds support for the standard Python curses module on Windows. Based on https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. Uses the PDCurses curses implementation.''' > > > > Do I have to install the curses package mentioned there before install/use windows-curses? How to use this windows-curses? still "import curses"? I am so confused! > > > 1. Install a more recent version of Python. Python 3.7 is the current > version. (Python 3.4 is no longer supported.) > > 2. Install windows-curses using pip for that version of Python. > > That's it! It works, thank you. From mkolstein at ifae.es Tue Jun 18 07:23:32 2019 From: mkolstein at ifae.es (Machiel Kolstein) Date: Tue, 18 Jun 2019 04:23:32 -0700 (PDT) Subject: python numpy histogram Message-ID: <9e4d0bf0-e9ce-4990-8a1b-95403d184ba5@googlegroups.com> Hi, I get the following error: ERROR: Traceback (most recent call last): File "exponential_distr.py", line 32, in numpy.histogram(data_array, bins=100, range=20000) File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 499, in histogram mn, mx = [mi + 0.0 for mi in range] TypeError: 'int' object is not iterable with the code shown below. I guess I am using "numpy.histogram" below. Also, is there a way to fill the histogram on an event by event base without using the clumsy way of constructing an array as I do below? And - final question - how can I most easily plot the histogram without having to define - again - the bins etc...? CODE: import numpy import numpy.random rate = float(1e5) average_dt = 1.0/rate print "average dt: ", average_dt calc_average = 0.0 total_num=1000.0 isFirst = True for index in range(0, int(total_num)): time = numpy.random.exponential(average_dt) # print "time: ", time, " = ", time*1e9, " ns" calc_average = calc_average + time # Idiot python way of constructing an array (God, I hate python...) if (isFirst == True): data_array = time isFirst = False else: data_array = numpy.hstack((data_array, time)) calc_average = calc_average/total_num print "calculated average: ", calc_average, " = ", calc_average*1e9, " ns" print "data_array: ", data_array numpy.histogram(data_array, bins=100, range=20000) # import matplotlib.pyplot as plt # plt.hist(data_array, bins=100, range=20000) # plt.show() -- Av?s - Aviso - Legal Notice - (LOPD) - http://legal.ifae.es From __peter__ at web.de Tue Jun 18 08:17:26 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 18 Jun 2019 14:17:26 +0200 Subject: python numpy histogram References: <9e4d0bf0-e9ce-4990-8a1b-95403d184ba5@googlegroups.com> Message-ID: Machiel Kolstein wrote: > > Hi, > > I get the following error: > > ERROR: > Traceback (most recent call last): > File "exponential_distr.py", line 32, in > numpy.histogram(data_array, bins=100, range=20000) > File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line > 499, in histogram > mn, mx = [mi + 0.0 for mi in range] > TypeError: 'int' object is not iterable > > with the code shown below. > I guess I am using "numpy.histogram" below. Also, is there a way to fill > the histogram on an event by event base without using the clumsy way of > constructing an array as I do below? > > CODE: > > import numpy > import numpy.random > > rate = float(1e5) > average_dt = 1.0/rate > print "average dt: ", average_dt > > calc_average = 0.0 > total_num=1000.0 > isFirst = True > for index in range(0, int(total_num)): > time = numpy.random.exponential(average_dt) > # print "time: ", time, " = ", time*1e9, " ns" > calc_average = calc_average + time > > # Idiot python way of constructing an array (God, I hate python...) Numpy is not python, its learning curve is a bit steeper. > if (isFirst == True): > data_array = time > isFirst = False > else: > data_array = numpy.hstack((data_array, time)) With both, it helps if you read the documentation, or at least the docstring: >>> import numpy >>> help(numpy.random.exponential) Help on built-in function exponential: exponential(...) exponential(scale=1.0, size=None) Exponential distribution. ... Parameters ---------- ... size : tuple of ints Number of samples to draw. The output is shaped according to `size`. So: data_array = numpy.random.exponential(average_dt, total_num) calc_average = data_array.mean() (If you follow the docstring you'd write (total_num,).) > calc_average = calc_average/total_num > print "calculated average: ", calc_average, " = ", calc_average*1e9, " ns" > print "data_array: ", data_array > > numpy.histogram(data_array, bins=100, range=20000) >>> help(numpy.histogram) Help on function histogram in module numpy.lib.function_base: histogram(a, bins=10, range=None, normed=False, weights=None, density=None) Compute the histogram of a set of data. Parameters ---------- ... range : (float, float), optional The lower and upper range of the bins. If not provided, range is simply ``(a.min(), a.max())``. Values outside the range are ignored. ... > #import matplotlib.pyplot as plt > #plt.hist(data_array, bins=100, range=20000) > #plt.show() > And - final question - how can I most > easily plot the histogram without having to define - again - the bins > etc...? Matplotlib is the way do go for plotting with Python. If matplotlib can do what you want you could omit numpy.histogram()... From rshepard at appl-ecosys.com Tue Jun 18 11:11:06 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 18 Jun 2019 08:11:06 -0700 (PDT) Subject: tkinter: on_cancel() method Message-ID: I have frames for data entry and modification. Each has two buttons: Save and Cancel. Is there a standard tkinter on_cancel() method responding to a user clicking on the Cancel button? My web searches find suggestions for 'after' responses, but no specific code to close the dialog box without saving any data. Using return and close() generate errors. TIA, Rich From mkolstein at ifae.es Tue Jun 18 09:03:51 2019 From: mkolstein at ifae.es (Machiel Kolstein) Date: Tue, 18 Jun 2019 06:03:51 -0700 (PDT) Subject: python numpy histogram In-Reply-To: <9e4d0bf0-e9ce-4990-8a1b-95403d184ba5@googlegroups.com> References: <9e4d0bf0-e9ce-4990-8a1b-95403d184ba5@googlegroups.com> Message-ID: <138ba45a-83bd-4e3e-9ee4-91b73abb0dd4@googlegroups.com> Thank you for your fast reply. You're right, I completely missed the fact that range should be given with two numbers (which in retrospect should have been obvious). Best regards, Machiel -- Av?s - Aviso - Legal Notice - (LOPD) - http://legal.ifae.es From jkn_gg at nicorp.f9.co.uk Tue Jun 18 11:21:48 2019 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 18 Jun 2019 08:21:48 -0700 (PDT) Subject: Is there an archive of this list with permanent URLs to each message? In-Reply-To: References: Message-ID: On Monday, June 17, 2019 at 10:28:44 AM UTC+1, Luciano Ramalho wrote: > Hello! When I wrote Fluent Python a few years ago I provided my > readers with hundreds of links to my sources, including several links > to messages in the python-list archive. > > Now as I prepare the 2nd edition I notice all my links to this list > are broken. Apparently mailman rebuilds the archives and changes the > ids of the messages. > > Is there an archive of python-list that preserves each message with a > permanent URL? > > Thanks! > > Luciano > > PS. For the curious, here is an instance of the problem. The message > currently at: > > https://mail.python.org/pipermail/python-list/2009-February/525280.html > > Used to be at this URL: > > https://mail.python.org/pipermail/python-list/2009-February/538048.html > > > > -- > Luciano Ramalho > | Author of Fluent Python (O'Reilly, 2015) > | http://shop.oreilly.com/product/0636920032519.do > | Technical Principal at ThoughtWorks > | Twitter: @ramalhoorg A second edition? Curses, just after I recently bought a copy of the first edition ;-o ... (It's a very good book BTW - thanks!) J^n From rshepard at appl-ecosys.com Tue Jun 18 13:13:04 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 18 Jun 2019 10:13:04 -0700 (PDT) Subject: tkinter: on_cancel() method [RESOLVED] In-Reply-To: References: Message-ID: On Tue, 18 Jun 2019, Rich Shepard wrote: > I have frames for data entry and modification. Each has two buttons: Save > and Cancel. Is there a standard tkinter on_cancel() method responding to a > user clicking on the Cancel button? Found the solution: self.destroy() Rich From luciano at ramalho.org Tue Jun 18 13:00:49 2019 From: luciano at ramalho.org (Luciano Ramalho) Date: Tue, 18 Jun 2019 14:00:49 -0300 Subject: Is there an archive of this list with permanent URLs to each message? In-Reply-To: References: Message-ID: On Tue, Jun 18, 2019 at 12:27 PM jkn wrote: > A second edition? Curses, just after I recently bought a copy of the first edition ;-o ... > > (It's a very good book BTW - thanks!) Thanks, J! The 2nd edition won't be available until Q1 2020 at the earliest. Dave Beazley once told me that Fluent Python was very forward looking, so the 1st edition is still very relevant IMHO. The examples that broke are the ones using asyncio, which was provisional at the time and had significant API changes (aiohttp, used in several examples, had even more breaking changes). Besides the asyncio breakage, there are a few better ways of doing things. And I will cover typing. Cheers, Luciano -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg From mal at europython.eu Tue Jun 18 14:28:30 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 18 Jun 2019 20:28:30 +0200 Subject: EuroPython 2019: Inviting European Python Conference Organizers Message-ID: As you may know, the EuroPython Society (EPS) has extended it?s mission to not only run the EuroPython conference, but also provide help for the Python community in Europe in general. * https://www.europython-society.org/ * As part of this, we would like to get to know, and help create closer ties between organizers of other European Python events. Organizers? Lunch ----------------- We would like to invite representatives of all European Python conference to EuroPython 2019 to join us for an organizers? lunch. We?re planing the lunch for Thursday or Friday. Details will be announced closer to the event. Our aim is to get to know each other, exchange experience in organizing events and to find out how we, as EPS, can most effectively help other conferences going forward. Free Tickets ------------ To support and facilitate this, we are giving out one free conference ticket per conference team, so that each team can send a representative to the organizers? lunch. If your team wants to send someone to join, please write to board at europython.eu, mentioning the conference you?re organizing and some background on your team. Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185683241297/europython-2019-inviting-european-python Tweet: https://twitter.com/europython/status/1141044706979274752 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Tue Jun 18 14:32:24 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 18 Jun 2019 20:32:24 +0200 Subject: EuroPython 2019: Community Discounts Message-ID: <308e7ef9-02a6-da19-c0e9-c60b409088d1@europython.eu> The EuroPython Society (EPS) does not only run the EuroPython conference, but also aims to provide help for the Python community in Europe in general. * https://www.europython-society.org/ * Let?s all meet at EuroPython ---------------------------- In addition to the Python Organizers Lunch (see previous post), which focuses on conference organizers, we are also establishing a program to support attendees of Python user groups and conferences in Europe. We?d like to invite all of you to EuroPython 2019 this year. Of course, we cannot give out free tickets to everyone, but we can at least recognize your participation in the Python community by giving out discounts for the conference. * https://ep2019.europython.eu/ * Discounts for EuroPython Tickets -------------------------------- If you are running a Python event (conference or user group) in Europe, please reach out to board at europython.eu to request a coupon code for your group, which you can then pass on to your group members or attendees. If you are not running a user group or conference, but a regular attendee of one, please contact your organizers to have them submit a request. We can only distribute codes at the user group and conference organizer level. The coupon codes are valid for conference tickets bought starting today and will give you a 10% discount on the ticket price (both regular and late bird prices). The codes are setup for user group sizes of between 30-50 members, but we are also extending this to organizers and attendees of larger conferences. If you need a code valid for larger groups, please mention this in your email. Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185683252247/europython-2019-community-discounts Tweet: https://twitter.com/europython/status/1141044869470871553 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From wiwindson at gmail.com Tue Jun 18 23:53:52 2019 From: wiwindson at gmail.com (Windson Yang) Date: Wed, 19 Jun 2019 11:53:52 +0800 Subject: Understand workflow about reading and writing files in Python Message-ID: I'm trying to understand the workflow of how Python read/writes data with buffer. I will be appreciated if someone can review it. ### Read n data 1. If the data already in the buffer, return data 2. If the data not in the buffer: 1. copy all the current data from the buffer 2. create a new buffer object, fill the new buffer with raw read which read data from disk. 3. concat the data in the old buffer and new buffer. 4. return the data ### Write n data 1. If data small enough to fill into the buffer, write data to the buffer 2. If data can't fill into the buffer 1. flush the data in the buffer 1. If succeed: 1. create a new buffer object. 2. fill the new buffer with data return from raw write 2. If failed: 1. Shifting the buffer to make room for writing data to the buffer 2. Buffer as much writing data as possible (may raise BlockingIOError) 2. return the data From nad at python.org Wed Jun 19 01:19:12 2019 From: nad at python.org (Ned Deily) Date: Wed, 19 Jun 2019 01:19:12 -0400 Subject: [RELEASE] Python 3.7.4rc1 and 3.6.9rc1 are now available Message-ID: Python 3.7.4rc1 and 3.6.9rc1 are now available. 3.7.4rc1 is the release preview of the next maintenance release of Python 3.7, the latest feature release of Python. 3.6.9rc1 is the release preview of the first security-fix release of Python 3.6. Assuming no critical problems are found prior to 2019-06-28, no code changes are planned between these release candidates and the final releases. These release candidates are intended to give you the opportunity to test the new security and bug fixes in 3.7.4 and security fixes in 3.6.9. We strongly encourage you to test your projects and report issues found to bugs.python.org as soon as possible. Please keep in mind that these are preview releases and, thus, their use is not recommended for production environments. You can find the release files, a link to their changelogs, and more information here: https://www.python.org/downloads/release/python-374rc1/ https://www.python.org/downloads/release/python-369rc1/ -- Ned Deily nad at python.org -- [] From PythonList at DancesWithMice.info Wed Jun 19 02:02:38 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 19 Jun 2019 18:02:38 +1200 Subject: Understand workflow about reading and writing files in Python In-Reply-To: References: Message-ID: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> I've not gone 'back' to refer to any ComSc theory on buffer-management. Perhaps you might benefit from such? I like your use of the word "shift", so I'll continue to use it. There are three separate units of data to consider - each of which could be called a "buffer". To avoid confusing (myself) I'll only call the 'middle one' that: 1 the unit of data 'coming' from the data-source 2 the "buffer" you are implementing 3 the unit of data 'going' out to a data-destination. 1 and 3 may be dictated to you, eg hardware or file specifications, code requirements, etc. So, data is shifted into the (2) buffer in a unit-size decided by (1) - in most use-cases each incoming unit will be the same size, but remember that the last 'unit' may/not be full-size. Similarly, data shifted out from the (2) buffer to (3). The size of (1) is likely not that of (3) - otherwise why use a "buffer"? The size of (2) must be larger than (1) and larger than (2) - for reasons already illustrated. I recall learning how to use buffers with a series of hand-drawn block diagrams. Recommend you try similarly! Now, let's add a few critiques, as requested (interposed below):- On 19/06/19 3:53 PM, Windson Yang wrote: > I'm trying to understand the workflow of how Python read/writes data with > buffer. I will be appreciated if someone can review it. > > ### Read n data - may need more than one read operation if the size of (3) "demands" more data than the size of (1)/one "read". > 1. If the data already in the buffer, return data - this a data-transfer of size (3) For extra credit/an unnecessary complication (but probable speed-up!): * if the data-remaining is less than size (3) consider a read-ahead mechanism > 2. If the data not in the buffer: - if buffer's data-len < size (3) > 1. copy all the current data from the buffer * if "buffer" is my (2), then no-op > 2. create a new buffer object, fill the new buffer with raw read which > read data from disk. * this becomes: perform read operation and append incoming data (size (1)) to "buffer" - hence why "buffer" is larger than (1), by definition. NB if size (1) is smaller than size (3), multiple read operations may be necessary. Thus a read-loop!? > 3. concat the data in the old buffer and new buffer. = now no-op. Hopefully the description of 'three buffers' removes this confusion of/between buffers. > 4. return the data * make the above steps into a while-loop and there won't be a separate step here (it is the existing step 1!) * build all of the above into a function/method, so that the 'mainline' only has to say 'give me data'! > ### Write n data > 1. If data small enough to fill into the buffer, write data to the buffer =yes, the data coming from source (1), which in this case is 'your' code may/not be sufficient to fill the output size (3). So, load it into the "buffer" (2). > 2. If data can't fill into the buffer > 1. flush the data in the buffer =This statement seems to suggest that if there is already some data in the buffer, it will be wiped. Not recommended! =Have replaced the next steps, see below for your consideration:- > 1. If succeed: > 1. create a new buffer object. > 2. fill the new buffer with data return from raw write > 2. If failed: > 1. Shifting the buffer to make room for writing data to the > buffer > 2. Buffer as much writing data as possible (may raise > BlockingIOError) > 2. return the data After above transfer from data-source (1) to "buffer" (2): * if len( data in "buffer" ) >= size (3): output else: keep going * output: shift size(3) from "buffer" to output retain 'the rest' in/as "buffer" NB if the size (2) of data in "buffer" is/could be multiples of size (3), then the "output" function should/could become a loop, ie keep emptying the "buffer" until size (2) < size (3). Finally, don't forget the special cases: What happens if we reach 'the end' (of 'input' or 'output' phase), and there is still data in (1) or (2)? Presumably, in "Read" we would discard (1), but in the case of "Write" we MUST empty "buffer" (2), even if it means the last write is of less than size (3). NB The 'rules' for the latter may vary between use-cases, eg add 'stuffing' if the output record MUST be x-bytes long. Hope this helps. Do you need to hand-code this stuff though, or is there a better way? -- Regards =dn From vakulb5678 at gmail.com Wed Jun 19 10:28:56 2019 From: vakulb5678 at gmail.com (vakul bhatt) Date: Wed, 19 Jun 2019 07:28:56 -0700 (PDT) Subject: s.sendall(filename + "\r\n") TypeError: a bytes-like object is required, not 'str' Message-ID: Hi Team, i m new to python, running below program, getting error Python Version : 3.7 32bit for windows Program: ============================ #simple Goopher client import socket, sys port = 70 host = sys.argv[1] filename = sys.argv[2] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.sendall(filename + "\r\n") while 1: buf = s.recv(2048) if not len(buf): break sys.stdout.write(buf) ============================ Error : ============================ python goopher.py quux.org / Traceback (most recent call last): File "goopher.py", line 13, in s.sendall(filename + "\r\n") TypeError: a bytes-like object is required, not 'str' ============================ please help. thanks & Regards From rosuav at gmail.com Wed Jun 19 10:57:56 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 20 Jun 2019 00:57:56 +1000 Subject: s.sendall(filename + "\r\n") TypeError: a bytes-like object is required, not 'str' In-Reply-To: References: Message-ID: On Thu, Jun 20, 2019 at 12:31 AM vakul bhatt wrote: > > Hi Team, > > i m new to python, running below program, getting error > Python Version : 3.7 32bit for windows > Program: > ============================ > #simple Goopher client > > import socket, sys > > port = 70 > host = sys.argv[1] > filename = sys.argv[2] > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((host, port)) > > s.sendall(filename + "\r\n") > > while 1: > buf = s.recv(2048) > if not len(buf): > break > sys.stdout.write(buf) > ============================ > > > Error : > > ============================ > python goopher.py quux.org / > Traceback (most recent call last): > File "goopher.py", line 13, in > s.sendall(filename + "\r\n") > TypeError: a bytes-like object is required, not 'str' > As the message says, you need to have a sequence of bytes, not a text string. You can't write text to a socket. The way to represent text using bytes is to use a character encoding such as UTF-8. Try this instead: s.sendall(filename.encode("UTF-8") + b"\r\n") That will send the bytes that make up the UTF-8 representation of the string, rather than trying to send the abstract characters. ChrisA From rshepard at appl-ecosys.com Wed Jun 19 18:50:56 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 19 Jun 2019 15:50:56 -0700 (PDT) Subject: tkinter: widget to display set returned from database table Message-ID: In a database application I want to design a view for the table rows returned from a select statement. Tkinter has a listbox widget and web searches suggest that multicolumn listboxes are best based on ttk.Treeview widgets, but my understanding of a treeview is to display a hierarchical set rather than a simple list. Each table has multiple columns and I want to create a view for each table that will allow the user to select a row. The SQL select statement will be formed from criteria provided in a separate dialog box. Advice needed, Rich From python at mrabarnett.plus.com Wed Jun 19 20:39:16 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 20 Jun 2019 01:39:16 +0100 Subject: tkinter: widget to display set returned from database table In-Reply-To: References: Message-ID: On 2019-06-19 23:50, Rich Shepard wrote: > In a database application I want to design a view for the table rows > returned from a select statement. Tkinter has a listbox widget and web > searches suggest that multicolumn listboxes are best based on ttk.Treeview > widgets, but my understanding of a treeview is to display a hierarchical set > rather than a simple list. > > Each table has multiple columns and I want to create a view for each table > that will allow the user to select a row. The SQL select statement will be > formed from criteria provided in a separate dialog box. > Here's a small example. #!python3.7 # -*- coding: utf-8 -*- # # Example demonstrating a multi-column table using ttk.Treeview and scrollbars. # import tkinter as tk import tkinter.ttk as ttk class TableExample(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.title('Table example') headings = ['English', 'Experanto'] self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=0) self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(1, weight=0) vscrollbar = tk.Scrollbar(self, orient='vertical') vscrollbar.grid(row=0, column=1, sticky='ns') hscrollbar = tk.Scrollbar(self, orient='horizontal') hscrollbar.grid(row=1, column=0, sticky='we') self.column_ids = ['#%d' % h for h in range(1, len(headings) + 1)] def fix_map(option): # Fix for setting text colour for Tkinter 8.6.9 # From: https://core.tcl.tk/tk/info/509cafafae # # Returns the style map for 'option' with any styles starting with # ('!disabled', '!selected', ...) filtered out. # style.map() returns an empty list for missing options, so this # should be future-safe. return [elm for elm in style.map('Treeview', query_opt=option) if elm[:2] != ('!disabled', '!selected')] style = ttk.Style() style.map('Treeview', foreground=fix_map('foreground'), background=fix_map('background')) self._table = ttk.Treeview(self, columns=self.column_ids, displaycolumns='#all', show=['headings'], yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) self._table.grid(row=0, column=0, sticky='nswe') for id, heading in zip(self.column_ids, headings): self._table.heading(id, text=heading) vscrollbar.config(command=self._table.yview) hscrollbar.config(command=self._table.xview) # Now to fill the table. words = [ ('zero', 'nul'), ('one', 'unu'), ('two', 'du'), ('three', 'tri'), ('four', 'kvar'), ('five', 'kvin'), ] for row in words: # Add a new row. row_id = self._table.insert('', 'end') # Fill the new row. for column_id, entry in zip(self.column_ids, row): self._table.set(row_id, column_id, entry) TableExample().mainloop() From tjreedy at udel.edu Thu Jun 20 02:10:15 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Jun 2019 02:10:15 -0400 Subject: tkinter: widget to display set returned from database table In-Reply-To: References: Message-ID: On 6/19/2019 6:50 PM, Rich Shepard wrote: > In a database application I want to design a view for the table rows > returned from a select statement. Tkinter has a listbox widget and web > searches suggest that multicolumn listboxes are best based on ttk.Treeview Right. > widgets, but my understanding of a treeview is to display a hierarchical > set rather than a simple list. There is no sin is using less than all the features of a widget. Anyway, think of the tree having one node, which you can hide (not show), representing the table, and n leaves, representing the rows of the table, which you do show. If you sort the selection by some categorical field, then you can make the display hierarchical by adding expandable rows for values of the sort field. Think of database reports where summary lines can be expanded and contracted. -- Terry Jan Reedy From rshepard at appl-ecosys.com Thu Jun 20 08:43:56 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 20 Jun 2019 05:43:56 -0700 (PDT) Subject: tkinter: widget to display set returned from database table In-Reply-To: References: Message-ID: On Thu, 20 Jun 2019, MRAB wrote: > Here's a small example. Thank you very much. Your example makes much more sense to me than do the ones I've found on the web. Best regards, Rich From rshepard at appl-ecosys.com Thu Jun 20 08:47:39 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 20 Jun 2019 05:47:39 -0700 (PDT) Subject: tkinter: widget to display set returned from database table In-Reply-To: References: Message-ID: On Thu, 20 Jun 2019, Terry Reedy wrote: > There is no sin is using less than all the features of a widget. Anyway, > think of the tree having one node, which you can hide (not show), > representing the table, and n leaves, representing the rows of the table, > which you do show. Terry, This explanation clarifies what I've read about the tkinter tree. > If you sort the selection by some categorical field, then you can make the > display hierarchical by adding expandable rows for values of the sort > field. Think of database reports where summary lines can be expanded and > contracted. My current thinking is that the sorting will be done by the SQL statement based on user input (and that's another widget I need to learn) so the output in the treelist will be as correct. Thanks very much, Rich From mal at europython.eu Thu Jun 20 10:40:26 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 20 Jun 2019 16:40:26 +0200 Subject: =?UTF-8?Q?EuroPython_2019:_Beginners=e2=80=99_Day_Workshop?= Message-ID: <67a1d2d8-543f-8e1e-d32a-e6e80cd41871@europython.eu> If you?re new to Python, you should come to our friendly, welcoming and helpful Beginners? Day Workshop. We cater to new Pythonistas of all levels: from absolute beginners through to experienced programmers encountering Python for the first time. * https://ep2019.europython.eu/events/beginners-day/ * What is Beginners? Day ? ------------------------ Beginners? day welcomes and supports folks who are new to Python programming. It takes place on Tuesday 9th July, from 9:30 - 16:00 at the workshop venue, FHNW Campus Muttenz. Just in time to get you ready for all the talks which follow on Wednesday, Thursday and Friday ! It?s also a great place to make friends with fellow attendees and figure out how to get the most out of EuroPython. Bring your laptop, because this will be a hands-on session! The day will start with workshops to give you the chance to try out Python in lots of different situations: making a game, creating a website, programming embedded devices or telling stories with data (in a Jupyter notebook). Later in the day you?ll have an opportunity to further explore those aspects of Python which appeal to you with the support of a team of experienced and helpful mentors. We?ll end the day with a question and answer session about Python, EuroPython and the wider Python ecosystem. The emphasis will be in creating a fun, supportive and useful path into the Python programming language and its community. Sign up for Beginners? Day -------------------------- You will need a conference pass to attend, but otherwise, it?s free, so if you?re thinking of coming to the conference, but you?re new to Python or programming, this could be the session for you: https://ep2019.europython.eu/registration/buy-tickets/ The session will be presented in English (although our mentors will typically speak a few other languages as well). If you?d like to come, please do register in advance for this session, so that we know how to plan to make it the best yet. We need to know the numbers for planing the workshop. Sign up for Beginners? Day here: https://docs.google.com/forms/d/e/1FAIpQLScBSJ8y--ROBI7HDQ01H1Cn9RI9amC9mRoOJMEppOmbZv0pMA/viewform Call for Mentors ---------------- The workshop is being organised by experienced Python programmer and educator, Nicholas H.Tollervey. Already know Python? Do you value working in an open, inclusive and collaborative way? Want to develop your mentorship skills? Fantastic! We?re looking for folks with the technical skills, patience, humour and empathy to work with beginners who may come from a wide variety of backgrounds and levels of experience. It?s rewarding, fun and a great way to give back to the community. We?d especially love to hear from you if you can add an extra language to help non-English speakers feel comfortable asking questions, or if you?ve never mentored before and want to try to share your knowledge for the first time. This is a supportive environment for both beginner programmers AND beginner mentors. :-) Please sign up as a mentor on our mentor registration form: https://docs.google.com/forms/d/e/1FAIpQLSdkphUVi_vplS7yvxI432R03BJPCapv-K29p1EPA0F5Tn8qhA/viewform Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185723885512/europython-2019-beginners-day-workshop Tweet: https://twitter.com/europython/status/1141675177400590336 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From jseacat at terracottagroup.com Thu Jun 20 11:50:03 2019 From: jseacat at terracottagroup.com (Julia Seacat) Date: Thu, 20 Jun 2019 15:50:03 +0000 Subject: help with python37.dll Message-ID: <48df5871a54f4088b5eb26d40b7ac6dc@terracottagroup.com> Hello, I installed python 3.7 (64 bit) for my Windows computer and am trying to install pip but it is giving me an error that the code execution cannot proceed because python37.dll was not found. How do I install or reinstall this program? Also I already subscribed to the list. Thank you, Julia Julia Seacat [cid:image004.jpg at 01D05CB6.58115AC0] 424-269-3800 | 800-718-9853 f | 2321 Rosecrans Avenue, Suite 3270 | El Segundo, CA 90245 | www.terracottagroup.com CONFIDENTIALITY NOTICE and DISCLAIMER: The foregoing is neither an offer nor acceptance concerning any existing agreement. No offer or acceptance is valid as against the Lender unless signed in ink by an authorized officer of the Lender. No email from the Lender shall be deemed to constitute an offer or acceptance concerning any agreement. The Lender intends that there shall be no claims of estoppel and that no person shall change position in reliance upon this correspondence. Nothing in this correspondence is to be construed as a waiver, limitation, or release of any and all rights and remedies of the Lender. This email message is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. If you are the intended recipient but do not wish to receive communications through this medium, please so advise the sender immediately. Nothing in this communication should be interpreted as a digital or electronic signature that can be used to authenticate a contract or other legal document. In the event this information was obtained in or by the non-intended recipient and/or in error, please contact 424-269-3800 immediately. From python at mrabarnett.plus.com Thu Jun 20 12:13:15 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 20 Jun 2019 17:13:15 +0100 Subject: help with python37.dll In-Reply-To: <48df5871a54f4088b5eb26d40b7ac6dc@terracottagroup.com> References: <48df5871a54f4088b5eb26d40b7ac6dc@terracottagroup.com> Message-ID: On 2019-06-20 16:50, Julia Seacat wrote: > Hello, > > I installed python 3.7 (64 bit) for my Windows computer and am trying to install pip but it is giving me an error that the code execution cannot proceed because python37.dll was not found. How do I install or reinstall this program? > You should already have pip; it's installed when you install Python 3.7. From markos at c2o.pro.br Thu Jun 20 21:39:14 2019 From: markos at c2o.pro.br (Markos) Date: Thu, 20 Jun 2019 22:39:14 -0300 Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: References: Message-ID: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> Hi, I'm studying Numpy and I don't understand the difference between >>> vector_1 = np.array( [ 1,0,1 ] ) with 1 bracket and >>> vector_2 = np.array( [ [ 1,0,1 ] ] ) with 2 brackets The shape of vector_1 is: >>> vector_1.shape (3,) But the shape of vector_2 is: >>> vector_2.shape (1, 3) The transpose on vector_1 don't work: >>> vector_1.T array([1, 0, 1]) But the transpose method in vector_2 works fine: >>> vector_2.T array([[1], ?????? [0], ?????? [1]]) I thought that both vectors would be treated as an matrix of 1 row and 3 columns. Why this difference? Any tip? Thank you, Markos From stephen_tucker at sil.org Fri Jun 21 04:57:05 2019 From: stephen_tucker at sil.org (Stephen Tucker) Date: Fri, 21 Jun 2019 09:57:05 +0100 Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> References: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> Message-ID: Markos, I can explain the difference from a non-numpy point of view - I hope you will be able to see how this difference affects what you are trying to do in numpy. vector_1 is an np.array consisting of a three-element list, with the three elements being 1, 0 and 1. vector_2 is an np.array consisting (at the top level) of a one-element list, with that element (at this top level) being a three-element list, with these three elements (at the lower level) being 1, 0 and 1. Stephen. On Fri, Jun 21, 2019 at 7:29 AM Markos wrote: > > Hi, > > I'm studying Numpy and I don't understand the difference between > > >>> vector_1 = np.array( [ 1,0,1 ] ) > > with 1 bracket and > > >>> vector_2 = np.array( [ [ 1,0,1 ] ] ) > > with 2 brackets > > The shape of vector_1 is: > > >>> vector_1.shape > (3,) > > But the shape of vector_2 is: > > >>> vector_2.shape > (1, 3) > > The transpose on vector_1 don't work: > > >>> vector_1.T > array([1, 0, 1]) > > But the transpose method in vector_2 works fine: > > >>> vector_2.T > array([[1], > [0], > [1]]) > > > I thought that both vectors would be treated as an matrix of 1 row and 3 > columns. > > Why this difference? > > Any tip? > > Thank you, > Markos > -- > https://mail.python.org/mailman/listinfo/python-list > From edmondo.giovannozzi at gmail.com Fri Jun 21 06:44:12 2019 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Fri, 21 Jun 2019 03:44:12 -0700 (PDT) Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: References: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> Message-ID: <1c06a6d8-49f7-485c-951c-7ed7ee72602a@googlegroups.com> Every array in numpy has a number of dimensions, "np.array" is a function that can create an array numpy given a list. when you write vector_1 = np.array([1,2,1]) you are passing a list of number to thet function array that will create a 1D array. As you are showing: vector_1.shape will return a tuple with the sizes of each dimension of the array that is: (3,) Note the comma thta indicate that is a tuple. While if you write: vector_2 = np.array([[1,2,3]]) You are passing a list of list to the function array that will instruct it to crete a 2D array, even though the size of the first dimension is 1: vector_2.shape (1,3) It is still a tuple as you can see. Try: vector_3 = np.array([[1,2,3],[4,5,6]]) And you'll see that i'll return a 2D array with a shape: vector_3.shape (2,3) As the external list has 2 elements that is two sublists each with 3 elements. The vector_2 case is just when the external list has only 1 element. I hope it is more clear now. Cherrs, Il giorno venerd? 21 giugno 2019 08:29:36 UTC+2, Markos ha scritto: > Hi, > > I'm studying Numpy and I don't understand the difference between > > >>> vector_1 = np.array( [ 1,0,1 ] ) > > with 1 bracket and > > >>> vector_2 = np.array( [ [ 1,0,1 ] ] ) > > with 2 brackets > > The shape of vector_1 is: > > >>> vector_1.shape > (3,) > > But the shape of vector_2 is: > > >>> vector_2.shape > (1, 3) > > The transpose on vector_1 don't work: > > >>> vector_1.T > array([1, 0, 1]) > > But the transpose method in vector_2 works fine: > > >>> vector_2.T > array([[1], > ?????? [0], > ?????? [1]]) > > > I thought that both vectors would be treated as an matrix of 1 row and 3 > columns. > > Why this difference? > > Any tip? > > Thank you, > Markos From edmondo.giovannozzi at gmail.com Fri Jun 21 06:54:57 2019 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Fri, 21 Jun 2019 03:54:57 -0700 (PDT) Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: <1c06a6d8-49f7-485c-951c-7ed7ee72602a@googlegroups.com> References: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> <1c06a6d8-49f7-485c-951c-7ed7ee72602a@googlegroups.com> Message-ID: <77a2961f-9ab1-485d-9403-35f1c16749f7@googlegroups.com> Keep also in mind that numpy is quite different from Matlab. In Matlab every vaiable is a matrix of at least 2 dimensions. This is not the case of numpy (and is not the case in Fortran too). every array can have a different number of dimensions. The transposition of an array with just 1 dimension is not really meaningful. On the other hand most of the time is not needed. For example le have a matrix: a = np.array([[1,2],[1,1]]) and an array: b = np.array([0.1,0.2]) You can left multiply or right multiply it to this matrix without any need to transpose it (as you have to do in Matlab): a @ b array([0.5,0.3]) b @ a array([0.3,0.4]) Cheers, From python at bdurham.com Fri Jun 21 09:27:35 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 21 Jun 2019 07:27:35 -0600 Subject: pip vs python -m pip? Message-ID: 64-bit Python 3.6.8 running on Windows with a virtual environment activated. "pip -v" reports 19.0.3 "python -m pip" reports 19.1.1 Is this behavior by design or a bug? My takeaway is that its better to run "python -m pip ..." vs "pip ..." when running pip related tasks. Thoughts? Malcolm From bill at baddogconsulting.com Fri Jun 21 09:37:03 2019 From: bill at baddogconsulting.com (Bill Deegan) Date: Fri, 21 Jun 2019 06:37:03 -0700 Subject: pip vs python -m pip? In-Reply-To: References: Message-ID: you must be picking up pip from a different python installl (or virtualenv) than you are picking up python. Check your %PATH% On Fri, Jun 21, 2019 at 6:29 AM Malcolm Greene wrote: > 64-bit Python 3.6.8 running on Windows with a virtual environment > activated. > > "pip -v" reports 19.0.3 > "python -m pip" reports 19.1.1 > > Is this behavior by design or a bug? > > My takeaway is that its better to run "python -m pip ..." vs "pip ..." > when running pip related tasks. > > Thoughts? > > Malcolm > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bdurham.com Fri Jun 21 09:49:40 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 21 Jun 2019 07:49:40 -0600 Subject: How to force "python -m site" ENABLE_USER_SITE to false? Message-ID: <85358451-4c2d-422a-8c32-de0b0a098c78@www.fastmail.com> Any suggestions on how one can force the "python -m site" ENABLE_USER_SITE value to false? Is it possible to globally force this setting - across all users - when installing a system wide version of Python ... or via a command line option when starting a Python session? Motivation: When ENABLE_USER_SITE is true, packages can get accidentally installed in user specific Python\Python3XX\site-packages folder, overriding system packages and ... apparently (at least under Windows) ... virtual environment packages as well. Thank you, Malcolm From python at bdurham.com Fri Jun 21 09:53:52 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 21 Jun 2019 07:53:52 -0600 Subject: pip vs python -m pip? In-Reply-To: References: Message-ID: <39038571-a518-4205-82e6-73cae037f154@www.fastmail.com> > you must be picking up pip from a different python install (or virtualenv) than you are picking up python. > Check your %PATH% That was our first guess. Only one version of Python installed on the system (we install on an empty, freshly serviced pack Windows VM). Only one version of python*.exe found via Explorer. This behavior observed across multiple Windows 2016 Enterprise servers and Windows 10 Professional desktops. Malcolm From tjol at tjol.eu Fri Jun 21 09:39:13 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 21 Jun 2019 15:39:13 +0200 Subject: pip vs python -m pip? In-Reply-To: References: Message-ID: <37e7951d-6f66-6144-1daa-703d4e9d28fd@tjol.eu> On 21/06/2019 15.27, Malcolm Greene wrote: > 64-bit Python 3.6.8 running on Windows with a virtual environment activated. > > "pip -v" reports 19.0.3 > "python -m pip" reports 19.1.1 > > Is this behavior by design or a bug? If the pip and python executables you're calling both live in the virtual environment, then it might be a bug > My takeaway is that its better to run "python -m pip ..." vs "pip ..." when running pip related tasks. It's a good rule of thumb. When you have multiple versions of Python installed side-by-side, there can be a danger that you call the wrong 'pip' by accident. I don't think this should be a concern in a virtual environment though Thomas From rosuav at gmail.com Fri Jun 21 10:00:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Jun 2019 00:00:45 +1000 Subject: pip vs python -m pip? In-Reply-To: <39038571-a518-4205-82e6-73cae037f154@www.fastmail.com> References: <39038571-a518-4205-82e6-73cae037f154@www.fastmail.com> Message-ID: On Fri, Jun 21, 2019 at 11:55 PM Malcolm Greene wrote: > > > you must be picking up pip from a different python install (or virtualenv) than you are picking up python. > > Check your %PATH% > > That was our first guess. Only one version of Python installed on the system (we install on an empty, freshly serviced pack Windows VM). Only one version of python*.exe found via Explorer. > > This behavior observed across multiple Windows 2016 Enterprise servers and Windows 10 Professional desktops. > Well, I'm pretty confident this isn't an actually desired behaviour, so to answer your original question, I'd say "bug" is the more accurate choice. That said, though... there are a LOT of ways that the Windows path can fail to pick up the correct 'pip'. Normally activating a venv should let you use "pip" to mean the right thing just as "python" does, but maybe something's cached? Are you doing this in cmd.exe, powershell, bash, or some other shell? ChrisA From ed at leafe.com Fri Jun 21 10:05:02 2019 From: ed at leafe.com (Ed Leafe) Date: Fri, 21 Jun 2019 09:05:02 -0500 Subject: How to force "python -m site" ENABLE_USER_SITE to false? In-Reply-To: <85358451-4c2d-422a-8c32-de0b0a098c78@www.fastmail.com> References: <85358451-4c2d-422a-8c32-de0b0a098c78@www.fastmail.com> Message-ID: <309C4BB4-C442-428B-A021-CD6CAA7D6E00@leafe.com> On Jun 21, 2019, at 8:49 AM, Malcolm Greene wrote: > > Any suggestions on how one can force the "python -m site" ENABLE_USER_SITE value to false? > > Is it possible to globally force this setting - across all users - when installing a system wide version of Python ... or via a command line option when starting a Python session? From StackOverflow: https://stackoverflow.com/questions/25584276/how-to-disable-site-enable-user-site-for-an-environment -- Ed Leafe From python at bdurham.com Fri Jun 21 10:23:28 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 21 Jun 2019 08:23:28 -0600 Subject: How to force "python -m site" ENABLE_USER_SITE to false? In-Reply-To: <309C4BB4-C442-428B-A021-CD6CAA7D6E00@leafe.com> References: <85358451-4c2d-422a-8c32-de0b0a098c78@www.fastmail.com> <309C4BB4-C442-428B-A021-CD6CAA7D6E00@leafe.com> Message-ID: > From: Ed Leafe > StackOverflow: https://stackoverflow.com/questions/25584276/how-to-disable-site-enable-user-site-for-an-environment Thanks Ed! My takeaway from the above article and our path going forward is to explictly force ENABLE_USER_SITE to false via Python's "-s" switch. Malcolm From python at bdurham.com Fri Jun 21 10:33:35 2019 From: python at bdurham.com (Malcolm Greene) Date: Fri, 21 Jun 2019 08:33:35 -0600 Subject: pip vs python -m pip? In-Reply-To: References: <39038571-a518-4205-82e6-73cae037f154@www.fastmail.com> Message-ID: <3ffbddcf-63e1-4d12-9e54-45f6e56227c7@www.fastmail.com> > From: Chris Angelico > Are you doing this in cmd.exe, powershell, bash, or some other shell? Same result via cmd.exe and PowerShell (ps1). > There are a LOT of ways that the Windows path can fail to pick up the correct 'pip'. Normally activating a venv should let you use "pip" to mean the right thing just as "python" does, but maybe something's cached? I think you're on to something. Running pip as a package (python -m pip) will force the use of the virtual env copy of pip. Running pip as an application vs package may use the system version of pip. Malcolm From skip.montanaro at gmail.com Fri Jun 21 12:10:23 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 21 Jun 2019 11:10:23 -0500 Subject: pip vs python -m pip? In-Reply-To: <3ffbddcf-63e1-4d12-9e54-45f6e56227c7@www.fastmail.com> References: <39038571-a518-4205-82e6-73cae037f154@www.fastmail.com> <3ffbddcf-63e1-4d12-9e54-45f6e56227c7@www.fastmail.com> Message-ID: Malcolm> Running pip as a package (python -m pip) will force the use of the virtual env copy of pip. Running pip as an application vs package may use the system version of pip. I believe it is for just this reason that the recommended spelling these days is "python -m pip". Skip From python at mrabarnett.plus.com Fri Jun 21 13:11:06 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 21 Jun 2019 18:11:06 +0100 Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> References: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> Message-ID: <9be53b0c-e31b-56eb-c1b3-ee204b69c122@mrabarnett.plus.com> On 2019-06-21 02:39, Markos wrote: > > Hi, > > I'm studying Numpy and I don't understand the difference between > >>>> vector_1 = np.array( [ 1,0,1 ] ) > > with 1 bracket and > >>>> vector_2 = np.array( [ [ 1,0,1 ] ] ) > > with 2 brackets > > The shape of vector_1 is: > >>>> vector_1.shape > (3,) > > But the shape of vector_2 is: > >>>> vector_2.shape > (1, 3) > > The transpose on vector_1 don't work: > >>>> vector_1.T > array([1, 0, 1]) > > But the transpose method in vector_2 works fine: > >>>> vector_2.T > array([[1], > ?????? [0], > ?????? [1]]) > > > I thought that both vectors would be treated as an matrix of 1 row and 3 > columns. > > Why this difference? > By similar reasoning, why not 3-dimensional (layer, row, column)? Or 4-dimensional? From markos at c2o.pro.br Sat Jun 22 11:20:54 2019 From: markos at c2o.pro.br (Markos) Date: Sat, 22 Jun 2019 12:20:54 -0300 Subject: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] ) In-Reply-To: <1c06a6d8-49f7-485c-951c-7ed7ee72602a@googlegroups.com> References: <165aadea-f9a8-bc41-e79a-b98ec4241bcf@c2o.pro.br> <1c06a6d8-49f7-485c-951c-7ed7ee72602a@googlegroups.com> Message-ID: <95816b1e-5d7d-d594-f6cd-726fcaae74fb@c2o.pro.br> Thanks Edmondo, Stephen, Mats and Steven you for the tips, I studied linear algebra many years ago and I remember only a few rudiments. But I was trying to visualize (in a geometric way) how the numpy represents arrays, and what the geometrical meaning of the transpose operation made by numpy. I think I understood a little bit more. The number of nested brackets indicates the number of array dimensions. the vector ( [1,2] ) is one-dimensional, but the vector ( [ [1,2] ] ) is two-dimensional. v_1 = np.array( [1,2] ) > v_1.shape (2,) > v_1 v_1 > v_1 array( [1, 2] ) > v_2 = np.array( [ [1,2] ] ) > v_2.shape (1, 2) And it does not make sense to transpose a one-dimensional array. > v_1.T array( [1, 2] ) > v_2.T array( [ [1], ???????????? [2] ] ) Anothe example: vector_1 = np.array( [?? 1,?? 2,?? 3,?? 4,?? 5,?? 6,?? 7,?? 8? ] ) ????????????????????????????????? ^ vector_2 = np.array( [??? [1, 2, 3, 4],??? [5, 6, 7, 8]? ]? ) ????????????????????????????????? ^? ^ vector_3 = np.array( [?? [?? [1,2],? [3,4]? ], [? [5,6],?? [7,8] ]? ]? ) ????????????????????????????????? ^ ^ ^ > vector_1 array([1, 2, 3, 4, 5, 6, 7, 8]) > vector_2 array( [ [1, 2, 3, 4], ???????????? [5, 6, 7, 8] ] ) > vector_3 array( [ [ [1, 2], ?????????????? [3, 4] ], ???????????? [ [5, 6], ?????????????? [7, 8] ] ] ) And looking for some tutorial about geometric aspects of matrices and the geometric meaning of the transpose I found that transposed is "mirrored along the diagonal" at: https://www.coranac.com/documents/geomatrix/ >vector_1.T array([1, 2, 3, 4, 5, 6, 7, 8]) > vector_2.T array( [ [1, 5], ???????????? [2, 6], ???????????? [3, 7], ???????????? [4, 8] ] ) > vector_3.T array( [ [ [1, 5], ?????????????? [3, 7]], ???????????? [ [2, 6], ?????????????? [4, 8] ] ] ) Thank you, Markos Em 21-06-2019 07:44, edmondo.giovannozzi at gmail.com escreveu: > Every array in numpy has a number of dimensions, > "np.array" is a function that can create an array numpy given a list. > > when you write > vector_1 = np.array([1,2,1]) > you are passing a list of number to thet function array that will create a 1D array. > As you are showing: > vector_1.shape > will return a tuple with the sizes of each dimension of the array that is: > (3,) > Note the comma thta indicate that is a tuple. > While if you write: > vector_2 = np.array([[1,2,3]]) > You are passing a list of list to the function array that will instruct it to crete a 2D array, even though the size of the first dimension is 1: > vector_2.shape > (1,3) > It is still a tuple as you can see. > Try: > vector_3 = np.array([[1,2,3],[4,5,6]]) > And you'll see that i'll return a 2D array with a shape: > vector_3.shape > (2,3) > As the external list has 2 elements that is two sublists each with 3 elements. > The vector_2 case is just when the external list has only 1 element. > > I hope it is more clear now. > Cherrs, > > > > > > > Il giorno venerd? 21 giugno 2019 08:29:36 UTC+2, Markos ha scritto: >> Hi, >> >> I'm studying Numpy and I don't understand the difference between >> >>>>> vector_1 = np.array( [ 1,0,1 ] ) >> with 1 bracket and >> >>>>> vector_2 = np.array( [ [ 1,0,1 ] ] ) >> with 2 brackets >> >> The shape of vector_1 is: >> >>>>> vector_1.shape >> (3,) >> >> But the shape of vector_2 is: >> >>>>> vector_2.shape >> (1, 3) >> >> The transpose on vector_1 don't work: >> >>>>> vector_1.T >> array([1, 0, 1]) >> >> But the transpose method in vector_2 works fine: >> >>>>> vector_2.T >> array([[1], >> ?????? [0], >> ?????? [1]]) >> >> >> I thought that both vectors would be treated as an matrix of 1 row and 3 >> columns. >> >> Why this difference? >> >> Any tip? >> >> Thank you, >> Markos From ar at zeit.io Sun Jun 23 03:56:51 2019 From: ar at zeit.io (Arup Rakshit) Date: Sun, 23 Jun 2019 13:26:51 +0530 Subject: Python refactoring question and create dynamic attributes Message-ID: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> In the below code: @classmethod def find(self, id): if isinstance(id, list): rows = self.__table__().get_all(*id).run(self.__db__().conn) result = [] for row in rows: acategory = Category() acategory.__dict__.update(row) result.append(acategory) return result else: adict = self.__table__().get(id).run(self.__db__().conn) acategory = Category() acategory.__dict__.update(adict) return acategory I have 2 questions: 1. Is there any better way to create attributes in an object without using __dict__().update() or this is a correct approach? 2. Can we get the same result what for row in rows: block is producing without killing the readability ? To see the context, here is my source code https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/app/models/category.py Thanks, Arup Rakshit ar at zeit.io From cs at cskk.id.au Sun Jun 23 05:01:43 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 23 Jun 2019 19:01:43 +1000 Subject: Python refactoring question and create dynamic attributes In-Reply-To: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> References: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> Message-ID: <20190623090143.GA16932@cskk.homeip.net> On 23Jun2019 13:26, Arup Rakshit wrote: >In the below code: > > @classmethod > def find(self, id): > if isinstance(id, list): > rows = self.__table__().get_all(*id).run(self.__db__().conn) > result = [] > for row in rows: > acategory = Category() > acategory.__dict__.update(row) > result.append(acategory) > return result > else: > adict = self.__table__().get(id).run(self.__db__().conn) > acategory = Category() > acategory.__dict__.update(adict) > return acategory > >I have 2 questions: > >1. Is there any better way to create attributes in an object without using __dict__().update() or this is a correct approach? setattr() is the usual approach, but that sets a single attribute at a time. If you have many then __dict__.update may be reasonable. You should bear in mind that not all objects have a __dict__. It is uncommon, but if a class is defined with a __slots__ attribute then its instances have fixed attribute names and there is no __dict__. Also some builtin types have not __dict__. However, you likely know that the objects you are using have a __dict__, so you're probably good. Also, __dict__ bypasses properties and descriptors. That might be important. >2. Can we get the same result what for row in rows: block is producing without killing the readability ? Not obviously. It looks pretty direct to me. Unless the Category class can be made to accept an attribute map in its __int__ method, then you might do some variable on: result = [ Category(row) for row in rows ] which is pretty readable. BTW, @classmethods receive the class as the first argument, not an instance. So you'd normally write: @classmethod def find(cls, id): ... and you would not have a self to use. is __table__ a class atribute or an instance attribute? >To see the context, here is my source code >https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/app/models/category.py Ah, so Category inherits from BaseModel. That means you can write your own __init__. If it accepted an optional mapping (i.e. a dict or row) you could put the .update inside __init__, supporting the list comprehension I suggest above. It looks like you've marks almost all the methods as @classmethods. Are you sure about that? They all seem written to use self, and thus be instance methods. Cheers, Cameron Simpson From ar at zeit.io Sun Jun 23 05:44:36 2019 From: ar at zeit.io (Arup Rakshit) Date: Sun, 23 Jun 2019 15:14:36 +0530 Subject: Python refactoring question and create dynamic attributes In-Reply-To: <20190623090143.GA16932@cskk.homeip.net> References: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> <20190623090143.GA16932@cskk.homeip.net> Message-ID: <9DE9F0B8-7E77-47F2-97D4-076B597B7FD8@zeit.io> > On 23-Jun-2019, at 2:31 PM, Cameron Simpson wrote: > > On 23Jun2019 13:26, Arup Rakshit wrote: >> In the below code: >> >> @classmethod >> def find(self, id): >> if isinstance(id, list): >> rows = self.__table__().get_all(*id).run(self.__db__().conn) >> result = [] >> for row in rows: >> acategory = Category() >> acategory.__dict__.update(row) >> result.append(acategory) >> return result >> else: >> adict = self.__table__().get(id).run(self.__db__().conn) >> acategory = Category() >> acategory.__dict__.update(adict) >> return acategory >> >> I have 2 questions: >> >> 1. Is there any better way to create attributes in an object without using __dict__().update() or this is a correct approach? > > setattr() is the usual approach, but that sets a single attribute at a time. If you have many then __dict__.update may be reasonable. > > You should bear in mind that not all objects have a __dict__. It is uncommon, but if a class is defined with a __slots__ attribute then its instances have fixed attribute names and there is no __dict__. Also some builtin types have not __dict__. However, you likely know that the objects you are using have a __dict__, so you're probably good. > > Also, __dict__ bypasses properties and descriptors. That might be important. > >> 2. Can we get the same result what for row in rows: block is producing without killing the readability ? > > Not obviously. It looks pretty direct to me. > > Unless the Category class can be made to accept an attribute map in its __int__ method, then you might do some variable on: > > result = [ Category(row) for row in rows ] > > which is pretty readable. > > BTW, @classmethods receive the class as the first argument, not an instance. So you'd normally write: > > @classmethod > def find(cls, id): > ? > What I know, is that first argument is reserved for the instance upon which it is called. It can be any name, so continued to use self. Yes these methods are class method intentionally. I am not aware of so far the naming rules of the first argument of a class or instance method. > and you would not have a self to use. is __table__ a class atribute or an instance attribute? Yes __table__ class attribute defined in the BaseModel. > >> To see the context, here is my source code https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/app/models/category.py > > Ah, so Category inherits from BaseModel. That means you can write your own __init__. If it accepted an optional mapping (i.e. a dict or row) you could put the .update inside __init__, supporting the list comprehension I suggest above. Nice idea. I?ll try this. > > It looks like you've marks almost all the methods as @classmethods. Are you sure about that? They all seem written to use self, and thus be instance methods. > > Cheers, > Cameron Simpson Thanks, Arup Rakshit ar at zeit.io From pkpearson at nowhere.invalid Sun Jun 23 13:58:02 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 23 Jun 2019 17:58:02 GMT Subject: finding a component in a list of pairs References: Message-ID: On 22 Jun 2019 13:24:38 GMT, Stefan Ram wrote: [snip] > > print( next( ( pair for pair in pairs if pair[ 0 ]== 'sun' ), > ( 0, '(unbekannt)' ))[ 1 ]) > print( next( itertools.dropwhile( lambda pair: pair[ 0 ]!= 'sun', pairs )) > [ 1 ]) [snip] > > The last two lines of the program show two different > approaches to search for the translation of ?sun?. > > Which approach is better? Or, do you have yet a better idea > about how to find the translation of ?sun? in ?pairs?? Are you allowed to use a dict? -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Sun Jun 23 15:14:18 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 23 Jun 2019 20:14:18 +0100 Subject: Python refactoring question and create dynamic attributes In-Reply-To: <9DE9F0B8-7E77-47F2-97D4-076B597B7FD8@zeit.io> References: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> <20190623090143.GA16932@cskk.homeip.net> <9DE9F0B8-7E77-47F2-97D4-076B597B7FD8@zeit.io> Message-ID: <708ff03c-4a54-8d23-a07c-5bd1bfaa5efe@mrabarnett.plus.com> On 2019-06-23 10:44, Arup Rakshit wrote: > >> On 23-Jun-2019, at 2:31 PM, Cameron Simpson wrote: >> >> On 23Jun2019 13:26, Arup Rakshit wrote: >>> In the below code: >>> >>> @classmethod >>> def find(self, id): >>> if isinstance(id, list): >>> rows = self.__table__().get_all(*id).run(self.__db__().conn) >>> result = [] >>> for row in rows: >>> acategory = Category() >>> acategory.__dict__.update(row) >>> result.append(acategory) >>> return result >>> else: >>> adict = self.__table__().get(id).run(self.__db__().conn) >>> acategory = Category() >>> acategory.__dict__.update(adict) >>> return acategory >>> >>> I have 2 questions: >>> >>> 1. Is there any better way to create attributes in an object without using __dict__().update() or this is a correct approach? >> >> setattr() is the usual approach, but that sets a single attribute at a time. If you have many then __dict__.update may be reasonable. >> >> You should bear in mind that not all objects have a __dict__. It is uncommon, but if a class is defined with a __slots__ attribute then its instances have fixed attribute names and there is no __dict__. Also some builtin types have not __dict__. However, you likely know that the objects you are using have a __dict__, so you're probably good. >> >> Also, __dict__ bypasses properties and descriptors. That might be important. >> >>> 2. Can we get the same result what for row in rows: block is producing without killing the readability ? >> >> Not obviously. It looks pretty direct to me. >> >> Unless the Category class can be made to accept an attribute map in its __int__ method, then you might do some variable on: >> >> result = [ Category(row) for row in rows ] >> >> which is pretty readable. >> >> BTW, @classmethods receive the class as the first argument, not an instance. So you'd normally write: >> >> @classmethod >> def find(cls, id): >> ? >> > > What I know, is that first argument is reserved for the instance upon which it is called. It can be any name, so continued to use self. Yes these methods are class method intentionally. I am not aware of so far the naming rules of the first argument of a class or instance method. > As Cameron wrote, the convention is that if it's an instance method you call its first parameter "self", whereas if it's a class method you call its first parameter "cls". [snip] From PythonList at DancesWithMice.info Sun Jun 23 15:59:09 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 24 Jun 2019 07:59:09 +1200 Subject: Python refactoring question and create dynamic attributes In-Reply-To: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> References: <037E8615-D3A7-477E-820C-EF31DC68AEAF@zeit.io> Message-ID: On 23/06/19 7:56 PM, Arup Rakshit wrote: > In the below code: > > @classmethod > def find(self, id): > if isinstance(id, list): > rows = self.__table__().get_all(*id).run(self.__db__().conn) > result = [] > for row in rows: > acategory = Category() > acategory.__dict__.update(row) > result.append(acategory) > return result > else: > adict = self.__table__().get(id).run(self.__db__().conn) > acategory = Category() > acategory.__dict__.update(adict) > return acategory > > I have 2 questions: > > 1. Is there any better way to create attributes in an object without using __dict__().update() or this is a correct approach? > 2. Can we get the same result what for row in rows: block is producing without killing the readability ? Examining the readability concern(s):- 1 If it seems complex, first write a comment (in plain English). 2 Is the most basic refactoring improvement is any possible improvement in attribute/variable names? A mid-point between these two: if you find the intricate coding of specific concepts awkward to read/explain, eg __table__().get_all(*id).run(self.__db__().conn) or __dict__.update(row) then might you consider a short 'helper function' - whose name will explain-all and whose body will 'hide' or abstract the complex detail? eg absorb_attributes( acategory, row ) (and yes, someone, somewhere, is absolutely itching to throw-in a Star Trek reference!) -- Regards =dn From wiwindson at gmail.com Sun Jun 23 22:12:18 2019 From: wiwindson at gmail.com (Windson Yang) Date: Mon, 24 Jun 2019 10:12:18 +0800 Subject: Fwd: Understand workflow about reading and writing files in Python In-Reply-To: References: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> Message-ID: Thank you so much for you review DL Neil, it really helps :D. However, there are some parts still confused me, I replyed as below. DL Neil ?2019?6?19??? ??2:03??? > I've not gone 'back' to refer to any ComSc theory on buffer-management. > Perhaps you might benefit from such? > > I just take a crash course on it so I want to know if I understand the details correctly :D > I like your use of the word "shift", so I'll continue to use it. > > There are three separate units of data to consider - each of which could > be called a "buffer". To avoid confusing (myself) I'll only call the > 'middle one' that: > 1 the unit of data 'coming' from the data-source > 2 the "buffer" you are implementing > 3 the unit of data 'going' out to a data-destination. > > Just to make it clear, when we use `f.write('abc')` in python, (1) means 'abc', (2) means the buffer handle by Python (by default 8kb), (2) means the file *f* we are writing to, right? 1 and 3 may be dictated to you, eg hardware or file specifications, code > requirements, etc. > > So, data is shifted into the (2) buffer in a unit-size decided by (1) - > in most use-cases each incoming unit will be the same size, but remember > that the last 'unit' may/not be full-size. Similarly, data shifted out > from the (2) buffer to (3). > > The size of (1) is likely not that of (3) - otherwise why use a > "buffer"? The size of (2) must be larger than (1) and larger than (2) - > for reasons already illustrated. > Is this a typo? (2) larger than (1) larger than (2)? > > I recall learning how to use buffers with a series of hand-drawn block > diagrams. Recommend you try similarly! > > > Now, let's add a few critiques, as requested (interposed below):- > > > On 19/06/19 3:53 PM, Windson Yang wrote:t > > I'm trying to understand the workflow of how Python read/writes data with > > buffer. I will be appreciated if someone can review it. > > > > ### Read n data > > - may need more than one read operation if the size of (3) "demands" > more data than the size of (1)/one "read". > Looks like the size of len of one read() depends on https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1655 ? > > > 1. If the data already in the buffer, return data > > - this a data-transfer of size (3) > > For extra credit/an unnecessary complication (but probable speed-up!): > * if the data-remaining is less than size (3) consider a read-ahead > mechanism > > > 2. If the data not in the buffer: > > - if buffer's data-len < size (3) > > > 1. copy all the current data from the buffer > > * if "buffer" is my (2), then no-op > I don't understand your point here, when we read data we would copy some data from the current buffer from python, right? ( https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1638), we use `out` (which point to res) to store the data here. > > > 2. create a new buffer object, fill the new buffer with raw read > which > > read data from disk. > > * this becomes: perform read operation and append incoming data (size > (1)) to "buffer" - hence why "buffer" is larger than (1), by definition. > NB if size (1) is smaller than size (3), multiple read operations may be > necessary. Thus a read-loop!? > > Yes, you are right, here is a while loop ( https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1652 ) > > > 3. concat the data in the old buffer and new buffer. > > = now no-op. Hopefully the description of 'three buffers' removes this > confusion of/between buffers. > > I don't get it. When we call the function like seek(0) then read(1000), we can still use the data from buffer from python, right? > > > 4. return the data > > * make the above steps into a while-loop and there won't be a separate > step here (it is the existing step 1!) > > > * build all of the above into a function/method, so that the 'mainline' > only has to say 'give me data'! > > > > ### Write n data > > 1. If data small enough to fill into the buffer, write data to the buffer > > =yes, the data coming from source (1), which in this case is 'your' code > may/not be sufficient to fill the output size (3). So, load it into the > "buffer" (2). > > > 2. If data can't fill into the buffer > > 1. flush the data in the buffer > > =This statement seems to suggest that if there is already some data in > the buffer, it will be wiped. Not recommended! > > We check if any data in the buffer if it does, we flush them to the disk ( https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1948 ) > =Have replaced the next steps, see below for your consideration:- > > > 1. If succeed: > > 1. create a new buffer object. > > 2. fill the new buffer with data return from raw write > > 2. If failed: > > 1. Shifting the buffer to make room for writing data to the > > buffer > > 2. Buffer as much writing data as possible (may raise > > BlockingIOError) > > 2. return the data > > After above transfer from data-source (1) to "buffer" (2): > > * if len( data in "buffer" ) >= size (3): output > else: keep going > > * output: > shift size(3) from "buffer" to output > retain 'the rest' in/as "buffer" > > NB if the size (2) of data in "buffer" is/could be multiples of size > (3), then the "output" function should/could become a loop, ie keep > emptying the "buffer" until size (2) < size (3). > > > Finally, don't forget the special cases: > What happens if we reach 'the end' (of 'input' or 'output' phase), and > there is still data in (1) or (2)? > Presumably, in "Read" we would discard (1), but in the case of "Write" > we MUST empty "buffer" (2), even if it means the last write is of less > than size (3). > > Yes, you are right, when we are writing data to the buffer and the buffer is full, we have to flush it. NB The 'rules' for the latter may vary between use-cases, eg add > 'stuffing' if the output record MUST be x-bytes long. > > > Hope this helps. > Do you need to hand-code this stuff though, or is there a better way? > I'm trying to write an article for it :D > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list Regards Windson From PythonList at danceswithmice.info Sun Jun 23 23:18:26 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 24 Jun 2019 15:18:26 +1200 Subject: Understand workflow about reading and writing files in Python In-Reply-To: References: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> Message-ID: <0f657d54-dc31-666c-b2a6-c8c88969f351@DancesWithMice.info> Yes, better to reply to list - others may 'jump in'... On 20/06/19 5:37 PM, Windson Yang wrote: > Thank you so much for you review DL Neil, it really helps :D. However, > there are some parts still confused me, I replyed as below. It's not a particularly easy topic... > DL Neil > ?2019?6?19??? ??2:03??? > > I've not gone 'back' to refer to any ComSc theory on buffer-management. > Perhaps you might benefit from such? > > I just take a crash course on it so I want to know if I understand the > details correctly :D ...there are so many ways one can mess-up! > I like your use of the word "shift", so I'll continue to use it. > > There are three separate units of data to consider - each of which > could > be called a "buffer". To avoid confusing (myself) I'll only call the > 'middle one' that: > 1 the unit of data 'coming' from the data-source > 2 the "buffer" you are implementing > 3 the unit of data 'going' out to a data-destination. > > Just to make it clear, when we use `f.write('abc')` in python, (1) means > 'abc', (2) means the buffer handle by Python (by default 8kb), (2) means > the file *f* we are writing to, right? No! (sorry) f.write() is an output operation, thus nr3. "f" is not a "buffer handle" but a "file handle" or more accurately a "file object". When we: one_input = f.read( NRbytes ) (ignoring EOF/short file and other exceptions) that many bytes will 'appear' in our program labelled as "one_input". However, the OpSys may have read considerably more data, depending upon the device(s) involved, the application, etc; eg if we ask for 2 bytes the operating system will read a much larger block (or applicable unit) of data from a disk drive. The same applies in reverse, with f.write( NRbytes/byte-object ), until we flush or close the file. Those situations account for nr1 and nr3. In the usual case, we have no control over the size of these buffers - and it is best not to meddle! Hence:- > 1 and 3 may be dictated to you, eg hardware or file specifications, > code > requirements, etc. > > So, data is shifted into the (2) buffer in a unit-size decided by (1) - > in most use-cases each incoming unit will be the same size, but > remember > that the last 'unit' may/not be full-size. Similarly, data shifted out > from the (2) buffer to (3). > > The size of (1) is likely not that of (3) - otherwise why use a > "buffer"? The size of (2) must be larger than (1) and larger than (2) - > for reasons already illustrated. > > Is this a typo? (2) larger than (1) larger than (2)? Correct - well spotted! nr2 > nr1 and nr2 > nr3 > I recall learning how to use buffers with a series of hand-drawn block > diagrams. Recommend you try similarly! Try this! > Now, let's add a few critiques, as requested (interposed below):- > > > On 19/06/19 3:53 PM, Windson Yang wrote:t > > I'm trying to understand the workflow of how Python read/writes > data with > > buffer. I will be appreciated if someone can review it. > > > > ### Read n data > > - may need more than one read operation if the size of (3) "demands" > more data than the size of (1)/one "read". > > > Looks like the size of len of one read() depends on > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1655?? You decide how many bytes should be read. That's how much will be transferred from the OpSys' I/O into the Python program's space. With the major exception, that if there is no (more) data available, it is defined as an exception (EOF = end of file) or if there are fewer bytes of data than requested (in which case you will be given only the number of bytes of data-available. > > 1. If the data already in the buffer, return data > > - this a data-transfer of size (3) > > For extra credit/an unnecessary complication (but probable speed-up!): > * if the data-remaining is less than size (3) consider a read-ahead > mechanism > > > 2. If the data not in the buffer: > > - if buffer's data-len < size (3) > > >? ? ? 1. copy all the current data from the buffer > > * if "buffer" is my (2), then no-op > > I don't understand your point here, when we read data we would copy some > data from the current buffer from python, right? > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1638), > we use `out` (which point to res) to store the data here. We're becoming confused: the original heading 'here' was "### Read n data" which is inconsistent with "out" and "from python". If the read operation is set to transfer (say) 2KB into the program at a time, but the code processes it in 100B units, then it would seem that after the first read, twenty process loops will run before it is necessary to issue another input request. In that example, the buffer (nr2) is twenty-times the length of the input 'buffer' (nr1). So, from the second to the twentieth iteration of the process, your step-1 "1. If the data already in the buffer, return data" (and thus my "no-op) applies! This is a major advantage of having a buffer in the first place - transfers within RAM are significantly faster than I/O operations! > >? ? ? 2. create a new buffer object, fill the new buffer with raw > read which > > read data from disk. > > * this becomes: perform read operation and append incoming data (size > (1)) to "buffer" - hence why "buffer" is larger than (1), by definition. > NB if size (1) is smaller than size (3), multiple read operations > may be > necessary. Thus a read-loop!? > > Yes, you are right, here is a while loop > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1652) > > > > >? ? ? 3. concat the data in the old buffer and new buffer. > > = now no-op. Hopefully the description of 'three buffers' removes this > confusion of/between buffers. > > ?I don't get it. When we call the function like seek(0) then > read(1000), we can still use the data from buffer from python, right? I fear that we are having terminology issues - see the original description of three 'buffers'. Which "buffer" are you talking about? 1 the seek/read are carried-out against a file object, which will indeed have its own buffer, size unknown to Python. (buffer 1) 2 the read(1000) operation will (on its own) allow you to populate a buffer within your code, 1000-bytes in length. (buffer 2) > >? ? ? 4. return the data > > * make the above steps into a while-loop and there won't be a separate > step here (it is the existing step 1!) > > > * build all of the above into a function/method, so that the 'mainline' > only has to say 'give me data'! > > > > ### Write n data > > 1. If data small enough to fill into the buffer, write data to > the buffer > > =yes, the data coming from source (1), which in this case is 'your' > code > may/not be sufficient to fill the output size (3). So, load it into the > "buffer" (2). > > > 2. If data can't fill into the buffer > >? ? ? 1. flush the data in the buffer > > =This statement seems to suggest that if there is already some data in > the buffer, it will be wiped. Not recommended! > > We check if any data in the buffer if it does, we flush them to the disk > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1948) > > > =Have replaced the next steps, see below for your consideration:- > > >? ? ? ? ? 1. If succeed: > >? ? ? ? ? ? ? 1. create a new buffer object. > >? ? ? ? ? ? ? 2. fill the new buffer with data return from raw write > >? ? ? ? ? 2. If failed: > >? ? ? ? ? ? ? 1. Shifting the buffer to make room for writing data > to the > > buffer > >? ? ? ? ? ? ? 2. Buffer as much writing data as possible (may raise > > BlockingIOError) > >? ? ? 2. return the data > > After above transfer from data-source (1) to "buffer" (2): > > * if len( data in "buffer" ) >= size (3): output > ? ? ? ? else: keep going > > * output: > ? ? ? ? shift size(3) from "buffer" to output > ? ? ? ? retain 'the rest' in/as "buffer" > > NB if the size (2) of data in "buffer" is/could be multiples of size > (3), then the "output" function should/could become a loop, ie keep > emptying the "buffer" until size (2) < size (3). > > > Finally, don't forget the special cases: > What happens if we reach 'the end' (of 'input' or 'output' phase), and > there is still data in (1) or (2)? > Presumably, in "Read" we would discard (1), but in the case of "Write" > we MUST empty "buffer" (2), even if it means the last write is of less > than size (3). > > Yes, you are right, when we are writing data to the buffer and the > buffer is full, we have to flush it. > > NB The 'rules' for the latter may vary between use-cases, eg add > 'stuffing' if the output record MUST be x-bytes long. > > > Hope this helps. > Do you need to hand-code this stuff though, or is there a better way? > > I'm trying to write an article for it :D Perhaps it would help to discuss the use-case you will use as the article's example. "I take a crash course" cf "write an article"??? Web-Refs: Wikipedia: https://en.wikipedia.org/wiki/Data_buffer The PSL's IO library (?the code you've been reading): https://docs.python.org/3.6/library/io.html?highlight=buffer#io.TextIOBase.buffer The PSL's Readline library (which may be easier to visualise for desktop-type users/coders - unless you're into IoT applications and similar) https://docs.python.org/3.6/library/readline.html?highlight=buffer PSL's Buffer protocol, in case you really want to 're-invent the wheel', but with some possibly-helpful explanation: https://docs.python.org/3.6/c-api/buffer.html?highlight=buffer -- Regards =dn From flebber.crue at gmail.com Sun Jun 23 23:41:57 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 23 Jun 2019 20:41:57 -0700 (PDT) Subject: generator to write N lines to file Message-ID: Afternoon Trying to create a generator to write the first N lines of text to a file. However, I keep receiving the islice object not the text, why? from itertools import islice fileName = dir / "7oldsamr.txt" dumpName = dir / "dump.txt" def getWord(infile, lineNum): with open(infile, 'r+') as f: lines_gen = islice(f, lineNum) yield lines_gen for line in getWord(fileName, 5): with open(dumpName, 'a') as f: f.write(line) Thanks, Sayth From __peter__ at web.de Mon Jun 24 02:26:15 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 24 Jun 2019 08:26:15 +0200 Subject: generator to write N lines to file References: Message-ID: Sayth Renshaw wrote: > Afternoon > > Trying to create a generator to write the first N lines of text to a file. > However, I keep receiving the islice object not the text, why? > > from itertools import islice > > fileName = dir / "7oldsamr.txt" > dumpName = dir / "dump.txt" > > def getWord(infile, lineNum): > with open(infile, 'r+') as f: > lines_gen = islice(f, lineNum) > yield lines_gen To get the individual lines you have to yield them for line in lines_gen: yield line This can be rewritten with some syntactic sugar as yield from lines_gen > for line in getWord(fileName, 5): > with open(dumpName, 'a') as f: > f.write(line) Note that getWord as written does not close the infile when you break out of the loop, e. g. for line in getWord(filename, 5): break To avoid that you can use a context manager: from itertools import islice from contextlib import contextmanager infile = ... outfile = ... @contextmanager def head(infile, numlines): with open(infile) as f: yield islice(f, numlines) with open(outfile, "w") as f: with head(infile, 5) as lines: f.writelines(lines) From mal at europython.eu Mon Jun 24 03:45:38 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 24 Jun 2019 09:45:38 +0200 Subject: EuroPython 2019: Schedule is online Message-ID: <342aa8a1-ea4c-db45-0f08-b78a8eb28ea6@europython.eu> We are pleased to announce the EuroPython 2019 schedule. We will again have more than 130 sessions in total, held by more than 130 speakers. Schedule for EuroPython 2019 * https://ep2019.europython.eu/events/schedule/ * Please note that the schedule may still change in details, but the overall layout is fixed now. Book your EuroPython 2019 Ticket -------------------------------- Please make sure you book your ticket in the coming days. We will switch to late bird rates next week. If you want to attend the training sessions, please buy a training pass in addition to your conference ticket, or get a combined ticket. We only have very few training seats left. Travel & accommodation tips --------------------------- Since we?re close the conference, Basel is in high demand. If you?re having problems finding a hotel, please also consider searching for apartments on the well known booking sites. We have collected a number of recommendations for accommodation and travel to Basel on the EuroPython 2019 website. If you get a hotel or apartment in Basel, you will additionally get a BaselCard for your stay, which allows you to use public transport in Basel for free. Please see our accommodation page for details. Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185811587232/europython-2019-schedule-is-online Tweet: https://twitter.com/europython/status/1143061849446989824 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From sagar.jape.1 at gmail.com Sun Jun 23 09:27:33 2019 From: sagar.jape.1 at gmail.com (Sagar Jape) Date: Sun, 23 Jun 2019 18:57:33 +0530 Subject: No subject Message-ID: I'm not able to install pip in my pc it gives following error. what should I do? From joel.goldstick at gmail.com Mon Jun 24 05:24:05 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 24 Jun 2019 05:24:05 -0400 Subject: No subject In-Reply-To: References: Message-ID: On Mon, Jun 24, 2019 at 4:13 AM Sagar Jape wrote: > > I'm not able to install pip in my pc it gives following error. what should > I do? > -- > https://mail.python.org/mailman/listinfo/python-list Copy and paste your session info. The list doesn't show images. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From barry at barrys-emacs.org Mon Jun 24 04:42:33 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 24 Jun 2019 09:42:33 +0100 Subject: User failed to install PIP In-Reply-To: References: Message-ID: I guess you attached an image of the error message. I also going to guess that you are a windows user. All attachments are stripped on this list. You will need to explain in text what you did and what the error message was. Note that PIP is install when you install python. Have you installed python? Once python is installed you can run PIP like this: C:\Users\barry> py -m pip Usage: C:\Python37.win64\python.exe -m pip [options] Barry > On 23 Jun 2019, at 14:27, Sagar Jape wrote: > > I'm not able to install pip in my pc it gives following error. what should > I do? > -- > https://mail.python.org/mailman/listinfo/python-list > From pkpearson at nowhere.invalid Mon Jun 24 12:36:15 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 24 Jun 2019 16:36:15 GMT Subject: finding a component in a list of pairs References: Message-ID: [snip] > print( dict( pairs ).get( 'sun', '(unknown)' )) You probably know this, but . . . just in case . . . If you're doing this many times, you'll want to construct the dict just once and then make many references to the dict, rather than re-constructing the dict every time you want to look up an element. -- To email me, substitute nowhere->runbox, invalid->com. From wiwindson at gmail.com Mon Jun 24 19:29:35 2019 From: wiwindson at gmail.com (Windson Yang) Date: Tue, 25 Jun 2019 07:29:35 +0800 Subject: Understand workflow about reading and writing files in Python In-Reply-To: References: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> <0f657d54-dc31-666c-b2a6-c8c88969f351@DancesWithMice.info> Message-ID: When you said "C-runtime buffered I/O", are you talking about Standard I/O in C (FILE * object)? AFAIN, In CPython, we didn't use Standard I/O, right? Dennis Lee Bieber ?2019?6?25??? ??12:48??? > On Mon, 24 Jun 2019 15:18:26 +1200, DL Neil > declaimed the following: > > > > > >However, the OpSys may have read considerably more data, depending upon > >the device(s) involved, the application, etc; eg if we ask for 2 bytes > >the operating system will read a much larger block (or applicable unit) > >of data from a disk drive. > > > > Depending upon implementation, there could be layers of buffers > involved... > > Python application requests, say, 50 bytes using a "buffered I/O" > file > object. That file object may invoke a C-runtime buffered I/O call that > requests whatever the C-runtime buffer-size is -- say a 512 byte sector. > That request goes to a low-level device driver for a file system/device > that does I/O in 4KB clusters. So the first read results in the OS reading > 4KB into a buffer, and passing 512 bytes to the C-call, which then returns > 50 bytes to the Python layer. > > The second read for 50 bytes is satisfied from the remaining bytes > in > the C-runtime sector buffer. The 11th read of 50 bytes will get 12 bytes > from the sector, and then the C-runtime has to request the next sector from > the OS, which is satisfied from the file system cluster buffer. After the > 8th sector is processed, the next request results in the OS going to disk > for the next cluster. > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com > http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From wiwindson at gmail.com Mon Jun 24 19:50:33 2019 From: wiwindson at gmail.com (Windson Yang) Date: Tue, 25 Jun 2019 07:50:33 +0800 Subject: Understand workflow about reading and writing files in Python In-Reply-To: <0f657d54-dc31-666c-b2a6-c8c88969f351@DancesWithMice.info> References: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> <0f657d54-dc31-666c-b2a6-c8c88969f351@DancesWithMice.info> Message-ID: DL Neil ?2019?6?24??? ??11:18??? > Yes, better to reply to list - others may 'jump in'... > > > On 20/06/19 5:37 PM, Windson Yang wrote: > > Thank you so much for you review DL Neil, it really helps :D. However, > > there are some parts still confused me, I replyed as below. > > It's not a particularly easy topic... > > > > DL Neil > > ?2019?6?19??? ??2:03??? > > > > I've not gone 'back' to refer to any ComSc theory on > buffer-management. > > Perhaps you might benefit from such? > > > > I just take a crash course on it so I want to know if I understand the > > details correctly :D > > ...there are so many ways one can mess-up! > > > > I like your use of the word "shift", so I'll continue to use it. > > > > There are three separate units of data to consider - each of which > > could > > be called a "buffer". To avoid confusing (myself) I'll only call the > > 'middle one' that: > > 1 the unit of data 'coming' from the data-source > > 2 the "buffer" you are implementing > > 3 the unit of data 'going' out to a data-destination. > > > > Just to make it clear, when we use `f.write('abc')` in python, (1) means > > 'abc', (2) means the buffer handle by Python (by default 8kb), (2) means > > the file *f* we are writing to, right? > > Sorry, this is my typo, (3) means the file *f* we are writing to, right? > No! (sorry) f.write() is an output operation, thus nr3. > > "f" is not a "buffer handle" but a "file handle" or more accurately a > "file object". > > When we: > > one_input = f.read( NRbytes ) > > (ignoring EOF/short file and other exceptions) that many bytes will > 'appear' in our program labelled as "one_input". > > However, the OpSys may have read considerably more data, depending upon > the device(s) involved, the application, etc; eg if we ask for 2 bytes > the operating system will read a much larger block (or applicable unit) > of data from a disk drive. > > The same applies in reverse, with f.write( NRbytes/byte-object ), until > we flush or close the file. > > Those situations account for nr1 and nr3. In the usual case, we have no > control over the size of these buffers - and it is best not to meddle! > > I agreed with you. Hence:- > > > 1 and 3 may be dictated to you, eg hardware or file specifications, > > code > > requirements, etc. > > > > So, data is shifted into the (2) buffer in a unit-size decided by > (1) - > > in most use-cases each incoming unit will be the same size, but > > remember > > that the last 'unit' may/not be full-size. Similarly, data shifted > out > > from the (2) buffer to (3). > > > > The size of (1) is likely not that of (3) - otherwise why use a > > "buffer"? The size of (2) must be larger than (1) and larger than > (2) - > > for reasons already illustrated. > > > > Is this a typo? (2) larger than (1) larger than (2)? > > Correct - well spotted! nr2 > nr1 and nr2 > nr3 > When we run 'f.write(100', I understand why nr2 (by defaut 8kb) > nr1 (100), but I'm not sure why nr2 > nr3 (file object) here? > > > > I recall learning how to use buffers with a series of hand-drawn > block > > diagrams. Recommend you try similarly! > > Try this! > > > > Now, let's add a few critiques, as requested (interposed below):- > > > > > > On 19/06/19 3:53 PM, Windson Yang wrote:t > > > I'm trying to understand the workflow of how Python read/writes > > data with > > > buffer. I will be appreciated if someone can review it. > > > > > > ### Read n data > > > > - may need more than one read operation if the size of (3) "demands" > > more data than the size of (1)/one "read". > > > > > > Looks like the size of len of one read() depends on > > > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1655 > ? > > > You decide how many bytes should be read. That's how much will be > transferred from the OpSys' I/O into the Python program's space. With > the major exception, that if there is no (more) data available, it is > defined as an exception (EOF = end of file) or if there are fewer bytes > of data than requested (in which case you will be given only the number > of bytes of data-available. > > > > > 1. If the data already in the buffer, return data > > > > - this a data-transfer of size (3) > > > > For extra credit/an unnecessary complication (but probable > speed-up!): > > * if the data-remaining is less than size (3) consider a read-ahead > > mechanism > > > > > 2. If the data not in the buffer: > > > > - if buffer's data-len < size (3) > > > > > 1. copy all the current data from the buffer > > > > * if "buffer" is my (2), then no-op > > > > I don't understand your point here, when we read data we would copy some > > data from the current buffer from python, right? > > ( > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1638), > > > we use `out` (which point to res) to store the data here. > > We're becoming confused: the original heading 'here' was "### Read n > data" which is inconsistent with "out" and "from python". > > > If the read operation is set to transfer (say) 2KB into the program at a > time, but the code processes it in 100B units, then it would seem that > after the first read, twenty process loops will run before it is > necessary to issue another input request. > > In that example, the buffer (nr2) is twenty-times the length of the > input 'buffer' (nr1). > > So, from the second to the twentieth iteration of the process, your > step-1 "1. If the data already in the buffer, return data" (and thus my > "no-op) applies! > > This is a major advantage of having a buffer in the first place - > transfers within RAM are significantly faster than I/O operations! > > Yes, that is what I trying to say. Looks like I should add more details for the code. > > > > 2. create a new buffer object, fill the new buffer with raw > > read which > > > read data from disk. > > > > * this becomes: perform read operation and append incoming data (size > > (1)) to "buffer" - hence why "buffer" is larger than (1), by > definition. > > NB if size (1) is smaller than size (3), multiple read operations > > may be > > necessary. Thus a read-loop!? > > > > Yes, you are right, here is a while loop > > ( > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1652) > > > > > > > > > > 3. concat the data in the old buffer and new buffer. > > > > = now no-op. Hopefully the description of 'three buffers' removes > this > > confusion of/between buffers. > > > > I don't get it. When we call the function like seek(0) then > > read(1000), we can still use the data from buffer from python, right? > > I fear that we are having terminology issues - see the original > description of three 'buffers'. Which "buffer" are you talking about? > 1 the seek/read are carried-out against a file object, which will indeed > have its own buffer, size unknown to Python. (buffer 1) > 2 the read(1000) operation will (on its own) allow you to populate a > buffer within your code, 1000-bytes in length. (buffer 2) > > Is the file object in has its own buffer? Does it only happen when we use Standard I/O (FILE*)? I'm not sure I used it in CPython, or maybe I missed something. > > > > 4. return the data > > > > * make the above steps into a while-loop and there won't be a > separate > > step here (it is the existing step 1!) > > > > > > * build all of the above into a function/method, so that the > 'mainline' > > only has to say 'give me data'! > > > > > > > ### Write n data > > > 1. If data small enough to fill into the buffer, write data to > > the buffer > > > > =yes, the data coming from source (1), which in this case is 'your' > > code > > may/not be sufficient to fill the output size (3). So, load it into > the > > "buffer" (2). > > > > > 2. If data can't fill into the buffer > > > 1. flush the data in the buffer > > > > =This statement seems to suggest that if there is already some data > in > > the buffer, it will be wiped. Not recommended! > > > > We check if any data in the buffer if it does, we flush them to the disk > > ( > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1948) > > > > > > > =Have replaced the next steps, see below for your consideration:- > > > > > 1. If succeed: > > > 1. create a new buffer object. > > > 2. fill the new buffer with data return from raw > write > > > 2. If failed: > > > 1. Shifting the buffer to make room for writing data > > to the > > > buffer > > > 2. Buffer as much writing data as possible (may raise > > > BlockingIOError) > > > 2. return the data > > > > After above transfer from data-source (1) to "buffer" (2): > > > > * if len( data in "buffer" ) >= size (3): output > > else: keep going > > > > * output: > > shift size(3) from "buffer" to output > > retain 'the rest' in/as "buffer" > > > > NB if the size (2) of data in "buffer" is/could be multiples of size > > (3), then the "output" function should/could become a loop, ie keep > > emptying the "buffer" until size (2) < size (3). > > > > > > Finally, don't forget the special cases: > > What happens if we reach 'the end' (of 'input' or 'output' phase), > and > > there is still data in (1) or (2)? > > Presumably, in "Read" we would discard (1), but in the case of > "Write" > > we MUST empty "buffer" (2), even if it means the last write is of > less > > than size (3). > > > > Yes, you are right, when we are writing data to the buffer and the > > buffer is full, we have to flush it. > > > > NB The 'rules' for the latter may vary between use-cases, eg add > > 'stuffing' if the output record MUST be x-bytes long. > > > > > > Hope this helps. > > Do you need to hand-code this stuff though, or is there a better way? > > > > I'm trying to write an article for it :D > > > Perhaps it would help to discuss the use-case you will use as the > article's example. > > "I take a crash course" cf "write an article"??? > > > Web-Refs: > > Wikipedia: https://en.wikipedia.org/wiki/Data_buffer > > The PSL's IO library (?the code you've been reading): > > https://docs.python.org/3.6/library/io.html?highlight=buffer#io.TextIOBase.buffer > > The PSL's Readline library (which may be easier to visualise for > desktop-type users/coders - unless you're into IoT applications and > similar) > https://docs.python.org/3.6/library/readline.html?highlight=buffer > > PSL's Buffer protocol, in case you really want to 're-invent the wheel', > but with some possibly-helpful explanation: > https://docs.python.org/3.6/c-api/buffer.html?highlight=buffer > > > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From flebber.crue at gmail.com Tue Jun 25 01:10:52 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 24 Jun 2019 22:10:52 -0700 (PDT) Subject: generator to write N lines to file In-Reply-To: References: Message-ID: <2fe3871d-fa77-46d9-b19c-0a72f73552d3@googlegroups.com> > To get the individual lines you have to yield them > > for line in lines_gen: > yield line > > This can be rewritten with some syntactic sugar as > > yield from lines_gen > > > for line in getWord(fileName, 5): > > with open(dumpName, 'a') as f: > > f.write(line) > > Note that getWord as written does not close the infile when you break out of > the loop, e. g. > > for line in getWord(filename, 5): > break > > To avoid that you can use a context manager: > > from itertools import islice > from contextlib import contextmanager > > infile = ... > outfile = ... > > @contextmanager > def head(infile, numlines): > with open(infile) as f: > yield islice(f, numlines) > > with open(outfile, "w") as f: > with head(infile, 5) as lines: > f.writelines(lines) Thank You Peter great advice as always. Sayth From eraygezer.94 at gmail.com Tue Jun 25 06:47:32 2019 From: eraygezer.94 at gmail.com (Eray Erdin) Date: Tue, 25 Jun 2019 13:47:32 +0300 Subject: About Messages on Installs Message-ID: Greetings, dear community members, I sometimes use npm and, in the installation process, some packages throw messages regarding to warnings or info/survey URLs. I wish to use something similar in a package I maintain. Is it possible to print some data to users' terminal in the installation process? Even if so, would it be considered a good practice? Many thanks in advance. Eray Erdin From PythonList at DancesWithMice.info Tue Jun 25 16:34:51 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 26 Jun 2019 08:34:51 +1200 Subject: Understand workflow about reading and writing files in Python In-Reply-To: References: <373ccbb4-ad2a-3ec8-97f8-6d0c8c9cb719@DancesWithMice.info> <0f657d54-dc31-666c-b2a6-c8c88969f351@DancesWithMice.info> Message-ID: <4c0318a6-368b-a097-8f3e-3aeb489a5c19@DancesWithMice.info> On 25/06/19 11:50 AM, Windson Yang wrote: > DL Neil > ?2019?6?24??? ??11:18??? > Yes, better to reply to list - others may 'jump in'... > On 20/06/19 5:37 PM, Windson Yang wrote: > > Thank you so much for you review DL Neil, it really helps :D. > However, > > there are some parts still confused me, I replyed as below. > It's not a particularly easy topic... > > DL Neil > > >> ?2019?6?19??? ?? > 2:03??? ... > ...there are so many ways one can mess-up! > >? ? ?I like your use of the word "shift", so I'll continue to use it. > >? ? ?There are three separate units of data to consider - each of > which > >? ? ?could > >? ? ?be called a "buffer". To avoid confusing (myself) I'll only > call the > >? ? ?'middle one' that: > >? ? ?1 the unit of data 'coming' from the data-source > >? ? ?2 the "buffer" you are implementing > >? ? ?3 the unit of data 'going' out to a data-destination. > > > > Just to make it clear, when we use `f.write('abc')` in python, > (1) means > > 'abc', (2) means the buffer handle by Python (by default 8kb), > (2) means > > the file *f* we are writing to, right? > Sorry, this is my typo, (3) means the file *f* we are writing to, right? Correct. - to avoid exactly this sort of confusion it is best NOT to use short names but to (carefully) choose meaningful variable-names! How about: 1 "input_file" (I'd prefer to add context, eg "expenses_file") and 3 "output_file" (again... "expenses_summary") > No! (sorry) f.write() is an output operation, thus nr3. > > "f" is not a "buffer handle" but a "file handle" or more accurately a > "file object". > > When we: > > ? ? ? ? one_input = f.read( NRbytes ) > > (ignoring EOF/short file and other exceptions) that many bytes will > 'appear' in our program labelled as "one_input". > > However, the OpSys may have read considerably more data, depending upon > the device(s) involved, the application, etc; eg if we ask for 2 bytes > the operating system will read a much larger block (or applicable unit) > of data from a disk drive. > > The same applies in reverse, with f.write( NRbytes/byte-object ), until > we flush or close the file. > > Those situations account for nr1 and nr3. In the usual case, we have no > control over the size of these buffers - and it is best not to meddle! > > I agreed with you. > > Hence:- > > >? ? ?1 and 3 may be dictated to you, eg hardware or file > specifications, > >? ? ?code > >? ? ?requirements, etc. > > > >? ? ?So, data is shifted into the (2) buffer in a unit-size > decided by (1) - > >? ? ?in most use-cases each incoming unit will be the same size, but > >? ? ?remember > >? ? ?that the last 'unit' may/not be full-size. Similarly, data > shifted out > >? ? ?from the (2) buffer to (3). > > > >? ? ?The size of (1) is likely not that of (3) - otherwise why use a > >? ? ?"buffer"? The size of (2) must be larger than (1) and larger > than (2) - > >? ? ?for reasons already illustrated. > > > > Is this a typo? (2) larger than (1) larger than (2)? > > Correct - well spotted! nr2 > nr1 and nr2 > nr3 > > > When we run 'f.write(100', I understand why nr2 (by defaut 8kb) > nr1 > (100), but I'm not sure why nr2 > nr3 (file object) here? The program's internal string or data-structure MUST be as large or larger than the output size. If the output file requires three fields of four kilobytes each, that's 12KB. If the internal buffer is only 1KB in length, how will it satisfy the 12KB specification? That said, a classic 'out by one' error. The earlier text should have said "len(nr2) >= len(nr3)"! > >? ? ?I recall learning how to use buffers with a series of > hand-drawn block > >? ? ?diagrams. Recommend you try similarly! > > Try this! > > > >? ? ?Now, let's add a few critiques, as requested (interposed below):- > > > > > >? ? ?On 19/06/19 3:53 PM, Windson Yang wrote:t > >? ? ? > I'm trying to understand the workflow of how Python > read/writes > >? ? ?data with > >? ? ? > buffer. I will be appreciated if someone can review it. > >? ? ? > > >? ? ? > ### Read n data > > > >? ? ?- may need more than one read operation if the size of (3) > "demands" > >? ? ?more data than the size of (1)/one "read". > > > > > > Looks like the size of len of one read() depends on > > > https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1655?? > > > You decide how many bytes should be read. That's how much will be > transferred from the OpSys' I/O into the Python program's space. With > the major exception, that if there is no (more) data available, it is > defined as an exception (EOF = end of file) or if there are fewer bytes > of data than requested (in which case you will be given only the number > of bytes of data-available. > > > >? ? ? > 1. If the data already in the buffer, return data > > > >? ? ?- this a data-transfer of size (3) > > > >? ? ?For extra credit/an unnecessary complication (but probable > speed-up!): > >? ? ?* if the data-remaining is less than size (3) consider a > read-ahead > >? ? ?mechanism > > > >? ? ? > 2. If the data not in the buffer: > > > >? ? ?- if buffer's data-len < size (3) > > > >? ? ? >? ? ? 1. copy all the current data from the buffer > > > >? ? ?* if "buffer" is my (2), then no-op > > > > I don't understand your point here, when we read data we would > copy some > > data from the current buffer from python, right? > > > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1638), > > > we use `out` (which point to res) to store the data here. > > We're becoming confused: the original heading 'here' was "### Read n > data" which is inconsistent with "out" and "from python". > > > If the read operation is set to transfer (say) 2KB into the program > at a > time, but the code processes it in 100B units, then it would seem that > after the first read, twenty process loops will run before it is > necessary to issue another input request. > > In that example, the buffer (nr2) is twenty-times the length of the > input 'buffer' (nr1). > > So, from the second to the twentieth iteration of the process, your > step-1 "1. If the data already in the buffer, return data" (and thus my > "no-op) applies! > > This is a major advantage of having a buffer in the first place - > transfers within RAM are significantly faster than I/O operations! > > Yes, that is what I trying to say. Looks like I should add more details > for the code. Code? Didn't you talk about an article? If you are coding, please see earlier comment (and web-refs) to save your time and the pitfalls inherent in 're-inventing the wheel'. > >? ? ? >? ? ? 2. create a new buffer object, fill the new buffer > with raw > >? ? ?read which > >? ? ? > read data from disk. > > > >? ? ?* this becomes: perform read operation and append incoming > data (size > >? ? ?(1)) to "buffer" - hence why "buffer" is larger than (1), by > definition. > >? ? ?NB if size (1) is smaller than size (3), multiple read operations > >? ? ?may be > >? ? ?necessary. Thus a read-loop!? > > > > Yes, you are right, here is a while loop > > > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1652) > > > > > > > > >? ? ? >? ? ? 3. concat the data in the old buffer and new buffer. > > > >? ? ?= now no-op. Hopefully the description of 'three buffers' > removes this > >? ? ?confusion of/between buffers. > > > >? ?I don't get it. When we call the function like seek(0) then > > read(1000), we can still use the data from buffer from python, right? > > I fear that we are having terminology issues - see the original > description of three 'buffers'. Which "buffer" are you talking about? > 1 the seek/read are carried-out against a file object, which will > indeed > have its own buffer, size unknown to Python. (buffer 1) > 2 the read(1000) operation will (on its own) allow you to populate a > buffer within your code, 1000-bytes in length. (buffer 2) > > Is the file object in has its own buffer?? Does it only happen when we > use Standard I/O (FILE*)? I'm not sure I used it in CPython, or maybe I > missed something. Yes, the standard Python facilities/APIs provide access to or otherwise supplement OpSys interfaces (and thus the hardware (or whatever) buffer). NB the i/o buffer (nrs1 and 3) may not be 'addressable' from Python code, other than by a read/write operation (and similar). All we do is read/write (etc) and Python + OpSys do the rest: ie take care of 'the gory details'. If you want to get 'down-and-dirty', I suspect you'll need to move to another (lower-level) language(?) > >? ? ? >? ? ? 4. return the data > > > >? ? ?* make the above steps into a while-loop and there won't be a > separate > >? ? ?step here (it is the existing step 1!) > > > > > >? ? ?* build all of the above into a function/method, so that the > 'mainline' > >? ? ?only has to say 'give me data'! > > > > > >? ? ? > ### Write n data > >? ? ? > 1. If data small enough to fill into the buffer, write data to > >? ? ?the buffer > > > >? ? ?=yes, the data coming from source (1), which in this case is > 'your' > >? ? ?code > >? ? ?may/not be sufficient to fill the output size (3). So, load > it into the > >? ? ?"buffer" (2). > > > >? ? ? > 2. If data can't fill into the buffer > >? ? ? >? ? ? 1. flush the data in the buffer > > > >? ? ?=This statement seems to suggest that if there is already > some data in > >? ? ?the buffer, it will be wiped. Not recommended! > > > > We check if any data in the buffer if it does, we flush them to > the disk > > > (https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1948) > > > > > > >? ? ?=Have replaced the next steps, see below for your consideration:- > > > >? ? ? >? ? ? ? ? 1. If succeed: > >? ? ? >? ? ? ? ? ? ? 1. create a new buffer object. > >? ? ? >? ? ? ? ? ? ? 2. fill the new buffer with data return from > raw write > >? ? ? >? ? ? ? ? 2. If failed: > >? ? ? >? ? ? ? ? ? ? 1. Shifting the buffer to make room for > writing data > >? ? ?to the > >? ? ? > buffer > >? ? ? >? ? ? ? ? ? ? 2. Buffer as much writing data as possible > (may raise > >? ? ? > BlockingIOError) > >? ? ? >? ? ? 2. return the data > > > >? ? ?After above transfer from data-source (1) to "buffer" (2): > > > >? ? ?* if len( data in "buffer" ) >= size (3): output > >? ? ? ? ? ? ? else: keep going > > > >? ? ?* output: > >? ? ? ? ? ? ? shift size(3) from "buffer" to output > >? ? ? ? ? ? ? retain 'the rest' in/as "buffer" > > > >? ? ?NB if the size (2) of data in "buffer" is/could be multiples > of size > >? ? ?(3), then the "output" function should/could become a loop, > ie keep > >? ? ?emptying the "buffer" until size (2) < size (3). > > > > > >? ? ?Finally, don't forget the special cases: > >? ? ?What happens if we reach 'the end' (of 'input' or 'output' > phase), and > >? ? ?there is still data in (1) or (2)? > >? ? ?Presumably, in "Read" we would discard (1), but in the case > of "Write" > >? ? ?we MUST empty "buffer" (2), even if it means the last write > is of less > >? ? ?than size (3). > > > > Yes, you are right, when we are writing data to the buffer and the > > buffer is full, we have to flush it. > > > >? ? ?NB The 'rules' for the latter may vary between use-cases, eg add > >? ? ?'stuffing' if the output record MUST be x-bytes long. > > > > > >? ? ?Hope this helps. > >? ? ?Do you need to hand-code this stuff though, or is there a > better way? > > > > I'm trying to write an article for it :D > > > Perhaps it would help to discuss the use-case you will use as the > article's example. > > "I take a crash course" cf "write an article"??? > > > Web-Refs: > > Wikipedia: https://en.wikipedia.org/wiki/Data_buffer > > The PSL's IO library (?the code you've been reading): > https://docs.python.org/3.6/library/io.html?highlight=buffer#io.TextIOBase.buffer > > The PSL's Readline library (which may be easier to visualise for > desktop-type users/coders - unless you're into IoT applications and > similar) > https://docs.python.org/3.6/library/readline.html?highlight=buffer > > PSL's Buffer protocol, in case you really want to 're-invent the > wheel', > but with some possibly-helpful explanation: > https://docs.python.org/3.6/c-api/buffer.html?highlight=buffer -- Regards =dn From flebber.crue at gmail.com Wed Jun 26 02:13:13 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 25 Jun 2019 23:13:13 -0700 (PDT) Subject: pandas split and melt() Message-ID: Hi Having fun with pandas filtering a work excel file. My current script opens selected and filters the data and saves as excel. import pandas as pd import numpy as np log = pd.read_excel("log_dump_py.xlsx") df = log.filter(items=['Completed', 'Priority', 'Session date', 'Consultant', 'Coach', 'Delivery Method', 'Focus of Coaching', 'Leader', 'Site', 'Coaching Description','Motor/Property', ],) completed_tasks = df.loc[(df['Completed'] == 'Yes') & (df['Motor/Property'] == 'Motor') & (df['Delivery Method'] == 'Group Coaching')] print(completed_tasks.head(n=5)) completed_tasks.to_excel("filtered_logs.xlsx") This leaves me with a set of several columns. The main column of concern for this example is a consultant Session date Consultant 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, Colem;#17230; How can I split the consultant column, keep only names and drop the numbers and for every session date create a line with data and consultants name? NB. There are varied amounts of consultants so splitting across columns is uneven. if it was even melt seems like it would be good https://dfrieds.com/data-analysis/melt-unpivot-python-pandas Thanks Sayth From PythonList at DancesWithMice.info Wed Jun 26 02:29:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 26 Jun 2019 18:29:59 +1200 Subject: pandas split and melt() In-Reply-To: References: Message-ID: <3130ebbe-4d5d-257f-9c18-ba0733bc1dc2@DancesWithMice.info> On 26/06/19 6:13 PM, Sayth Renshaw wrote: > Hi > Having fun with pandas filtering a work excel file. > My current script opens selected and filters the data and saves as excel. ... > This leaves me with a set of several columns. The main column of concern for this example is a consultant > Session date Consultant > 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, Colem;#17230; > > How can I split the consultant column, keep only names and drop the numbers and for every session date create a line with data and consultants name? > NB. There are varied amounts of consultants so splitting across columns is uneven. if it was even melt seems like it would be good https://dfrieds.com/data-analysis/melt-unpivot-python-pandas Keep it simple: https://docs.python.org/3.6/library/string.html -- Regards =dn From flebber.crue at gmail.com Wed Jun 26 02:46:12 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 25 Jun 2019 23:46:12 -0700 (PDT) Subject: pandas split and melt() In-Reply-To: References: <3130ebbe-4d5d-257f-9c18-ba0733bc1dc2@DancesWithMice.info> Message-ID: <388079b1-d396-478c-9108-05b071889c66@googlegroups.com> > > NB. There are varied amounts of consultants so splitting across columns is uneven. if it was even melt seems like it would be good https://dfrieds.com/data-analysis/melt-unpivot-python-pandas > > Keep it simple: https://docs.python.org/3.6/library/string.html > > -- > Regards =dn I have managed to split but not filter the numbers. All other code being the same. ... completed_tasks = df.loc[(df['Completed'] == 'Yes') & (df['Motor/Property'] == 'Motor') & (df['Delivery Method'] == 'Group Coaching')] completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";") pattern = "\\#d" completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";") completed_tasks['Consultant'] = completed_tasks['Consultant'].str.contains(pattern) ... Works without the regex which causes this error AttributeError: Can only use .str accessor with string values, which use np.object_ dtype pattern = "\\#d" completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";") Sayth From flebber.crue at gmail.com Wed Jun 26 03:05:23 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 26 Jun 2019 00:05:23 -0700 (PDT) Subject: pandas split and melt() In-Reply-To: <388079b1-d396-478c-9108-05b071889c66@googlegroups.com> References: <3130ebbe-4d5d-257f-9c18-ba0733bc1dc2@DancesWithMice.info> <388079b1-d396-478c-9108-05b071889c66@googlegroups.com> Message-ID: <1a17f140-36fc-4ee1-81ac-f57673ccd386@googlegroups.com> Update. Option 1. - This annihilates all text in the column leaving nothing. completed_tasks['Consultant'] = completed_tasks['Consultant'].str.rstrip('.#123') Option 2. - returns unhashable series list. output = completed_tasks[completed_tasks['Consultant']].str.contains(r'/\b[^\d\W]+\b/g') neither option works as the column is a list. Thanks Sayth From ar at zeit.io Wed Jun 26 03:46:07 2019 From: ar at zeit.io (Arup Rakshit) Date: Wed, 26 Jun 2019 13:16:07 +0530 Subject: Pytest share fixture data across the class methods Message-ID: <64107A82-2FB5-4C73-9526-D85E64044152@zeit.io> Hi, I am using pytest to test my flask end points. I have grouped tests related to all unauthenticated access in a class as you see below: @pytest.mark.usefixtures("client_class") class TestUnauthorizedRecipesAcces: def test_update_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.put( url_for("recipes.recipes_api", _method="PUT", id=recipe.id), json={"inactive": "10 min", "level": "easy"}, ).status_code == 401 ) def test_delete_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.delete( url_for("recipes.recipes_api", _method="DELETE", id=recipe.id) ).status_code == 401 ) def test_fetch_a_recipe(self, create_recipe_record): recipe = create_recipe_record( { "cook": "9 min", "inactive": "20 min", "level": "Easy", "prep": "5 min", "title": "Grilled Salmon I", "total": "34 min", "yields": "6 servings", } ) assert ( self.client.get( url_for("recipes.recipes_api", _method="GET", id=recipe.id) ).status_code == 401 ) def test_attach_a_category_to_a_recipe( self, create_recipe_record, create_category_record ): recipe = create_recipe_record( { "cook": "45 min", "inactive": "", "level": "", "prep": "30 min", "title": "Grilled Salmon II", "total": "1 hr 15 min", "yields": "4 servings", } ) category = create_category_record({"title": "Grilled Chicken"}) assert ( self.client.post( url_for( "recipe_categories.recipe_categories_api", _method="POST", recipe_id=recipe.id, ), json={"id": category.id}, ).status_code == 401 ) def test_remove_a_category_from_a_recipe( self, create_recipe_record, create_category_record ): recipe = create_recipe_record( { "cook": "45 min", "inactive": "", "level": "", "prep": "30 min", "title": "Grilled Salmon II", "total": "1 hr 15 min", "yields": "4 servings", } ) category = create_category_record({"title": "Grilled Chicken"}) recipe.add_category(category.id) assert ( self.client.delete( url_for( "recipe_categories.recipe_categories_api", _method="DELETE", recipe_id=recipe.id, id=category.id, ) ).status_code == 401 ) Those test data I created to build urls, other than that there are no used of category, recipe records in this group. I was wondering if pytest can help to share the data across all the methods instead of creating them everytime in each method as I did above. Can you suggest me some tricks? I am looking for something like: @pytest.mark.usefixtures("client_class") class TestUnauthorizedRecipesAcces: # .... def test_remove_a_category_from_a_recipe(self): assert ( self.client.delete( url_for( "recipe_categories.recipe_categories_api", _method="DELETE", recipe_id=self.recipe.id, id=self.category.id, ) ).status_code == 401 ) How can I achieve this. Fixtures create_recipe_record, create_category_record are created in contest.py file as a function scope (https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/tests/conftest.py) . The tests can be seen here https://gitlab.com/aruprakshit/flask_awesome_recipes/blob/master/tests/test_recipes.py#L253 . Please give me some directions. Thanks, Arup Rakshit ar at zeit.io From __peter__ at web.de Wed Jun 26 04:13:55 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Jun 2019 10:13:55 +0200 Subject: pandas split and melt() References: Message-ID: Sayth Renshaw wrote: > Hi > > Having fun with pandas filtering a work excel file. > My current script opens selected and filters the data and saves as excel. > > import pandas as pd > import numpy as np > > log = pd.read_excel("log_dump_py.xlsx") > df = log.filter(items=['Completed', 'Priority', 'Session date', > 'Consultant', 'Coach', > 'Delivery Method', 'Focus of Coaching', 'Leader', 'Site', > 'Coaching Description','Motor/Property', > ],) > completed_tasks = df.loc[(df['Completed'] == 'Yes') & > (df['Motor/Property'] == 'Motor') & (df['Delivery Method'] == 'Group > Coaching')] print(completed_tasks.head(n=5)) > completed_tasks.to_excel("filtered_logs.xlsx") > > This leaves me with a set of several columns. The main column of concern > for this example is a consultant > > Session date Consultant > 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, > Colem;#17230; > > How can I split the consultant column, keep only names and drop the > numbers and for every session date create a line with data and consultants > name? > > NB. There are varied amounts of consultants so splitting across columns is > uneven. if it was even melt seems like it would be good > https://dfrieds.com/data-analysis/melt-unpivot-python-pandas > > > Thanks > > Sayth Since I didn't find a cool shortcut I decided to use brute force: $ cat pandas_explode_column.py import pandas as pd df = pd.DataFrame( [ [ "2019-06-21 11:15:00", "WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, Colem;#17230;" ], [ "2019-06-22 10:00:00", "Doe, John;#42;Robbins, Rita;" ] ], columns=["Session date", "Consultant"] ) def explode_consultants(consultants): consultants = (c.lstrip("#") for c in consultants.split(";")) return (c for c in consultants if c.strip("0123456789")) def explode_column(df, column, split): for _index, row in df.iterrows(): for part in split(row[column]): yield [part if c == column else row[c] for c in df.columns] def explode(df, column, split): return pd.DataFrame( explode_column(df, "Consultant", split), columns=df.columns ) df2 = explode(df, "Consultant", explode_consultants) print(df) print(df2) $ python3 pandas_explode_column.py Session date Consultant 0 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE... 1 2019-06-22 10:00:00 Doe, John;#42;Robbins, Rita; [2 rows x 2 columns] Session date Consultant 0 2019-06-21 11:15:00 WNEWSKI, Joan 1 2019-06-21 11:15:00 BALIN, Jock 2 2019-06-21 11:15:00 DUNE, Colem 3 2019-06-22 10:00:00 Doe, John 4 2019-06-22 10:00:00 Robbins, Rita [5 rows x 2 columns] $ From mal at europython.eu Wed Jun 26 04:27:39 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 26 Jun 2019 10:27:39 +0200 Subject: EuroPython 2019: Mobile Conference App available Message-ID: We are pleased to announce the mobile conference app for EuroPython 2019, again hosted on the Attendify platform: EuroPython 2019 Conference App * https://ep2019.europython.eu/events/conference-app/ * Engage with the conference and its attendees -------------------------------------------- The mobile app gives you access to the conference schedule (even offline), helps you in planing your conference experience (create your personal schedule with reminders) and provides a rich social engagement platform for all attendees. You can create a profile within the app or link this to your existing social accounts, share messages and photos, and easily reach out to other fellow attendees - all from within the app. Vital for all EuroPython 2019 attendees --------------------------------------- We will again use the conference app to keep you updated by sending updates of the schedule and inform you of important announcements via push notifications, so please consider downloading it. Many useful features -------------------- Please see our EuroPython 2019 Conference App page for more details on features and guides on how to use them. https://ep2019.europython.eu/events/conference-app/ Don?t forget to get your EuroPython ticket ------------------------------------------ If you want to join the EuroPython fun, be sure to get your tickets as soon as possible. https://ep2019.europython.eu/registration/buy-tickets/ Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). The schedule is available at: https://ep2019.europython.eu/events/schedule/ Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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://blog.europython.eu/post/185858710877/europython-2019-mobile-conference-app-available Tweet: https://twitter.com/europython/status/1143796573702434817 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From khandelwalrajat963 at gmail.com Wed Jun 26 04:32:39 2019 From: khandelwalrajat963 at gmail.com (khandelwalrajat963 at gmail.com) Date: Wed, 26 Jun 2019 01:32:39 -0700 (PDT) Subject: File not able to link from drive Message-ID: <1d964c95-e05e-4afd-a9bc-900fbae0daac@googlegroups.com> I am running a code to connect the google drive with google colab.But I have a issue after connection.My Files are not able to read by google colab even after link is established . I have to read files from google drive in Google colab My Code.... !pip install -U -q PyDrive from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from google.colab import auth from oauth2client.client import GoogleCredentials # Authenticate and create the PyDrive client. auth.authenticate_user() gauth = GoogleAuth() gauth.credentials = GoogleCredentials.get_application_default() drive = GoogleDrive(gauth) I am also try this but still no results.. from google.colab import drive drive.mount('/content/drive') From flebber.crue at gmail.com Wed Jun 26 04:53:24 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 26 Jun 2019 01:53:24 -0700 (PDT) Subject: pandas split and melt() In-Reply-To: References: Message-ID: <3dc807aa-77e0-47bc-8e2f-c65684bae684@googlegroups.com> > > Since I didn't find a cool shortcut I decided to use brute force: > > $ cat pandas_explode_column.py > import pandas as pd > > df = pd.DataFrame( > [ > [ > "2019-06-21 11:15:00", > "WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, Colem;#17230;" > ], > [ > "2019-06-22 10:00:00", "Doe, John;#42;Robbins, Rita;" > ] > ], > columns=["Session date", "Consultant"] > ) > > def explode_consultants(consultants): > consultants = (c.lstrip("#") for c in consultants.split(";")) > return (c for c in consultants if c.strip("0123456789")) > > def explode_column(df, column, split): > for _index, row in df.iterrows(): > for part in split(row[column]): > yield [part if c == column else row[c] for c in df.columns] > > def explode(df, column, split): > return pd.DataFrame( > explode_column(df, "Consultant", split), columns=df.columns > ) > > df2 = explode(df, "Consultant", explode_consultants) > > print(df) > print(df2) > $ python3 pandas_explode_column.py > Session date Consultant > 0 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE... > 1 2019-06-22 10:00:00 Doe, John;#42;Robbins, Rita; > > [2 rows x 2 columns] > Session date Consultant > 0 2019-06-21 11:15:00 WNEWSKI, Joan > 1 2019-06-21 11:15:00 BALIN, Jock > 2 2019-06-21 11:15:00 DUNE, Colem > 3 2019-06-22 10:00:00 Doe, John > 4 2019-06-22 10:00:00 Robbins, Rita > > [5 rows x 2 columns] > $ Mind a little blown :-). Going to have to play and break this several times to fully get it. Thanks Sayth From __peter__ at web.de Wed Jun 26 07:08:56 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Jun 2019 13:08:56 +0200 Subject: pandas split and melt() References: <3dc807aa-77e0-47bc-8e2f-c65684bae684@googlegroups.com> Message-ID: Sayth Renshaw wrote: > Peter Otten wrote: >> def explode_consultants(consultants): Should have called that split_consultants(); takes a string and >> consultants = (c.lstrip("#") for c in consultants.split(";")) splits by ";", removes leading "#" >> return (c for c in consultants if c.strip("0123456789")) filters out the digit-only values. >> def explode_column(df, column, split): >> for _index, row in df.iterrows(): iterates over the rows of the data frame >> for part in split(row[column]): iterates over the names extracted by explode_consultants() from the "Consultants" field >> yield [part if c == column else row[c] for c in df.columns] Makes one row per consultant, replacing the contents of the Consultants column with the current consultant (bound to the part variable, e. g. with part = "Doe, John" yield [ "Doe, John" if c == "Consultants" else row[c] for c in ["Session Date", "Consultants"] ] >> def explode(df, column, split): Make a new data frame from the rows generated by explode_column(), reusing the column names from the original data frame. >> return pd.DataFrame( >> explode_column(df, "Consultant", split), columns=df.columns Here's a bug -- "Consultant" is hardcoded, but the column argument should be instead. >> ) >> df2 = explode(df, "Consultant", explode_consultants) >> >> print(df) >> print(df2) >> $ python3 pandas_explode_column.py >> Session date Consultant >> 0 2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE... >> 1 2019-06-22 10:00:00 Doe, John;#42;Robbins, Rita; >> >> [2 rows x 2 columns] >> Session date Consultant >> 0 2019-06-21 11:15:00 WNEWSKI, Joan >> 1 2019-06-21 11:15:00 BALIN, Jock >> 2 2019-06-21 11:15:00 DUNE, Colem >> 3 2019-06-22 10:00:00 Doe, John >> 4 2019-06-22 10:00:00 Robbins, Rita >> >> [5 rows x 2 columns] >> $ > > Mind a little blown :-). Going to have to play and break this several > times to fully get it. Here's another usage example for explode() which "explodes" the "ham" column using range(): >>> df3 = pd.DataFrame([[2, "foo"], [3, "bar"], [0, "baz"]], columns=["ham", "spam"]) >>> explode(df3, "ham", range) ham spam 0 0 foo 1 1 foo 2 0 bar 3 1 bar 4 2 bar [5 rows x 2 columns] From Cecil at decebal.nl Wed Jun 26 07:02:11 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 13:02:11 +0200 Subject: Copying a row from a range of Excel files to another Message-ID: <8736jwfw3w.fsf@munus.decebal.nl> I was asked to copy a certain line from about 300 Excel lines to a new Excel file. That is not something I would like to do by hand and I immediately thought: that should be possible with Python. And it is. I was surprised how fast I could write that with openpyxl. My first try was not very neat, but a proof of concept. Then by looking better at the possibilities I could get much cleaner code. But I am still not completely happy. At the moment I have the following code: wb_out = Workbook() for filepath in filepathArr: current_row = [] wb_in = load_workbook(filepath) for cell in wb_in.active[src_row]: current_row.append(cell.value) wb_out.active.append(current_row) wb_in.close() wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) wb_out.close() I could not find a way to copy a row from one workbook to another. That is why I put the row in current_row and do an append. Am I overlooking something, or is that really the way to do this? I am not used to writing GUI programs. (I have to learn tkinter also.) What is the best way to handle potential errors? It could go wrong on line 1, 4, 5, 7, 8, 9 and 10. Should I catch every exception alone, or all together, or something in between? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 07:41:39 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 13:41:39 +0200 Subject: Creating a Windows executable on a Linux system Message-ID: <87tvccefpo.fsf@munus.decebal.nl> I need to write a Python desktop program. I create it on a Linux system, but it has to run on a Windows system. When looking at how to create an executable it seems that you need to be on a Windows system to create a Windows executable. Is this true, or is it possible to create a Windows executable on a Linux system? Any pointers about best practice creating a standalone executable are welcome. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 07:25:15 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 13:25:15 +0200 Subject: Make sure the window title is visible in tkinter Message-ID: <87y31oegh0.fsf@munus.decebal.nl> I need to write a desktop program. I choose to use tkinter. How can I make sure the window title is visible? For example when I have the following code: from tkinter import Button, filedialog, Label, messagebox, Tk window = Tk() window.title('A long window title') Button (window, text = 'Short text').pack() window.mainloop() I see only a part of the 'A', but I would like to see the complete: 'A long window title' -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 07:55:41 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 13:55:41 +0200 Subject: What type of error is it Message-ID: <87pnn0ef2a.fsf@munus.decebal.nl> I am writing a GUI program with tkinter. One function I have is: def select_dir(): try: directory = filedialog.askdirectory() if directory == '': messagebox.showinfo(info_str, canceled_report) return chdir(directory) filepathArr = sorted(glob(regex)) if len(filepathArr) == 0: messagebox.showwarning(warning_str, nofiles_str) return generate_report(filepathArr) except: messagebox.showerror(error_str, error_select_str) raise I use the raise to see what the exception was. That works, because tkinter takes over again. This works for me when I run it from the command-line, but it has to become a stand-alone executable. Is there a way to find out what the cause of the exception was, so I can put it in the error message? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From peter.heitzer at rz.uni-regensburg.de Wed Jun 26 08:10:45 2019 From: peter.heitzer at rz.uni-regensburg.de (Peter Heitzer) Date: 26 Jun 2019 12:10:45 GMT Subject: Creating a Windows executable on a Linux system References: <87tvccefpo.fsf@munus.decebal.nl> Message-ID: Cecil Westerhof wrote: >I need to write a Python desktop program. I create it on a Linux >system, but it has to run on a Windows system. When looking at how to >create an executable it seems that you need to be on a Windows system >to create a Windows executable. Is this true, or is it possible to >create a Windows executable on a Linux system? >Any pointers about best practice creating a standalone executable are >welcome. Is using a portable Python installation an option? -- Dipl.-Inform(FH) Peter Heitzer, peter.heitzer at rz.uni-regensburg.de From Cecil at decebal.nl Wed Jun 26 08:06:36 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 14:06:36 +0200 Subject: What type of error is it References: <87pnn0ef2a.fsf@munus.decebal.nl> Message-ID: <87lfxoeek3.fsf@munus.decebal.nl> Cecil Westerhof writes: > I am writing a GUI program with tkinter. One function I have is: > def select_dir(): > try: > directory = filedialog.askdirectory() > if directory == '': > messagebox.showinfo(info_str, canceled_report) > return > chdir(directory) > filepathArr = sorted(glob(regex)) > if len(filepathArr) == 0: > messagebox.showwarning(warning_str, nofiles_str) > return > generate_report(filepathArr) > except: > messagebox.showerror(error_str, error_select_str) > raise > > I use the raise to see what the exception was. That works, because > tkinter takes over again. > This works for me when I run it from the command-line, but it has to > become a stand-alone executable. Is there a way to find out what the > cause of the exception was, so I can put it in the error message? Found it. I just need to change the last three lines to: except Exception as err: messagebox.showerror(error_str, error_select_str + '\n\n\n\n' + str(err)) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 08:15:36 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 14:15:36 +0200 Subject: Copying a row from a range of Excel files to another References: <8736jwfw3w.fsf@munus.decebal.nl> Message-ID: <87h88cee53.fsf@munus.decebal.nl> Cecil Westerhof writes: > I was asked to copy a certain line from about 300 Excel lines to a new > Excel file. That is not something I would like to do by hand and I > immediately thought: that should be possible with Python. > > And it is. I was surprised how fast I could write that with openpyxl. > My first try was not very neat, but a proof of concept. Then by > looking better at the possibilities I could get much cleaner code. But > I am still not completely happy. At the moment I have the following > code: > wb_out = Workbook() > for filepath in filepathArr: > current_row = [] > wb_in = load_workbook(filepath) > for cell in wb_in.active[src_row]: > current_row.append(cell.value) > wb_out.active.append(current_row) > wb_in.close() > wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) > wb_out.close() > > I could not find a way to copy a row from one workbook to another. > That is why I put the row in current_row and do an append. Am I > overlooking something, or is that really the way to do this? > > > I am not used to writing GUI programs. (I have to learn tkinter also.) > What is the best way to handle potential errors? It could go wrong on > line 1, 4, 5, 7, 8, 9 and 10. Should I catch every exception alone, or > all together, or something in between? I rewrote it like: wb_in = None wb_out = None try: wb_out = Workbook() for filepath in filepathArr: current_row = [] wb_in = load_workbook(filepath) for cell in wb_in.active[src_row]: current_row.append(cell.value) wb_out.active.append(current_row) wb_in.close() wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) wb_out.close() messagebox.showinfo(info_str, created_report) except Exception as err: if wb_in: wb_in.close() if wb_out: wb_close messagebox.showerror(error_str, error_generate + '\n\n\n\n' + str(err)) Is it necessary to close the workbooks to circumvent a resource leak? Is it a problem when a workbook is closed two times? If so I need to make sure that this is not possible. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From best_lay at yahoo.com Wed Jun 26 08:47:00 2019 From: best_lay at yahoo.com (Wildman) Date: Wed, 26 Jun 2019 07:47:00 -0500 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> Message-ID: On Wed, 26 Jun 2019 13:25:15 +0200, Cecil Westerhof wrote: > I need to write a desktop program. I choose to use tkinter. How can I > make sure the window title is visible? For example when I have the > following code: > from tkinter import Button, filedialog, Label, messagebox, Tk > > > window = Tk() > window.title('A long window title') > Button (window, text = 'Short text').pack() > window.mainloop() > > I see only a part of the 'A', but I would like to see the complete: > 'A long window title' According to link below, it is not possible... "Tkinter has no way of knowing how long the title is on the titlebar." https://stackoverflow.com/questions/35273690/tkinter-window-not-wide-enough-to-display-window-title -- 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 Cecil at decebal.nl Wed Jun 26 08:47:32 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 14:47:32 +0200 Subject: Creating a Windows executable on a Linux system References: <87tvccefpo.fsf@munus.decebal.nl> Message-ID: <87d0j0ecnv.fsf@munus.decebal.nl> "Peter Heitzer" writes: > Cecil Westerhof wrote: >>I need to write a Python desktop program. I create it on a Linux >>system, but it has to run on a Windows system. When looking at how to >>create an executable it seems that you need to be on a Windows system >>to create a Windows executable. Is this true, or is it possible to >>create a Windows executable on a Linux system? > >>Any pointers about best practice creating a standalone executable are >>welcome. > Is using a portable Python installation an option? That is not supported anymore. But they pointed to WinPython. I will look into that/ One important thing is that the application uses openpyxl and tkinter. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 09:07:35 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 15:07:35 +0200 Subject: Copying a row from a range of Excel files to another References: <8736jwfw3w.fsf@munus.decebal.nl> <87h88cee53.fsf@munus.decebal.nl> Message-ID: <874l4cebqg.fsf@munus.decebal.nl> Cecil Westerhof writes: > Is it necessary to close the workbooks to circumvent a resource > leak? Still like to know. When not necessary it is better not to cloes them I think. > Is it a problem when a workbook is closed two times? If so I need to > make sure that this is not possible. That is not a problem. I tried it and it just works. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Jun 26 09:05:15 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 15:05:15 +0200 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> Message-ID: <878stoebuc.fsf@munus.decebal.nl> Wildman writes: > On Wed, 26 Jun 2019 13:25:15 +0200, Cecil Westerhof wrote: > >> I need to write a desktop program. I choose to use tkinter. How can I >> make sure the window title is visible? For example when I have the >> following code: >> from tkinter import Button, filedialog, Label, messagebox, Tk >> >> >> window = Tk() >> window.title('A long window title') >> Button (window, text = 'Short text').pack() >> window.mainloop() >> >> I see only a part of the 'A', but I would like to see the complete: >> 'A long window title' > > According to link below, it is not possible... > "Tkinter has no way of knowing how long the title is on the titlebar." > > https://stackoverflow.com/questions/35273690/tkinter-window-not-wide-enough-to-display-window-title OK, then I will have to live with it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From cousinstanley at gmail.com Wed Jun 26 10:03:50 2019 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 26 Jun 2019 07:03:50 -0700 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> Message-ID: Cecil Westerhof wrote: > I need to write a desktop program. I choose to use tkinter. > > How can I make sure the window title is visible? For example > when I have the following code : > from tkinter import Button, filedialog, Label, messagebox, Tk > > > window = Tk() > window.title('A long window title') > Button (window, text = 'Short text').pack() > window.mainloop() > > I see only a part of the 'A', but I would like to see > the complete : > > 'A long window title' > You might try setting a given window geometry to accomodate the long title .... win_w = 400 win_h = 300 ofs_h = 40 ofs_v = 30 window.geometry( "%dx%d+%d+%d" % ( win_w , win_h , ofs_h , ofs_v ) ) Maybe add a bit of extra space for users with different default font sizes .... Not a general solution but perhaps workable .... -- Stanley C. Kitching Human Being Phoenix, Arizona From grant.b.edwards at gmail.com Wed Jun 26 10:16:17 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 26 Jun 2019 14:16:17 -0000 (UTC) Subject: Creating a Windows executable on a Linux system References: <87tvccefpo.fsf@munus.decebal.nl> Message-ID: On 2019-06-26, Cecil Westerhof wrote: > [...] it seems that you need to be on a Windows system to create a > Windows executable. Is this true, or is it possible to create a > Windows executable on a Linux system? AFIAK, you have to use a Windows system to create a windows executable. In the past, I used py2exe+InnoSetup for both tkinter and wxPython Windows apps. But, py2exe seems to be a dead project and the last time I tried to use it (a couple years ago) I couldn't get it to work on recent Windows+Python versions. Currently I use cx_freeze+InnoSetup for tkinter apps. (I no longer have any wxPython apps I maintain for Windows.) Another popular option is PyInstaller, but I've never tried it. http://www.py2exe.org/ https://anthony-tuininga.github.io/cx_Freeze/ https://www.pyinstaller.org/ http://www.jrsoftware.org/isinfo.php -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com From grant.b.edwards at gmail.com Wed Jun 26 10:21:07 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 26 Jun 2019 14:21:07 -0000 (UTC) Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> Message-ID: On 2019-06-26, Cousin Stanley wrote: > You might try setting a given window geometry > to accomodate the long title .... > [...] > window.geometry( "%dx%d+%d+%d" % ( win_w , win_h , ofs_h , ofs_v ) ) > Maybe add a bit of extra space for users with different default > font sizes .... IIRC, there is a way to get tkInter to render a string in a particular font so that you can then find out how wide the result is in pixels. It's been a long time since I needed to do that, and it was a bit of a hassle. I'm not sure how you would make sure it's rendered in the same font as the window title. -- Grant Edwards grant.b.edwards Yow! I'm a fuschia bowling at ball somewhere in Brittany gmail.com From Cecil at decebal.nl Wed Jun 26 11:47:39 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 17:47:39 +0200 Subject: Hiding a progressbar in tkinter Message-ID: <87zhm4cpr8.fsf@munus.decebal.nl> I just started with GUI stuff in tkinter. I have a progressbar, but I want it to be only visible when it is used. So I tried the following: window = Tk() window.title(window_str) frame = Frame(window) frame.pack(side = "top", fill = "both", expand = True) Button(window, text = button_str, command = select_dir).pack() progress = ttk.Progressbar(window, orient = "horizontal", length = 200, mode = "determinate") progress.pack() progress.lower(frame) window.mainloop() But that does not hide the progressbar. What am I doing wrong? I could use pack_forget, but that will change the dimensions of the window. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From david at aeolia.co.uk Wed Jun 26 12:30:31 2019 From: david at aeolia.co.uk (David Sumbler) Date: Wed, 26 Jun 2019 17:30:31 +0100 Subject: Creating a Windows executable on a Linux system In-Reply-To: <87tvccefpo.fsf@munus.decebal.nl> References: <87tvccefpo.fsf@munus.decebal.nl> Message-ID: <1d7cd2ff0efbc8f3876aa8bc0014b50e216092db.camel@aeolia.co.uk> On Wed, 2019-06-26 at 13:41 +0200, Cecil Westerhof wrote: > I need to write a Python desktop program. I create it on a Linux > system, but it has to run on a Windows system. When looking at how to > create an executable it seems that you need to be on a Windows system > to create a Windows executable. Is this true, or is it possible to > create a Windows executable on a Linux system? > > Any pointers about best practice creating a standalone executable are > welcome. I'm no expert, but installing pyinstaller in wine works for me. I admit, though, that I have only tried it with one file, which I wanted to send to my brother. I'm using Ubuntu 18.04, and the command: wine ~/.wine/drive_c/Python34/Scripts/pyinstaller.exe --onefile bin/GradientProfile_v2.py produces a file that my brother can run on his Windows 10 machine. David From best_lay at yahoo.com Wed Jun 26 13:16:55 2019 From: best_lay at yahoo.com (Wildman) Date: Wed, 26 Jun 2019 12:16:55 -0500 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> <878stoebuc.fsf@munus.decebal.nl> Message-ID: On Wed, 26 Jun 2019 15:05:15 +0200, Cecil Westerhof wrote: >> OK, then I will have to live with it. I did find some references to a method where you first disable the Tkinter title bar using overrideredirect(True). Then you create a new title bar using a frame and canvas. You can then set the font/size for the canvas. I think you could do it with a label but if you want an icon and close (X) button, that could be a problem. IFAIK you can have only one image on a label. -- GNU/Linux user #557453 "I am Lrrr! Ruler of the planet Omicron Persei 8! Can I crash on your couch?" -Lrrr From best_lay at yahoo.com Wed Jun 26 14:21:09 2019 From: best_lay at yahoo.com (Wildman) Date: Wed, 26 Jun 2019 13:21:09 -0500 Subject: Hiding a progressbar in tkinter References: <87zhm4cpr8.fsf@munus.decebal.nl> Message-ID: On Wed, 26 Jun 2019 17:47:39 +0200, Cecil Westerhof wrote: > I just started with GUI stuff in tkinter. I have a progressbar, but I > want it to be only visible when it is used. So I tried the following: > window = Tk() > window.title(window_str) > frame = Frame(window) > frame.pack(side = "top", fill = "both", expand = True) > Button(window, text = button_str, command = select_dir).pack() > progress = ttk.Progressbar(window, orient = "horizontal", length = 200, > mode = "determinate") > progress.pack() > progress.lower(frame) > window.mainloop() > > But that does not hide the progressbar. What am I doing wrong? > > I could use pack_forget, but that will change the dimensions of the > window. Here is an example using grid_forget(). https://stackoverflow.com/questions/33768577/tkinter-gui-with-progress-bar Disclaimer: I have not tested this code and cannot say for certain that it will work the way you want. -- GNU/Linux user #557453 "Be vewy vewy qwiwet, I'm hunting wabbits." -Elmer Fudd From python at mrabarnett.plus.com Wed Jun 26 14:58:41 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 26 Jun 2019 19:58:41 +0100 Subject: Hiding a progressbar in tkinter In-Reply-To: <87zhm4cpr8.fsf@munus.decebal.nl> References: <87zhm4cpr8.fsf@munus.decebal.nl> Message-ID: <7ac72ae4-fb60-7bb6-9f3e-97c50b49e838@mrabarnett.plus.com> On 2019-06-26 16:47, Cecil Westerhof wrote: > I just started with GUI stuff in tkinter. I have a progressbar, but I > want it to be only visible when it is used. So I tried the following: > window = Tk() > window.title(window_str) > frame = Frame(window) > frame.pack(side = "top", fill = "both", expand = True) > Button(window, text = button_str, command = select_dir).pack() > progress = ttk.Progressbar(window, orient = "horizontal", length = 200, > mode = "determinate") > progress.pack() > progress.lower(frame) > window.mainloop() > > But that does not hide the progressbar. What am I doing wrong? > > I could use pack_forget, but that will change the dimensions of the > window. > The progress bar isn't hidden because there's nothing on top of it to hide it. import tkinter as tk import tkinter.ttk as ttk window = tk.Tk() window.title(window_str) frame = tk.Frame(window) frame.pack(side='top', fill='both', expand=True) tk.Button(window, text=button_str, command=select_dir).pack() # Create a frame to hold the progress bar. progress_frame = tk.Frame(window) progress_frame.pack(fill='x', expand=True) # Put the progress bar into the progress frame, ensuring that it fills the grid cell. progress = ttk.Progressbar(progress_frame, orient='horizontal', length=200, mode='determinate') progress.grid(row=0, column=0, sticky='nsew') # Now put a blank frame into the progress frame over the progress bar, ensuring that it fills the same grid cell. blank = tk.Frame(progress_frame) blank.grid(row=0, column=0, sticky='nsew') # Raise the progress bar over the blank frame to reveal it. progress.tkraise() # Lower the progress bar underneath the blank frame to hide it. progress.lower() window.mainloop() From python at mrabarnett.plus.com Wed Jun 26 15:07:23 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 26 Jun 2019 20:07:23 +0100 Subject: Copying a row from a range of Excel files to another In-Reply-To: <87h88cee53.fsf@munus.decebal.nl> References: <8736jwfw3w.fsf@munus.decebal.nl> <87h88cee53.fsf@munus.decebal.nl> Message-ID: <46943943-46a7-7bac-c336-50dc5b730349@mrabarnett.plus.com> On 2019-06-26 13:15, Cecil Westerhof wrote: > Cecil Westerhof writes: > >> I was asked to copy a certain line from about 300 Excel lines to a new >> Excel file. That is not something I would like to do by hand and I >> immediately thought: that should be possible with Python. >> >> And it is. I was surprised how fast I could write that with openpyxl. >> My first try was not very neat, but a proof of concept. Then by >> looking better at the possibilities I could get much cleaner code. But >> I am still not completely happy. At the moment I have the following >> code: >> wb_out = Workbook() >> for filepath in filepathArr: >> current_row = [] >> wb_in = load_workbook(filepath) >> for cell in wb_in.active[src_row]: >> current_row.append(cell.value) >> wb_out.active.append(current_row) >> wb_in.close() >> wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) >> wb_out.close() >> >> I could not find a way to copy a row from one workbook to another. >> That is why I put the row in current_row and do an append. Am I >> overlooking something, or is that really the way to do this? >> >> >> I am not used to writing GUI programs. (I have to learn tkinter also.) >> What is the best way to handle potential errors? It could go wrong on >> line 1, 4, 5, 7, 8, 9 and 10. Should I catch every exception alone, or >> all together, or something in between? > > I rewrote it like: > wb_in = None > wb_out = None > try: > wb_out = Workbook() > for filepath in filepathArr: > current_row = [] > wb_in = load_workbook(filepath) > for cell in wb_in.active[src_row]: > current_row.append(cell.value) > wb_out.active.append(current_row) > wb_in.close() > wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) > wb_out.close() > messagebox.showinfo(info_str, created_report) > except Exception as err: > if wb_in: > wb_in.close() > if wb_out: Missing (): > wb_close > messagebox.showerror(error_str, > error_generate + '\n\n\n\n' + str(err)) > > Is it necessary to close the workbooks to circumvent a resource leak? > Is it a problem when a workbook is closed two times? If so I need to > make sure that this is not possible. > Does Workbook support the 'with' statement? If it does, then that's the best way of doing it. (Untested) with Workbook() as wb_out: for filepath in filepathArr: current_row = [] with load_workbook(filepath) as wb_in: for cell in wb_in.active[src_row]: current_row.append(cell.value) wb_out.active.append(current_row) wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) From thecjguy1 at gmail.com Wed Jun 26 17:21:50 2019 From: thecjguy1 at gmail.com (Chris Roberts) Date: Wed, 26 Jun 2019 14:21:50 -0700 (PDT) Subject: for line3 in myips matching too longer matches. Message-ID: ### CODE: elif line1.rstrip(?\n?) in line2.strip(?\n?): for line3 in myips: print ?###? print ?line1 is %s? % line1.rstrip(?\n?) print ?line2 is %s? % line2.strip(?\n?) ### OUTPUT: line1 is 10.10.168.2 line2 is - address: 10.10.168.27 # myhost ### I think the problem is here: line1.rstrip(?\n?) in line2.strip(?\n?): I want it to match only 10.10.168.2 AND 10.10.168.2: NOT match 10.10.168.2[0-9] If someone out there knows a simple solution. I would love to see it. Thanks in advance. crzzy1 From Cecil at decebal.nl Wed Jun 26 17:14:19 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 26 Jun 2019 23:14:19 +0200 Subject: Copying a row from a range of Excel files to another References: <8736jwfw3w.fsf@munus.decebal.nl> <87h88cee53.fsf@munus.decebal.nl> <46943943-46a7-7bac-c336-50dc5b730349@mrabarnett.plus.com> Message-ID: <87v9wscams.fsf@munus.decebal.nl> MRAB writes: > Does Workbook support the 'with' statement? > > If it does, then that's the best way of doing it. > > (Untested) > > with Workbook() as wb_out: > for filepath in filepathArr: > current_row = [] > > with load_workbook(filepath) as wb_in: > for cell in wb_in.active[src_row]: > current_row.append(cell.value) > > wb_out.active.append(current_row) > > wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + > report_end) It seems not. I get AttributeError. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From cs at cskk.id.au Wed Jun 26 19:08:11 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 27 Jun 2019 09:08:11 +1000 Subject: for line3 in myips matching too longer matches. In-Reply-To: References: Message-ID: <20190626230811.GA77454@cskk.homeip.net> On 26Jun2019 14:21, Chris Roberts wrote: > >### >CODE: > elif line1.rstrip(?\n?) in line2.strip(?\n?): > for line3 in myips: > print ?###? > print ?line1 is %s? % line1.rstrip(?\n?) > print ?line2 is %s? % line2.strip(?\n?) >### >OUTPUT: >line1 is 10.10.168.2 >line2 is - address: 10.10.168.27 # myhost >### > >I think the problem is here: >line1.rstrip(?\n?) in line2.strip(?\n?): > >I want it to >match only 10.10.168.2 AND 10.10.168.2: >NOT match 10.10.168.2[0-9] > >If someone out there knows a simple solution. I would love to see it. Well the usual solution is to break line2 in to "words". When you go: '10.10.168.2' in ' - address: 10.10.168.27 # myhost' you're testing a substring match. But if you go: '10.10.168.2' in ['-', 'address:', '10.10.168.27', '#', 'myhost'] it does a membership test i.e. does the _exact string_ '10.10.168.2' occur in this list of strings. (This isn't magic, the "in" operator uses an object's __contains__ method (or falls back to iteration and comparison), so the nature of the test is driven by the type of the object being tested (on the right, for "in")). So... address = line1.rstrip('\n') words = line2.split() if address in words: ... Personally I'd be being pickier about line1 as well, but ifyour input is well defined that may not matter. Cheers, Cameron Simpson From python at mrabarnett.plus.com Wed Jun 26 20:34:41 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 27 Jun 2019 01:34:41 +0100 Subject: Copying a row from a range of Excel files to another In-Reply-To: <87v9wscams.fsf@munus.decebal.nl> References: <8736jwfw3w.fsf@munus.decebal.nl> <87h88cee53.fsf@munus.decebal.nl> <46943943-46a7-7bac-c336-50dc5b730349@mrabarnett.plus.com> <87v9wscams.fsf@munus.decebal.nl> Message-ID: On 2019-06-26 22:14, Cecil Westerhof wrote: > MRAB writes: > >> Does Workbook support the 'with' statement? >> >> If it does, then that's the best way of doing it. >> >> (Untested) >> >> with Workbook() as wb_out: >> for filepath in filepathArr: >> current_row = [] >> >> with load_workbook(filepath) as wb_in: >> for cell in wb_in.active[src_row]: >> current_row.append(cell.value) >> >> wb_out.active.append(current_row) >> >> wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + >> report_end) > > It seems not. I get AttributeError. > You didn't say which line. Anyway, if Workbooks are closed using a method called "close", you can wrap them in a "closing" context manager: from contextlib import closing with closing(Workbook()) as wb_out: for filepath in filepathArr: current_row = [] with closing(load_workbook(filepath)) as wb_in: for cell in wb_in.active[src_row]: current_row.append(cell.value) wb_out.active.append(current_row) wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) From flebber.crue at gmail.com Wed Jun 26 20:37:03 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 26 Jun 2019 17:37:03 -0700 (PDT) Subject: for line3 in myips matching too longer matches. In-Reply-To: References: Message-ID: <5dbec65f-d7c0-4655-89f5-1f5cae2721b6@googlegroups.com> Chris Roberts wrote: > ### > CODE: > elif line1.rstrip(?\n?) in line2.strip(?\n?): > for line3 in myips: > print ?###? > print ?line1 is %s? % line1.rstrip(?\n?) > print ?line2 is %s? % line2.strip(?\n?) > ### > OUTPUT: > line1 is 10.10.168.2 > line2 is - address: 10.10.168.27 # myhost > ### > > I think the problem is here: > line1.rstrip(?\n?) in line2.strip(?\n?): > > I want it to > match only 10.10.168.2 AND 10.10.168.2: > NOT match 10.10.168.2[0-9] > > If someone out there knows a simple solution. I would love to see it. > Thanks in advance. > crzzy1 Not sure exactly what the input is but a comprehension would do this. [x for x in input_line.split(' ') if == '10.10.168.2'] Cheers Sayth From flebber.crue at gmail.com Wed Jun 26 20:45:12 2019 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 26 Jun 2019 17:45:12 -0700 (PDT) Subject: Copying a row from a range of Excel files to another In-Reply-To: <8736jwfw3w.fsf@munus.decebal.nl> References: <8736jwfw3w.fsf@munus.decebal.nl> Message-ID: Cecil Westerhof wrote: > I was asked to copy a certain line from about 300 Excel lines to a new > Excel file. That is not something I would like to do by hand and I > immediately thought: that should be possible with Python. > > And it is. I was surprised how fast I could write that with openpyxl. > My first try was not very neat, but a proof of concept. Then by > looking better at the possibilities I could get much cleaner code. But > I am still not completely happy. At the moment I have the following > code: > wb_out = Workbook() > for filepath in filepathArr: > current_row = [] > wb_in = load_workbook(filepath) > for cell in wb_in.active[src_row]: > current_row.append(cell.value) > wb_out.active.append(current_row) > wb_in.close() > wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + report_end) > wb_out.close() > > I could not find a way to copy a row from one workbook to another. > That is why I put the row in current_row and do an append. Am I > overlooking something, or is that really the way to do this? > > > > -- > Cecil Westerhof Pandas may work out better. import pandas as pd df = pd.read_excel('spreadsheet') # find the row by filtering with regex df2 = df.'column'.str.contains('criteria as regex') df2.pd.save_excel('output.xlsx') Cheers Sayth From adam.preble at gmail.com Thu Jun 27 20:13:27 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Thu, 27 Jun 2019 17:13:27 -0700 (PDT) Subject: Plumbing behind super() Message-ID: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> I'm trying to mimick Python 3.6 as a .NET science project and have started to get into subclassing. The super() not-a-keyword-honestly-guys has tripped me up. I have to admit that I've professionally been doing a ton Python 2.7, so I'm not good on my Python 3.6 trivia yet. I think I have the general gist of this, but want some affirmation. If you use super() in a method, all it does is load super as a global on to the interpreter stack and call it without any arguments. So I'm left to wonder how it's able to figure anything out when it's being literally given nothing... except that it's not being given literally nothing: static PyObject * super_getattro(PyObject *self, PyObject *name) I was thinking maybe self has become more special in Python 3.6, but I don't think that's true since I've ported code to Python3 before that had inner classes where I'd use "inner_self" to disambiguate with the outer self. And though I thought it was so at first, it just turned out I screwed up my little code snippet to expose it. If self was special then I presume I could find it in my lookups and inject it. So how do I go from CALL_FUNCTION on a super() global without anything else on the stack to somehow having all the information I need? Is there something tracking that I'm in an object scope when calling stuff? From PythonList at DancesWithMice.info Thu Jun 27 21:29:50 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 28 Jun 2019 13:29:50 +1200 Subject: Plumbing behind super() In-Reply-To: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> Message-ID: <70e7ae59-7dea-74b2-8263-61673df0daef@DancesWithMice.info> On 28/06/19 12:13 PM, adam.preble at gmail.com wrote: > I'm trying to mimick Python 3.6 as a .NET science project and have started to get into subclassing. The super() not-a-keyword-honestly-guys has tripped me up. I have to admit that I've professionally been doing a ton Python 2.7, so I'm not good on my Python 3.6 trivia yet. I think I have the general gist of this, but want some affirmation. > > If you use super() in a method, all it does is load super as a global on to the interpreter stack and call it without any arguments. So I'm left to wonder how it's able to figure anything out when it's being literally given nothing... ... > I was thinking maybe self has become more special in Python 3.6, but I don't think that's true since I've ported code to Python3 before that had inner classes where I'd use "inner_self" to disambiguate with the outer self. And though I thought it was so at first, it just turned out I screwed up my little code snippet to expose it. If self was special then I presume I could find it in my lookups and inject it. > > So how do I go from CALL_FUNCTION on a super() global without anything else on the stack to somehow having all the information I need? Is there something tracking that I'm in an object scope when calling stuff? You are missing quite a bit by not becoming familiar with Python2 -> 3 differences! I'm mystified by "literally given nothing". 1 All 'new' classes descend from object. 2 class Son( Father ):... literally gives 'Father' (At present) The base class must have been defined (frame on the stack) before it may be referenced. Self does not require super, it refers to the class itself. If a class has not defined an attribute, eg self.my_attribute, but the base class has defined an attribute of that name, then self.my_attribute will as initialised by the base class. Welcome to the intricacies of managing scope! -- Regards =dn From adam.preble at gmail.com Thu Jun 27 23:27:34 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Thu, 27 Jun 2019 20:27:34 -0700 (PDT) Subject: Plumbing behind super() In-Reply-To: References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> <70e7ae59-7dea-74b2-8263-61673df0daef@DancesWithMice.info> Message-ID: <4d1edd62-8b50-4e2f-b07c-1760fcd0fc23@googlegroups.com> On Thursday, June 27, 2019 at 8:30:21 PM UTC-5, DL Neil wrote: > I'm mystified by "literally given nothing". I'm focusing there particularly on the syntax of writing "super()" without any arguments to it. However, internally it's getting fed stuff. > If a class has not defined an attribute, eg self.my_attribute, but the > base class has defined an attribute of that name, then self.my_attribute > will as initialised by the base class. Welcome to the intricacies of > managing scope! I'm thinking my problem was more fundamental here. I finally got the debugger to bypass all the calls to the internal super() implementation that are done on startup and run instead just a bit of user-specified code. It's looking like super() actually gobbles the self pointer that goes on to the stack when __init__ is first created and replaces it when its done by returning it again. I think. Maybe. From random832 at fastmail.com Fri Jun 28 00:11:09 2019 From: random832 at fastmail.com (Random832) Date: Fri, 28 Jun 2019 00:11:09 -0400 Subject: Plumbing behind super() In-Reply-To: <4d1edd62-8b50-4e2f-b07c-1760fcd0fc23@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> <70e7ae59-7dea-74b2-8263-61673df0daef@DancesWithMice.info> <4d1edd62-8b50-4e2f-b07c-1760fcd0fc23@googlegroups.com> Message-ID: On Thu, Jun 27, 2019, at 23:32, adam.preble at gmail.com wrote: > On Thursday, June 27, 2019 at 8:30:21 PM UTC-5, DL Neil wrote: > > I'm mystified by "literally given nothing". > > I'm focusing there particularly on the syntax of writing "super()" > without any arguments to it. However, internally it's getting fed stuff. Any function which is defined inside a class and accesses 'super' is provided a 'cell variable' (i.e. nonlocal) called __class__, which super inspects on the stack to identify the class (along with finding the self argument) >>> class C: ... def foo(): super ... >>> C.foo.__closure__ (,) >>> C.foo.__code__.co_freevars ('__class__',) You can also provide this cell manually by defining it as a nested function inside another function which has a local variable __class__. >>> def bar(): ... __class__ = C ... return lambda self: super() ... >>> bar()(C()) , > You can see all this happening in https://github.com/python/cpython/blob/3.8/Objects/typeobject.c#L7812 From adam.preble at gmail.com Fri Jun 28 00:10:03 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Thu, 27 Jun 2019 21:10:03 -0700 (PDT) Subject: Plumbing behind super() In-Reply-To: <4d1edd62-8b50-4e2f-b07c-1760fcd0fc23@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> <70e7ae59-7dea-74b2-8263-61673df0daef@DancesWithMice.info> <4d1edd62-8b50-4e2f-b07c-1760fcd0fc23@googlegroups.com> Message-ID: I was wrong in the last email because I accidentally in super_gettro instead of super_init. Just for some helper context: >>> class Foo: ... pass ... >>> class Bar(Foo): ... def __init__(self): ... super().__init__() ... self.a = 2 ... >>> dis(Bar) Disassembly of __init__: 3 0 LOAD_GLOBAL 0 (super) 2 CALL_FUNCTION 0 4 LOAD_ATTR 1 (__init__) 6 CALL_FUNCTION 0 8 POP_TOP 4 10 LOAD_CONST 1 (2) 12 LOAD_FAST 0 (self) 14 STORE_ATTR 2 (a) 16 LOAD_CONST 0 (None) 18 RETURN_VALUE I originally set a breakpoint at super_getattro so I was seeing it getting the self pointer from TOS, but I think I needed super_init--especially since that is getting called from a CALL_FUNCTION opcode, instead of super_getattro and it's LOAD_ATTR. I think that's from the self.a assignment. The super_init code melted my brain! It looks like it's grabbing the current frame and interrogating it to find __class__. I think I have the same amount of visibility and similar structure in what I'm writing but... woah. From tjol at tjol.eu Fri Jun 28 03:20:50 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 28 Jun 2019 09:20:50 +0200 Subject: Plumbing behind super() In-Reply-To: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> Message-ID: <2d38792d-2932-0f24-791a-eee5a2a23741@tjol.eu> On 28/06/2019 02:13, adam.preble at gmail.com wrote: > I'm trying to mimick Python 3.6 as a .NET science project and have started to get into subclassing. The super() not-a-keyword-honestly-guys has tripped me up. I have to admit that I've professionally been doing a ton Python 2.7, so I'm not good on my Python 3.6 trivia yet. I think I have the general gist of this, but want some affirmation. > > If you use super() in a method, all it does is load super as a global on to the interpreter stack and call it without any arguments. So I'm left to wonder how it's able to figure anything out when it's being literally given nothing... Python is open source, so let's open the source! The magic happens when super() is constructed, in super_init https://github.com/python/cpython/blob/a8b27e623d75377aabe50df27e97cab4e81a174a/Objects/typeobject.c#L7814 Once super_getattro is called, the super object has already been set up, and it already knows which object/class to look at. As you can see, super_init takes the calling frame and checks the first argument of the previous call, which, when called from a method, will generally be 'self' https://github.com/python/cpython/blob/a8b27e623d75377aabe50df27e97cab4e81a174a/Objects/typeobject.c#L7849 There's some additional code that, I think, handles being called from a closure (but I don't know the C api well enough to be sure) We can sort-of emulate this in pure Python with the inspect module ### def not_quite_super(): ??? f = inspect.stack()[1].frame ??? obj = list(f.f_locals.values())[0] ??? print(type(obj), obj) class A: ??? def __init__(self, a=0, b=1): ??????? c = a + b # this is just to add some more locals to the mix ??????? not_quite_super() A() ### Once you have the caller object, the rest is just like calling super() with arguments. I'm not actually sure that Python example above is guaranteed to work, but I *think* it should in versions where dicts are ordered (3.6+). Obviously it doesn't handle all the cases super() handles. > > except that it's not being given literally nothing: > > static PyObject * > super_getattro(PyObject *self, PyObject *name) > > I was thinking maybe self has become more special in Python 3.6, but I don't think that's true since I've ported code to Python3 before that had inner classes where I'd use "inner_self" to disambiguate with the outer self. And though I thought it was so at first, it just turned out I screwed up my little code snippet to expose it. If self was special then I presume I could find it in my lookups and inject it. > > So how do I go from CALL_FUNCTION on a super() global without anything else on the stack to somehow having all the information I need? Is there something tracking that I'm in an object scope when calling stuff? > From Cecil at decebal.nl Fri Jun 28 04:20:03 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 10:20:03 +0200 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> <878stoebuc.fsf@munus.decebal.nl> Message-ID: <87r27ecea4.fsf@munus.decebal.nl> Cecil Westerhof writes: > Wildman writes: > >> On Wed, 26 Jun 2019 13:25:15 +0200, Cecil Westerhof wrote: >> >>> I need to write a desktop program. I choose to use tkinter. How can I >>> make sure the window title is visible? For example when I have the >>> following code: >>> from tkinter import Button, filedialog, Label, messagebox, Tk >>> >>> >>> window = Tk() >>> window.title('A long window title') >>> Button (window, text = 'Short text').pack() >>> window.mainloop() >>> >>> I see only a part of the 'A', but I would like to see the complete: >>> 'A long window title' >> >> According to link below, it is not possible... >> "Tkinter has no way of knowing how long the title is on the titlebar." >> >> https://stackoverflow.com/questions/35273690/tkinter-window-not-wide-enough-to-display-window-title > > OK, then I will have to live with it. I just make sure something is in my window that has such a width that the tittle will be displayed. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Jun 28 04:27:07 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 10:27:07 +0200 Subject: Creating a Windows executable on a Linux system References: <87tvccefpo.fsf@munus.decebal.nl> Message-ID: <87mui2cdyc.fsf@munus.decebal.nl> Cecil Westerhof writes: > I need to write a Python desktop program. I create it on a Linux > system, but it has to run on a Windows system. When looking at how to > create an executable it seems that you need to be on a Windows system > to create a Windows executable. Is this true, or is it possible to > create a Windows executable on a Linux system? > > Any pointers about best practice creating a standalone executable are > welcome. For the moment it is not a problem. It is allowed to install Python openpyxl on the systems where this application has to run. Letting the application name end on pyw and put a link on the desktop makes it work for the people that need to work with it. Still interested in getting it to work (for when I get in the situation that I have to distribute a Python program where it is not allowed to install Python), but it is not urgent anymore. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Jun 28 04:44:31 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 10:44:31 +0200 Subject: Copying a row from a range of Excel files to another References: <8736jwfw3w.fsf@munus.decebal.nl> <87h88cee53.fsf@munus.decebal.nl> <46943943-46a7-7bac-c336-50dc5b730349@mrabarnett.plus.com> <87v9wscams.fsf@munus.decebal.nl> Message-ID: <87imsqcd5c.fsf@munus.decebal.nl> MRAB writes: > On 2019-06-26 22:14, Cecil Westerhof wrote: >> MRAB writes: >> >>> Does Workbook support the 'with' statement? >>> >>> If it does, then that's the best way of doing it. >>> >>> (Untested) >>> >>> with Workbook() as wb_out: >>> for filepath in filepathArr: >>> current_row = [] >>> >>> with load_workbook(filepath) as wb_in: >>> for cell in wb_in.active[src_row]: >>> current_row.append(cell.value) >>> >>> wb_out.active.append(current_row) >>> >>> wb_out.save(report_start + datetime.now().strftime('%Y-%m-%d') + >>> report_end) >> >> It seems not. I get AttributeError. >> > You didn't say which line. I made a minimalist program to show it: #!/usr/bin/env python3 from openpyxl import Workbook with Workbook() as wb_out: print('In loop') print('After loop') This results in: Traceback (most recent call last): File "./test.py", line 7, in with Workbook() as wb_out: AttributeError: __exit__ > Anyway, if Workbooks are closed using a method called "close", you can > wrap them in a "closing" context manager: That seems to work. I changed it to: #!/usr/bin/env python3 from contextlib import closing from datetime import datetime from openpyxl import Workbook with closing(Workbook()) as wb_out: print('In loop') wb_out.save('testing_' + datetime.now().strftime('%Y-%m-%d') + '.xlsx') print('After loop') And I see: In loop After loop And a testing Excel file. Thanks. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Jun 28 04:48:36 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 10:48:36 +0200 Subject: Creating a Windows executable on a Linux system References: <87tvccefpo.fsf@munus.decebal.nl> <87mui2cdyc.fsf@munus.decebal.nl> Message-ID: <87ef3eccyj.fsf@munus.decebal.nl> Cecil Westerhof writes: > Cecil Westerhof writes: > >> I need to write a Python desktop program. I create it on a Linux >> system, but it has to run on a Windows system. When looking at how to >> create an executable it seems that you need to be on a Windows system >> to create a Windows executable. Is this true, or is it possible to >> create a Windows executable on a Linux system? >> >> Any pointers about best practice creating a standalone executable are >> welcome. > > For the moment it is not a problem. > It is allowed to install Python openpyxl on the systems Oops, that should have been: It is allowed to install Python AND openpyxl on the systems > where this application has to run. Letting the > application name end on pyw and put a link on the desktop makes it > work for the people that need to work with it. > > Still interested in getting it to work (for when I get in the > situation that I have to distribute a Python program where it is not > allowed to install Python), but it is not urgent anymore. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Jun 28 05:17:09 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 11:17:09 +0200 Subject: Only a message at the highest exception Message-ID: <87a7e2cbmy.fsf@munus.decebal.nl> I have a tkinter program where I have a function generate_report which in a try block calls the function append_row. This function has also a try block. When they get an exception they give message. But when append_row has already given a message then generate_report should not. To implement this I use the following class: class AlreadyHandledException(Exception): pass Then in append_row I have: except Exception as err: messagebox.showerror(error_str, error_append + '\n\n\n\n' + str(err)) raise AlreadyHandledException() And in generate_report I have: except Exception as err: if type(err).__name__ != "AlreadyHandledException": messagebox.showerror(error_str, error_generate + '\n\n\n\n' + str(err)) progress.pack_forget() Is this an acceptable way, or should I do it differently? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Fri Jun 28 05:37:30 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Jun 2019 19:37:30 +1000 Subject: Only a message at the highest exception In-Reply-To: <87a7e2cbmy.fsf@munus.decebal.nl> References: <87a7e2cbmy.fsf@munus.decebal.nl> Message-ID: On Fri, Jun 28, 2019 at 7:33 PM Cecil Westerhof wrote: > > I have a tkinter program where I have a function generate_report which > in a try block calls the function append_row. This function has also a > try block. When they get an exception they give message. But when > append_row has already given a message then generate_report should > not. To implement this I use the following class: > class AlreadyHandledException(Exception): > pass > > Then in append_row I have: > except Exception as err: > messagebox.showerror(error_str, > error_append + '\n\n\n\n' + str(err)) > raise AlreadyHandledException() > > And in generate_report I have: > except Exception as err: > if type(err).__name__ != "AlreadyHandledException": > messagebox.showerror(error_str, > error_generate + '\n\n\n\n' + str(err)) > progress.pack_forget() > > Is this an acceptable way, or should I do it differently? > Well, first off, I would use two separate except clauses, rather than a type check. But are you able to just NOT catch the exception inside append_row? Let it be handled at the top level only. ChrisA From Cecil at decebal.nl Fri Jun 28 06:04:17 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 12:04:17 +0200 Subject: Hiding a progressbar in tkinter References: <87zhm4cpr8.fsf@munus.decebal.nl> <7ac72ae4-fb60-7bb6-9f3e-97c50b49e838@mrabarnett.plus.com> Message-ID: <875zoqc9ge.fsf@munus.decebal.nl> MRAB writes: > On 2019-06-26 16:47, Cecil Westerhof wrote: >> I just started with GUI stuff in tkinter. I have a progressbar, but I >> want it to be only visible when it is used. So I tried the following: >> window = Tk() >> window.title(window_str) >> frame = Frame(window) >> frame.pack(side = "top", fill = "both", expand = True) >> Button(window, text = button_str, command = select_dir).pack() >> progress = ttk.Progressbar(window, orient = "horizontal", length = 200, >> mode = "determinate") >> progress.pack() >> progress.lower(frame) >> window.mainloop() >> >> But that does not hide the progressbar. What am I doing wrong? >> >> I could use pack_forget, but that will change the dimensions of the >> window. >> > The progress bar isn't hidden because there's nothing on top of it to > hide it. > > import tkinter as tk > import tkinter.ttk as ttk > > window = tk.Tk() > window.title(window_str) > frame = tk.Frame(window) > frame.pack(side='top', fill='both', expand=True) > tk.Button(window, text=button_str, command=select_dir).pack() > > # Create a frame to hold the progress bar. > progress_frame = tk.Frame(window) > progress_frame.pack(fill='x', expand=True) > > # Put the progress bar into the progress frame, ensuring that it fills > the grid cell. > progress = ttk.Progressbar(progress_frame, orient='horizontal', > length=200, mode='determinate') > progress.grid(row=0, column=0, sticky='nsew') > > # Now put a blank frame into the progress frame over the progress bar, > ensuring that it fills the same grid cell. > blank = tk.Frame(progress_frame) > blank.grid(row=0, column=0, sticky='nsew') > > # Raise the progress bar over the blank frame to reveal it. > progress.tkraise() > > # Lower the progress bar underneath the blank frame to hide it. > progress.lower() > > window.mainloop() Works like a charm. Thanks. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Jun 28 06:17:32 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 12:17:32 +0200 Subject: Only a message at the highest exception References: <87a7e2cbmy.fsf@munus.decebal.nl> Message-ID: <871rzec8ub.fsf@munus.decebal.nl> Chris Angelico writes: > On Fri, Jun 28, 2019 at 7:33 PM Cecil Westerhof wrote: >> >> I have a tkinter program where I have a function generate_report which >> in a try block calls the function append_row. This function has also a >> try block. When they get an exception they give message. But when >> append_row has already given a message then generate_report should >> not. To implement this I use the following class: >> class AlreadyHandledException(Exception): >> pass >> >> Then in append_row I have: >> except Exception as err: >> messagebox.showerror(error_str, >> error_append + '\n\n\n\n' + str(err)) >> raise AlreadyHandledException() >> >> And in generate_report I have: >> except Exception as err: >> if type(err).__name__ != "AlreadyHandledException": >> messagebox.showerror(error_str, >> error_generate + '\n\n\n\n' + str(err)) >> progress.pack_forget() >> >> Is this an acceptable way, or should I do it differently? >> > > Well, first off, I would use two separate except clauses, rather than > a type check. You are completely right. > But are you able to just NOT catch the exception inside > append_row? Let it be handled at the top level only. I am giving different messages. I changed the top part to: except AlreadyHandledException: pass except Exception as err: messagebox.showerror(error_str, error_generate + '\n\n\n\n' + str(err)) progress.lower() -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From cs at cskk.id.au Fri Jun 28 07:23:51 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 28 Jun 2019 21:23:51 +1000 Subject: Only a message at the highest exception In-Reply-To: <871rzec8ub.fsf@munus.decebal.nl> References: <871rzec8ub.fsf@munus.decebal.nl> Message-ID: <20190628112351.GA36700@cskk.homeip.net> On 28Jun2019 12:17, Cecil Westerhof wrote: >Chris Angelico writes: >> On Fri, Jun 28, 2019 at 7:33 PM Cecil Westerhof wrote: >>> I have a tkinter program where I have a function generate_report >>> which >>> in a try block calls the function append_row. This function has also a >>> try block. When they get an exception they give message. But when >>> append_row has already given a message then generate_report should >>> not. To implement this I use the following class: >>> >>> class AlreadyHandledException(Exception): >>> pass >>> >>> Then in append_row I have: >>> except Exception as err: >>> messagebox.showerror(error_str, >>> error_append + '\n\n\n\n' + str(err)) >>> raise AlreadyHandledException() >>> >>> And in generate_report I have: >>> except Exception as err: >>> if type(err).__name__ != "AlreadyHandledException": >>> messagebox.showerror(error_str, >>> error_generate + '\n\n\n\n' + str(err)) >>> progress.pack_forget() >>> >>> Is this an acceptable way, or should I do it differently? >> >> Well, first off, I would use two separate except clauses, rather than >> a type check. > >You are completely right. > >> But are you able to just NOT catch the exception inside >> append_row? Let it be handled at the top level only. > >I am giving different messages. I changed the top part to: > except AlreadyHandledException: > pass > except Exception as err: > messagebox.showerror(error_str, error_generate + '\n\n\n\n' + str(err)) > progress.lower() For contrast, another approach. By catching AlreadyHandledException and just going "pass" you're effectively swalling that exception. For your purpose, that works. However, in a since, why raise an exception you _know_ you're going to deliberately ignore? What if you have append_row return a Boolean? True on success, False on failure but situation handled (i.e. append_row has shown an error, or whatever recovery you adopt). And keep the uncaught exceptions for the _unhandled_ situation. The "exceptional" situation. Example: def append_row(...): ... try: ...stuff... except ExpectedExceptionHere as err: messagebox.showerror(....) ...maybe some cleanup... return False ... return True Then your generate_report code goes: try: appended = append_row(....) except Exception as err: messagebox.showerror(....) else: if appended: hooray! else: unhappy, but continuing avoiding a "do nothing" special except clause. Cheers, Cameron Simpson From Cecil at decebal.nl Fri Jun 28 08:19:48 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 14:19:48 +0200 Subject: Only a message at the highest exception References: <871rzec8ub.fsf@munus.decebal.nl> <20190628112351.GA36700@cskk.homeip.net> Message-ID: <87tvc9c36j.fsf@munus.decebal.nl> Cameron Simpson writes: > On 28Jun2019 12:17, Cecil Westerhof wrote: >>Chris Angelico writes: >>> On Fri, Jun 28, 2019 at 7:33 PM Cecil Westerhof wrote: >>>> I have a tkinter program where I have a function generate_report >>>> which >>>> in a try block calls the function append_row. This function has also a >>>> try block. When they get an exception they give message. But when >>>> append_row has already given a message then generate_report should >>>> not. To implement this I use the following class: >>>> >>>> class AlreadyHandledException(Exception): >>>> pass >>>> >>>> Then in append_row I have: >>>> except Exception as err: >>>> messagebox.showerror(error_str, >>>> error_append + '\n\n\n\n' + str(err)) >>>> raise AlreadyHandledException() >>>> >>>> And in generate_report I have: >>>> except Exception as err: >>>> if type(err).__name__ != "AlreadyHandledException": >>>> messagebox.showerror(error_str, >>>> error_generate + '\n\n\n\n' + str(err)) >>>> progress.pack_forget() >>>> >>>> Is this an acceptable way, or should I do it differently? >>> >>> Well, first off, I would use two separate except clauses, rather than >>> a type check. >> >>You are completely right. >> >>> But are you able to just NOT catch the exception inside >>> append_row? Let it be handled at the top level only. >> >>I am giving different messages. I changed the top part to: >> except AlreadyHandledException: >> pass >> except Exception as err: >> messagebox.showerror(error_str, error_generate + '\n\n\n\n' + str(err)) >> progress.lower() > > For contrast, another approach. > > By catching AlreadyHandledException and just going "pass" you're > effectively swalling that exception. For your purpose, that works. > > However, in a since, why raise an exception you _know_ you're going to > deliberately ignore? I am not. I am using it to quit generating the report. Just ignoring that I could not append a record does not sound correct to me. Yes they got a message that something went wrong. But if there is still a generated report, things will go wrong. > What if you have append_row return a Boolean? True on success, False on > failure but situation handled (i.e. append_row has shown an error, or > whatever recovery you adopt). And keep the uncaught exceptions for the > _unhandled_ situation. The "exceptional" situation. > > Example: > > def append_row(...): > ... > try: > ...stuff... > except ExpectedExceptionHere as err: > messagebox.showerror(....) > ...maybe some cleanup... > return False > ... > return True > > Then your generate_report code goes: > > try: > appended = append_row(....) > except Exception as err: > messagebox.showerror(....) > else: > if appended: > hooray! > else: > unhappy, but continuing And that is exactly what I not want to do. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From jasonanyilian at gmail.com Fri Jun 28 11:06:37 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Fri, 28 Jun 2019 08:06:37 -0700 (PDT) Subject: How do you insert an item into a dictionary (in python 3.7.2)? Message-ID: How do you insert an item into a dictionary? For example, I make a dictionary called "dictionary". dictionary = {1: 'value1', 2: 'value3'} What if I wanted to add a value2 in the middle of value1 and value3? From jasonanyilian at gmail.com Fri Jun 28 11:10:23 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Fri, 28 Jun 2019 08:10:23 -0700 (PDT) Subject: Make sure the window title is visible in tkinter In-Reply-To: <87y31oegh0.fsf@munus.decebal.nl> References: <87y31oegh0.fsf@munus.decebal.nl> Message-ID: <680fbf0d-8a04-469a-a720-b44451ae7f5b@googlegroups.com> On Wednesday, June 26, 2019, at 7:44:15 AM UTC-4, Cecil Westerhof wrote: > I need to write a desktop program. I choose to use tkinter. How can I > make sure the window title is visible? For example when I have the > following code: > from tkinter import Button, filedialog, Label, messagebox, Tk > > > window = Tk() > window.title('A long window title') > Button (window, text = 'Short text').pack() > window.mainloop() > > I see only a part of the 'A', but I would like to see the complete: > 'A long window title' > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof Maybe you should try to maximize the window so you can see everything. It put in your code and I could see more of the title. From cspealma at redhat.com Fri Jun 28 11:16:45 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Fri, 28 Jun 2019 11:16:45 -0400 Subject: How do you insert an item into a dictionary (in python 3.7.2)? In-Reply-To: References: Message-ID: You simply assign to the key, like so: dictionary[3] = 'value2' But it isn't clear what you mean by "in the middle". On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez wrote: > How do you insert an item into a dictionary? For example, I make a > dictionary called "dictionary". > > dictionary = {1: 'value1', 2: 'value3'} > > What if I wanted to add a value2 in the middle of value1 and value3? > -- > 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 Fri Jun 28 11:35:57 2019 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 28 Jun 2019 11:35:57 -0400 Subject: How do you insert an item into a dictionary (in python 3.7.2)? In-Reply-To: References: Message-ID: On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez wrote: > > How do you insert an item into a dictionary? For example, I make a dictionary called "dictionary". > > dictionary = {1: 'value1', 2: 'value3'} > > What if I wanted to add a value2 in the middle of value1 and value3? Dicts are not ordered. If you need that use an OrderedDict (https://docs.python.org/3.7/library/collections.html#collections.OrderedDict) From jon+usenet at unequivocal.eu Fri Jun 28 11:48:52 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 28 Jun 2019 15:48:52 -0000 (UTC) Subject: How do you insert an item into a dictionary (in python 3.7.2)? References: Message-ID: On 2019-06-28, Larry Martell wrote: > On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez > wrote: >> >> How do you insert an item into a dictionary? For example, I make a dictionary called "dictionary". >> >> dictionary = {1: 'value1', 2: 'value3'} >> >> What if I wanted to add a value2 in the middle of value1 and value3? > > Dicts are not ordered. If you need that use an OrderedDict > (https://docs.python.org/3.7/library/collections.html#collections.OrderedDict) This is no longer true from Python 3.6 onwards - dicts are ordered. There's no way to insert an item anywhere other than at the end though. From rosuav at gmail.com Fri Jun 28 11:53:30 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Jun 2019 01:53:30 +1000 Subject: How do you insert an item into a dictionary (in python 3.7.2)? In-Reply-To: References: Message-ID: On Sat, Jun 29, 2019 at 1:51 AM Jon Ribbens via Python-list wrote: > > On 2019-06-28, Larry Martell wrote: > > On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez > > wrote: > >> > >> How do you insert an item into a dictionary? For example, I make a dictionary called "dictionary". > >> > >> dictionary = {1: 'value1', 2: 'value3'} > >> > >> What if I wanted to add a value2 in the middle of value1 and value3? > > > > Dicts are not ordered. If you need that use an OrderedDict > > (https://docs.python.org/3.7/library/collections.html#collections.OrderedDict) > > This is no longer true from Python 3.6 onwards - dicts are ordered. > There's no way to insert an item anywhere other than at the end though. They retain order, but they're not an "ordered collection" the way a list is. You can't logically insert into a sequence, because it's not a sequence. You can't say "what's the 43rd entry in this dict?" because it doesn't have a 43rd entry. All it has is a recollection of the order things were inserted. ChrisA From shivam.patel at lendbuzz.com Fri Jun 28 12:45:16 2019 From: shivam.patel at lendbuzz.com (shivam.patel at lendbuzz.com) Date: Fri, 28 Jun 2019 09:45:16 -0700 (PDT) Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: References: Message-ID: <72c1cf6d-dac4-464e-a48e-83337f1a6a98@googlegroups.com> On Tuesday, April 8, 2014 at 8:55:46 AM UTC-4, Peter Otten wrote: > Dennis wrote: > > > In Pylint you can change the spacing multiplier from 4 spaces to two > > in its pylintrc, but for the life of me I cannot find a way to do this > > with the flake8 / pep8 utilities. > > > > I want to avoid ignoring E111 altogether if at all possible, because > > it may catch other spacing problems that are not as obvious. > > > > hacky/non-hacky solutions welcome of course. > > The check is hardcoded > > if indent_char == ' ' and indent_level % 4: > yield 0, "E111 indentation is not a multiple of four" > > so your only short-term solution is to modify the script's source code. What file is this? From rgaddi at highlandtechnology.invalid Fri Jun 28 12:58:52 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 28 Jun 2019 09:58:52 -0700 Subject: Use global, or not In-Reply-To: <87pnmxbz9t.fsf@munus.decebal.nl> References: <87pnmxbz9t.fsf@munus.decebal.nl> Message-ID: On 6/28/19 6:44 AM, Cecil Westerhof wrote: > I have written a GUI program where I have quit a few global variables. > I did not like this, so I now use one global dict. Something like: [snip] > global_dict = { > 'messages': messages, > 'progress': progress, > 'window': window, > } > > And in the program do things like: > global_dict['progress']['value'] += 1 > global_dict['window'].update_idletasks() > global_dict['window'].update_idletasks() > > and: > messagebox.showwarning(global_dict['titles']['warning'], > global_dict['messages']['nofiles']) > > > Is that an acceptable way to do this? > It works. I guess it makes your use of items in the global namespace inherently intentional rather than allowing accidental globals. I'm not sure how much value it adds though. That said, I've got a whole bunch of programs that all use a dict called Registry that they all import from a shared package; making them program-wide globals. I use it for a few pieces of static information ('application', 'version') as well as to pass device handles around, since an open connection to a given piece of physical hardware is an inherently global thing. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From Cecil at decebal.nl Fri Jun 28 09:44:14 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 28 Jun 2019 15:44:14 +0200 Subject: Use global, or not Message-ID: <87pnmxbz9t.fsf@munus.decebal.nl> I have written a GUI program where I have quit a few global variables. I did not like this, so I now use one global dict. Something like: global global_dict canceled_report = 'Genereren rapportage gecanceled.' created_report = 'Rapportage voor {} bestanden is gemaakt.' error_append = 'Er ging iets fout bij het toevoegen van een record.' error_generate = 'Er ging iets fout bij het genereren van de rapportage.' error_select = 'Er ging iets fout bij het selecteren van de directory.' error_widening = 'Er ging iets fout bij instellen van de wijdte.' error_nofiles = 'Er zijn geen bestanden om te verwerken.' messages = { 'canceled': canceled_report, 'created': created_report, 'append': error_append, 'generate': error_generate, 'select': error_select, 'widening': error_widening, 'nofiles': error_nofiles, } error_str = 'Foutmelding' info_str = 'Info' warning_str = 'Waarschuwing' titles = { 'error': error_str, 'info': info_str, 'warning': warning_str, } . . . window = Tk() . . . progress = ttk.Progressbar(progress_frame, orient = 'horizontal', length = 200, mode = 'determinate') . . . global_dict = { 'messages': messages, 'progress': progress, 'window': window, } And in the program do things like: global_dict['progress']['value'] += 1 global_dict['window'].update_idletasks() global_dict['window'].update_idletasks() and: messagebox.showwarning(global_dict['titles']['warning'], global_dict['messages']['nofiles']) Is that an acceptable way to do this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From toby at tobiah.org Fri Jun 28 16:25:37 2019 From: toby at tobiah.org (Tobiah) Date: Fri, 28 Jun 2019 13:25:37 -0700 Subject: Handle foreign character web input Message-ID: A guy comes in and enters his last name as R?nngren. So what did the browser really give me; is it encoded in some way, like latin-1? Does it depend on whether the name was cut and pasted from a Word doc. etc? Should I handle these internally as unicode? Right now my database tables are latin-1 and things seem to usually work, but not always. Also, what do people do when searching for a record. Is there some way to get 'Ronngren' to match the other possible foreign spellings? From rosuav at gmail.com Fri Jun 28 16:33:32 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Jun 2019 06:33:32 +1000 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: On Sat, Jun 29, 2019 at 6:31 AM Tobiah wrote: > > A guy comes in and enters his last name as R?nngren. > > So what did the browser really give me; is it encoded > in some way, like latin-1? Does it depend on whether > the name was cut and pasted from a Word doc. etc? > Should I handle these internally as unicode? Right > now my database tables are latin-1 and things seem > to usually work, but not always. Definitely handle them as Unicode. You'll receive them in some encoding, probably UTF-8, and it depends on the browser. Ideally, your back-end library (eg Flask) will deal with that for you. > Also, what do people do when searching for a record. > Is there some way to get 'Ronngren' to match the other > possible foreign spellings? Ehh....... probably not. That's a human problem, not a programming one. Best of luck. ChrisA From toby at tobiah.org Fri Jun 28 16:58:32 2019 From: toby at tobiah.org (Tobiah) Date: Fri, 28 Jun 2019 13:58:32 -0700 Subject: Handle foreign character web input References: Message-ID: On 6/28/19 1:33 PM, Chris Angelico wrote:> On Sat, Jun 29, 2019 at 6:31 AM Tobiah wrote: >> >> A guy comes in and enters his last name as R?nngren. >> >> So what did the browser really give me; is it encoded >> in some way, like latin-1? Does it depend on whether >> the name was cut and pasted from a Word doc. etc? >> Should I handle these internally as unicode? Right >> now my database tables are latin-1 and things seem >> to usually work, but not always. > > Definitely handle them as Unicode. You'll receive them in some > encoding, probably UTF-8, and it depends on the browser. Ideally, your > back-end library (eg Flask) will deal with that for you. It varies by browser? So these records are coming in from all over the world. How do people handle possibly assorted encodings that may come in? I'm using Web2py. Does the request come in with an encoding built in? Is that how people get the proper unicode object? >> Also, what do people do when searching for a record. >> Is there some way to get 'Ronngren' to match the other >> possible foreign spellings? > > Ehh....... probably not. That's a human problem, not a programming > one. Best of luck. Well so I'm at an event. A guy comes up to me at the kiosk and say his name is R?nngren. I can't find him, typing in "ron" so I ask him how to spell his last name. What does he say, and what do I type? From inhahe at gmail.com Fri Jun 28 17:30:19 2019 From: inhahe at gmail.com (inhahe) Date: Fri, 28 Jun 2019 17:30:19 -0400 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: : > > On 6/28/19 1:33 PM, Chris Angelico wrote:> On Sat, Jun 29, 2019 at 6:31 AM > Tobiah wrote: > > >> Also, what do people do when searching for a record. > >> Is there some way to get 'Ronngren' to match the other > >> possible foreign spellings? > > > > I think I've heard of algorithms that can match spellings with exotic characters, but I don't remember what they're called. I think they're out there. It's a black science, though, so some of their decisions in how to match or not match are probably arbitrary. From rosuav at gmail.com Fri Jun 28 17:44:59 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Jun 2019 07:44:59 +1000 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: On Sat, Jun 29, 2019 at 7:01 AM Tobiah wrote: > > > On 6/28/19 1:33 PM, Chris Angelico wrote:> On Sat, Jun 29, 2019 at 6:31 AM Tobiah wrote: > >> > >> A guy comes in and enters his last name as R?nngren. > >> > >> So what did the browser really give me; is it encoded > >> in some way, like latin-1? Does it depend on whether > >> the name was cut and pasted from a Word doc. etc? > >> Should I handle these internally as unicode? Right > >> now my database tables are latin-1 and things seem > >> to usually work, but not always. > > > > Definitely handle them as Unicode. You'll receive them in some > > encoding, probably UTF-8, and it depends on the browser. Ideally, your > > back-end library (eg Flask) will deal with that for you. > It varies by browser? > So these records are coming in from all over the world. How > do people handle possibly assorted encodings that may come in? > > I'm using Web2py. Does the request come in with an encoding > built in? Is that how people get the proper unicode object? Yes. Normally, the browser will say "hey, here's a request body, and this is the encoding and formatting". Try it - see what you get. ChrisA From akkana at shallowsky.com Fri Jun 28 18:25:35 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 28 Jun 2019 16:25:35 -0600 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: <20190628222535.GD1228@shallowsky.com> On Sat, Jun 29, 2019 at 6:31 AM Tobiah wrote: > Also, what do people do when searching for a record. > Is there some way to get 'Ronngren' to match the other > possible foreign spellings? SequenceMatcher in difflib can do fuzzy string comparisons and should work for cases like that. There are other methods too -- include "fuzzy" in your web searches and you'll probably find several options. ...Akkana From tjreedy at udel.edu Fri Jun 28 19:19:59 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Jun 2019 19:19:59 -0400 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: On 6/28/2019 4:25 PM, Tobiah wrote: > A guy comes in and enters his last name as R?nngren. > > So what did the browser really give me; is it encoded > in some way, like latin-1?? Does it depend on whether > the name was cut and pasted from a Word doc. etc? > Should I handle these internally as unicode?? Right > now my database tables are latin-1 and things seem > to usually work, but not always. Unless you want to restrict your app to people with or converible to latin-1 (western Europe) names, you should use utf-8 or let the database encode for you. > Also, what do people do when searching for a record. > Is there some way to get 'Ronngren' to match the other > possible foreign spellings? I have seen a program that converts all latin-1 chars to ascii for matching. -- Terry Jan Reedy From PythonList at DancesWithMice.info Fri Jun 28 20:40:38 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 29 Jun 2019 12:40:38 +1200 Subject: Use global, or not In-Reply-To: <87pnmxbz9t.fsf@munus.decebal.nl> References: <87pnmxbz9t.fsf@munus.decebal.nl> Message-ID: <8792020e-bdcf-6e14-bcdf-9e0fc0b1b87c@DancesWithMice.info> On 29/06/19 1:44 AM, Cecil Westerhof wrote: > I have written a GUI program where I have quit a few global variables. > I did not like this, so I now use one global dict. Something like: > global global_dict ... > Is that an acceptable way to do this? If it works, isn't that the largest part of "acceptable"? In each case, (previously discussed and/or below) you are taking advantage of "namespaces" to keep one 'lot' of values separated and distinct from others - as well as finding a means of 'passing them around'. The other half of the considerations is how the values are being retrieved/utilised within the mainline code. An alternative might be to use a class. Then accessing a single value becomes instance.attribute, but when you have need for several attribute's values or to compute a value from several attributes, an instance.method() may simplify things. I use the above idea for a 'configuration' class which has values built from constants/defaults, plus command-line arguments, etc (as appropriate to the application and user-needs). Another approach might be to use a module. After import module as module_name, single-value access becomes module_name.cancelled_report (etc). -- Regards =dn From cs at cskk.id.au Sat Jun 29 02:55:50 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 29 Jun 2019 16:55:50 +1000 Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: References: Message-ID: <20190629065550.GA50337@cskk.homeip.net> On 07Apr2014 20:06, Dennis wrote: >In Pylint you can change the spacing multiplier from 4 spaces to two >in its pylintrc, but for the life of me I cannot find a way to do this >with the flake8 / pep8 utilities. > >I want to avoid ignoring E111 altogether if at all possible, because >it may catch other spacing problems that are not as obvious. I ignore E111 and hope other linters catch stuff it will now miss. I've also taken to having my files autoformatted with yapf on save, which makes a lot of formatting more rigorous. My current lint script runs pyflakes, pep8 and pylint. My personal lint script: https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint My personal format script: https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/format Take what you'd like. Cheers, Cameron Simpson From Cecil at decebal.nl Sat Jun 29 07:42:45 2019 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 29 Jun 2019 13:42:45 +0200 Subject: Use global, or not References: <87pnmxbz9t.fsf@munus.decebal.nl> <8792020e-bdcf-6e14-bcdf-9e0fc0b1b87c@DancesWithMice.info> Message-ID: <87lfxkbosq.fsf@munus.decebal.nl> DL Neil writes: > On 29/06/19 1:44 AM, Cecil Westerhof wrote: >> I have written a GUI program where I have quit a few global variables. >> I did not like this, so I now use one global dict. Something like: >> global global_dict > ... > >> Is that an acceptable way to do this? > > > If it works, isn't that the largest part of "acceptable"? Depends on your way of thinking. ;-) I think it is always best when you write in a language to do it in that languages way. In this case Python. I also think this is a program that could be interesting to share. Then it becomes even more important to do it the Python way. And my experience is that when asking this type of question you often get a tip that helps you make your program better. > In each case, (previously discussed and/or below) you are taking > advantage of "namespaces" to keep one 'lot' of values separated and > distinct from others - as well as finding a means of 'passing them > around'. The other half of the considerations is how the values are > being retrieved/utilised within the mainline code. > > An alternative might be to use a class. Then accessing a single value > becomes instance.attribute, but when you have need for several > attribute's values or to compute a value from several attributes, an > instance.method() may simplify things. That was the other possibility I was thinking about. And that would be maybe better. Because I now do things like: global_dict['messages']['created'].format(len(filepathArr)) much better would be: instance.created(len(filepathArr)) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From jmariano65 at gmail.com Sat Jun 29 08:39:52 2019 From: jmariano65 at gmail.com (=?UTF-8?Q?jos=C3=A9_mariano?=) Date: Sat, 29 Jun 2019 05:39:52 -0700 (PDT) Subject: Do I need a parser? Message-ID: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> Dear all, I'm sure that this subject has been addressed many times before on this forum, but my poor knowledge of English and of computer jargon and concepts results on not being able to find the answer i'm looking for when I search the forum. So here is my problem: I have this open source project for the scientific community were i want to duplicate an old MS-DOS application written in Fortran. I don't have the source code. The idea is to re-write the software in Python. Originally, the old application would would need to input files: one config file, written with a specific format (see below) and a second one, the so-called scrip file, that defines the sequence of operations to be performed by the main software, also written in a specific format. To make the transition to the new application as painless as possible to the users, because most of them have their collection of scrips (and settings) developed over the years and are not willing to learn a new script language, I would like to make the new app 100% compatible with the old input files. The operation of the new software would be like this: From the shell, run "my_new_software old_script_file.***". The new software would load the old_script, parse it (?), set the internal variables, load the script and run it. So, to get to my questions: - To load and read the config file I need a parser, right? Is their a parser library where we can define the syntax of the language to use? Are there better (meaning easier) ways to accomplish the same result? - For the interpretation of the script file, I don't have any clue how to this... One important thing, the script language admits some simple control flow statements like do-wile, again written using a specific sintax. Thanks a lot for the help and sorry for the long post. Mariano Example of a config (settings) file ======================== ..... CONDAD -11 BURAD2 4 SALT1 1.0 KNO3 ELEC5 -2.0 mV 400 58 0. 0 ..... Example of a script =================== !Conductivity titration cmnd bur1 f set vinit 100 set endpt 2000 set mvinc 20 set drftim 1 set rdcrit cond 0.5 per_min set dosinc bur1 0.02 1000 set titdir up titratc cond bur1 From tjol at tjol.eu Sat Jun 29 10:06:56 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 29 Jun 2019 16:06:56 +0200 Subject: Do I need a parser? In-Reply-To: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> References: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> Message-ID: On 29/06/2019 14:39, jos? mariano wrote: > Dear all, > > I'm sure that this subject has been addressed many times before on this forum, but my poor knowledge of English and of computer jargon and concepts results on not being able to find the answer i'm looking for when I search the forum. > > So here is my problem: I have this open source project for the scientific community were i want to duplicate an old MS-DOS application written in Fortran. I don't have the source code. The idea is to re-write the software in Python. Originally, the old application would would need to input files: one config file, written with a specific format (see below) and a second one, the so-called scrip file, that defines the sequence of operations to be performed by the main software, also written in a specific format. Is there any way you can get the source code? Can you track down the original author? Are there old backups? That might eliminate the need for rewriting, and, in any case, would make it so much easier to be sure you're doing the right thing and not missing something. > > To make the transition to the new application as painless as possible to the users, because most of them have their collection of scrips (and settings) developed over the years and are not willing to learn a new script language, I would like to make the new app 100% compatible with the old input files. Obviously. Make sure you have tests, tests, and more tests. If there's documentation, use it, but don't trust it. That's assuming there are loads of old scripts, that just continuing to use the old program is not an option. DOSbox to the rescue? Another option might be to write a script that parses the old files and converts them to something more friendly to your infrastructure, such as YAML config files and Python scripts. This has two benefits: (1) a human can easily check the result. If there are some incompatibilities, they'll be easier to spot. If the script misses something, the user can add it in. (2) it might be easier to add new features later It is a more complex and less user-friendly solution, though. > > The operation of the new software would be like this: From the shell, run "my_new_software old_script_file.***". The new software would load the old_script, parse it (?), set the internal variables, load the script and run it. > > So, to get to my questions: > > - To load and read the config file I need a parser, right? Is their a parser library where we can define the syntax of the language to use? Are there better (meaning easier) ways to accomplish the same result? You need to parse the file, obviously. Python is good for this sort of thing. str.split() and the re module are your friends. The format looks reasonably simple, so I'd just parse it into a simple data structure with the basic tools Python provides. > - For the interpretation of the script file, I don't have any clue how to this... One important thing, the script language admits some simple control flow statements like do-wile, again written using a specific sintax. From the look of it, it's one instruction per line, and the first word of the line is, in some sense, a command? In this case, one way I can think of to run it would be an interpreter structured something like this: class ScriptRunner: ???? def __init__(self, config, script): ???????? self._variables = {} ???????? self._config = config ???????? self._script_lines = [] ???????? for line in script.split('\n'): ???????????? line = line.strip() ???????????? if line.startswith('!'): ???????????????? #comment ???????????????? continue ???????????? cmd, *args = line.split() ???????????? self._script_lines.append((cmd.lower(), args)) ???? def run_script(self): ???????? self._script_iter = iter(self._script_lines) ???????? while True: ???????????? try: ???????????????? cmd, args = next(self._script_iter) ???????????????? self.dispatch(cmd, args) ???????????? except StopIteration: ???????????????? return ??? def dispatch(self, cmd, args): ??????? method_name = f'_cmd_{cmd}' ??????? method = getattr(self, method_name) ??????? method(args) ??? def _cmd_set(self, args): ??????? varname, value = args ??????? self._variables[varname] = value ??? def _cmd_while(self, loop_args): ??????? # check condition or something ??????? loop_body = [] ??????? while True: ???????????? try: ???????????????? cmd, args = next(self._script_iter) ???????????????? # MAGIC ???????????????? if cmd == 'endwhile': ???????????????????? break ???????????????? else: ???????????????????? loop_body.append((cmd, args)) ???????????? except StopIteration: ???????????????? raise RuntimeError('loop not ended') ??????? while condition_is_met: ??????????? for cmd, args in loop_body: ???????????????? # otherwise, just carry on executing the loop body ???????????????? self.dispatch(cmd, args) In any case, there are three things you need to keep track of: variables, where in the script you are, and what control structure currently "has control". In this stub, I've used the object for holding program state (variables that is), a Python iterator to hold the program counter, and the Python stack to hold the control flow information. There are other ways you can do it, of course. If the language allows for things like subroutines or GOTO, things get a little more complicated There are also tools for this kind of thing. The traditional (UNIX) choice would be lex & yacc, but I think there are Python parser libraries that you could use. Others might mention them. I'd tend to say they're overkill for your purpose, but what do I know. > > Thanks a lot for the help and sorry for the long post. > > Mariano > > > > Example of a config (settings) file > ======================== > ..... > CONDAD -11 > BURAD2 4 SALT1 1.0 KNO3 > ELEC5 -2.0 mV 400 58 0. 0 > ..... > > > Example of a script > =================== > !Conductivity titration > cmnd bur1 f > set vinit 100 > set endpt 2000 > set mvinc 20 > set drftim 1 > set rdcrit cond 0.5 per_min > set dosinc bur1 0.02 1000 > set titdir up > titratc cond bur1 > From tjol at tjol.eu Sat Jun 29 03:19:14 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 29 Jun 2019 09:19:14 +0200 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> On 28/06/2019 22:25, Tobiah wrote: > A guy comes in and enters his last name as R?nngren. With a capital ? in the middle? That's unusual. > > So what did the browser really give me; is it encoded > in some way, like latin-1?? Does it depend on whether > the name was cut and pasted from a Word doc. etc? > Should I handle these internally as unicode?? Right > now my database tables are latin-1 and things seem > to usually work, but not always. If your database is using latin-1, German and French names will work, but Croatian and Polish names often won't. Not to mention people using other writing systems. So G?nther and Fran?ois are ok, but Boles?aw turns into Boles?aw and don't even think about anybody called ???????? or ????. > > Also, what do people do when searching for a record. > Is there some way to get 'Ronngren' to match the other > possible foreign spellings? From python at bdurham.com Sat Jun 29 12:19:24 2019 From: python at bdurham.com (Malcolm Greene) Date: Sat, 29 Jun 2019 10:19:24 -0600 Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: <20190629065550.GA50337@cskk.homeip.net> References: <20190629065550.GA50337@cskk.homeip.net> Message-ID: <7caf6a72-7bf3-430a-a182-80a37b905169@www.fastmail.com> > I've also taken to having my files auto-formatted with yapf on save ... @Cameron: Have you considered black at all and if so, what are your thoughts? Thanks, Malcolm From Richard at Damon-Family.org Sat Jun 29 13:25:22 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 29 Jun 2019 13:25:22 -0400 Subject: Handle foreign character web input In-Reply-To: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> References: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> Message-ID: On 6/29/19 3:19 AM, Thomas Jollans wrote: > On 28/06/2019 22:25, Tobiah wrote: >> A guy comes in and enters his last name as R?nngren. > With a capital ? in the middle? That's unusual. >> >> So what did the browser really give me; is it encoded >> in some way, like latin-1?? Does it depend on whether >> the name was cut and pasted from a Word doc. etc? >> Should I handle these internally as unicode?? Right >> now my database tables are latin-1 and things seem >> to usually work, but not always. > > > If your database is using latin-1, German and French names will work, > but Croatian and Polish names often won't. Not to mention people using > other writing systems. > > So G?nther and Fran?ois are ok, but Boles?aw turns into Boles?aw and > don't even think about anybody called ???????? or ????. I would say that currently, the only real reason to use an encoding other than Unicode (normally UTF-8) would be historical inertia. Maybe a field that will only ever have plain ASCII characters could use ASCII (such a field would never have real natural language words, but only computer generated codes). All the various 'codepages' were useful in their day, when machines were less capable, and Unicode hadn't been invented or wasn't supported well or was too expensive to use. Now (as I understand it), all Python (3) 'Strings' are internally Unicode, if you need something with a different encoding it needs to be in Bytes. -- Richard Damon From bgailer at gmail.com Sat Jun 29 14:51:25 2019 From: bgailer at gmail.com (bob gailer) Date: Sat, 29 Jun 2019 14:51:25 -0400 Subject: Do I need a parser? In-Reply-To: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> References: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> Message-ID: I might be able to help. I'd need to understand a bit more about the configuration and scripting languages. Do you have any reference material? Or some way to look up the titration device on the internet? -- Bob Gailer From ameyer2 at yahoo.com Sat Jun 29 15:56:19 2019 From: ameyer2 at yahoo.com (Alan Meyer) Date: Sat, 29 Jun 2019 15:56:19 -0400 Subject: Handle foreign character web input In-Reply-To: References: Message-ID: On 6/28/19 4:25 PM, Tobiah wrote: > A guy comes in and enters his last name as R?nngren. > > So what did the browser really give me; is it encoded > in some way, like latin-1?? Does it depend on whether > the name was cut and pasted from a Word doc. etc? > Should I handle these internally as unicode?? Right > now my database tables are latin-1 and things seem > to usually work, but not always. > > Also, what do people do when searching for a record. > Is there some way to get 'Ronngren' to match the other > possible foreign spellings? The first thing I'd want to do is to produce a front-end to discover the character set (latin-1, whatever) and convert it to a standard UTF-8. e.g.: data.decode('latin1').encode('utf8') That gets rid of character set variations in the data, simplifying things before any of the hard work has to be done. Then you have a choice - store and index everything as utf-8, or transliterate some or all strings to 7 bit US ASCII. You may have to perform the same processing on input search strings. I have not used it myself but there is a Python port of a Perl module by Sean M. Burke called Unidecode. It will transliterate non-US ASCII strings into ASCII using reasonable substitutions of non-ASCII sequences. I believe that there are other packages that can also do this. The easy way to use packages like this is to transliterate entire records before putting them into your database, but then you may perplex or even offend some users who will look at a record and say "What's this? That's not French!" You'll also have to transliterate all input search strings. A more sophisticated way is to leave the records in Unicode, but add transliterated index strings for those index strings that wind up containing utf-8 non-ASCII chars. There are various ways to do this that tradeoff time, space, and programming effort. You can store two versions of each record, search one and display the other. You can just process index strings and add the transliterations to the record. What to choose depends on your needs and resources. And of course all bets are off if some of your data is Chinese, Japanese, Hebrew, or maybe even Russian or Greek. Sometimes I think, Why don't we all just learn Esperanto? But we all know that that isn't going to happen. Alan From jon+usenet at unequivocal.eu Sat Jun 29 16:15:02 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 29 Jun 2019 20:15:02 -0000 (UTC) Subject: Handle foreign character web input References: Message-ID: On 2019-06-28, Chris Angelico wrote: > On Sat, Jun 29, 2019 at 6:31 AM Tobiah wrote: >> A guy comes in and enters his last name as R?nngren. >> >> So what did the browser really give me; is it encoded >> in some way, like latin-1? Does it depend on whether >> the name was cut and pasted from a Word doc. etc? >> Should I handle these internally as unicode? Right >> now my database tables are latin-1 and things seem >> to usually work, but not always. > > Definitely handle them as Unicode. You'll receive them in some > encoding, probably UTF-8, and it depends on the browser. You can basically assume it is the encoding that the page the form was on was using - which is a good reason to always explicitly specify utf-8 encoding on HTML pages. >> Also, what do people do when searching for a record. >> Is there some way to get 'Ronngren' to match the other >> possible foreign spellings? > > Ehh....... probably not. That's a human problem, not a programming > one. Best of luck. And yet there are many programs which attempt to solve it. The Python module 'unidecode' will do a decent stab of it if the language is vaguely European. Certainly, storing the UTF-8 string and also the 'unidecoded' ASCII string and searching on both is unlikely to hurt and will often help. Additionally using Metaphone or similar will probably also help. From ameyer2 at yahoo.com Sat Jun 29 16:15:46 2019 From: ameyer2 at yahoo.com (Alan Meyer) Date: Sat, 29 Jun 2019 16:15:46 -0400 Subject: Do I need a parser? In-Reply-To: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> References: <5e122997-3e60-4cff-9e5d-6b69601d3805@googlegroups.com> Message-ID: On 6/29/19 8:39 AM, jos? mariano wrote: > Dear all, > > I'm sure that this subject has been addressed many times before on this forum, but my poor knowledge of English and of computer jargon and concepts results on not being able to find the answer i'm looking for when I search the forum. > > So here is my problem: I have this open source project for the scientific community were i want to duplicate an old MS-DOS application written in Fortran. I don't have the source code. The idea is to re-write the software in Python. Originally, the old application would would need to input files: one config file, written with a specific format (see below) and a second one, the so-called scrip file, that defines the sequence of operations to be performed by the main software, also written in a specific format. > > To make the transition to the new application as painless as possible to the users, because most of them have their collection of scrips (and settings) developed over the years and are not willing to learn a new script language, I would like to make the new app 100% compatible with the old input files. > > The operation of the new software would be like this: From the shell, run "my_new_software old_script_file.***". The new software would load the old_script, parse it (?), set the internal variables, load the script and run it. > > So, to get to my questions: > > - To load and read the config file I need a parser, right? Is their a parser library where we can define the syntax of the language to use? Are there better (meaning easier) ways to accomplish the same result? > > - For the interpretation of the script file, I don't have any clue how to this... One important thing, the script language admits some simple control flow statements like do-wile, again written using a specific sintax. > > Thanks a lot for the help and sorry for the long post. > > Mariano > > > > Example of a config (settings) file > ======================== > ..... > CONDAD -11 > BURAD2 4 SALT1 1.0 KNO3 > ELEC5 -2.0 mV 400 58 0. 0 > ..... > > > Example of a script > =================== > !Conductivity titration > cmnd bur1 f > set vinit 100 > set endpt 2000 > set mvinc 20 > set drftim 1 > set rdcrit cond 0.5 per_min > set dosinc bur1 0.02 1000 > set titdir up > titratc cond bur1 I'll just add a general comment here. Yes, you do need a parser and that parser should be a separate module or separate class from the rest of your program. As Thomas Jollans wrote, str.split() might be enough to do all of the string twiddling for you. If you have a separate class (or group of classes) that produces a configuration object and a script object then, if you discover examples of configuration or script files that you weren't aware of when you wrote the code, then may you only need to modify your parser code and may not have to modify your script execution logic. Finally, I want to say that I wish everyone in the U.S. had as much command of English as you do. Si pudiera hablar espa?ol tan bien como usted habla ingl?s, estar?a muy feliz. (You should have seen what that looked like before I applied Google Translate :) Alan From adam.preble at gmail.com Sat Jun 29 19:15:19 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Sat, 29 Jun 2019 16:15:19 -0700 (PDT) Subject: Plumbing behind super() In-Reply-To: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> Message-ID: <5c0596ca-f3ee-43e8-8007-6e634f09c994@googlegroups.com> Thanks for the replies from everybody. It looks like I should double check super_init and see what truck is coming from that which will hit me with a gotcha later. I'm very naively right now plucking the class from my locals and I was able to proceed in the very, very short term. I think I would have run into something like this earlier but I was doing something else incorrectly with self references in general. I was having my byte code push the object reference on the stack for method calls instead of using a naive one. For example: m.change_a(2) Disregarding unrelated code, it disassembles to this in a 3.6 intepreter: 3 6 LOAD_FAST 0 (m) 8 LOAD_ATTR 1 (change_a) 10 LOAD_CONST 1 (2) 12 CALL_FUNCTION 1 I have been doing an oopsies of trying to push the self reference on the stack for the method. So I'm doing something like: 3 6 LOAD_FAST 0 (m) 8 LOAD_ATTR 1 (change_a) X LOAD_FAST 0 (m) 10 LOAD_CONST 1 (2) 12 CALL_FUNCTION 2 Whoops. Now I need to figure out how the interpreter knows that change_a is a method and knows what self to feed it. I'm assuming that's in the cell variables similar to what super()'s doing as explained here. I haven't implemented cell variables so this is where I'm stuck in a sand pit. From cs at cskk.id.au Sat Jun 29 19:24:19 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 30 Jun 2019 09:24:19 +1000 Subject: change spacing to two instead of four with pep8 or flake8? In-Reply-To: <7caf6a72-7bf3-430a-a182-80a37b905169@www.fastmail.com> References: <7caf6a72-7bf3-430a-a182-80a37b905169@www.fastmail.com> Message-ID: <20190629232419.GA58805@cskk.homeip.net> On 29Jun2019 10:19, Malcolm Greene wrote: >> I've also taken to having my files auto-formatted with yapf on save ... > >@Cameron: Have you considered black at all and if so, what are your >thoughts? I did consider black. Its core selling point was its total inflexibility. Use this and stop _caring_ about the formatting: it will be PEP8 compliant and readable. It is like "go fmt" in that regard (Which I use with Go, when I use Go - you can see that in the "format" script I posted). The target here is: all code uses the same style, the chosen style is good (readable, reasonable, acceptable to most people), let's just use it and spent our time worrying about coding instead of style. However, I want flexibility. Like the OP, I use 2 spece indentation and have my own foibles. Here is the .style.yapf file I use in my personal code: [style] based_on_style = pep8 blank_line_before_module_docstring = True blank_line_before_nested_class_or_def = True blank_lines_around_top_level_definition = 1 dedent_closing_brackets = True #indent_dictionary_value = True indent_width = 2 split_before_expression_after_opening_paren = True split_before_first_argument = True split_complex_comprehension = True space_between_ending_comma_and_closing_bracket = False split_before_dot = true use_tabs = False This comes remarkably close to the style I was hand applying before biting the bullet and putting in the work required to get my editor to autoformat on save. [ Aside: another nice thing about autoformatting, over the "nice!" feeling one gets seeing the code shuffle around in front of one's face, is that if there's a syntax error the code _doesn't_ shuffle around and one can go "whoops" and eyeball the code more closely. ] Cheers, Cameron Simpson From tjol at tjol.eu Sat Jun 29 19:32:27 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 30 Jun 2019 01:32:27 +0200 Subject: Plumbing behind super() In-Reply-To: <5c0596ca-f3ee-43e8-8007-6e634f09c994@googlegroups.com> References: <2d7efa58-4943-45b6-9190-d25b331364b4@googlegroups.com> <5c0596ca-f3ee-43e8-8007-6e634f09c994@googlegroups.com> Message-ID: <2440ad2d-eb40-e939-416f-3ca7baffa482@tjol.eu> On 30/06/2019 01:15, adam.preble at gmail.com wrote: > > Whoops. Now I need to figure out how the interpreter knows that change_a is a method and knows what self to feed it. I'm assuming that's in the cell variables similar to what super()'s doing as explained here. I haven't implemented cell variables so this is where I'm stuck in a sand pit. Look up descriptors. Actually, carefully (re)read all of https://docs.python.org/3/reference/datamodel.html From PythonList at DancesWithMice.info Sat Jun 29 21:57:45 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 30 Jun 2019 13:57:45 +1200 Subject: Use global, or not In-Reply-To: <87lfxkbosq.fsf@munus.decebal.nl> References: <87pnmxbz9t.fsf@munus.decebal.nl> <8792020e-bdcf-6e14-bcdf-9e0fc0b1b87c@DancesWithMice.info> <87lfxkbosq.fsf@munus.decebal.nl> Message-ID: On 29/06/19 11:42 PM, Cecil Westerhof wrote: > DL Neil writes: >> On 29/06/19 1:44 AM, Cecil Westerhof wrote: >>> I have written a GUI program where I have quit a few global variables. >>> I did not like this, so I now use one global dict. Something like: >>> global global_dict >> ... >> >>> Is that an acceptable way to do this? >> >> If it works, isn't that the largest part of "acceptable"? > > Depends on your way of thinking. ;-) You detected that I had my tongue firmly stuck in my cheek! > I think it is always best when you write in a language to do it in > that languages way. In this case Python. > I also think this is a program that could be interesting to share. > Then it becomes even more important to do it the Python way. > And my experience is that when asking this type of question you often > get a tip that helps you make your program better. Here's hoping that you have/will! Speaking personally, I avoid using "global". Earlier, the topic of "namespaces" was broached. The danger of nesting one namespace inside another is that the local scope may (accidentally) override THE name, or that one forgets the "global variable_name" line-of-code. Added to which, are OOP virtues which talk about separation and encapsulation, etc... The pythonic way includes contentions: 1 There should be one-- and preferably only one --obvious way to do it. - although you might not like the next line, until it is understood to be a joke at Guido's expense... 2 "we are all adults here". >> In each case, (previously discussed and/or below) you are taking >> advantage of "namespaces" to keep one 'lot' of values separated and >> distinct from others - as well as finding a means of 'passing them >> around'. The other half of the considerations is how the values are >> being retrieved/utilised within the mainline code. >> >> An alternative might be to use a class. Then accessing a single value >> becomes instance.attribute, but when you have need for several >> attribute's values or to compute a value from several attributes, an >> instance.method() may simplify things. > > That was the other possibility I was thinking about. And that would be > maybe better. Because I now do things like: > global_dict['messages']['created'].format(len(filepathArr)) > > much better would be: > instance.created(len(filepathArr)) +1 Scanning my projects directory, there seems to be quite a mix of classes and modules to handle this situation. ("one way"..."obvious"???) The last example might recommend an investigation of "property". I'm slightly reluctant to suggest this to someone coming from another, more structured, language, eg Java, because it is so easy to make a literal-translation between languages and (as you have said) miss a pythonic advantage, eg direct access to instance.attribute (cf the need to code "getters", such as "instance.get_attribute()"). Most (Python) "property" tutorials seem to center on attempts to reproduce "private variables". (you can't really/easily and (again) aren't we "all adults...") However, I like using @property whenever there is some computation-required involving attributes, eg class name(): ... @property def filepath_length( self ): return len( filepath_arr ) ... instance.filepath_length Again, speaking personally, the advantages relate to readability and separation of concerns (I'd like the answer delivered, not the need to compute something which the object should do as part of 'itself' - IMHO) Warning: there's a few statements and opinions 'here' which others may care to argue - and like you I'm happy to (hope to) learn something useful... Refs: The "Zen of Python": start python and import this https://docs.python.org/3.6/howto/descriptor.html?highlight=property https://docs.python.org/3.6/library/functions.html?highlight=property#property https://docs.python.org/3.6/tutorial/classes.html -- Regards =dn From torriem at gmail.com Sat Jun 29 22:54:48 2019 From: torriem at gmail.com (Michael Torrie) Date: Sat, 29 Jun 2019 20:54:48 -0600 Subject: Use global, or not In-Reply-To: <87lfxkbosq.fsf@munus.decebal.nl> References: <87pnmxbz9t.fsf@munus.decebal.nl> <8792020e-bdcf-6e14-bcdf-9e0fc0b1b87c@DancesWithMice.info> <87lfxkbosq.fsf@munus.decebal.nl> Message-ID: On 06/29/2019 05:42 AM, Cecil Westerhof wrote: > That was the other possibility I was thinking about. And that would be > maybe better. Because I now do things like: > global_dict['messages']['created'].format(len(filepathArr)) > > much better would be: > instance.created(len(filepathArr)) Sure. But if you put all your globals in a class, you're most likely only ever going to instantiate it once, so it's really a singleton. And the standard Python implementation of a singleton is usually a module. So just create a file called globals.py and place all your globals in there. Then import it into each module that needs it and refer to it as globals.whatever. This is what I do and I've seen others do this also. So it must be right! haha. From torriem at gmail.com Sun Jun 30 00:52:28 2019 From: torriem at gmail.com (Michael Torrie) Date: Sat, 29 Jun 2019 22:52:28 -0600 Subject: How do you insert an item into a dictionary (in python 3.7.2)? In-Reply-To: References: Message-ID: <5dd20576-bc9b-1113-497c-d0a532839f0d@gmail.com> On 06/28/2019 09:06 AM, CrazyVideoGamez wrote: > How do you insert an item into a dictionary? For example, I make a dictionary called "dictionary". > > dictionary = {1: 'value1', 2: 'value3'} > > What if I wanted to add a value2 in the middle of value1 and value3? How about: dict[1.5] = 'value2' In seriousness, though, it looks like you really want to be using a list instead of a dict. You can insert things into a list using the "insert" method of the list. a = ['value1', 'value3'] print (a[0]) a.insert(1,'value2') print (a) From mal at europython.eu Sun Jun 30 06:37:30 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 30 Jun 2019 12:37:30 +0200 Subject: EuroPython 2019: More Attendee Updates Message-ID: <640d5e38-8d2a-bdb0-fe45-47eb8c35f2e2@europython.eu> We have had a whole set of updates in the last two days. In order not to spam you too much with all the blog post texts, we're sending out a summary. EuroPython 2019 Keynotes ------------------------ We are proud to announce our keynote lineup for EuroPython 2019: - AI in Contemporary Art by Luba Elliott - Are women underrepresented in the High Performance Computing (HPC) community? by Athina Frantzana - Getting Your Data Joie De Vivre Back! by Lynn Cherny - Python Performance: Past, Present and Future by Victor Stinner - Why You Should Pursue Public Speaking and How to Get There by Yenny Cheung Full text: https://blog.europython.eu/post/185904088457/europython-2019-keynotes EuroPython 2019: Call for On-site Volunteers -------------------------------------------- Ever wanted to help out during Europython ? Do you want to *really* take part in EuroPython, meet new people and help them at the same time ? We have just the right thing for you: apply as EuroPython Volunteer and be part of the great team that is making EuroPython 2019 a reality this year. Full text and how to sign up: https://blog.europython.eu/post/185904252962/europython-2019-call-for-on-site-volunteers EuroPython 2019: Social event tickets available ----------------------------------------------- After the keynotes and talks on Thursday, July 11th, we?ve organized a social event at the workshop venue, the FHNW Muttenz. Starting at 19:00 CEST, you can join us for an evening party with finger food, drinks and music. Full text: https://blog.europython.eu/post/185929674552/europython-2019-social-event-tickets-available EuroPython 2019: SIM cards for attendees ---------------------------------------- Switzerland is often not included in European cell provider?s roaming packages and also not covered by the EU roaming regulation, so you can potentially incur significant charges when going online with your mobile or notebook. In order to make things easier for you, we have purchased 300 SIM cards from a local Swiss cell provider, which we will make available in our ticket shop. After purchase, you can then pick up the cards at the registration desk (please bring your receipt). Full text and how to buy: https://blog.europython.eu/post/185929675562/europython-2019-sim-cards-for-attendees Dates and Venues ---------------- EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at the Congress Center Basel (CCB) for the main conference days (Wed-Fri) and the FHNW Muttenz for the workshops/trainings/sprints days (Mon-Tue, Sat-Sun). The schedule is available at: https://ep2019.europython.eu/events/schedule/ Tickets can be purchased on our registration page: https://ep2019.europython.eu/registration/buy-tickets/ For more details, please have a look at our website and the FAQ: https://ep2019.europython.eu/faq 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 posts: https://blog.europython.eu/ Tweets: https://twitter.com/europython/ Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Sun Jun 30 06:40:22 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 30 Jun 2019 12:40:22 +0200 Subject: EuroPython 2019: Introducing MongoDB Message-ID: We are very pleased to have MongoDB as Keystone Sponsor for EuroPython 2019. You can visit them at the most central booth in our exhibit area on the second floor in the Congress Center Basel (CCB), and take the opportunity to chat with their staff and learn more about the MongoDB eco-system. Please find below a hosted blog post from MongoDB. Enjoy, ? EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ MongoDB ? Python ---------------- MongoDB is the leading modern, general-purpose database platform, designed to unleash the power of software and data for developers and the applications they build. We have architected our database to cater to the needs of modern-day applications from the ground-up with built-in support for high availability through sophisticated replication with self-healing recovery and horizontal scalability through native sharding. MongoDB Atlas is our fully-automated database-as-a-service offering, engineered and run by the same team that builds the database. At MongoDB, it is our mission to make data ridiculously easy to work with and we love, love, LOVE Python because it helps us do exactly that. To bring the power of MongoDB to the Python ecosystem, we?ve developed PyMongo - the Python driver for MongoDB. With over 3 million downloads per month, PyMongo is one of our most popular drivers. Our Driver team also maintains Motor - an asynchronous Python driver for MongoDB and PyMODM - our object-document mapper. While Python is an important and popular tool for our users, it is also an integral part of developer workflows across our engineering teams. Our Documentation team, for instance, maintains the Giza library which is used to render the entire official MongoDB documentation. Our Education team builds MongoDB University with Django and uses PyMODM and MongoDB Atlas to store application data. The University site has over 1 million registered users and over 100,000 active users per month?all powered by MongoDB. Python is also an integral part of our CI/CD process used to test our core database and all drivers. Join us at our workshop where we will teach you how to harness the power of MongoDB Atlas to build a highly-available CRUD application using Flask and PyMongo. You will learn more about MongoDB?s document data model, how we ensure high-availability and best practices for building applications using MongoDB. We will also showcase how to build the same application in MongoDB Stitch - our serverless platform. Bring your laptops! MongoDB is proud to support the Python community. In the past, we have sponsored conferences such as PyCon and PyGotham, and also hosted meetups such as PyLadies. Drop by our booth (#10) to say ?hi? to our awesome team and to learn more about Python at MongoDB! You can also join the conversation with other MongoDB and Python community members in our Community Slack Workspace. Register at http://launchpass.com/mongo-d or login at http://mongo-db.slack.com. From Richard at Damon-Family.org Sun Jun 30 08:21:53 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 30 Jun 2019 08:21:53 -0400 Subject: Handle foreign character web input In-Reply-To: <24016ef6-4122-4293-b2e1-8f2812807dfd@googlegroups.com> References: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> <24016ef6-4122-4293-b2e1-8f2812807dfd@googlegroups.com> Message-ID: On 6/30/19 4:00 AM, moi wrote: > Le samedi 29 juin 2019 19:25:40 UTC+2, Richard Damon a ?crit?: >> >> Now (as I understand it), all Python (3) 'Strings' are internally >> Unicode, if you need something with a different encoding it needs to be >> in Bytes. >> >> -- > > Unfortunately not. > > The only thing Python succeeds to propose is a mechanism > which does the opposite of UTF-8 when it comes to handle > memory *and* - at the same time - which also does the opposite > of UTF-32 regarding performance. > > For some other reasons, this mechanism leads to buggy > code. > My understanding was that the Python 3 'String' class always used a Unicode encoding (never a code-page encoding). If you indexed into a string you would get at each location the full code point value of that character. Now Unicode isn't just UTF-8 or UTF-32/UCS-4 or the like, those are just different ways to encode into memory/a stream Unicode code points. It may be that Python makes some awkward choices of how it wants to store the characters in memory, but to the programmer, it is just Unicode code points. If you specifically want something list a UTF-8 encoding, that is one of the usages of Bytes was. From cousinstanley at gmail.com Sun Jun 30 09:56:05 2019 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 30 Jun 2019 06:56:05 -0700 Subject: Make sure the window title is visible in tkinter References: <87y31oegh0.fsf@munus.decebal.nl> <56a28c28-03e0-4947-9722-8977fc5457df@googlegroups.com> Message-ID: Cousin Stanley wrote .... >> You might try setting a given window geometry >> to accomodate the long title .... >> >> win_w = 400 >> win_h = 300 >> >> ofs_h = 40 >> ofs_v = 30 >> >> window.geometry( "%dx%d+%d+%d" % ( win_w , win_h , ofs_h , ofs_v ) ) >> >> >> Maybe add a bit of extra space for users >> with different default font sizes .... >> >> Not a general solution >> but perhaps workable .... moi wrote .... > No, huge mistake. It isn't clear to me how specifying a particular geometry for one's own self-coded tkinter gui prgrams with windows that are resize-able would be a mistake .... > Take for example the Windows installer. > > The window is so small, you can not even read the path > where Python will be installed. > > Bonus: the windows is not resizable and part of items > are not even visible. > > It would be to bad to not mimic this behavior. > > Just tested it 2 min ago on my Windows 7.1 with py3.7.3. I didn't suggest modifying 3rd party programs, but the suggestion I offered was meant to be applied to one's own code .... I have used a given geometry for dozens of my own tkinter gui programs such that a modest window size which assures that all widgets are viewable when first presented to the user .... -- Stanley C. Kitching Human Being Phoenix, Arizona From rosuav at gmail.com Sun Jun 30 10:04:15 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jul 2019 00:04:15 +1000 Subject: Handle foreign character web input In-Reply-To: References: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> <24016ef6-4122-4293-b2e1-8f2812807dfd@googlegroups.com> Message-ID: On Sun, Jun 30, 2019 at 10:26 PM Richard Damon wrote: > > On 6/30/19 4:00 AM, moi wrote: > > Le samedi 29 juin 2019 19:25:40 UTC+2, Richard Damon a ?crit : > >> > >> Now (as I understand it), all Python (3) 'Strings' are internally > >> Unicode, if you need something with a different encoding it needs to be > >> in Bytes. > >> > >> -- > > > > Unfortunately not. > > > > The only thing Python succeeds to propose is a mechanism > > which does the opposite of UTF-8 when it comes to handle > > memory *and* - at the same time - which also does the opposite > > of UTF-32 regarding performance. > > > > For some other reasons, this mechanism leads to buggy > > code. > > > > My understanding was that the Python 3 'String' class always used a > Unicode encoding (never a code-page encoding). If you indexed into a > string you would get at each location the full code point value of that > character. Now Unicode isn't just UTF-8 or UTF-32/UCS-4 or the like, > those are just different ways to encode into memory/a stream Unicode > code points. It may be that Python makes some awkward choices of how it > wants to store the characters in memory, but to the programmer, it is > just Unicode code points. If you specifically want something list a > UTF-8 encoding, that is one of the usages of Bytes was. I didn't see who you were quoting, but it looks like our old "Py3's Unicode is buggy" troll is back (or maybe he never left, he just got banned from the mailing list). The ONLY bugginess he has ever shown is a performance regression on a very specific sort of operation where the old (Py2) behaviour was *actually* buggy. Take no notice of him; he is either trolling or somehow deluded, and either way, he never listens to people's responses. Waste none of your time on him. ChrisA From torriem at gmail.com Sun Jun 30 10:10:24 2019 From: torriem at gmail.com (Michael Torrie) Date: Sun, 30 Jun 2019 08:10:24 -0600 Subject: Handle foreign character web input In-Reply-To: References: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> <24016ef6-4122-4293-b2e1-8f2812807dfd@googlegroups.com> Message-ID: On 06/30/2019 06:21 AM, Richard Damon wrote: > On 6/30/19 4:00 AM, moi wrote: >> Unfortunately not. >> >> The only thing Python succeeds to propose is a mechanism >> which does the opposite of UTF-8 when it comes to handle >> memory *and* - at the same time - which also does the opposite >> of UTF-32 regarding performance. I guess "moi" is banned from the mailing list for posting this kind of rubbish, just like our other old unicode troll as I see no trace of his post on the list. Which is just as well. It's completely wrong. The in-memory, internal byte encoding of unicode is irrelevant to the programmer. In Python 3 we deal with unicode. Period. Any performance issues he or our other unicode troll (perhaps the same person?) stem from not understanding the nature of immutable strings. >> For some other reasons, this mechanism leads to buggy >> code. No it doesn't. Without any evidence to back him up, this is a complete fabrication on Moi's part. > My understanding was that the Python 3 'String' class always used a > Unicode encoding (never a code-page encoding). If you indexed into a > string you would get at each location the full code point value of that > character. Now Unicode isn't just UTF-8 or UTF-32/UCS-4 or the like, > those are just different ways to encode into memory/a stream Unicode > code points. It may be that Python makes some awkward choices of how it > wants to store the characters in memory, but to the programmer, it is > just Unicode code points. If you specifically want something list a > UTF-8 encoding, that is one of the usages of Bytes was. That's correct. It doesn't matter what format Python chooses to use in memory. Some argue that O(1) indexing of a unicode string is not important because indexing a unicode string by code point (a "character") is incorrect some/much of the time, owing to the fact that sometimes what is seen as a single character on the screen is actually composed of more than one code point (grapheme cluster). Hence using UTF-8 internally is good enough, and encoding to bytes is a no-op (fast). From Richard at Damon-Family.org Sun Jun 30 15:07:27 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 30 Jun 2019 15:07:27 -0400 Subject: Handle foreign character web input In-Reply-To: References: <8dea3921-63db-df9f-5482-b6732c4344ee@tjol.eu> <24016ef6-4122-4293-b2e1-8f2812807dfd@googlegroups.com> Message-ID: <23cf5919-e3d2-189c-ef5d-59382641335d@Damon-Family.org> On 6/30/19 10:04 AM, Chris Angelico wrote: > On Sun, Jun 30, 2019 at 10:26 PM Richard Damon wrote: >> On 6/30/19 4:00 AM, moi wrote: >> > I didn't see who you were quoting, but it looks like our old "Py3's > Unicode is buggy" troll is back (or maybe he never left, he just got > banned from the mailing list). The ONLY bugginess he has ever shown is > a performance regression on a very specific sort of operation where > the old (Py2) behaviour was *actually* buggy. Take no notice of him; > he is either trolling or somehow deluded, and either way, he never > listens to people's responses. Waste none of your time on him. > > ChrisA Looking back, I made that reply on comp.lang.python and I guess the person is blocked from being relayed to python-list. I guess I forgot which place I was reading at the time. -- Richard Damon From mmuratkutlu at gmail.com Sun Jun 30 16:18:39 2019 From: mmuratkutlu at gmail.com (mmuratkutlu at gmail.com) Date: Sun, 30 Jun 2019 13:18:39 -0700 (PDT) Subject: I have anaconda, but Pycharm can't find it In-Reply-To: References: Message-ID: Hi everyone, I know this problem's solution because I solve in my computer. First of all, you can delete the project files. After that download python on official website and last version. after this step restart pycharm and create new project... Good luck From kayanjaismail070 at gmail.com Sun Jun 30 16:49:30 2019 From: kayanjaismail070 at gmail.com (kayanjaismail070 at gmail.com) Date: Sun, 30 Jun 2019 13:49:30 -0700 (PDT) Subject: python Message-ID: <65f591e5-521a-46bc-868f-cc5617c702fe@googlegroups.com> Use a while loop and write a python program to display the first n, numbers divisible by both 3 and 5 . the amount of numbers to be displayed should be dictated by the user input (Hint: if the users 10, then the numbers divisible by both 4 and 5 to be displayed should be 10) From ikorot01 at gmail.com Sun Jun 30 17:57:01 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 30 Jun 2019 16:57:01 -0500 Subject: python In-Reply-To: <65f591e5-521a-46bc-868f-cc5617c702fe@googlegroups.com> References: <65f591e5-521a-46bc-868f-cc5617c702fe@googlegroups.com> Message-ID: Hi, On Sun, Jun 30, 2019 at 3:52 PM wrote: > > Use a while loop and write a python program to display the first n, numbers divisible by both 3 and 5 . the amount of numbers to be displayed should be dictated by the user input (Hint: if the users 10, then the numbers divisible by both 4 and 5 to be displayed should be 10) And what are we suppose to do do with it? Please give more information - what you tried, what doesn't work, did you try to debug it, what algorithm being used? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Jun 30 17:00:16 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jul 2019 07:00:16 +1000 Subject: python In-Reply-To: <65f591e5-521a-46bc-868f-cc5617c702fe@googlegroups.com> References: <65f591e5-521a-46bc-868f-cc5617c702fe@googlegroups.com> Message-ID: On Mon, Jul 1, 2019 at 6:51 AM wrote: > > Use a while loop and write a python program to display the first n, numbers divisible by both 3 and 5 . the amount of numbers to be displayed should be dictated by the user input (Hint: if the users 10, then the numbers divisible by both 4 and 5 to be displayed should be 10) > This isn't a "do my homework for me" service. Do your homework. ChrisA From giaym.mail at gmail.com Sun Jun 30 19:18:23 2019 From: giaym.mail at gmail.com (gia .) Date: Sun, 30 Jun 2019 18:18:23 -0500 Subject: Python 3.7.3 - ImportError: dynamic module does not define module export function (PyInit_*) Message-ID: Hi, I was trying to upgrade a python 2 extension in Linux and hit this error upon trying to import it into python 3. The weird thing is that I can see the symbol when I use readelf -a, so it is not missing, it has visibility default and it defines as extern "C" PyObject* return type (using the macro). I build with g++ 6, global visibility hidden and inline hidden, would that affect it? does it need to find other functions? readelf -d shows that a NEEDED library is my altinstall build of python 3.7.3's libs, so that makes me think g++ found the correct library (there is an oder system library installed). RUNPATH is configured with a relative path that leads upwards in the folder tree to the python libs. It points to the same lib folder as the interpreter's RUNPATH, which is also relative. The module name starts with a underscore, so that's a point of worry, the standard mentioned ascii, so I assumed underscore is fine, but maybe it meant alphanumeric. The module is _mymodule_python3, and the init is PyInit__mymodule_python3, with the *.so being _mymodule_python3.so and a python file mymodule.py that loads the module inside using 'import my.package._mymodule_python3'. The cpp file is encoded in utf8, but the module name string that goes in the module def is not L"", it is plain char. I load python3 manually and then import this py file and it finds the so file, but at the end prints the error, I can exit, load another python3 and import the so directly and same outputs. sys.path doesnt point to the system install. I read the standard page and it seems everything is set up correctly (although it obviously isn't or it should be working). I've had a lot of difficulty debugging the import call because it is frozen so I can't just edit the _bootstrap.py file, I edit it and it still uses the frozen code. I even edited the file in the source tree itself by adding a few print calls then rebuilt cpython, and they seem to be consumed by the freeze pass, as nothing gets printed, how do you debug it properly? google is not helping me. import is failing at _gcd_import (name, package = None, level = 0) -> find and load. And if I use a different loading method by importing importlib (used in documentation page), it manages to obtain the spec which looks okay upon printing it, but fails upon trying to load and return the module object with spec.loader.create_module. Appreciate ideas or a proper debugging method for the import function.