From pahome.chen at mirlab.org Thu Nov 1 05:29:04 2018 From: pahome.chen at mirlab.org (lampahome) Date: Thu, 1 Nov 2018 17:29:04 +0800 Subject: matplotlib.plot.show always blocks the execution of python script Message-ID: I want to plot a graph and *still run following code without closing the graph automatically like Matlab does*. I try plt.show(block=False) , it failed and appear in a small moment then close itself. I also try plt.draw() or interactive mode , it failed, too. plt.draw() will block until I close it. interactive mode and plot.show() will appear nothing My version is below: user at ya:~/$ sudo pip freeze | grep matplotlib matplotlib==2.2.3 user at ya:~/$ sudo pip -V pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7) Environments: I only execute script in Ubuntu ex: user at ya: python xxx.py Distributor ID: Ubuntu Description: Ubuntu 16.04.5 LTS Release: 16.04 Codename: xenial Can anyone help me? I just want to do like Matlab which won't close the plotted graph even if the script finishes. From kgrenczuk at gmail.com Thu Nov 1 10:40:06 2018 From: kgrenczuk at gmail.com (jacob m) Date: Thu, 1 Nov 2018 15:40:06 +0100 Subject: gmpy2 problem Message-ID: Hi guys I have some problems with gmpy2 module installation - pip install gmpy2 doesn't work for me [image: image.png] How to fix it? Regards From rhodri at kynesim.co.uk Thu Nov 1 11:40:24 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 1 Nov 2018 15:40:24 +0000 Subject: gmpy2 problem In-Reply-To: References: Message-ID: <5f186e5f-0ee7-b86b-290b-14d29885241b@kynesim.co.uk> On 01/11/2018 14:40, jacob m wrote: > Hi guys > I have some problems with gmpy2 module installation - pip install gmpy2 > doesn't work for me > [image: image.png] > > How to fix it? Hi Jacob, I'm afraid the screen-shot that you sent was automatically stripped off by the mailing list. Could you copy the error text (preferably cut-and-paste the whole thing rather than retyping!)? The more information you can give us, the better the advice will be from the people who actually understand pip :-) -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Thu Nov 1 13:41:48 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 1 Nov 2018 17:41:48 +0000 Subject: gmpy2 problem In-Reply-To: References: <5f186e5f-0ee7-b86b-290b-14d29885241b@kynesim.co.uk> Message-ID: Replying to the list since I have absolutely no idea about gmpy2 or pip... On 01/11/2018 16:56, jacob m wrote: > Hi Rodhri, of course I can paste the text :) > " > creating build > creating build/temp.linux-x86_64-3.7 > creating build/temp.linux-x86_64-3.7/src > gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 > -Wall -fPIC -DWITHMPFR -DWITHMPC -I/home/lib/python3.7/include/python3.7m > -c src/gmpy2.c -o build/temp.linux-x86_64-3.7/src/gmpy2.o > In file included from src/gmpy2.c:426:0: > src/gmpy.h:106:12: fatal error: gmp.h: No such file or directory > # include "gmp.h" > ^~~~~~~ > compilation terminated. > error: command 'gcc' failed with exit status 1 > > ---------------------------------------- > Command "/home/lib/python3.7/bin/python3.7 -u -c "import setuptools, > tokenize;__file__='/tmp/pip-install-kiqba_j_/gmpy2/setup.py';f=getattr(tokenize, > 'open', open)(__file__);code=f.read().replace('\r\n', > '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record > /tmp/pip-record-2jatj1mi/install-record.txt > --single-version-externally-managed --compile" failed with error code 1 in > /tmp/pip-install-kiqba_j_/gmpy2/ > " A little googling suggests that you need to install the libgmp3-dev package: $ sudo apt install libgmp3-dev > On Thu, 1 Nov 2018 at 16:46, Rhodri James wrote: > >> On 01/11/2018 14:40, jacob m wrote: >>> Hi guys >>> I have some problems with gmpy2 module installation - pip install gmpy2 >>> doesn't work for me >>> [image: image.png] >>> >>> How to fix it? >> >> Hi Jacob, >> >> I'm afraid the screen-shot that you sent was automatically stripped off >> by the mailing list. Could you copy the error text (preferably >> cut-and-paste the whole thing rather than retyping!)? The more >> information you can give us, the better the advice will be from the >> people who actually understand pip :-) -- Rhodri James *-* Kynesim Ltd From kamukamadariet at gmail.com Fri Nov 2 03:57:33 2018 From: kamukamadariet at gmail.com (Dariet Kamukama) Date: Fri, 2 Nov 2018 00:57:33 -0700 (PDT) Subject: introduction Message-ID: <5d3074a2-5188-4b35-958b-7697da5b79ac@googlegroups.com> hey hw is every body here, am new to the group and want to learn python From jeff at magentatech.com Fri Nov 2 10:42:24 2018 From: jeff at magentatech.com (Jeff M) Date: Fri, 2 Nov 2018 07:42:24 -0700 (PDT) Subject: AES Encryption/Decryption Message-ID: Python newbie here, looking for code samples for encrypting and decrypting functions, using AES. See lots of stuff on the interwebs, but lots of comments back an forth about bugs, or implemented incorrect, etc... I need to encrypt some strings that will be passed around in URL, and then also some PII data at rest. Thanks. From lutz.horn at posteo.de Fri Nov 2 10:52:23 2018 From: lutz.horn at posteo.de (Lutz Horn) Date: Fri, 2 Nov 2018 15:52:23 +0100 Subject: AES Encryption/Decryption In-Reply-To: References: Message-ID: <20181102145223.GA26868@lutz-pc.ecm4u.intra> On Fri, Nov 02, 2018 at 07:42:24AM -0700, Jeff M wrote: > Python newbie here, looking for code samples for encrypting and > decrypting functions, using AES. See lots of stuff on the interwebs, > but lots of comments back an forth about bugs, or implemented > incorrect, etc... > > I need to encrypt some strings that will be passed around in URL, and > then also some PII data at rest. Use https://pypi.org/project/cryptography/ Lutz From christian at python.org Fri Nov 2 11:05:23 2018 From: christian at python.org (Christian Heimes) Date: Fri, 2 Nov 2018 16:05:23 +0100 Subject: AES Encryption/Decryption In-Reply-To: References: Message-ID: On 02/11/2018 15.42, Jeff M wrote: > Python newbie here, looking for code samples for encrypting and decrypting functions, using AES. See lots of stuff on the interwebs, but lots of comments back an forth about bugs, or implemented incorrect, etc... > > I need to encrypt some strings that will be passed around in URL, and then also some PII data at rest. Don't use raw AES. It's hard to get it right in the first place. I'd recommend Fernet if you want something based on AES. Fernet is a good high level algorithm that combines AES, safe padding, block mode, and MAC in a sane and safe message format. https://cryptography.io/en/latest/fernet/ Christian From sgonzales at inflightwarningsystems.com Fri Nov 2 13:53:43 2018 From: sgonzales at inflightwarningsystems.com (Steve Gonzales) Date: Fri, 2 Nov 2018 17:53:43 +0000 Subject: FW: error code Message-ID: <0e1a6394e645462f8066a526ee4e7c6f@inflightwarningsystems.com> I just subscribed. From: Steve Gonzales Sent: Friday, November 02, 2018 7:20 AM To: 'python-list at python.org' Subject: error code Hello Python, I have installed c:\Python37 to my path and I still experience this issue "'python' is not recognized as an internal or external command, operable program or batch file.". I just installed the latest python version win 64bit using the newest sublime editor. Hopefully you can recommend a fix. Best Regards, Steve Gonzales Manager - Predictive Solutions (office)714-993-9394 ext. 21310 (direct)714-646-7707 [cid:image001.jpg at 01D3C521.6937E5E0] Predict the Future of Your Flight Operations CONFIDENTIALITY NOTICE: This e-mail and any transmitted files are private and confidential and are solely for the use of the recipient(s) to whom it is addressed. Any unauthorized review, use, disclosure, distribution or copying of this communication is strictly forbidden. If you have received this communication in error, please delete and immediately notify the sender via the e-mail return address. Thank you for your compliance. From songbird at anthive.com Fri Nov 2 15:03:01 2018 From: songbird at anthive.com (songbird) Date: Fri, 2 Nov 2018 15:03:01 -0400 Subject: introduction References: <5d3074a2-5188-4b35-958b-7697da5b79ac@googlegroups.com> Message-ID: <5kjuaf-ks3.ln1@anthive.com> Dariet Kamukama wrote: > hey hw is every body here, am new to the group and want to learn python i'm good, thanks... :) i'm also a beginner with python. do you have other programming experience? i have a fair amount of non OOP experience in mostly functional types like C or Pascal. some Lisp, assembler, algol, sql, fortran, many other bits of this and that (shell languages, awk, sed, lex, yacc, etc.)... all i can say about learning a new language is that i need to have a project to work on to make it interesting so i've picked a project and am working on it and picking up ideas as i go and have time to study more. i'm woefully bad at OOP concepts and it takes me a while for things to sink in. i see familiar names here from other lists i've been reading and writing to a few. :) songbird From songbird at anthive.com Fri Nov 2 15:38:42 2018 From: songbird at anthive.com (songbird) Date: Fri, 2 Nov 2018 15:38:42 -0400 Subject: amusing error message Message-ID: <2nluaf-d44.ln1@anthive.com> hello, :) this is just a bit of amusement, i'll post my current question in another thread... please don't critique my style or lack of classes/objects in the code yet - i'm way too new. :) my current project is at: https://salsa.debian.org/ant-guest/gfpoken-in-python/ https://salsa.debian.org/ant-guest/gfpoken-in-python/tree/next i'm using pyglet (most recent version) and gtk... the amusing bit: working on my git next branch... in my_sprite.py if i take the self out of on_animation_end parentheses i get this error message: TypeError: The 'on_animation_end' event was dispatched with 0 arguments, but the handler 'on_animation_end' at /home/me/src/salsa/ngfp/my_sprite.py:23 is written with 0 arguments. 0 <> 0 !!!!! :) songbird From songbird at anthive.com Fri Nov 2 15:58:25 2018 From: songbird at anthive.com (songbird) Date: Fri, 2 Nov 2018 15:58:25 -0400 Subject: pyglet, i don't understand why this code isn't working Message-ID: <1smuaf-d44.ln1@anthive.com> hello, :) my question is below, a bit of background first. i'm very new to python and picking it up by working on a project for fun. please don't critique my style or lack of classes/objects in the code yet - i'm way too new. :) my current project is at: https://salsa.debian.org/ant-guest/gfpoken-in-python/ https://salsa.debian.org/ant-guest/gfpoken-in-python/tree/next i'm using pyglet (most recent version) and gtk... in Debian Linux testing. my question is that in on_animation_end in the my_sprite.py class doesn't seem to work as i'd expect. i never reach: print ("Do we Ever get here?") statement. and i'm curious if i've just messed up something obvious here or if my problem is elsewhere? i don't really quite understand subclasses/super yet so perhaps i've abused it? the overall issue is that i'm trying to turn off and on the animation and while i can do it in code like below i haven't yet been able to figure out how to get that into my other code... thanks for your input/consideration. :) p.s. if you don't know the game gfpoken it is in debian/linux and it is a mirror puzzle game. the man page is there. i haven't written help screen or directions yet, but you click on things to the right and place them on the grid on the left until the output of the animation matches the colored arrows. it is mostly done other than some directions, checking the boards for matching/winning, winning game screen and help. just trying to iron this issue out... ===== import pyglet marble_roll_image = pyglet.image.load('green_marbles.png') marble_seq = pyglet.image.ImageGrid(marble_roll_image, 1, 16) anim = pyglet.image.Animation.from_image_sequence(marble_seq, 0.1, True) marble_anim_sprite = pyglet.sprite.Sprite(anim) window = pyglet.window.Window() def test_off (dt, sprite): pyglet.clock.unschedule(sprite._animate) def test_on (dt, sprite): pyglet.clock.schedule(sprite._animate) pyglet.clock.schedule_once(test_off, 5, marble_anim_sprite) pyglet.clock.schedule_once(test_on, 10, marble_anim_sprite) @window.event def on_draw(): window.clear() marble_anim_sprite.draw() @marble_anim_sprite.event def on_animation_end (): print ("on_animation_end ") pyglet.app.run() ===== songbird From python at mrabarnett.plus.com Fri Nov 2 16:48:54 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 2 Nov 2018 20:48:54 +0000 Subject: FW: error code In-Reply-To: <0e1a6394e645462f8066a526ee4e7c6f@inflightwarningsystems.com> References: <0e1a6394e645462f8066a526ee4e7c6f@inflightwarningsystems.com> Message-ID: On 2018-11-02 17:53, Steve Gonzales wrote: [snip] > Hello Python, > > I have installed c:\Python37 to my path and I still experience this issue "'python' is not recognized as an internal or external command, > operable program or batch file.". I just installed the latest python version win 64bit using the newest sublime editor. Hopefully you can recommend a fix. > Use the Python launcher "py". [snip] From python at mrabarnett.plus.com Fri Nov 2 16:57:34 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 2 Nov 2018 20:57:34 +0000 Subject: pyglet, i don't understand why this code isn't working In-Reply-To: <1smuaf-d44.ln1@anthive.com> References: <1smuaf-d44.ln1@anthive.com> Message-ID: On 2018-11-02 19:58, songbird wrote: > > hello, :) > > my question is below, a bit of background first. > i'm very new to python and picking it up by working > on a project for fun. > > please don't critique my style or lack of > classes/objects in the code yet - i'm way too new. :) > > > my current project is at: > > https://salsa.debian.org/ant-guest/gfpoken-in-python/ > https://salsa.debian.org/ant-guest/gfpoken-in-python/tree/next > > i'm using pyglet (most recent version) and gtk... > in Debian Linux testing. > > my question is that in on_animation_end in the my_sprite.py > class doesn't seem to work as i'd expect. > > i never reach: print ("Do we Ever get here?") statement. > > and i'm curious if i've just messed up something obvious > here or if my problem is elsewhere? > [snip] In __init__ you initialise self.animation_initial_turn_it_off to True. Nowhere in your code do you change it, so it remains True. From songbird at anthive.com Fri Nov 2 17:33:58 2018 From: songbird at anthive.com (songbird) Date: Fri, 2 Nov 2018 17:33:58 -0400 Subject: pyglet, i don't understand why this code isn't working References: <1smuaf-d44.ln1@anthive.com> Message-ID: <6fsuaf-od5.ln1@anthive.com> MRAB wrote: > On 2018-11-02 19:58, songbird wrote: >> >> hello, :) >> >> my question is below, a bit of background first. >> i'm very new to python and picking it up by working >> on a project for fun. >> >> please don't critique my style or lack of >> classes/objects in the code yet - i'm way too new. :) >> >> >> my current project is at: >> >> https://salsa.debian.org/ant-guest/gfpoken-in-python/ >> https://salsa.debian.org/ant-guest/gfpoken-in-python/tree/next >> >> i'm using pyglet (most recent version) and gtk... >> in Debian Linux testing. >> >> my question is that in on_animation_end in the my_sprite.py >> class doesn't seem to work as i'd expect. >> >> i never reach: print ("Do we Ever get here?") statement. >> >> and i'm curious if i've just messed up something obvious >> here or if my problem is elsewhere? >> > [snip] > In __init__ you initialise self.animation_initial_turn_it_off to True. > > Nowhere in your code do you change it, so it remains True. i wish it were that easy... see my_sprite.py ... def on_animation_end (self): # we're already running when initialised so we # have to shut it off until we restart it again # but we only have to do this once as from then on # each animation will check the global flag to see # if it should run # print ("AF AC ", self.animation_foo, self.animation_count) self.animation_foo = False self.animation_count += 1 if ((self.animation_initial_turn_it_off == True) and (self.animation_running == True)): print ("initial shut down animation AR True") pyglet.clock.unschedule(self._animate) self.animation_initial_turn_if_off = False ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ self.animation_running = False pprint.pprint(MySprite.__mro__) pprint.pprint(MySprite.on_animation_end) elif ((self.animation_initial_turn_it_off == True) and (self.animation_running == False)): # we shouldn't get here, but just in case # just turn it off again... # print ("initial shut down animation AR False") self.animation_initial_turn_if_off = False ... songbird From __peter__ at web.de Fri Nov 2 18:53:48 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Nov 2018 23:53:48 +0100 Subject: pyglet, i don't understand why this code isn't working References: <1smuaf-d44.ln1@anthive.com> <6fsuaf-od5.ln1@anthive.com> Message-ID: songbird wrote: > MRAB wrote: >> On 2018-11-02 19:58, songbird wrote: >>> >>> hello, :) >>> >> [snip] >> In __init__ you initialise self.animation_initial_turn_it_off to True. >> >> Nowhere in your code do you change it, so it remains True. > > i wish it were that easy... > > see my_sprite.py It *is* that that easy. Just spot the typo in > self.animation_initial_turn_if_off = False > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From songbird at anthive.com Fri Nov 2 19:07:51 2018 From: songbird at anthive.com (songbird) Date: Fri, 2 Nov 2018 19:07:51 -0400 Subject: pyglet, i don't understand why this code isn't working References: <1smuaf-d44.ln1@anthive.com> <6fsuaf-od5.ln1@anthive.com> Message-ID: <7v1vaf-rl7.ln1@anthive.com> Peter Otten wrote: > songbird wrote: >> MRAB wrote: >>> On 2018-11-02 19:58, songbird wrote: >>>> >>>> hello, :) >>>> > >>> [snip] >>> In __init__ you initialise self.animation_initial_turn_it_off to True. >>> >>> Nowhere in your code do you change it, so it remains True. >> >> i wish it were that easy... >> >> see my_sprite.py > > It *is* that that easy. Just spot the typo in > >> self.animation_initial_turn_if_off = False >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ i just did... 1 minute ago, learnin how to use debugger and there it was. lol thanks :) songbird From spencer.graves at effectivedefense.org Fri Nov 2 19:17:05 2018 From: spencer.graves at effectivedefense.org (Spencer Graves) Date: Fri, 2 Nov 2018 18:17:05 -0500 Subject: Mixing R and Python in the same Jupyter Notebook and finding Python code within an RMarkdown document Message-ID: <29a605c0-2c3d-1d2e-ce62-266a26964cc1@effectivedefense.org> Hello, All: ????? Two questions: ??? ??????? 1.? Is it feasible to mix R and Python code in the same Jupyter notebook?? If yes, can you please point me to an example? ??? ??????? 2.? How can one find Python code from within and R Markdown document? ??? ??? ????????? ** "https://github.com/sbgraves237/radioMonitor" includes "radioMonitor-init2018-10-11.Rmd" that shows it's possible to mix R and Python snippets in the same R Markdown (*.Rmd) document.? However, "radioMonitor0_1.Rmd" calls 'system("py idle0_1.py")' in an R snippet, which does what I want (namely recording 5 seconds of whatever is connected to "audio in" or something similar on your computer and writing it to "KKFI2018-10-12t13_16-5sec.wav". ????? Thanks, ????? Spencer Graves From pacqa100 at yahoo.com.au Fri Nov 2 23:46:31 2018 From: pacqa100 at yahoo.com.au (Peter) Date: Sat, 3 Nov 2018 14:46:31 +1100 Subject: AES Encryption/Decryption In-Reply-To: References: Message-ID: <7b6cc639-886d-3dbf-f43f-4ee34e6db034@yahoo.com.au> On 3/11/2018 1:42 AM, Jeff M wrote: > Python newbie here, looking for code samples for encrypting and decrypting functions, using AES. See lots of stuff on the interwebs, but lots of comments back an forth about bugs, or implemented incorrect, etc... > > I need to encrypt some strings that will be passed around in URL, and then also some PII data at rest. > > Thanks. > Although not specifically what you asked about, it's also useful to be aware of the new secrets module in Python 3.6. Peter From tjol at tjol.eu Sat Nov 3 06:55:11 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 3 Nov 2018 11:55:11 +0100 Subject: Mixing R and Python in the same Jupyter Notebook and finding Python code within an RMarkdown document In-Reply-To: <29a605c0-2c3d-1d2e-ce62-266a26964cc1@effectivedefense.org> References: <29a605c0-2c3d-1d2e-ce62-266a26964cc1@effectivedefense.org> Message-ID: <03c40e53-3130-097e-ead2-7f57f570bc4b@tjol.eu> On 03/11/2018 00:17, Spencer Graves wrote: > Hello, All: > > > ????? Two questions: > > > ??? ??????? 1.? Is it feasible to mix R and Python code in the same > Jupyter notebook?? If yes, can you please point me to an example? While Jupyter are always linked to *one* specific language, rpy2's ipython %%R magic lets you intersperse calls to R from Python notebooks (much like the %%cython magic) https://rpy2.bitbucket.io/ example: http://lgautier.github.io/jpd-pdapr-slides/notebooks/potholes.html > > > ??? ??????? 2.? How can one find Python code from within and R Markdown > document? > > > ??? ??? ????????? ** "https://github.com/sbgraves237/radioMonitor" > includes "radioMonitor-init2018-10-11.Rmd" that shows it's possible to > mix R and Python snippets in the same R Markdown (*.Rmd) document.? > However, "radioMonitor0_1.Rmd" calls 'system("py idle0_1.py")' in an R > snippet, which does what I want (namely recording 5 seconds of whatever > is connected to "audio in" or something similar on your computer and > writing it to "KKFI2018-10-12t13_16-5sec.wav". > > > ????? Thanks, > ????? Spencer Graves > From info at egenix.com Sat Nov 3 09:35:57 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Sat, 3 Nov 2018 14:35:57 +0100 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_07.11.2018?= Message-ID: [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf https://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 07.11.2018, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2018-11-07 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Charlie Clark "Context Managers and Generators" Marc-Andr? Lemburg "The History of Unicode in Python" Jens Diemer "Django for Runners" Ilya Kamenschchikov "Object Detection Using TensorFlow" Sowie einige Buchrezensionen. 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: * https://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * https://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * https://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: https://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Nov 03 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From songbird at anthive.com Sat Nov 3 12:45:57 2018 From: songbird at anthive.com (songbird) Date: Sat, 3 Nov 2018 12:45:57 -0400 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> Message-ID: <5vv0bf-if2.ln1@anthive.com> Rhodri James wrote: ... > I completely agree. I too have come from a background in C, and still > do most of my day job in C or assembler. It took a while before I was > writing idiomatic Python, never mind efficient Python (arguably I still > don't, but as Rob says, who cares?). Don't worry about it; at some > point you will discover that the "obvious" Python you are writing looks > a lot like the code you are looking at now and thinking "that's really > clever, I'll never be able to to that." at this stage of my own process in learning, i'm trying to read the FAQs i can find, any tutorials, answers to specific questions on stackoverflow on particular topics to see if i can understand the issues, etc. as for my own code, yes, it's horrible at the moment, but to me working code is always the final arbitor. i much prefer simple and stepwise refinement if speed isn't the issue i think clarity and simplicity is more important. speed is only more important for large projects that process a ton of data. in 3-5yrs i expect to understand more of what the theory and more conceptual things going on as i read more of the history and how the language has developed. i won't consider myself fluent until i start "thinking" in it and can visualise the data structures/objects in my head and such as i currently do for C. songbird From tmrsg11 at gmail.com Sun Nov 4 11:55:20 2018 From: tmrsg11 at gmail.com (Mike C) Date: Sun, 4 Nov 2018 16:55:20 +0000 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: <5vv0bf-if2.ln1@anthive.com> References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> , <5vv0bf-if2.ln1@anthive.com> Message-ID: Same here. Debugging in Python is annoying, I like to step through my code line by line, it's impossible to do it with object-oriented programming language. Also, there's no good REPL IDE. Spyder barely works with some basic features. PyCharm, the most popular, takes too long to start, and you have to setup folders and directories EVERY SINGLE TIME at startup. ________________________________ From: Python-list on behalf of songbird Sent: Saturday, November 3, 2018 12:45:57 PM To: python-list at python.org Subject: Re: Overwhelmed by the Simplicity of Python. Any Recommendation? Rhodri James wrote: ... > I completely agree. I too have come from a background in C, and still > do most of my day job in C or assembler. It took a while before I was > writing idiomatic Python, never mind efficient Python (arguably I still > don't, but as Rob says, who cares?). Don't worry about it; at some > point you will discover that the "obvious" Python you are writing looks > a lot like the code you are looking at now and thinking "that's really > clever, I'll never be able to to that." at this stage of my own process in learning, i'm trying to read the FAQs i can find, any tutorials, answers to specific questions on stackoverflow on particular topics to see if i can understand the issues, etc. as for my own code, yes, it's horrible at the moment, but to me working code is always the final arbitor. i much prefer simple and stepwise refinement if speed isn't the issue i think clarity and simplicity is more important. speed is only more important for large projects that process a ton of data. in 3-5yrs i expect to understand more of what the theory and more conceptual things going on as i read more of the history and how the language has developed. i won't consider myself fluent until i start "thinking" in it and can visualise the data structures/objects in my head and such as i currently do for C. songbird -- https://mail.python.org/mailman/listinfo/python-list From ike at koeln.ccc.de Sun Nov 4 14:25:31 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Sun, 4 Nov 2018 20:25:31 +0100 Subject: Asyncio tasks getting cancelled Message-ID: <20181104192531.GA6642@ma.tura-home.de> Hi all, I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) are not kept referenced by asyncio itself, causing the task to be cancelled when the creating function finishes (and noone is awaiting the corresponding futue). Am I doing something wrong or is this expected behavior? The code sample I tried: > import asyncio > > async def foobar(): > print(1) > await asyncio.sleep(1) > print(2) > > async def main(): > asyncio.create_task(foobar()) > #await asyncio.sleep(2) > > loop = asyncio.get_event_loop() > asyncio.run(main()) > loop.run_forever() The sample does print "2" only when uncommenting the asyncio.sleep(2) line. Greetings. From larry.martell at gmail.com Sun Nov 4 15:59:58 2018 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 4 Nov 2018 15:59:58 -0500 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> Message-ID: On Sun, Nov 4, 2018 at 11:56 AM Mike C wrote: > > Same here. Debugging in Python is annoying, I like to step through my code line by line, it's impossible to do it with object-oriented programming language. > > Also, there's no good REPL IDE. > > Spyder barely works with some basic features. PyCharm, the most popular, takes too long to start, and you have to setup folders and directories EVERY SINGLE TIME at startup. I use pdb and I have no issues debugging nor stepping through my code line-by-line when needed. What does it being OO have to do with it? But then again, I also know better then to top post. > Rhodri James wrote: > ... > > I completely agree. I too have come from a background in C, and still > > do most of my day job in C or assembler. It took a while before I was > > writing idiomatic Python, never mind efficient Python (arguably I still > > don't, but as Rob says, who cares?). Don't worry about it; at some > > point you will discover that the "obvious" Python you are writing looks > > a lot like the code you are looking at now and thinking "that's really > > clever, I'll never be able to to that." > > at this stage of my own process in learning, i'm > trying to read the FAQs i can find, any tutorials, > answers to specific questions on stackoverflow on > particular topics to see if i can understand the > issues, etc. > > as for my own code, yes, it's horrible at the > moment, but to me working code is always the > final arbitor. i much prefer simple and stepwise > refinement if speed isn't the issue i think clarity > and simplicity is more important. > > speed is only more important for large projects > that process a ton of data. > > in 3-5yrs i expect to understand more of what > the theory and more conceptual things going on as > i read more of the history and how the language > has developed. > > i won't consider myself fluent until i start > "thinking" in it and can visualise the data > structures/objects in my head and such as i > currently do for C. From leo at superlel.me Sun Nov 4 17:10:59 2018 From: leo at superlel.me (=?UTF-8?Q?L=c3=a9o_El_Amri?=) Date: Sun, 4 Nov 2018 23:10:59 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181104192531.GA6642@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> Message-ID: On 04/11/2018 20:25, ike at koeln.ccc.de wrote: > I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) > are not kept referenced by asyncio itself, causing the task to be > cancelled when the creating function finishes (and noone is awaiting the > corresponding futue). Am I doing something wrong or is this expected > behavior? > > The code sample I tried: > >> import asyncio >> >> async def foobar(): >> print(1) >> await asyncio.sleep(1) >> print(2) >> >> async def main(): >> asyncio.create_task(foobar()) >> #await asyncio.sleep(2) >> >> loop = asyncio.get_event_loop() >> asyncio.run(main()) >> loop.run_forever() > I don't know anything about asyncio in Python 3.7, but given the documentation, asyncio.run() will start a loop and run the coroutine into it until there is nothing to do anymore, then free the loop it created. I assume it's kind of a run_forever() with some code before it to schedule the coroutine. Thus, I don't think it's appropriate to allocate the loop by yourself with get_event_loop(), then to run it with run_forever(). Usually, when you're already running into a coroutine, you're using "await other_coroutine()" instead of "asyncio.create_task(other_coroutine())". Buy it should not be the root cause of your issue. With theses information only, it looks like a Python bug to me (Or an implementation defined behavior. By the way what is your platform ?). You could try to change either one of asyncio.create_task() or asyncio.run() with "older" Python API (Python 3.6, preferably). In the case of run() it would be a simple loop.create_task(main()) instead of the asyncio.asyncio.run(main()). In the case of asyncio.create_task() it would be asyncio.get_event_loop(foobar()). But anyway, I highly recommend you to use the "await other_coroutine()" syntax I talked about earlier. It may even fix the issue (90% chance). I don't have Python 3.7 right now, so I can't help further. I hope someone with knowledge in asyncio under Python 3.7 will be able to help. - L?o From ian.g.kelly at gmail.com Mon Nov 5 01:55:47 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 Nov 2018 23:55:47 -0700 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> Message-ID: On Sun, Nov 4, 2018 at 3:58 PM L?o El Amri via Python-list wrote: > > On 04/11/2018 20:25, ike at koeln.ccc.de wrote: > > I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) > > are not kept referenced by asyncio itself, causing the task to be > > cancelled when the creating function finishes (and noone is awaiting the > > corresponding futue). Am I doing something wrong or is this expected > > behavior? > > > > The code sample I tried: > > > >> import asyncio > >> > >> async def foobar(): > >> print(1) > >> await asyncio.sleep(1) > >> print(2) > >> > >> async def main(): > >> asyncio.create_task(foobar()) > >> #await asyncio.sleep(2) > >> > >> loop = asyncio.get_event_loop() > >> asyncio.run(main()) > >> loop.run_forever() > > > > I don't know anything about asyncio in Python 3.7, but given the > documentation, asyncio.run() will start a loop and run the coroutine > into it until there is nothing to do anymore, then free the loop it > created. I assume it's kind of a run_forever() with some code before it > to schedule the coroutine. My understanding of asyncio.run() from https://github.com/python/asyncio/pull/465 is that asyncio.run() is more or less the equivalent of loop.run_until_complete() with finalization, not loop.run_forever(). Thus this result makes sense to me: asyncio.run() runs until main() finishes, then stops. Without the sleep(2), main() starts creates the foobar() task and then returns without awaiting it, so the sleep(1) never finishes. asyncio.run() also finalizes its event loop, so I assume that the loop being run_forever must be a different event loop since running it doesn't just raise an exception. Therefore it doesn't resume the foobar() coroutine since it doesn't know about it. Combining asyncio.run() with loop.run_forever() makes little sense. The purpose of asyncio.run() as I understand it is to avoid having to manage the event loop oneself. If the goal here is for the task created by main() to complete before the loop exits, then main() should await it, and not just create it without awaiting it. From robin at reportlab.com Mon Nov 5 04:47:40 2018 From: robin at reportlab.com (Robin Becker) Date: Mon, 5 Nov 2018 09:47:40 +0000 Subject: builtins confusion Message-ID: <0dddd264-f9e4-0183-81b5-81739cf747c1@chamonix.reportlab.co.uk> For some reason I find my windows 32 bit python 2.7.13 has a package called builtins installed in site-packages. This creates confusion about how to look at builtins. The __init__.py looks like this from __future__ import absolute_import import sys __future_module__ = True if sys.version_info[0] < 3: from __builtin__ import * # Overwrite any old definitions with the equivalent future.builtins ones: from future.builtins import * else: raise ImportError('This package should not be accessible on Python 3. ' 'Either you are trying to run from the python-future src folder ' 'or your installation of python-future is corrupted.') this creates complete confusion about how to import __builtin__ versus builtins. I think this is associated in some way with pyinstaller, but am not sure. Is this a reasonable way to import either builtins / __builtin__ try: import __builtin__ except ImportError: import builtins as __builtin__ -- Robin Becker From leo at superlel.me Mon Nov 5 04:55:56 2018 From: leo at superlel.me (=?UTF-8?Q?L=c3=a9o_El_Amri?=) Date: Mon, 5 Nov 2018 10:55:56 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> Message-ID: <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> On 05/11/2018 07:55, Ian Kelly wrote: >> I assume it's kind of a run_forever() with some code before it >> to schedule the coroutine. > > My understanding of asyncio.run() from > https://github.com/python/asyncio/pull/465 is that asyncio.run() is > more or less the equivalent of loop.run_until_complete() with > finalization, not loop.run_forever(). Thus this result makes sense to > me: asyncio.run() runs until main() finishes, then stops. Without the > sleep(2), main() starts creates the foobar() task and then returns > without awaiting it, so the sleep(1) never finishes. asyncio.run() > also finalizes its event loop, so I assume that the loop being > run_forever must be a different event loop since running it doesn't > just raise an exception. Therefore it doesn't resume the foobar() > coroutine since it doesn't know about it. That totally make sense. I agree with this supposition. > If the goal here is for the task created by main() to complete before > the loop exits, then main() should await it, and not just create it > without awaiting it. I said the following: > Usually, when you're already running into a coroutine, you're using > "await other_coroutine()" instead of > "asyncio.create_task(other_coroutine())". Which is not accurate. What Ian said is accurate. One indeed may need to schedule a coroutine in some situation. I just assumed that's wasn't what the OP intended to do given the name of the "main" function. I also said: > But anyway, I highly recommend you to use the "await other_coroutine()" > syntax I talked about earlier. It may even fix the issue (90% chance). This should indeed fix the issue, but this is definitely not what one is looking for if one really want to _schedule_ a coroutine. - L?o From tjol at tjol.eu Mon Nov 5 05:00:49 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 5 Nov 2018 11:00:49 +0100 Subject: builtins confusion In-Reply-To: <0dddd264-f9e4-0183-81b5-81739cf747c1@chamonix.reportlab.co.uk> References: <0dddd264-f9e4-0183-81b5-81739cf747c1@chamonix.reportlab.co.uk> Message-ID: On 2018-11-05 10:47, Robin Becker wrote: > ??? raise ImportError('This package should not be accessible on Python 3. ' > ????????????????????? 'Either you are trying to run from the python-future src folder ' > ????????????????????? 'or your installation of python-future is corrupted.') It would appear that this is from the python-future package. The PyPI page makes the "why?" fairly clear: https://pypi.org/project/future/ From robin at reportlab.com Mon Nov 5 06:28:06 2018 From: robin at reportlab.com (Robin Becker) Date: Mon, 5 Nov 2018 11:28:06 +0000 Subject: builtins confusion In-Reply-To: References: <0dddd264-f9e4-0183-81b5-81739cf747c1@chamonix.reportlab.co.uk> Message-ID: On 05/11/2018 10:00, Thomas Jollans wrote: > On 2018-11-05 10:47, Robin Becker wrote: >> ??? raise ImportError('This package should not be accessible on Python 3. ' >> ????????????????????? 'Either you are trying to run from the python-future src folder ' >> ????????????????????? 'or your installation of python-future is corrupted.') > > It would appear that this is from the python-future package. > > The PyPI page makes the "why?" fairly clear: > https://pypi.org/project/future/ > yes I think it comes from pefile which pyinstaller uses. Problem is that this module just hides an import error and may change other people's attempts at feature recognition. -- Robin Becker From rhodri at kynesim.co.uk Mon Nov 5 07:06:48 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 5 Nov 2018 12:06:48 +0000 Subject: gmpy2 problem In-Reply-To: References: <5f186e5f-0ee7-b86b-290b-14d29885241b@kynesim.co.uk> Message-ID: Jacob, please reply to the list, not to me personally. As I said, I have no idea about gmpy2 or pip, I just know how to google. On 01/11/2018 23:28, jacob m wrote: > I tried to install libgmp3-dev, but it didn't solved my problem > > On Thu, 1 Nov 2018 at 18:44, Rhodri James wrote: > >> Replying to the list since I have absolutely no idea about gmpy2 or pip... >> >> On 01/11/2018 16:56, jacob m wrote: >>> Hi Rodhri, of course I can paste the text :) >>> " >>> creating build >>> creating build/temp.linux-x86_64-3.7 >>> creating build/temp.linux-x86_64-3.7/src >>> gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv >> -O3 >>> -Wall -fPIC -DWITHMPFR -DWITHMPC -I/home/lib/python3.7/include/python3.7m >>> -c src/gmpy2.c -o build/temp.linux-x86_64-3.7/src/gmpy2.o >>> In file included from src/gmpy2.c:426:0: >>> src/gmpy.h:106:12: fatal error: gmp.h: No such file or directory >>> # include "gmp.h" >>> ^~~~~~~ >>> compilation terminated. >>> error: command 'gcc' failed with exit status 1 >>> >>> ---------------------------------------- >>> Command "/home/lib/python3.7/bin/python3.7 -u -c "import setuptools, >>> >> tokenize;__file__='/tmp/pip-install-kiqba_j_/gmpy2/setup.py';f=getattr(tokenize, >>> 'open', open)(__file__);code=f.read().replace('\r\n', >>> '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record >>> /tmp/pip-record-2jatj1mi/install-record.txt >>> --single-version-externally-managed --compile" failed with error code 1 >> in >>> /tmp/pip-install-kiqba_j_/gmpy2/ >>> " >> >> A little googling suggests that you need to install the libgmp3-dev >> package: >> >> $ sudo apt install libgmp3-dev >> >>> On Thu, 1 Nov 2018 at 16:46, Rhodri James wrote: >>> >>>> On 01/11/2018 14:40, jacob m wrote: >>>>> Hi guys >>>>> I have some problems with gmpy2 module installation - pip install gmpy2 >>>>> doesn't work for me >>>>> [image: image.png] >>>>> >>>>> How to fix it? >>>> >>>> Hi Jacob, >>>> >>>> I'm afraid the screen-shot that you sent was automatically stripped off >>>> by the mailing list. Could you copy the error text (preferably >>>> cut-and-paste the whole thing rather than retyping!)? The more >>>> information you can give us, the better the advice will be from the >>>> people who actually understand pip :-) >> >> >> -- >> Rhodri James *-* Kynesim Ltd >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Rhodri James *-* Kynesim Ltd From kgrenczuk at gmail.com Mon Nov 5 07:11:38 2018 From: kgrenczuk at gmail.com (jacob m) Date: Mon, 5 Nov 2018 13:11:38 +0100 Subject: gmpy2 problem In-Reply-To: References: <5f186e5f-0ee7-b86b-290b-14d29885241b@kynesim.co.uk> Message-ID: Sorry Rhodri, my gmail set your email as default recipient when I was responding, I forgot to change that. Sorry for that Regards On Mon, 5 Nov 2018 at 13:06, Rhodri James wrote: > Jacob, please reply to the list, not to me personally. As I said, I > have no idea about gmpy2 or pip, I just know how to google. > > On 01/11/2018 23:28, jacob m wrote: > > I tried to install libgmp3-dev, but it didn't solved my problem > > > > On Thu, 1 Nov 2018 at 18:44, Rhodri James wrote: > > > >> Replying to the list since I have absolutely no idea about gmpy2 or > pip... > >> > >> On 01/11/2018 16:56, jacob m wrote: > >>> Hi Rodhri, of course I can paste the text :) > >>> " > >>> creating build > >>> creating build/temp.linux-x86_64-3.7 > >>> creating build/temp.linux-x86_64-3.7/src > >>> gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g > -fwrapv > >> -O3 > >>> -Wall -fPIC -DWITHMPFR -DWITHMPC > -I/home/lib/python3.7/include/python3.7m > >>> -c src/gmpy2.c -o build/temp.linux-x86_64-3.7/src/gmpy2.o > >>> In file included from src/gmpy2.c:426:0: > >>> src/gmpy.h:106:12: fatal error: gmp.h: No such file or directory > >>> # include "gmp.h" > >>> ^~~~~~~ > >>> compilation terminated. > >>> error: command 'gcc' failed with exit status 1 > >>> > >>> ---------------------------------------- > >>> Command "/home/lib/python3.7/bin/python3.7 -u -c "import setuptools, > >>> > >> > tokenize;__file__='/tmp/pip-install-kiqba_j_/gmpy2/setup.py';f=getattr(tokenize, > >>> 'open', open)(__file__);code=f.read().replace('\r\n', > >>> '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record > >>> /tmp/pip-record-2jatj1mi/install-record.txt > >>> --single-version-externally-managed --compile" failed with error code 1 > >> in > >>> /tmp/pip-install-kiqba_j_/gmpy2/ > >>> " > >> > >> A little googling suggests that you need to install the libgmp3-dev > >> package: > >> > >> $ sudo apt install libgmp3-dev > >> > >>> On Thu, 1 Nov 2018 at 16:46, Rhodri James > wrote: > >>> > >>>> On 01/11/2018 14:40, jacob m wrote: > >>>>> Hi guys > >>>>> I have some problems with gmpy2 module installation - pip install > gmpy2 > >>>>> doesn't work for me > >>>>> [image: image.png] > >>>>> > >>>>> How to fix it? > >>>> > >>>> Hi Jacob, > >>>> > >>>> I'm afraid the screen-shot that you sent was automatically stripped > off > >>>> by the mailing list. Could you copy the error text (preferably > >>>> cut-and-paste the whole thing rather than retyping!)? The more > >>>> information you can give us, the better the advice will be from the > >>>> people who actually understand pip :-) > >> > >> > >> -- > >> Rhodri James *-* Kynesim Ltd > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > > > -- > Rhodri James *-* Kynesim Ltd > From ike at koeln.ccc.de Mon Nov 5 10:38:18 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Mon, 5 Nov 2018 16:38:18 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> Message-ID: <20181105153817.GA4165@ma.tura-home.de> This weird mixing was actually a side effect of me quickly coming up with a small example, sorry for the confusion. I just saw, actually using the same loop gets rid of the behavior in this case and now I'm not sure about my assertions any more. Yet it still looks like asyncio doen'st keep strong references. Hmm. The original problem prompting my question is here: https://github.com/ldo/dbussy/issues/13 Also this is a python 3.7.1 on a current Fedora 29. > > Usually, when you're already running into a coroutine, you're using > > "await other_coroutine()" instead of > > "asyncio.create_task(other_coroutine())". > > Which is not accurate. What Ian said is accurate. One indeed may need to > schedule a coroutine in some situation. I just assumed that's wasn't > what the OP intended to do given the name of the "main" function. > > I also said: > > > But anyway, I highly recommend you to use the "await other_coroutine()" > > syntax I talked about earlier. It may even fix the issue (90% chance). > > This should indeed fix the issue, but this is definitely not what one is > looking for if one really want to _schedule_ a coroutine. Which is what I want in this case. Scheduling a new (long-running) task as a side effect, but returning early oneself. The new task can't be awaited right there, because the creating one should return already. > If the goal here is for the task created by main() to complete before > the loop exits, then main() should await it, and not just create it > without awaiting it. So if this happens somewhere deep in the hirarchy of your application you would need some mechanism to pass the created tasks back up the chain to the main function? Greetings. From rgaddi at highlandtechnology.invalid Mon Nov 5 11:56:57 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 5 Nov 2018 08:56:57 -0800 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> Message-ID: On 11/4/18 8:55 AM, Mike C wrote: > Same here. Debugging in Python is annoying, I like to step through my code line by line, it's impossible to do it with object-oriented programming language. > > Also, there's no good REPL IDE. > > Spyder barely works with some basic features. PyCharm, the most popular, takes too long to start, and you have to setup folders and directories EVERY SINGLE TIME at startup. > I've never been a fan of IDEs, but a code editor window on the left and the IPython QtConsole on the right is a pretty efficient way to blaze through code. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From leo at superlel.me Mon Nov 5 15:10:02 2018 From: leo at superlel.me (=?UTF-8?Q?L=c3=a9o_El_Amri?=) Date: Mon, 5 Nov 2018 21:10:02 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181105153817.GA4165@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> Message-ID: On 05/11/2018 16:38, ike at koeln.ccc.de wrote: > I just saw, actually > using the same loop gets rid of the behavior in this case and now I'm > not sure about my assertions any more. It's fixing the issue because you're running loop with the run_forever(). As Ian and myself pointed out, using both asyncio.run() and loop.run_forever() is not what you are looking for. > Yet it still looks like asyncio > doen'st keep strong references. You may want to look at PEP 3156. It's the PEP defining asyncio. Ian made a good explanation about why your loop wasn't running the coroutine scheduled from main(). >> This should indeed fix the issue, but this is definitely not what one is >> looking for if one really want to _schedule_ a coroutine. > > Which is what I want in this case. Scheduling a new (long-running) task > as a side effect, but returning early oneself. The new task can't be > awaited right there, because the creating one should return already. > >> If the goal here is for the task created by main() to complete before >> the loop exits, then main() should await it, and not just create it >> without awaiting it. > > So if this happens somewhere deep in the hirarchy of your application > you would need some mechanism to pass the created tasks back up the > chain to the main function? Sorry, I don't get what is you're trying to express. Either you await for a coroutine, which means the calling one is "paused" until the awaited coroutine finish its job, either you schedule a coroutine, which means it will be ran once the already stacked events/coroutines on the loop are all ran. In your case, you probably want to change > loop = asyncio.get_event_loop() > asyncio.run(main()) > loop.run_forever() to > loop = asyncio.get_event_loop() > loop.create_task(main()) > loop.run_forever() - L?o [1] https://www.python.org/dev/peps/pep-3156/ From ian.g.kelly at gmail.com Mon Nov 5 15:57:56 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 5 Nov 2018 13:57:56 -0700 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181105153817.GA4165@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> Message-ID: On Mon, Nov 5, 2018 at 8:41 AM wrote: > > > But anyway, I highly recommend you to use the "await other_coroutine()" > > > syntax I talked about earlier. It may even fix the issue (90% chance). > > > > This should indeed fix the issue, but this is definitely not what one is > > looking for if one really want to _schedule_ a coroutine. > > Which is what I want in this case. Scheduling a new (long-running) task > as a side effect, but returning early oneself. The new task can't be > awaited right there, because the creating one should return already. If you want to do this in the asyncio.run main coroutine, then that seems like a problematic design. Once the main coroutine returns, the event loop should be considered no longer running, and any still pending callbacks or futures won't resolve. > > If the goal here is for the task created by main() to complete before > > the loop exits, then main() should await it, and not just create it > > without awaiting it. > > So if this happens somewhere deep in the hirarchy of your application > you would need some mechanism to pass the created tasks back up the > chain to the main function? I haven't used asyncio.run yet myself, so take all this with a grain of salt, but it seems to me that anything that you want to resolve before the event loop terminates should be awaited either directly or indirectly by the main coroutine. From the documentation: """ This function always creates a new event loop and closes it at the end. It should be used as a main entry point for asyncio programs, and should ideally only be called once. """ So I think part of the idea with this is that the asyncio.run main coroutine is considered the main function of your async app. Once it returns, the program should be effectively done. For example, maybe the main coroutine spins up a web server and returns when the web server shuts down. If that doesn't suit your program, for instance there's no core task to await, but you want to schedule a lot of things that need to resolve and that the main coroutine has no way to know about, then it may be the case that asyncio.run is not right for your use case and you should use loop.run_forever() instead. You'll still need some criteria for figuring out when to exit though, and it seems to me that whatever that is you could just bundle it up in a coroutine and await it from main. From philip.m at tura-home.de Mon Nov 5 18:44:36 2018 From: philip.m at tura-home.de (philip.m at tura-home.de) Date: Tue, 6 Nov 2018 00:44:36 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> Message-ID: <20181105234436.GA15200@ma.tura-home.de> On Mon, Nov 05, 2018 at 01:57:56PM -0700, Ian Kelly wrote: > > Which is what I want in this case. Scheduling a new (long-running) task > > as a side effect, but returning early oneself. The new task can't be > > awaited right there, because the creating one should return already. > > If you want to do this in the asyncio.run main coroutine, then that > seems like a problematic design. Once the main coroutine returns, the > event loop should be considered no longer running, and any still > pending callbacks or futures won't resolve. This is only true for the small example I provided. In the actual code this is somewhere deep in the hirarchy. > > > If the goal here is for the task created by main() to complete before > > > the loop exits, then main() should await it, and not just create it > > > without awaiting it. > > > > So if this happens somewhere deep in the hirarchy of your application > > you would need some mechanism to pass the created tasks back up the > > chain to the main function? > > I haven't used asyncio.run yet myself, so take all this with a grain > of salt, but it seems to me that anything that you want to resolve > before the event loop terminates should be awaited either directly or > indirectly by the main coroutine. From the documentation: > > """ > This function always creates a new event loop and closes it at the > end. It should be used as a main entry point for asyncio programs, and > should ideally only be called once. > """ > > So I think part of the idea with this is that the asyncio.run main > coroutine is considered the main function of your async app. Once it > returns, the program should be effectively done. For example, maybe > the main coroutine spins up a web server and returns when the web > server shuts down. Again sorry for the confusion, but I don't think this is an issue with restarting loops, as this isn't happening in my application. For context: https://github.com/ldo/dbussy/issues/13 https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 It really feels like asyncio is loosing strong references to scheduled tasks, as excplicitly keeping them around helps. Also, the error messages I'm getting are the ones from here: https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145 Which indicates that the tasks actually weren't even started at all? > If that doesn't suit your program, for instance there's no core task > to await, but you want to schedule a lot of things that need to > resolve and that the main coroutine has no way to know about, then it > may be the case that asyncio.run is not right for your use case and > you should use loop.run_forever() instead. You'll still need some > criteria for figuring out when to exit though, and it seems to me that > whatever that is you could just bundle it up in a coroutine and await > it from main. Though not really related with my actual problem, so getting off topic, but I can imagine an architecture where that would be "There aren't any running tasks any more." or even "Never." Also, I may be overlooking things, but I haven't found a way to add a task before calling run_forever(), as asyncio will then say the loop isn't running yet. So I'm not sure how you would jumpstart in that case. From ike at koeln.ccc.de Mon Nov 5 18:45:03 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Tue, 6 Nov 2018 00:45:03 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> Message-ID: <20181105234503.GB15200@ma.tura-home.de> On Mon, Nov 05, 2018 at 01:57:56PM -0700, Ian Kelly wrote: > > Which is what I want in this case. Scheduling a new (long-running) task > > as a side effect, but returning early oneself. The new task can't be > > awaited right there, because the creating one should return already. > > If you want to do this in the asyncio.run main coroutine, then that > seems like a problematic design. Once the main coroutine returns, the > event loop should be considered no longer running, and any still > pending callbacks or futures won't resolve. This is only true for the small example I provided. In the actual code this is somewhere deep in the hirarchy. > > > If the goal here is for the task created by main() to complete before > > > the loop exits, then main() should await it, and not just create it > > > without awaiting it. > > > > So if this happens somewhere deep in the hirarchy of your application > > you would need some mechanism to pass the created tasks back up the > > chain to the main function? > > I haven't used asyncio.run yet myself, so take all this with a grain > of salt, but it seems to me that anything that you want to resolve > before the event loop terminates should be awaited either directly or > indirectly by the main coroutine. From the documentation: > > """ > This function always creates a new event loop and closes it at the > end. It should be used as a main entry point for asyncio programs, and > should ideally only be called once. > """ > > So I think part of the idea with this is that the asyncio.run main > coroutine is considered the main function of your async app. Once it > returns, the program should be effectively done. For example, maybe > the main coroutine spins up a web server and returns when the web > server shuts down. Again sorry for the confusion, but I don't think this is an issue with restarting loops, as this isn't happening in my application. For context: https://github.com/ldo/dbussy/issues/13 https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 It really feels like asyncio is loosing strong references to scheduled tasks, as excplicitly keeping them around helps. Also, the error messages I'm getting are the ones from here: https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145 Which indicates that the tasks actually weren't even started at all? > If that doesn't suit your program, for instance there's no core task > to await, but you want to schedule a lot of things that need to > resolve and that the main coroutine has no way to know about, then it > may be the case that asyncio.run is not right for your use case and > you should use loop.run_forever() instead. You'll still need some > criteria for figuring out when to exit though, and it seems to me that > whatever that is you could just bundle it up in a coroutine and await > it from main. Though not really related with my actual problem, so getting off topic, but I can imagine an architecture where that would be "There aren't any running tasks any more." or even "Never." Also, I may be overlooking things, but I haven't found a way to add a task before calling run_forever(), as asyncio will then say the loop isn't running yet. So I'm not sure how you would jumpstart in that case. From ike at koeln.ccc.de Mon Nov 5 18:50:37 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Tue, 6 Nov 2018 00:50:37 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181105234503.GB15200@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234503.GB15200@ma.tura-home.de> Message-ID: <20181105235037.GC15200@ma.tura-home.de> On Tue, Nov 06, 2018 at 12:45:03AM +0100, ike at koeln.ccc.de wrote: > Also, I may be overlooking things, but I haven't found a way to add a > task before calling run_forever(), as asyncio will then say the loop > isn't running yet. So I'm not sure how you would jumpstart in that case. Ok, I was confused there. It doesn't work by using asyncio.create_task but it will with loop.create_task. Sorry for the noise. From ian.g.kelly at gmail.com Mon Nov 5 21:15:04 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 5 Nov 2018 19:15:04 -0700 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181105234436.GA15200@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234436.GA15200@ma.tura-home.de> Message-ID: On Mon, Nov 5, 2018 at 6:20 PM wrote: > Again sorry for the confusion, but I don't think this is an issue with > restarting loops, as this isn't happening in my application. Sure, I wasn't talking about restarting loops so much as strategies for making sure that everything has completed in the first place. > For context: > https://github.com/ldo/dbussy/issues/13 > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > It really feels like asyncio is loosing strong references to scheduled > tasks, as excplicitly keeping them around helps. Also, the error > messages I'm getting are the ones from here: > https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145 > Which indicates that the tasks actually weren't even started at all? No, it indicates that it was cleaned up (likely because the program exited) before the task completed. Which likely implies that the loop exited without waiting for it. From the stack trace, you're using loop.run_until_complete(main()). Like asyncio.run, that only runs until the specific thing you pass it completes, which might wait on other things or might not. Anything else that's still pending is going to be left up in the air unless you subsequently restart the same event loop. > Though not really related with my actual problem, so getting off topic, > but I can imagine an architecture where that would be "There aren't any > running tasks any more." or even "Never." Well, "never" is easy; that's just loop.run_forever(). "No more running tasks" is trickier; I'm not sure how one might do that without collecting all the tasks (at least, all the top-level tasks) oneself. Implementing a custom task factory might help. From ike at koeln.ccc.de Mon Nov 5 22:40:51 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Tue, 6 Nov 2018 04:40:51 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234436.GA15200@ma.tura-home.de> Message-ID: <20181106034051.GA27582@ma.tura-home.de> On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote: > > For context: > > https://github.com/ldo/dbussy/issues/13 > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > > > It really feels like asyncio is loosing strong references to scheduled > > tasks, as excplicitly keeping them around helps. Also, the error > > messages I'm getting are the ones from here: > > https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145 > > Which indicates that the tasks actually weren't even started at all? > > No, it indicates that it was cleaned up (likely because the program > exited) before the task completed. Which likely implies that the loop > exited without waiting for it. From the stack trace, you're using > loop.run_until_complete(main()). Like asyncio.run, that only runs > until the specific thing you pass it completes, which might wait on > other things or might not. Anything else that's still pending is going > to be left up in the air unless you subsequently restart the same > event loop. What I meant was, the error message is specific to futures in the 'PENDING' state. Which should be set to 'RUNNING' before any actions occur. So it appears the tasks weren't started at all. Also the cleanup happens instantly, ie before the loop exits (as the main loop has an asyncio.sleep timeout. Printing a message also clearly shows this happens way before main returns. From Varshit.Jain at ideavate.com Tue Nov 6 04:05:31 2018 From: Varshit.Jain at ideavate.com (Varshit Jain) Date: Tue, 6 Nov 2018 14:35:31 +0530 Subject: Unable to remove python from my computer. Message-ID: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> Hi Python Support Team, I just want to remove python 3.6.6 from my computer. I am unable to do it. Please find attached video that describe my problem. Suggest me solution / Steps to remove python from my PC. Regards, Varshit Jain From tjol at tjol.eu Tue Nov 6 04:25:22 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 6 Nov 2018 10:25:22 +0100 Subject: Unable to remove python from my computer. In-Reply-To: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> References: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> Message-ID: <658fd744-f7c9-ff1c-2eb4-4b8aa60eb321@tjol.eu> On 2018-11-06 10:05, Varshit Jain wrote: > Hi Python Support Team, > > > I just want to remove python 3.6.6 from my computer. I am unable to do > it. Please find attached video that describe my problem. Use your words, friend! (this list is text-only) From rhodri at kynesim.co.uk Tue Nov 6 06:41:37 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 6 Nov 2018 11:41:37 +0000 Subject: Unable to remove python from my computer. In-Reply-To: <658fd744-f7c9-ff1c-2eb4-4b8aa60eb321@tjol.eu> References: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> <658fd744-f7c9-ff1c-2eb4-4b8aa60eb321@tjol.eu> Message-ID: <57bcfc7b-8302-fecf-efae-e1b75d239bf6@kynesim.co.uk> On 06/11/2018 09:25, Thomas Jollans wrote: > On 2018-11-06 10:05, Varshit Jain wrote: >> Hi Python Support Team, >> >> >> I just want to remove python 3.6.6 from my computer. I am unable to do >> it. Please find attached video that describe my problem. > > Use your words, friend! > > (this list is text-only) More exactly, I'm afraid the mailing list has stripped off the video you attached, so we can't watch it. I'm afraid I wouldn't in any case; I learned long ago not to open attachments from people I don't already know. Could you please describe to us your problem? Are you using Windows, Linux, Mac or something else? Copy any error messages the uninstaller might have given you, preferably cutting and pasting rather than just retyping them (it's easy to mistype something critical!). Please don't send us screen shots, those will just get stripped off by the mailing list as well. -- Rhodri James *-* Kynesim Ltd From srinivasan.rns at gmail.com Tue Nov 6 13:10:05 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 6 Nov 2018 23:40:05 +0530 Subject: SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: Message-ID: Dear Python Experts Team, As am newbie to python development, I am trying to use the below function to get verify the filesystem type of the SD card parition using bash command in python using subprocess module, I ma seeing the below Error "SyntaxError: can't assign to literal" *CODE:* *====* import helper from os import path import subprocess import os import otg_ni class emmc(object): """ emmc getters and setters info: https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt """ def __init__(self): self._helper = helper.helper() self._otg_ni = otg_ni.otg_ni() *def get_fstype_of_mounted_partition(self, fs):* """ Get the filesystem type of the mounted partition. :partition_name : Partition path as string (e.g. /dev/mmcblk0p1) :return: filesystem type as string or None if not found """ * cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* *return self._helper.execute_cmd_output_string(cmd)* *def execute_cmd_output_string(self, cmd, enable_shell=False):* """ Execute a command and return its output as a string. :param cmd: abs path of the command with arguments :param enable_shell : force the cmd to be run as shell script :return: a string. """ try: result = subprocess.check_output(split(cmd), stderr=subprocess.STDOUT, shell=enable_shell) except subprocess.CalledProcessError as e: s = """While executing '{}' something went wrong. Return code == '{}' Return output:\n'{}' """.format(cmd, e.returncode, e.output, shell=enable_shell) raise AssertionError(s) return result.strip().decode("utf-8") *if __name__ == "__main__":* m = emmc() * m.get_fstype_of_mounted_partition("/dev/mmcblk0p1")* *Error:* *======* root:~/qa/test_library# python3 sd.py File "sd.py", line 99 * cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* * ^* *SyntaxError: can't assign to literal* root:~/qa/test_library# Kindly do the needful as early as possible, as am stuck with this issue from past 2 days no clues yet, please redirect me to the correct forum if this is not the right place for pasting python related queries Many Thanks in advance, Srini From rhodri at kynesim.co.uk Tue Nov 6 13:41:20 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 6 Nov 2018 18:41:20 +0000 Subject: SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: Message-ID: <5d5dec76-d5a4-a524-bf3f-37412f44e185@kynesim.co.uk> On 06/11/2018 18:10, srinivasan wrote: > root:~/qa/test_library# python3 sd.py > File "sd.py", line 99 > * cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* > * ^* > *SyntaxError: can't assign to literal* Look at the 'cut' element of the pipeline. You have used double quotes in a double quoted string without escaping them. As a result, the interpreter thinks you are trying to assign the string literal " -f3" to the string literal "blkid -o export %s | grep 'Type' | cut -d" -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Nov 6 13:41:20 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 6 Nov 2018 18:41:20 +0000 Subject: SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: Message-ID: <5d5dec76-d5a4-a524-bf3f-37412f44e185@kynesim.co.uk> On 06/11/2018 18:10, srinivasan wrote: > root:~/qa/test_library# python3 sd.py > File "sd.py", line 99 > * cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* > * ^* > *SyntaxError: can't assign to literal* Look at the 'cut' element of the pipeline. You have used double quotes in a double quoted string without escaping them. As a result, the interpreter thinks you are trying to assign the string literal " -f3" to the string literal "blkid -o export %s | grep 'Type' | cut -d" -- Rhodri James *-* Kynesim Ltd From lie.1296 at gmail.com Tue Nov 6 16:51:47 2018 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 6 Nov 2018 13:51:47 -0800 (PST) Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> , > <5vv0bf-if2.ln1@anthive.com> Message-ID: <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> > I like to step through my code line by line, > it's impossible to do it with > object-oriented programming language. I suggest pudb, it's a curses based debugger, which is nicer than pdb, but doesn't require tedious IDE setup. > Also, there's no good REPL IDE. Not quite sure what you meant by REPL IDE, but did you try IPython From ian.g.kelly at gmail.com Tue Nov 6 17:39:24 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 6 Nov 2018 15:39:24 -0700 Subject: Asyncio tasks getting cancelled In-Reply-To: <20181106034051.GA27582@ma.tura-home.de> References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234436.GA15200@ma.tura-home.de> <20181106034051.GA27582@ma.tura-home.de> Message-ID: n Mon, Nov 5, 2018 at 8:43 PM wrote: > > On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote: > > > For context: > > > https://github.com/ldo/dbussy/issues/13 > > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > > > > > It really feels like asyncio is loosing strong references to scheduled > > > tasks, as excplicitly keeping them around helps. Also, the error > > > messages I'm getting are the ones from here: > > > https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145 > > > Which indicates that the tasks actually weren't even started at all? > > > > No, it indicates that it was cleaned up (likely because the program > > exited) before the task completed. Which likely implies that the loop > > exited without waiting for it. From the stack trace, you're using > > loop.run_until_complete(main()). Like asyncio.run, that only runs > > until the specific thing you pass it completes, which might wait on > > other things or might not. Anything else that's still pending is going > > to be left up in the air unless you subsequently restart the same > > event loop. > > What I meant was, the error message is specific to futures in the > 'PENDING' state. Which should be set to 'RUNNING' before any actions > occur. So it appears the tasks weren't started at all. Ah. I don't think asyncio uses a RUNNING state. There's nothing about it in the docs; tasks are either done or they're not: https://docs.python.org/3/library/asyncio-task.html#task-object And inspecting the current task also shows PENDING: py> from asyncio import * py> async def main(): ... print(current_task()._state) ... py> run(main()) PENDING > Also the cleanup happens instantly, ie before the loop exits (as the > main loop has an asyncio.sleep timeout. Printing a message also clearly > shows this happens way before main returns. Okay, that wasn't clear from the log you posted. It's not obvious to me why that would be happening. although it does sound like the tasks are getting created and then immediately garbage-collected for some reason. It could be a bug in asyncio, or it could be a bug in the way the tasks are created, e.g. on a separate event loop that gets dropped on the floor. From ian.g.kelly at gmail.com Tue Nov 6 17:42:46 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 6 Nov 2018 15:42:46 -0700 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234436.GA15200@ma.tura-home.de> <20181106034051.GA27582@ma.tura-home.de> Message-ID: On Tue, Nov 6, 2018 at 3:39 PM Ian Kelly wrote: > > n Mon, Nov 5, 2018 at 8:43 PM wrote: > > What I meant was, the error message is specific to futures in the > > 'PENDING' state. Which should be set to 'RUNNING' before any actions > > occur. So it appears the tasks weren't started at all. > > Ah. I don't think asyncio uses a RUNNING state. There's nothing about > it in the docs; tasks are either done or they're not: > https://docs.python.org/3/library/asyncio-task.html#task-object > > And inspecting the current task also shows PENDING: > > py> from asyncio import * > py> async def main(): > ... print(current_task()._state) > ... > py> run(main()) > PENDING Looks like the only states are PENDING, CANCELLED, and FINISHED: https://github.com/python/cpython/blob/3.7/Lib/asyncio/base_futures.py#L17 From jladasky at itu.edu Tue Nov 6 21:30:05 2018 From: jladasky at itu.edu (jladasky at itu.edu) Date: Tue, 6 Nov 2018 18:30:05 -0800 (PST) Subject: int.to_bytes() for a single byte Message-ID: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> I'm using Python 3.6. I have a need to convert several small integers into single bytes. As far as I can tell from reading through the Python docs, the correct way to accomplish this task is: b = i.to_bytes(1, "big") This seems to work, but I find it cumbersome. I have to supply the byteorder argument to prevent a TypeError. However, byte order doesn't matter if I'm only generating a single byte. Whether I choose "big" or "little" I should get the same result. Is there another function which provides a more logical interface to this straightforward task? Thanks for any suggestions. From bgailer at gmail.com Tue Nov 6 21:43:50 2018 From: bgailer at gmail.com (bob gailer) Date: Tue, 6 Nov 2018 21:43:50 -0500 Subject: int.to_bytes() for a single byte In-Reply-To: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> References: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> Message-ID: On 11/6/2018 9:30 PM, jladasky at itu.edu wrote: > I'm using Python 3.6. I have a need to convert several small integers into single bytes. As far as I can tell from reading through the Python docs, the correct way to accomplish this task is: > > b = i.to_bytes(1, "big") > > This seems to work, but I find it cumbersome. I have to supply the byteorder argument to prevent a TypeError. However, byte order doesn't matter if I'm only generating a single byte. Whether I choose "big" or "little" I should get the same result. Is there another function which provides a more logical interface to this straightforward task? Take a look at the struct module. Bob Gailer From tjreedy at udel.edu Tue Nov 6 22:18:44 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 6 Nov 2018 22:18:44 -0500 Subject: int.to_bytes() for a single byte In-Reply-To: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> References: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> Message-ID: On 11/6/2018 9:30 PM, jladasky at itu.edu wrote: > b = i.to_bytes(1, "big") > >Is there another function which provides a more logical interface to this straightforward task? Yes >>> 33 .to_bytes(1, 'big') b'!' >>> bytes((33,)) b'!' See >>> bytes( # in IDLE or >>> help(bytes) -- Terry Jan Reedy From jladasky at itu.edu Tue Nov 6 23:22:50 2018 From: jladasky at itu.edu (jladasky at itu.edu) Date: Tue, 6 Nov 2018 20:22:50 -0800 (PST) Subject: int.to_bytes() for a single byte In-Reply-To: References: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> Message-ID: On Tuesday, November 6, 2018 at 7:19:09 PM UTC-8, Terry Reedy wrote: > On 11/6/2018 9:30 PM, j...y at it.u wrote: > > > b = i.to_bytes(1, "big") > > > >Is there another function which provides a more logical interface to this straightforward task? > > Yes > >>> 33 .to_bytes(1, 'big') > b'!' > >>> bytes((33,)) > b'!' Thanks Terry, that's what I was looking for. I had tried using the bytes() constructor directly, and was getting a byte array of zeros, of the length specified by the integer. That's in the documentation, and it might be useful, but I haven't seen an obvious use case, and it isn't what I wanted. Wrapping the integer in a tuple solves the problem of it being interpreted as a length. From tjol at tjol.eu Wed Nov 7 04:14:51 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 7 Nov 2018 10:14:51 +0100 Subject: int.to_bytes() for a single byte In-Reply-To: References: <822183ce-a17d-493b-90a1-c282e9e997ad@googlegroups.com> Message-ID: On 07/11/2018 05:22, jladasky at itu.edu wrote: > On Tuesday, November 6, 2018 at 7:19:09 PM UTC-8, Terry Reedy wrote: >> On 11/6/2018 9:30 PM, j...y at it.u wrote: >> >>> b = i.to_bytes(1, "big") >>> >>> Is there another function which provides a more logical interface to this straightforward task? >> >> Yes >> >>> 33 .to_bytes(1, 'big') >> b'!' >> >>> bytes((33,)) >> b'!' > > Thanks Terry, that's what I was looking for. > > I had tried using the bytes() constructor directly, and was getting a byte array of zeros, of the length specified by the integer. That's in the documentation, and it might be useful, but I haven't seen an obvious use case, and it isn't what I wanted. Wrapping the integer in a tuple solves the problem of it being interpreted as a length. > A bytes is a sequence of 8-bit integers, which is why the constructor takes a sequence (or, well, iterable) of integers. >>> bytes([49,50,51]) b'123' From tjol at tjol.eu Wed Nov 7 04:20:42 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 7 Nov 2018 10:20:42 +0100 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> Message-ID: <20a48471-70ac-22e5-4280-62db805a38e5@tjol.eu> On 06/11/2018 22:51, Lie Ryan wrote: >> I like to step through my code line by line, >> it's impossible to do it with >> object-oriented programming language. > > I suggest pudb, it's a curses based debugger, which is nicer than pdb, but doesn't require tedious IDE setup. I'll just take this opportunity to point out (for those that don't know) that Visual Studio Code (an open source cross-platform programmer's text editor of the same calibre as Sublime or Atom, not an IDE) has great support for (graphical) debugging of Python code. Not tedious to set up, particularly. Obviously there are plugins for other editors, but they're usually not this well-integrated. > >> Also, there's no good REPL IDE. > > Not quite sure what you meant by REPL IDE, but did you try IPython > If you find yourself wanting a debugger in an IPython/Jupyter notebook, ipdb is pretty nice. From srinivasan.rns at gmail.com Wed Nov 7 04:22:00 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 7 Nov 2018 10:22:00 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> Message-ID: After changing the line to *"cmd = "blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3" % fs"*, Now I dont see the error "SyntaxError: can't assign to literal" This is not returning exactly "*vfat*" instead of this, it is returning as "* /dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* " Could you please help me as it seems to be like grep and cut commands are not working in the above line ie., on *cmd = "blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3" % fs*? On Wed, Nov 7, 2018 at 9:41 AM Avi Gross wrote: > I may be missing something but it looks like the embedded double quotes > may be a problem in this: > > cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % ... > > if you use single quotes as in: > > cut -d"=" > > becomes > > cut -d'=' > > or escape the double quotes with \" and so on ... > > The above seems to be seen as: > > cmd=ALPHA=BETA % ... > > where ALPHA="blkid -o export %s | grep 'TYPE' | cut -d" > and BETA=" -f3" > > Other issues may also be there. > -----Original Message----- > From: Tutor On Behalf Of > Alan Gauld via Tutor > Sent: Tuesday, November 6, 2018 7:37 PM > To: tutor at python.org > Cc: python-dev at python.org > Subject: Re: [Tutor] SyntaxError: can't assign to literal while using > ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using > subprocess module in Python > > On 06/11/2018 18:07, srinivasan wrote: > > > bash command in python using subprocess module, I ma seeing the below > > * cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % > > (fs)* > > In general you should try to do as little as possible using bash and > subprocess. Especially try to avoid long pipelines since you are starting a > new OS process for every element in the pipeline. That means, in your case, > you are running 4 processes to get your result - Python, blkid, grep and cut > > Python is designed to do much of what the shell command can do almost as > easily and much more efficiently (no new processes being started). > > In this case just execute the blkid bit in bash because its too difficult > to replicate simply in Python. Then use Python to search for the TYPE lines > and slice them to size. > > That will, in turn, simplify your command string and remove the issue of > multiple quotes. > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From pahome.chen at mirlab.org Wed Nov 7 04:36:22 2018 From: pahome.chen at mirlab.org (lampahome) Date: Wed, 7 Nov 2018 17:36:22 +0800 Subject: Does this behavior have a better design pattern? Message-ID: I have two categories A,B, and A has 2 items A1,A2 B have 2 items B1, B2. I have two class A and B, and A will handle A1,A2, B handle B1,B2. I want to parse one of A1,A2,B1,B2 to script and generate the corresponding class(object). Ex: Both in class A and B, all have func1(), func2(). What I thought to design is below: ------------------------------------------------- class Data(object): def __Init__(): ... def func1(self): pass def func2(self): pass class A(Data): def __Init__(): ... def func1(self): A_do() def func2(self): A_does() class B(Data): def __Init__(): ... def func1(self): B_do() def func2(self): B_does() def get_class(obj): if obj == 'A1' or obj == 'A2': return A(obj) else: return B(obj) # A = get_class(A1) # B = get_class(B2) ------------------------------------------------------------- Above is I thought to make code clear, and this pattern is called simple factory? *Is there better design pattern for me?* thanks From brian.j.oney at googlemail.com Wed Nov 7 05:10:01 2018 From: brian.j.oney at googlemail.com (Brian J. Oney) Date: Wed, 07 Nov 2018 11:10:01 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> Message-ID: <1541585401.1731.1.camel@gmail.com> On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote: > blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3 You don't need to escape the single quotes. Try either: "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" or: 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' or: "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" HTH From __peter__ at web.de Wed Nov 7 06:00:14 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Nov 2018 12:00:14 +0100 Subject: Does this behavior have a better design pattern? References: Message-ID: lampahome wrote: > Above is I thought to make code clear, and this pattern is called simple > factory? This is a factory function: > def get_class(obj): > if obj == 'A1' or obj == 'A2': > return A(obj) > else: > return B(obj) The rest is just cruft ;) > > *Is there better design pattern for me?* If A does B to C, is that a crime? Your problem description suffers from overgeneralisation. Generally speaking you get better solutions when you ask yourself "How can I solve this problem efficiently?" rather than "What fancy design patterns can I use while solving this problem?" From srinivasan.rns at gmail.com Wed Nov 7 06:31:40 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 7 Nov 2018 12:31:40 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: <1541585401.1731.1.camel@gmail.com> References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: Even after changing as per the below "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" or: 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' or: "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" Still my output is: */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* My expected output should be only: *vfat* Could you guys please do the needful? On Wed, Nov 7, 2018 at 11:10 AM Brian J. Oney wrote: > On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote: > > blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3 > > You don't need to escape the single quotes. > Try either: > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > HTH > From cai at gmx.us Wed Nov 7 07:19:40 2018 From: cai at gmx.us (Qian Cai) Date: Wed, 07 Nov 2018 13:19:40 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: srinivasan wrote: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > Still my output is: > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > My expected output should be only: > *vfat* > > Could you guys please do the needful? > > Perfect place to use sed instead of grep/cut. From rosuav at gmail.com Wed Nov 7 07:37:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Nov 2018 23:37:54 +1100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: On Wed, Nov 7, 2018 at 11:36 PM Qian Cai wrote: > > srinivasan wrote: > > Even after changing as per the below > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > > or: > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > > or: > > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > > > Still my output is: > > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > > > My expected output should be only: > > *vfat* > > > > Could you guys please do the needful? > > > > > Perfect place to use sed instead of grep/cut. ... or to use subprocess.check_output() to run just the blkid command, and then do the parsing in Python. ChrisA From srinivasan.rns at gmail.com Wed Nov 7 07:41:52 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 7 Nov 2018 13:41:52 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: Some I managed to fix temporarily as below, might be useful for others. Also please correct me if anything wrong or for any improvements in the below cmd = "blkid -o export %s" % partition_path out = self._helper.execute_cmd_output_string(cmd) var = out.split("TYPE=", 1)[1] quoted = re.compile('(?<=^\")[^"]*') for string in quoted.findall(var): return string On Wed, Nov 7, 2018 at 1:39 PM Chris Angelico wrote: > On Wed, Nov 7, 2018 at 11:36 PM Qian Cai wrote: > > > > srinivasan wrote: > > > Even after changing as per the below > > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > > > or: > > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > > > or: > > > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > > > > > Still my output is: > > > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > > > > > My expected output should be only: > > > *vfat* > > > > > > Could you guys please do the needful? > > > > > > > > Perfect place to use sed instead of grep/cut. > > ... or to use subprocess.check_output() to run just the blkid command, > and then do the parsing in Python. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rhodri at kynesim.co.uk Wed Nov 7 07:54:40 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 7 Nov 2018 12:54:40 +0000 Subject: Unable to remove python from my computer. In-Reply-To: References: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> <658fd744-f7c9-ff1c-2eb4-4b8aa60eb321@tjol.eu> <57bcfc7b-8302-fecf-efae-e1b75d239bf6@kynesim.co.uk> Message-ID: <7797aad2-cf4d-3af8-aaaa-21caba6419ac@kynesim.co.uk> I assume "on a PC" actually means "on Windows". Redirected back to the list since I neither know nor care about wrangling Python on Windows. On 07/11/2018 12:27, Jack Gilbert wrote: > on a PC: > > click start, (click on the window, lower left hand corner)[ in 8.1] > Control Panel > Programs and Features > > you will see a list of programs installed on your machine in alphabetical > order > look for Python x.x.x(32 bit) click to highlight > click uninstall near the top of the screen > wait > wait > wait > the machine might ask you,, are you sure you want to uninstall this > program? click ok or yes > wait > wait > wait > wait some more > > you might see the status bar move to the right as the machine clears the > program > > wait > wait > > the machine will say,, this progam has been uninstalled > > you should see or rather not see the program in the list and any python > icon that you have on your desktop will also be removed. > > I have Python 3.6.4(32-bit) on a 64bit PC with 5TB HDD, Dell machine, > running 8.1 > > > > > Virus-free. > www.avg.com > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > On Tue, Nov 6, 2018 at 5:42 AM Rhodri James wrote: > >> On 06/11/2018 09:25, Thomas Jollans wrote: >>> On 2018-11-06 10:05, Varshit Jain wrote: >>>> Hi Python Support Team, >>>> >>>> >>>> I just want to remove python 3.6.6 from my computer. I am unable to do >>>> it. Please find attached video that describe my problem. >>> >>> Use your words, friend! >>> >>> (this list is text-only) >> >> More exactly, I'm afraid the mailing list has stripped off the video you >> attached, so we can't watch it. I'm afraid I wouldn't in any case; I >> learned long ago not to open attachments from people I don't already know. >> >> Could you please describe to us your problem? Are you using Windows, >> Linux, Mac or something else? Copy any error messages the uninstaller >> might have given you, preferably cutting and pasting rather than just >> retyping them (it's easy to mistype something critical!). Please don't >> send us screen shots, those will just get stripped off by the mailing >> list as well. >> >> -- >> Rhodri James *-* Kynesim Ltd >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Wed Nov 7 07:54:40 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 7 Nov 2018 12:54:40 +0000 Subject: Unable to remove python from my computer. In-Reply-To: References: <79e2b55e-21db-715d-4184-1a2f1d3f80ba@ideavate.com> <658fd744-f7c9-ff1c-2eb4-4b8aa60eb321@tjol.eu> <57bcfc7b-8302-fecf-efae-e1b75d239bf6@kynesim.co.uk> Message-ID: <7797aad2-cf4d-3af8-aaaa-21caba6419ac@kynesim.co.uk> I assume "on a PC" actually means "on Windows". Redirected back to the list since I neither know nor care about wrangling Python on Windows. On 07/11/2018 12:27, Jack Gilbert wrote: > on a PC: > > click start, (click on the window, lower left hand corner)[ in 8.1] > Control Panel > Programs and Features > > you will see a list of programs installed on your machine in alphabetical > order > look for Python x.x.x(32 bit) click to highlight > click uninstall near the top of the screen > wait > wait > wait > the machine might ask you,, are you sure you want to uninstall this > program? click ok or yes > wait > wait > wait > wait some more > > you might see the status bar move to the right as the machine clears the > program > > wait > wait > > the machine will say,, this progam has been uninstalled > > you should see or rather not see the program in the list and any python > icon that you have on your desktop will also be removed. > > I have Python 3.6.4(32-bit) on a 64bit PC with 5TB HDD, Dell machine, > running 8.1 > > > > > Virus-free. > www.avg.com > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > On Tue, Nov 6, 2018 at 5:42 AM Rhodri James wrote: > >> On 06/11/2018 09:25, Thomas Jollans wrote: >>> On 2018-11-06 10:05, Varshit Jain wrote: >>>> Hi Python Support Team, >>>> >>>> >>>> I just want to remove python 3.6.6 from my computer. I am unable to do >>>> it. Please find attached video that describe my problem. >>> >>> Use your words, friend! >>> >>> (this list is text-only) >> >> More exactly, I'm afraid the mailing list has stripped off the video you >> attached, so we can't watch it. I'm afraid I wouldn't in any case; I >> learned long ago not to open attachments from people I don't already know. >> >> Could you please describe to us your problem? Are you using Windows, >> Linux, Mac or something else? Copy any error messages the uninstaller >> might have given you, preferably cutting and pasting rather than just >> retyping them (it's easy to mistype something critical!). Please don't >> send us screen shots, those will just get stripped off by the mailing >> list as well. >> >> -- >> Rhodri James *-* Kynesim Ltd >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Wed Nov 7 07:57:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Nov 2018 23:57:28 +1100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: On Wed, Nov 7, 2018 at 11:42 PM srinivasan wrote: > > Some I managed to fix temporarily as below, might be useful for others. Also please correct me if anything wrong or for any improvements in the below > > cmd = "blkid -o export %s" % partition_path > out = self._helper.execute_cmd_output_string(cmd) > var = out.split("TYPE=", 1)[1] > quoted = re.compile('(?<=^\")[^"]*') > for string in quoted.findall(var): > return string Leaving aside the fact that MS Comic Sans is known to the State of California to cause cancer, this code is probably okay if you don't mind it being overengineered. Here's a much simpler version, albeit untested: out = subprocess.check_output(["blkid", "-o", "export", partition_path]) for line in out.split("\n"): item, value = line.split("=") if item == "TYPE": return value No helper needed. Safe against command injection. Uses the known format of the command's output; if you want other information as well as the type, you could get that too. ChrisA From ben.usenet at bsb.me.uk Wed Nov 7 09:06:33 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 07 Nov 2018 14:06:33 +0000 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: <87o9b19e3a.fsf@bsb.me.uk> srinivasan writes: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > Still my output is: > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > My expected output should be only: > *vfat* > > Could you guys please do the needful? Why not blkid %s -o value --match-tag TYPE ? Or, better still, lsblk %s -n -o FSTYPE It's not easy to answer your question about fixing the line you have, because the output you are getting it not consistent with what you are showing. (And I can't find the original post that presumably has Python code I could run myself.) The format I get with -o export is: DEVNAME=/dev/sda1 UUID=2726bf5f-2655-4986-815d-e4532374f218 TYPE=ext3 PARTUUID=000453d3-01 for which "blkid %s -o export | grep TYPE | cut -c6-" would work. Alternatively I get the result you want from "blkid %s -o export | grep TYPE | cut -d= -f2" Note that "TYPE" and "=" don't really need to be quoted at all. Someone suggested sed, and that too can be used like this: blkid %s -o export | sed -ne '/TYPE=/s///p' -- Ben. From srinivasan.rns at gmail.com Wed Nov 7 10:57:02 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 7 Nov 2018 16:57:02 +0100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: <87o9b19e3a.fsf@bsb.me.uk> References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> <87o9b19e3a.fsf@bsb.me.uk> Message-ID: Many Thanks a lot , I can use for reliably "lsblk %s -n -o FSTYPE" in the reused code of mine as below cmd = "lsblk %s -n -o FSTYPE" % partition_path return self._helper.execute_cmd_output_string(cmd) I really appreciate for all your support w.r.t this.. I feel I have kick started my learning in python :) Have a great day ahead! On Wed, Nov 7, 2018 at 3:11 PM Ben Bacarisse wrote: > srinivasan writes: > > > Even after changing as per the below > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > > or: > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > > or: > > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > > > Still my output is: > > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > > > My expected output should be only: > > *vfat* > > > > Could you guys please do the needful? > > Why not > > blkid %s -o value --match-tag TYPE > > ? Or, better still, > > lsblk %s -n -o FSTYPE > > It's not easy to answer your question about fixing the line you have, > because the output you are getting it not consistent with what you are > showing. (And I can't find the original post that presumably has Python > code I could run myself.) > > The format I get with -o export is: > > DEVNAME=/dev/sda1 > UUID=2726bf5f-2655-4986-815d-e4532374f218 > TYPE=ext3 > PARTUUID=000453d3-01 > > for which > > "blkid %s -o export | grep TYPE | cut -c6-" > > would work. Alternatively I get the result you want from > > "blkid %s -o export | grep TYPE | cut -d= -f2" > > Note that "TYPE" and "=" don't really need to be quoted at all. > > Someone suggested sed, and that too can be used like this: > > blkid %s -o export | sed -ne '/TYPE=/s///p' > > -- > Ben. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Wed Nov 7 15:31:55 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 7 Nov 2018 20:31:55 +0000 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: <20a48471-70ac-22e5-4280-62db805a38e5@tjol.eu> References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> <20a48471-70ac-22e5-4280-62db805a38e5@tjol.eu> Message-ID: <24b887cb-af51-5f43-cf01-8151a43e318f@mrabarnett.plus.com> On 2018-11-07 09:20, Thomas Jollans wrote: > On 06/11/2018 22:51, Lie Ryan wrote: >>> I like to step through my code line by line, >>> it's impossible to do it with >>> object-oriented programming language. >> >> I suggest pudb, it's a curses based debugger, which is nicer than pdb, but doesn't require tedious IDE setup. > > I'll just take this opportunity to point out (for those that don't know) > that Visual Studio Code (an open source cross-platform programmer's text > editor of the same calibre as Sublime or Atom, not an IDE) has great > support for (graphical) debugging of Python code. Not tedious to set up, > particularly. Obviously there are plugins for other editors, but they're > usually not this well-integrated. > I find that the code does run more slowly, though. >> >>> Also, there's no good REPL IDE. >> >> Not quite sure what you meant by REPL IDE, but did you try IPython >> > > If you find yourself wanting a debugger in an IPython/Jupyter notebook, > ipdb is pretty nice. > From tjol at tjol.eu Wed Nov 7 17:29:54 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 7 Nov 2018 23:29:54 +0100 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: <24b887cb-af51-5f43-cf01-8151a43e318f@mrabarnett.plus.com> References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> <20a48471-70ac-22e5-4280-62db805a38e5@tjol.eu> <24b887cb-af51-5f43-cf01-8151a43e318f@mrabarnett.plus.com> Message-ID: On 07/11/2018 21:31, MRAB wrote: > On 2018-11-07 09:20, Thomas Jollans wrote: >> On 06/11/2018 22:51, Lie Ryan wrote: >>>> I like to step through my code line by line, >>>> it's impossible to do it with >>>> object-oriented programming language. >>> >>> I suggest pudb, it's a curses based debugger, which is nicer than >>> pdb, but doesn't require tedious IDE setup. >> >> I'll just take this opportunity to point out (for those that don't know) >> that Visual Studio Code (an open source cross-platform programmer's text >> editor of the same calibre as Sublime or Atom, not an IDE) has great >> support for (graphical) debugging of Python code. Not tedious to set up, >> particularly. Obviously there are plugins for other editors, but they're >> usually not this well-integrated. >> > I find that the code does run more slowly, though. Can't argue with that. I'm not totally sold on vscode, either. But I enjoy the debugger! > >>> >>>> Also, there's no good REPL IDE. >>> >>> Not quite sure what you meant by REPL IDE, but did you try IPython >>> >> >> If you find yourself wanting a debugger in an IPython/Jupyter notebook, >> ipdb is pretty nice. >> From pahome.chen at mirlab.org Wed Nov 7 20:28:49 2018 From: pahome.chen at mirlab.org (lampahome) Date: Thu, 8 Nov 2018 09:28:49 +0800 Subject: Does this behavior have a better design pattern? In-Reply-To: References: Message-ID: > > > The rest is just cruft ;) > > > > *Is there better design pattern for me?* > > If A does B to C, is that a crime? > No > Your problem description suffers from overgeneralisation. > > Generally speaking you get better solutions when you ask yourself > "How can I solve this problem efficiently?" > > In another hand, how can I solve this problem efficiently? or any pythonic way to solve this? From therealnohax at gmail.com Wed Nov 7 20:52:52 2018 From: therealnohax at gmail.com (NoHaxAllSwagg) Date: Wed, 7 Nov 2018 19:52:52 -0600 Subject: Number 7 syntax ERROR Message-ID: <5be396f6.1c69fb81.15429.0899@mx.google.com> Hello, I have been experiencing difficulty while trying to run scripts on my IDLE software, considering that when I run my program, I get an error at the top of the page in the ?Python 3.7.1? area, highlighting the seven telling me that there is a syntax error, in this case, I cant remove that area, so I cant run my script, please help Sincerely, Zed Sent from Mail for Windows 10 From torriem at gmail.com Wed Nov 7 23:18:08 2018 From: torriem at gmail.com (Michael Torrie) Date: Wed, 7 Nov 2018 21:18:08 -0700 Subject: Overwhelmed by the Simplicity of Python. Any Recommendation? In-Reply-To: <24b887cb-af51-5f43-cf01-8151a43e318f@mrabarnett.plus.com> References: <928b9a9e-b1bc-15b9-6b5e-24ee0db75f60@kynesim.co.uk> <5vv0bf-if2.ln1@anthive.com> <3e157571-c197-4e33-9d44-a86332af5bf1@googlegroups.com> <20a48471-70ac-22e5-4280-62db805a38e5@tjol.eu> <24b887cb-af51-5f43-cf01-8151a43e318f@mrabarnett.plus.com> Message-ID: On 11/07/2018 01:31 PM, MRAB wrote: > On 2018-11-07 09:20, Thomas Jollans wrote: >> I'll just take this opportunity to point out (for those that don't know) >> that Visual Studio Code (an open source cross-platform programmer's text >> editor of the same calibre as Sublime or Atom, not an IDE) has great >> support for (graphical) debugging of Python code. Not tedious to set up, >> particularly. Obviously there are plugins for other editors, but they're >> usually not this well-integrated. >> > I find that the code does run more slowly, though. Why? Python is python, isn't it? Usually code runs slower in a debugger. Isn't VS code using pdb under the hood? From iankilty2 at gmail.com Thu Nov 8 00:04:49 2018 From: iankilty2 at gmail.com (Ian K.) Date: Wed, 7 Nov 2018 22:04:49 -0700 Subject: installing modules problem Message-ID: Hello, My name is Ian Kilty and I have been having trouble with pip. I have pip installed, and I have tried to install modules they say they are installed in cmd, but when I go into python and import the module, it can't find it. I hope there is a simple solution to this problem, please let me know as soon as possible. -- from Not A User because I don't want to be made fun of in Tron -- From tjol at tjol.eu Thu Nov 8 05:51:01 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 8 Nov 2018 11:51:01 +0100 Subject: installing modules problem In-Reply-To: References: Message-ID: <74e5933e-2133-26c6-34ee-494a2260545e@tjol.eu> On 2018-11-08 06:04, Ian K. wrote: > Hello, > > My name is Ian Kilty and I have been having trouble with pip. I have pip > installed, and I have tried to install modules they say they are installed > in cmd, but when I go into python and import the module, it can't find it. > I hope there is a simple solution to this problem, please let me know as > soon as possible. > > -- from Not A User because I don't want to be made fun of in Tron -- > Hi! some questions: - is there any chance you have multiple versions of python installed? Could you be using the wrong pip? - what operating system are you using? - what are you trying to install and use? - how exactly are you trying to install and import this module? (exact commands, exact copy-pasted output) -- Thomas From sukurcf at gmail.com Thu Nov 8 06:13:46 2018 From: sukurcf at gmail.com (Siva Sukumar Reddy) Date: Thu, 8 Nov 2018 16:43:46 +0530 Subject: installing modules problem In-Reply-To: <74e5933e-2133-26c6-34ee-494a2260545e@tjol.eu> References: <74e5933e-2133-26c6-34ee-494a2260545e@tjol.eu> Message-ID: Also make sure that the Pythonpath contains the folder where the modules are installed in your machine. - site packages folder. On Thu 8 Nov, 2018, 16:28 Thomas Jollans On 2018-11-08 06:04, Ian K. wrote: > > Hello, > > > > My name is Ian Kilty and I have been having trouble with pip. I have pip > > installed, and I have tried to install modules they say they are > installed > > in cmd, but when I go into python and import the module, it can't find > it. > > I hope there is a simple solution to this problem, please let me know as > > soon as possible. > > > > -- from Not A User because I don't want to be made fun of in Tron -- > > > > Hi! > > some questions: > > - is there any chance you have multiple versions of python installed? > Could you be using the wrong pip? > - what operating system are you using? > - what are you trying to install and use? > - how exactly are you trying to install and import this module? (exact > commands, exact copy-pasted output) > > -- Thomas > -- > https://mail.python.org/mailman/listinfo/python-list > From tdldev at gmail.com Thu Nov 8 08:34:16 2018 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 8 Nov 2018 08:34:16 -0500 Subject: Number 7 syntax ERROR In-Reply-To: <5be396f6.1c69fb81.15429.0899@mx.google.com> References: <5be396f6.1c69fb81.15429.0899@mx.google.com> Message-ID: <5d319ff6-ee03-a690-9eac-adaf5c0b9ddc@gmail.com> On 11/7/18 8:52 PM, NoHaxAllSwagg wrote: > Hello, > I have been experiencing difficulty while trying to run scripts on my IDLE software, considering that when I run my program, I get an error at the top of the page in the ?Python 3.7.1? area, highlighting the seven telling me that there is a syntax error, in this case, I cant remove that area, so I cant run my script, please help > Sincerely, > Zed > > Sent from Mail for Windows 10 > Just curious what happens when you run that same script outside of IDLE? Does it work? From __peter__ at web.de Thu Nov 8 09:14:00 2018 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Nov 2018 15:14 +0100 Subject: Number 7 syntax ERROR References: <5be396f6.1c69fb81.15429.0899@mx.google.com> Message-ID: NoHaxAllSwagg wrote: > Hello, > I have been experiencing difficulty while trying to run scripts on my IDLE > software, considering that when I run my program, I get an error at the > top of the page in the ?Python 3.7.1? area, highlighting the seven telling > me that there is a syntax error, in this case, I cant remove that area, so > I cant run my script, please help Sincerely, Zed You are probably in the "shell" window. The purpose of that window is to try small snippets of Python code, e. g. if you enter 1 + 2 + 3 it will print 6 To run a script you are developing with idle save it and then use [Run Module] in the [Run] menu, or hit the F5 key. Example: Click [File] [New File], enter print("hello world") into the window that opens, then click [File] [Save] and enter hello.py as the filename. If you followed these instructions and hit F5 the "shell" window will appear with something like ===== RESTART: /path/to/hello.py ====== hello world If you made a mistake in your code, say you forgot the closing " in print("hello world) a dialog box describing the syntax error will appear instead. When you want to run the hello.py script like this python3.7 hello.py you have to do that in a shell window of your operating system, not in idle. From vlastimil.brom at gmail.com Thu Nov 8 09:26:14 2018 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 8 Nov 2018 15:26:14 +0100 Subject: Number 7 syntax ERROR In-Reply-To: <5be396f6.1c69fb81.15429.0899@mx.google.com> References: <5be396f6.1c69fb81.15429.0899@mx.google.com> Message-ID: 2018-11-08 2:52 GMT+01:00, NoHaxAllSwagg : > Hello, > I have been experiencing difficulty while trying to run scripts on my IDLE > software, considering that when I run my program, I get an error at the top > of the page in the ?Python 3.7.1? area, highlighting the seven telling me > that there is a syntax error, in this case, I cant remove that area, so I > cant run my script, please help > Sincerely, > Zed > > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, it looks like, You are trying to run some "text" which is not valid as python code. It might be something starting with an "introduction" shown at python terminal, e.g.: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 ... At least this part is not a valid, runable python code, and the highlighted part "7" is the first place, where the syntax error was detected. You might try removing this starting part of the script source and see whether it does something expected. Otherwise there might be some other problems with it. There are restrictions on changing the text already entered to the interactive interpretter like IDLE; you may try to save and edit the source as a *.py file in some code editor (or in IDLE as new file...) and running it directly. hth, vbr From 00jhenryg at gmail.com Thu Nov 8 10:13:44 2018 From: 00jhenryg at gmail.com (Jack Gilbert) Date: Thu, 8 Nov 2018 09:13:44 -0600 Subject: TEST Message-ID: not to tick anybody off, I want to see if this is the correct way to post to the python list. Thanks to all who are helping me. Jack G From grant.b.edwards at gmail.com Thu Nov 8 10:47:33 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 8 Nov 2018 15:47:33 +0000 (UTC) Subject: Does this behavior have a better design pattern? References: Message-ID: On 2018-11-07, Peter Otten <__peter__ at web.de> wrote: > lampahome wrote: > >> Above is I thought to make code clear, and this pattern is called simple >> factory? [...] >> *Is there better design pattern for me?* > Generally speaking you get better solutions when you ask yourself > "How can I solve this problem efficiently?" > rather than > "What fancy design patterns can I use while solving this problem?" I'd rather start with "how can I solve this problem simply and clearly". By "clearly" I mean that the source code is easy to understand and reason about. I don't worry about "efficiency" unless testing shows that the simple, clear solution isn't efficient enough to meet requirements. -- Grant Edwards grant.b.edwards Yow! And furthermore, at my bowling average is gmail.com unimpeachable!!! From __peter__ at web.de Thu Nov 8 11:54:22 2018 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Nov 2018 17:54:22 +0100 Subject: Does this behavior have a better design pattern? References: Message-ID: Grant Edwards wrote: > On 2018-11-07, Peter Otten <__peter__ at web.de> wrote: >> lampahome wrote: >> >>> Above is I thought to make code clear, and this pattern is called simple >>> factory? > > [...] > >>> *Is there better design pattern for me?* > >> Generally speaking you get better solutions when you ask yourself > >> "How can I solve this problem efficiently?" >> rather than >> "What fancy design patterns can I use while solving this problem?" > > I'd rather start with "how can I solve this problem simply and > clearly". By "clearly" I mean that the source code is easy to > understand and reason about. > > I don't worry about "efficiency" unless testing shows that the simple, > clear solution isn't efficient enough to meet requirements. You are absolutely right. From tjreedy at udel.edu Thu Nov 8 12:31:44 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 8 Nov 2018 12:31:44 -0500 Subject: Number 7 syntax ERROR In-Reply-To: <5be396f6.1c69fb81.15429.0899@mx.google.com> References: <5be396f6.1c69fb81.15429.0899@mx.google.com> Message-ID: On 11/7/2018 8:52 PM, NoHaxAllSwagg wrote: > I have been experiencing difficulty while trying to run scripts on my IDLE software, considering that when I run my program, I get an error at the top of the page in the ?Python 3.7.1? area, highlighting the seven telling me that there is a syntax error, in this case, I cant remove that area, so I cant run my script, please help You need to us give more information about exactly what you did and exactly what you saw for us to give much help. To start, copy and past the code you ran and the result you see. -- Terry Jan Reedy From a24061 at ducksburg.com Thu Nov 8 14:31:07 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 08 Nov 2018 19:31:07 +0000 Subject: Suggestions for plotting slide rule & sector scales? Message-ID: I like old scientific instruments & that sort of thing, & am wondering what libraries I could use for programmatically generating mathematical scales, ideally able to display the result in the GUI & save it as a png (or other standard graphics format). Ideally, I'd like to be able to write code like this: line = foo_library.draw_line(0, 0, 100, 0) for x in range(1,101): line.add_minor_tick(math.log10(x) * 100/2, side=top) for x in range(1,11): line.add_major_tick(math.log10(x*10) * 100/2, label=str(x), side=top) for x in range(0,100): line.add_minor_tick(x, side=bottom) for x in range(0,10): line.add_major_tick(x*10, label=str(x), side=bottom) and get a line 100 mm long with a log scale on the top and a linear scale on the bottom. Thanks, Adam -- It takes a thousand men to invent a telegraph, or a steam engine, or a phonograph, or a telephone or any other important thing --- and the last man gets the credit and we forget the others. ---Mark Twain From pahome.chen at mirlab.org Thu Nov 8 20:45:50 2018 From: pahome.chen at mirlab.org (lampahome) Date: Fri, 9 Nov 2018 09:45:50 +0800 Subject: how can I solve this problem simply and clearly Message-ID: I have two categories A,B, and A has 2 items A1,A2, and B have 2 items B1, B2. I have two class A and B, and A will handle A1,A2, B handle B1,B2. I want to parse one of A1,A2,B1,B2 to script and generate the corresponding class(object). Ex: Both in class A and B, all have func1(), func2(). What I thought to design is below: ------------------------------------------------- class Data(object): def __Init__(): ... def func1(self): pass def func2(self): pass class A(Data): def __Init__(): ... def func1(self): A_do() def func2(self): A_does() class B(Data): def __Init__(): ... def func1(self): B_do() def func2(self): B_does() def get_class(obj): if obj == 'A1' or obj == 'A2': return A(obj) else: return B(obj) # A = get_class(A1) # B = get_class(B2) ------------------------------------------------------------- The function *get_class() *is the question that can I solve this problem clearly? or other else code snippets ? thx From gabriella19930611 at gmail.com Thu Nov 8 22:30:11 2018 From: gabriella19930611 at gmail.com (Annie Lu) Date: Thu, 8 Nov 2018 19:30:11 -0800 (PST) Subject: What's wrong with these codes as failed to read the strings in Chinese? Is it because Chinese characters can't be read on Mac? Many thanks Message-ID: # -*- coding: UTF-8 -*- ... f = open('/Users/annielu/Desktop/namelist1801.txt') >>> namelist1801txt = f.read() >>> f.close() >>> namelist1801txt '\xe9\x99\x88\xe5\xb7\x8d\n\xe8\x83\xa1\xe6\x99\xba\xe5\x81\xa5\r\xe9\xbb\x84\xe5\x9d\xa4\xe6\xa6\x95\r\xe6\x9d\x8e\xe6\x98\x9f\xe7\x81\xbf\r\xe5\x88\x98\xe8\xb6\x85\xe6\x9d\xb0\r\xe7\x8e\x8b\xe4\xbf\x8a\xe5\x80\xbc\r\xe4\xbd\x99\xe4\xb8\x9c\xe6\xbd\xae\r\xe9\x99\x88\xe6\x80\x9d\xe5\x87\xbd\r\xe5\x86\xaf\xe5\xb0\x91\xe5\x90\x9b\r\xe9\xbb\x84\xe5\x98\x89\xe8\xb0\x8a\r\xe9\xbb\x84\xe7\x90\xaa\xe7\x90\xaa\r\xe8\xb5\x96\xe5\xa9\x89\xe5\xa9\xb7\r\xe8\xb5\x96\xe5\xbd\xa6\xe9\x9c\x8f\r\xe5\xbb\x96\xe7\xbf\xa0\xe7\x9b\x88\r\xe6\x9e\x97\xe7\xbe\xbd\xe7\x8f\x82\r\xe5\x88\x98\xe5\xae\x89\xe7\x90\xaa\r\xe9\xa9\xac\xe7\x91\x9e\r\xe5\xbd\xad\xe5\x98\x89\xe4\xbb\xaa\r\xe9\x82\xb1\xe6\xaf\x93\xe4\xbb\xaa\r\xe5\xad\x99\xe6\xa3\xae\xe6\xa3\x8b\r\xe8\xb0\xad\xe5\x98\x89\xe7\x90\xaa\r\xe7\x8e\x8b\xe5\xa4\xa9\xe9\x9f\xb5\r\xe5\x90\xb4\xe5\xad\x90\xe7\x8f\xba\r\xe6\x9d\xa8\xe5\x88\xa9\xe8\x8c\xb5\r\xe5\xa7\x9a\xe5\x98\x89\xe9\x9b\xaf\r\xe8\xa2\x81\xe6\x9c\x88\xe6\xbb\xa2\r\xe5\xbc\xa0\xe9\x87\x87\xe7\x8e\x89\r\xe5\xbc\xa0\xe6\xb2\x81\xe7\x8e\xa5' >>> From hxy9243 at gmail.com Thu Nov 8 22:47:59 2018 From: hxy9243 at gmail.com (Kevin Hu) Date: Thu, 8 Nov 2018 21:47:59 -0600 Subject: What's wrong with these codes as failed to read the strings in Chinese? Is it because Chinese characters can't be read on Mac? Many thanks In-Reply-To: References: Message-ID: <804303B4-1286-473F-B482-629C79A8FD28@gmail.com> Dear Annie, Looks like you?re trying to read in a file with encoded characters. By default Python3 reads file in bytes, and you?ll need to decode it. Looks like it?s utf-8 encoding. More at: https://docs.python.org/3/howto/unicode.html You can simply add: namelist_decoded = namelist1801txt.decode(?utf-8?) Which should give you the actual characters: > ??\n???\r???\r???\r??? Some tutorials lying around Internet: https://www.programiz.com/python-programming/methods/string/encode https://www.pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/ Regards, Kevin > On Nov 8, 2018, at 21:30, Annie Lu wrote: > > # -*- coding: UTF-8 -*- > ... f = open('/Users/annielu/Desktop/namelist1801.txt') >>>> namelist1801txt = f.read() >>>> f.close() >>>> namelist1801txt > '\xe9\x99\x88\xe5\xb7\x8d\n\xe8\x83\xa1\xe6\x99\xba\xe5\x81\xa5\r\xe9\xbb\x84\xe5\x9d\xa4\xe6\xa6\x95\r\xe6\x9d\x8e\xe6\x98\x9f\xe7\x81\xbf\r\xe5\x88\x98\xe8\xb6\x85\xe6\x9d\xb0\r\xe7\x8e\x8b\xe4\xbf\x8a\xe5\x80\xbc\r\xe4\xbd\x99\xe4\xb8\x9c\xe6\xbd\xae\r\xe9\x99\x88\xe6\x80\x9d\xe5\x87\xbd\r\xe5\x86\xaf\xe5\xb0\x91\xe5\x90\x9b\r\xe9\xbb\x84\xe5\x98\x89\xe8\xb0\x8a\r\xe9\xbb\x84\xe7\x90\xaa\xe7\x90\xaa\r\xe8\xb5\x96\xe5\xa9\x89\xe5\xa9\xb7\r\xe8\xb5\x96\xe5\xbd\xa6\xe9\x9c\x8f\r\xe5\xbb\x96\xe7\xbf\xa0\xe7\x9b\x88\r\xe6\x9e\x97\xe7\xbe\xbd\xe7\x8f\x82\r\xe5\x88\x98\xe5\xae\x89\xe7\x90\xaa\r\xe9\xa9\xac\xe7\x91\x9e\r\xe5\xbd\xad\xe5\x98\x89\xe4\xbb\xaa\r\xe9\x82\xb1\xe6\xaf\x93\xe4\xbb\xaa\r\xe5\xad\x99\xe6\xa3\xae\xe6\xa3\x8b\r\xe8\xb0\xad\xe5\x98\x89\xe7\x90\xaa\r\xe7\x8e\x8b\xe5\xa4\xa9\xe9\x9f\xb5\r\xe5\x90\xb4\xe5\xad\x90\xe7\x8f\xba\r\xe6\x9d\xa8\xe5\x88\xa9\xe8\x8c\xb5\r\xe5\xa7\x9a\xe5\x98\x89\xe9\x9b\xaf\r\xe8\xa2\x81\xe6\x9c\x88\xe6\xbb\xa2\r\xe5\xbc\xa0\xe9\x87\x87\xe7\x8e\ > x89\r\xe5\xbc\xa0\xe6\xb2\x81\xe7\x8e\xa5' >>>> > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Fri Nov 9 01:41:16 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 9 Nov 2018 17:41:16 +1100 Subject: What's wrong with these codes as failed to read the strings in Chinese? Is it because Chinese characters can't be read on Mac? Many thanks In-Reply-To: References: Message-ID: <20181109064116.GA82140@cskk.homeip.net> On 08Nov2018 19:30, Annie Lu wrote: ># -*- coding: UTF-8 -*- >... f = open('/Users/annielu/Desktop/namelist1801.txt') >>>> namelist1801txt = f.read() >>>> f.close() >>>> namelist1801txt >'\xe9\x99\x88\xe5\xb7\x8d\n\xe8\x83\xa1\xe6\x99\xba\xe5\x81\xa5\r\xe9\xbb\x84\xe5\x9d\xa4\xe6\xa6\x95\r\xe6\x9d\x8e\xe6\x98\x9f\xe7\x81\xbf\r\xe5\x88\x98\xe8\xb6\x85\xe6\x9d\xb0\r\xe7\x8e\x8b\xe4\xbf\x8a\xe5\x80\xbc\r\xe4\xbd\x99\xe4\xb8\x9c\xe6\xbd\xae\r\xe9\x99\x88\xe6\x80\x9d\xe5\x87\xbd\r\xe5\x86\xaf\xe5\xb0\x91\xe5\x90\x9b\r\xe9\xbb\x84\xe5\x98\x89\xe8\xb0\x8a\r\xe9\xbb\x84\xe7\x90\xaa\xe7\x90\xaa\r\xe8\xb5\x96\xe5\xa9\x89\xe5\xa9\xb7\r\xe8\xb5\x96\xe5\xbd\xa6\xe9\x9c\x8f\r\xe5\xbb\x96\xe7\xbf\xa0\xe7\x9b\x88\r\xe6\x9e\x97\xe7\xbe\xbd\xe7\x8f\x82\r\xe5\x88\x98\xe5\xae\x89\xe7\x90\xaa\r\xe9\xa9\xac\xe7\x91\x9e\r\xe5\xbd\xad\xe5\x98\x89\xe4\xbb\xaa\r\xe9\x82\xb1\xe6\xaf\x93\xe4\xbb\xaa\r\xe5\xad\x99\xe6\xa3\xae\xe6\xa3\x8b\r\xe8\xb0\xad\xe5\x98\x89\xe7\x90\xaa\r\xe7\x8e\x8b\xe5\xa4\xa9\xe9\x9f\xb5\r\xe5\x90\xb4\xe5\xad\x90\xe7\x8f\xba\r\xe6\x9d\xa8\xe5\x88\xa9\xe8\x8c\xb5\r\xe5\xa7\x9a\xe5\x98\x89\xe9\x9b\xaf\r\xe8\xa2\x81\xe6\x9c\x88\xe6\xbb\xa2\r\xe5\xbc\xa0\xe9\x87\x87\xe7\x8e\ > x89\r\xe5\xbc\xa0\xe6\xb2\x81\xe7\x8e\xa5' >>>> It should be fine, but how it works out is very dependent on: - your Python version, particularly Python 2 versus Python 3 - the text encoding used in the file namelist1801.txt If you're not using Python 3, I recommend that you do. I _suspect_ from the output you have shown, that you are using Python 2. On a UNIX system (your Mac is a UNIX system, BTW), a text file is a stream of bytes. Because it contains text, that text is encoded to bytes in some fashion. On modern systems, the commonest encoding is 'utf-8', a variable length encoding of Unicode code points. In order to read text back from a file, it must be decoded. You've opened your file as text (which is good, because it contains text). In Python 2 that is pretty simply minded: you get back _byte_ strings: Python 2 strings are just arrays of bytes, so no decoding really happens. For ASCII text, that gets by. For languages requiring glyphs beyond that, interpretation is needed. You need unicode strings, which are _not_ Python 2's default, so your text needs converting. In Python 3, strings are unicode strings to start with. You must still indicate the file encoding, but there is a default inferred from your operating environment, and that is usually 'utf-8'. So here's an (untested) Python 2 example loop: with open('namelist.txt') as f: for line in f: line = line.strip() print("line =", line) uline = unicode(line, 'utf-8') print("uline =", uline) Here's a Python 2 example of taking your text string and converting it: >>> s='\xe9\x99\x88\xe5\xb7\x8d\n\xe8\x83\xa1\xe6\x99\xba\xe5\x81\xa5\r\xe9\xbb\x84\xe5\x9d\xa4\xe6\xa6\x95\r\xe6\x9d\x8e\xe6\x98\x9f\xe7\x81\xbf\r\xe5\x88\x98\xe8\xb6\x85' >>> unicode(s,'utf-8') u'\u9648\u5dcd\n\u80e1\u667a\u5065\r\u9ec4\u5764\u6995\r\u674e\u661f\u707f\r\u5218\u8d85' >>> print(unicode(s,'utf-8')) ?? ??? >>> I cannot read Chinese text, but the glyphs look like it to my eye. I'm using a Mac, and did nothing special. Note that I had to take portion of your text which ended on a complete unicode character, otherwise the decode fails. My first cut/paste stopped one byte beyond the \x85 that ends the string above, and failed. Your entire string should also decode cleanly. In Python 3 the loop is much cleaner: with open('namelist.txt', encoding='utf-8') as f: for line in f: line = line.strip() print("line =", line) because the file open understands the encoding. I have explicitly specified 'utf-8' there, but you may find that it is the default for you. Cheers, Cameron Simpson From dieter at handshake.de Fri Nov 9 01:58:33 2018 From: dieter at handshake.de (dieter) Date: Fri, 09 Nov 2018 07:58:33 +0100 Subject: how can I solve this problem simply and clearly References: Message-ID: <87k1lmu486.fsf@handshake.de> lampahome writes: > I have two categories A,B, and A has 2 items A1,A2, and B have 2 items B1, > B2. > > I have two class A and B, and A will handle A1,A2, B handle B1,B2. > > I want to parse one of A1,A2,B1,B2 to script and generate the corresponding > class(object). > > Ex: Both in class A and B, all have func1(), func2(). > What I thought to design is below: > ------------------------------------------------- > ... > def get_class(obj): > if obj == 'A1' or obj == 'A2': > return A(obj) > else: > return B(obj) > > # A = get_class(A1) Try `A = get_class('A1')` (instead of `A = get_class(A1)`). In Python, you must carefully distinquish between a name (such as `A1`) and a string (such as `'A1'`). A name is used to refer to something, previously "bound" to the name (e.g. via an assignment). If you use a name not yet bound (like in your `get_class(A1)`), you will get a `NameError`. From Karsten.Hilbert at gmx.net Fri Nov 9 03:02:59 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 9 Nov 2018 09:02:59 +0100 Subject: how can I solve this problem simply and clearly In-Reply-To: References: Message-ID: <20181109080258.GA5081@hermes.hilbert.loc> On Fri, Nov 09, 2018 at 09:45:50AM +0800, lampahome wrote: > def __Init__(): There's a typo right there. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From __peter__ at web.de Fri Nov 9 03:16:36 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Nov 2018 09:16:36 +0100 Subject: What's wrong with these codes as failed to read the strings in Chinese? Is it because Chinese characters can't be read on Mac? Many thanks References: <20181109064116.GA82140@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > In Python 3 the loop is much cleaner: > > with open('namelist.txt', encoding='utf-8') as f: > for line in f: > line = line.strip() > print("line =", line) In Python 2.7 you can use io.open(): import io with io.open('namelist.txt', encoding='utf-8') as f: for line in f: line = line.strip() print "line =", line However, if you have the choice go with Python 3 which is where all improvements to the language and its libraries go. From datascienceduke at gmail.com Fri Nov 9 03:32:57 2018 From: datascienceduke at gmail.com (denis meng) Date: Fri, 9 Nov 2018 16:32:57 +0800 Subject: Cloud platform with GPU Message-ID: Good day all, I am looking for a good cloud platform to do all my python development for machine learning with GPU availability, so far I have used Amazon ec2, google colab, kaggle etc but none of them was very satisfactory. Anyone has good experience with other options? please share and TIA Denis From as at sci.fi Fri Nov 9 07:09:34 2018 From: as at sci.fi (Anssi Saari) Date: Fri, 09 Nov 2018 14:09:34 +0200 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: Chris Angelico writes: > No helper needed. Safe against command injection. Uses the known > format of the command's output; if you want other information as well > as the type, you could get that too. Can someone let me in on this secret helper module? Doesn't seem to match the helper module in PyPI at least. From rosuav at gmail.com Fri Nov 9 07:23:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Nov 2018 23:23:11 +1100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: > > Chris Angelico writes: > > > No helper needed. Safe against command injection. Uses the known > > format of the command's output; if you want other information as well > > as the type, you could get that too. > > Can someone let me in on this secret helper module? Doesn't seem to > match the helper module in PyPI at least. > What helper? I said you don't need one. Just use subprocess directly. ChrisA From fabiofz at gmail.com Fri Nov 9 09:15:36 2018 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 9 Nov 2018 12:15:36 -0200 Subject: =?UTF-8?B?4oCLUHlEZXYgNy4wLjMgUmVsZWFzZWQ=?= Message-ID: PyDev 7.0.3 Release Highlights ------------------------------- * **Mypy** * PyDev can now use Mypy when doing code analysis. * **Black Formatter** * PyDev can now use black as the code formatting engine. * **Virtual environments** * It's now possible to use pipenv for managing virtual environments. * It's possible to manage virtual environments from the editor. * Ctrl+2, pip * Ctrl+2, pipenv * Ctrl+2, conda * **Debugger** * Should be **much** faster for those on Python 3.6 onwards with cython extensions (using frame evaluation). * The Python 3.7 grammar is now available as an option (even though it's the same as 3.6). * Removed support for using the Python 2.4 grammar. * The 2to3 integration shows a better dialog. * It's possible to autogenerate docstring parameters using the Google Code format (patch by ghbcode). About PyDev --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny From sharan.basappa at gmail.com Fri Nov 9 09:54:15 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Fri, 9 Nov 2018 06:54:15 -0800 (PST) Subject: pandas read_csv Message-ID: are there any requirements about the format of the CSV file when using read_csv from pandas? For example, is it necessary that the csv file has to have same number of columns in every line etc. I am trying to load a csv file and I get the following error. I really don't know what the issue is ... Any help is appreciated ... ParserErrorTraceback (most recent call last) D:\Projects\Initiatives\machine learning\programs\log\log_analysis_1.py in () 10 11 #data_df = pd.read_csv("BGL_MERGED.log", nrows=100, header=None, delimiter=r'\s"') ---> 12 data_df = pd.read_csv("d:\Projects\Initiatives\machine learning\programs\log\BGL_MERGED.log", nrows=100, header=None) 13 logger.debug("data frame %s \n", data_df) 14 print('Cols %d' %(len(data_df.columns))) D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision) 653 skip_blank_lines=skip_blank_lines) 654 --> 655 return _read(filepath_or_buffer, kwds) 656 657 parser_f.__name__ = name D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in _read(filepath_or_buffer, kwds) 409 410 try: --> 411 data = parser.read(nrows) 412 finally: 413 parser.close() D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in read(self, nrows) 1003 raise ValueError('skipfooter not supported for iteration') 1004 -> 1005 ret = self._engine.read(nrows) 1006 1007 if self.options.get('as_recarray'): D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in read(self, nrows) 1746 def read(self, nrows=None): 1747 try: -> 1748 data = self._reader.read(nrows) 1749 except StopIteration: 1750 if self._first_chunk: pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.read (pandas\_libs\parsers.c:10862)() pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory (pandas\_libs\parsers.c:11343)() pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_rows (pandas\_libs\parsers.c:11884)() pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows (pandas\_libs\parsers.c:11755)() pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error (pandas\_libs\parsers.c:28765)() ParserError: Error tokenizing data. C error: Expected 1 fields in line 8, saw 3 From David.Raymond at tomtom.com Fri Nov 9 11:01:19 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Fri, 9 Nov 2018 16:01:19 +0000 Subject: Windows file associations fix Message-ID: Would some kind person be so good as to point me to instructions on how to fix Windows file associations and default programs for the various Python extensions (.py/.pyw/etc)? I know I've fixed this before after installing a new version, but didn't save the instructions, and apparently my searching skills are getting worse as the tips I'm finding at the moment aren't helping. And why does the Python installer have a check box for "Associate files with Python" if it then promptly proceeds to destroy all those associations? Could we maybe get that part of the installer fixed for future versions? Desired state: Double click a .py file and have it run in a new console. Being able to just type "foo.py" in a command prompt and have it run without needing to run "{python|py|explicit-python-executable} foo.py" Currently: Windows 7. Attempting to run a .py file opens up the "Open with" dialog with a bunch of other programs listed. Clicking browse to manually select the new python.exe doesn't add it to the list and won't let me do the association. Do have administrator permissions, did do the install "for all users", did include the py launcher, have tried repairing, reinstalling and rebooting. Did look at the "Python on Windows FAQ" (https://docs.python.org/3/faq/windows.html#how-do-i-make-python-scripts-executable) which confirms the installer should set it up to work the way I'm looking for and had it previously. The rest of the installation is fine, the only issue is the file associations. Any patient assistance appreciated. Thank you, From rgaddi at highlandtechnology.invalid Fri Nov 9 11:46:01 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 9 Nov 2018 08:46:01 -0800 Subject: pandas read_csv In-Reply-To: References: Message-ID: On 11/9/18 6:54 AM, Sharan Basappa wrote: > are there any requirements about the format of the CSV file when using read_csv from pandas? > For example, is it necessary that the csv file has to have same number of columns in every line etc. > > I am trying to load a csv file and I get the following error. > I really don't know what the issue is ... > Any help is appreciated ... > > ParserErrorTraceback (most recent call last) > D:\Projects\Initiatives\machine learning\programs\log\log_analysis_1.py in () > 10 > 11 #data_df = pd.read_csv("BGL_MERGED.log", nrows=100, header=None, delimiter=r'\s"') > ---> 12 data_df = pd.read_csv("d:\Projects\Initiatives\machine learning\programs\log\BGL_MERGED.log", nrows=100, header=None) > 13 logger.debug("data frame %s \n", data_df) > 14 print('Cols %d' %(len(data_df.columns))) > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision) > 653 skip_blank_lines=skip_blank_lines) > 654 > --> 655 return _read(filepath_or_buffer, kwds) > 656 > 657 parser_f.__name__ = name > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in _read(filepath_or_buffer, kwds) > 409 > 410 try: > --> 411 data = parser.read(nrows) > 412 finally: > 413 parser.close() > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in read(self, nrows) > 1003 raise ValueError('skipfooter not supported for iteration') > 1004 > -> 1005 ret = self._engine.read(nrows) > 1006 > 1007 if self.options.get('as_recarray'): > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc in read(self, nrows) > 1746 def read(self, nrows=None): > 1747 try: > -> 1748 data = self._reader.read(nrows) > 1749 except StopIteration: > 1750 if self._first_chunk: > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.read (pandas\_libs\parsers.c:10862)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory (pandas\_libs\parsers.c:11343)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_rows (pandas\_libs\parsers.c:11884)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows (pandas\_libs\parsers.c:11755)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error (pandas\_libs\parsers.c:28765)() > ParserError: Error tokenizing data. C error: Expected 1 fields in line 8, saw 3 > Offhand, and as a guess based on nothing, I would speculate that something about line 8 of your CSV file differs from lines 1-7. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rvadiga at gmail.com Fri Nov 9 11:59:15 2018 From: rvadiga at gmail.com (Venkatesh Adiga) Date: Fri, 9 Nov 2018 22:29:15 +0530 Subject: pandas read_csv In-Reply-To: References: Message-ID: Sharan I had similar issue of reading different column sized csv file... Instead of using pandas I used csv reader which handles with no error... Regards Venkat On Fri, 9 Nov 2018, 8:28 pm Sharan Basappa, wrote: > are there any requirements about the format of the CSV file when using > read_csv from pandas? > For example, is it necessary that the csv file has to have same number of > columns in every line etc. > > I am trying to load a csv file and I get the following error. > I really don't know what the issue is ... > Any help is appreciated ... > > ParserErrorTraceback (most recent call last) > D:\Projects\Initiatives\machine learning\programs\log\log_analysis_1.py in > () > 10 > 11 #data_df = pd.read_csv("BGL_MERGED.log", nrows=100, header=None, > delimiter=r'\s"') > ---> 12 data_df = pd.read_csv("d:\Projects\Initiatives\machine > learning\programs\log\BGL_MERGED.log", nrows=100, header=None) > 13 logger.debug("data frame %s \n", data_df) > 14 print('Cols %d' %(len(data_df.columns))) > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc > in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, > usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, > true_values, false_values, skipinitialspace, skiprows, nrows, na_values, > keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, > infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, > chunksize, compression, thousands, decimal, lineterminator, quotechar, > quoting, escapechar, comment, encoding, dialect, tupleize_cols, > error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, > delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, > buffer_lines, memory_map, float_precision) > 653 skip_blank_lines=skip_blank_lines) > 654 > --> 655 return _read(filepath_or_buffer, kwds) > 656 > 657 parser_f.__name__ = name > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc > in _read(filepath_or_buffer, kwds) > 409 > 410 try: > --> 411 data = parser.read(nrows) > 412 finally: > 413 parser.close() > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc > in read(self, nrows) > 1003 raise ValueError('skipfooter not supported for > iteration') > 1004 > -> 1005 ret = self._engine.read(nrows) > 1006 > 1007 if self.options.get('as_recarray'): > D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pandas\io\parsers.pyc > in read(self, nrows) > 1746 def read(self, nrows=None): > 1747 try: > -> 1748 data = self._reader.read(nrows) > 1749 except StopIteration: > 1750 if self._first_chunk: > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.read > (pandas\_libs\parsers.c:10862)() > pandas/_libs/parsers.pyx in > pandas._libs.parsers.TextReader._read_low_memory > (pandas\_libs\parsers.c:11343)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_rows > (pandas\_libs\parsers.c:11884)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows > (pandas\_libs\parsers.c:11755)() > pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error > (pandas\_libs\parsers.c:28765)() > ParserError: Error tokenizing data. C error: Expected 1 fields in line 8, > saw 3 > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Fri Nov 9 12:15:37 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Nov 2018 18:15:37 +0100 Subject: pandas read_csv References: Message-ID: Sharan Basappa wrote: > are there any requirements about the format of the CSV file when using > read_csv from pandas? For example, is it necessary that the csv file has > to have same number of columns in every line etc. > ParserError: Error tokenizing data. C error: Expected 1 fields in line 8, saw 3 The error message is quite clear, look for extra fields in line 8 of your data ;) Now let's make a few experiments: >>> import pandas, io >>> def dump(s): ... return pandas.read_csv(io.StringIO(s)) ... >>> dump("""foo,bar ... 1,2 ... """ ... ) foo bar 0 1 2 [1 rows x 2 columns] >>> dump("""foo,bar ... 1,2,3 ... 4,5 ... """) foo bar 1 2 3 4 5 NaN [2 rows x 2 columns] >>> dump("""foo,bar ... 1,2 ... 3,4,5 ... """) Traceback (most recent call last): File "", line 4, in File "", line 2, in dump File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 420, in parser_f return _read(filepath_or_buffer, kwds) File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 225, in _read return parser.read() File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 626, in read ret = self._engine.read(nrows) File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 1070, in read data = self._reader.read(nrows) File "parser.pyx", line 727, in pandas.parser.TextReader.read (pandas/parser.c:6937) File "parser.pyx", line 749, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:7156) File "parser.pyx", line 802, in pandas.parser.TextReader._read_rows (pandas/parser.c:7757) File "parser.pyx", line 789, in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:7640) File "parser.pyx", line 1697, in pandas.parser.raise_parser_error (pandas/parser.c:19092) pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 3 >From this I infer that no row in the csv file may contain more columns than the first data row. Missing columns are added automatically. There is also an option to suppress rows containing too many columns: >>> pandas.read_csv(io.StringIO("foo,bar\n1,2\n3,4,5\n6,7"), error_bad_lines=False) b'Skipping line 3: expected 2 fields, saw 3\n' foo bar 0 1 2 1 6 7 [2 rows x 2 columns] From cousinstanley at gmail.com Fri Nov 9 13:16:53 2018 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 09 Nov 2018 11:16:53 -0700 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: srinivasan wrote: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" > > Still my output is: > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* > > My expected output should be only: > *vfat* > > Could you guys please do the needful? I tried a simiar command line from a rock64 sbc shell and found that -f2 instead of -f3 returned only vfat .... -- Stanley C. Kitching Human Being Phoenix, Arizona From info at wingware.com Fri Nov 9 14:43:15 2018 From: info at wingware.com (Wingware) Date: Fri, 09 Nov 2018 14:43:15 -0500 Subject: ANN: Wing Python IDE 6.1.2 released Message-ID: <5BE5E353.2060707@wingware.com> Hi, We've just released Wing 6.1.2 , which allows creating a new virtualenv from the New Project dialog, implements VI mode inner/all text object operations such as ciw and das, exits VI insert mode when jk is typed rapidly, fixes reporting of top-level exceptions and skipped tests in pytest, supports goto-definition links in docstrings, allows setting the main debug file from editor tabs and the Open Files tool, remembers current tab in preferences and properties dialogs, and makes many other improvements.For details, see https://wingware.com/pub/wingide/6.1.2/CHANGELOG.txt Download Now About Wing Wingware's family of cross-platform Python IDEs make Python development easier, with powerful integrated editing, debugging, unit testing, and project management features. Wing runs on Windows, Linux, and OS X, and can be used to develop any kind of Python code for web, desktop, scientific, data analysis, embedded scripting, and other applications. Version 6 introduces many new features, including improved multi-selection , much easier remote development , debugging from the Python Shell , recursive debugging , PEP 484 and 526 type hinting , PEP 8 reformatting , support for Python 3.6 and 3.7, ability to create a new virtualenv from the New Project dialog, improved VI mode, support for Vagrant , Jupyter , Django 1.10+ and 2.0, and Windows Subsystem for Linux , improved support for matplotlib , easier Raspberry Pi development, optimized debugger, OS X full screen mode, One Dark color palette, Russian localization (thanks to Alexandr Dragukin), expanded free product line, and much more. For details, see What's New in Wing Version 6 . Wing 6 works with Python versions 2.5 through 2.7 and 3.2 through 3.7, including also Anaconda, ActivePython, EPD, Stackless, and others derived from the CPython implementation. Wing Pro requires purchasing or upgrading a license, or obtaining a 30-day trial at startup. Wing 101 and Wing Personal are free versions that omit some features . For more product information, please visit wingware.com Upgrading You can try Wing 6 without removing older versions. Wing 6 will read and convert your old preferences, settings, and projects. Projects should be saved to a new name since previous versions of Wing cannot read Wing 6 projects. See also Migrating from Older Versions and Upgrading . Links Release notice: https://wingware.com/news/2018-11-08 Downloads and Free Trial: https://wingware.com/downloads Buy: https://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From robertvstepp at gmail.com Fri Nov 9 16:41:41 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 9 Nov 2018 15:41:41 -0600 Subject: Windows file associations fix In-Reply-To: References: Message-ID: On Fri, Nov 9, 2018 at 10:02 AM David Raymond wrote: > Currently: Windows 7. Attempting to run a .py file opens up the "Open with" dialog with a bunch of other programs listed. Clicking browse to manually select the new python.exe doesn't add it to the list and won't let me do the association. > > Do have administrator permissions, did do the install "for all users", did include the py launcher, have tried repairing, reinstalling and rebooting. > > Did look at the "Python on Windows FAQ" (https://docs.python.org/3/faq/windows.html#how-do-i-make-python-scripts-executable) which confirms the installer should set it up to work the way I'm looking for and had it previously. > > The rest of the installation is fine, the only issue is the file associations. I do not know if this is relevant or not for Windows 7, but during the past week my phone's Google news feed had an article about a recent Windows *10* update breaking file associations. Might a recent Windows *7* update have done the same? -- boB From eryksun at gmail.com Fri Nov 9 18:42:48 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 9 Nov 2018 17:42:48 -0600 Subject: Windows file associations fix In-Reply-To: References: Message-ID: On 11/9/18, David Raymond wrote: > > And why does the Python installer have a check box for "Associate files with > Python" if it then promptly proceeds to destroy all those associations? > Could we maybe get that part of the installer fixed for future versions? The installer configures the HKCR setting to associate .py[w] files; however, it doesn't delete a user-choice setting in the shell. You should be able to restore the user choice to the launcher via the open-with -> choose another app dialog. Select the Python icon with a rocket on it (for py.exe; the python.exe icon has no rocket), enable the option to always use this application, and click ok. If that doesn't restore the association, you'll have to manually inspect and modify the settings. The following lists the shell's cached association for the .py file extension, including the user choice, if any: set "winkey=HKCU\Software\Microsoft\Windows\CurrentVersion" reg query %winkey%\Explorer\FileExts\.py /s Output: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\OpenWithList a REG_SZ py.exe MRUList REG_SZ a HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\OpenWithProgids Python.File REG_NONE HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\UserChoice Hash REG_SZ aA7ZxnDmUdM= ProgId REG_SZ Python.File Currently I have a UserChoice setting locked in. The permissions and hash value prevent us from modifying this key, but we can delete it, in which case the shell reverts to using the cached OpenWith* associations. Here's a command to delete this key (or use regedit if you prefer a GUI), where %winkey% was previously defined above: reg delete %winkey%\Explorer\FileExts\.py\UserChoice If we instead delete the FileExts\.py key, the shell recomputes the association from the underlying HKCR settings, where HKCR is a merged view of [HKLM | HKCU]\Software\Classes. If that doesn't solve the problem, check the default value of [HKCU | HKLM]\Software\Classes\.py, and its OpenWithProgIds subkey if defined. Python's installer associates .py files with the "Python.File" program identifier (progid). If that's set correctly, check [HKCU | HKLM]\Software\Classes\Python.File to ensure it's set up to use the py.exe launcher. For example, the following displays the default "open" command for the local-machine Python.File progid: reg query HKLM\Software\Classes\Python.File\shell\open\command Output: HKEY_LOCAL_MACHINE\Software\Classes\Python.File\shell\open\command (Default) REG_SZ "C:\Windows\py.exe" "%1" %* "%1" (or sometimes "%L") is the fully-qualified path of the target .py script, and %* has the command-line arguments, if any. As a side note, you've probably seen examples that use CMD's assoc and ftype commands (from NT 4.0, circa 1996). These commands work with HKLM\Software\Classes, which is fine for classic file associations configured for all users. However, they do not show or modify HKCU settings, and they're unaware of updates to how the shell works since XP/Vista such as HKCR\Applications, HKCR\SystemFileAssociations, and application capability file associations linked in [HKCU | HKLM]\Software\RegisteredApplications. > Currently: Windows 7. Attempting to run a .py file opens up the "Open with" > dialog with a bunch of other programs listed. Clicking browse to manually > select the new python.exe doesn't add it to the list and won't let me do the > association. You shouldn't manually associate .py files by browsing for py.exe or python.exe. If you do this, the system creates an automatic progid that only includes the "%1" target, without the %* command-line arguments. Typically this broken progid will be "HKCU\Software\Classes\Applications\py.exe", or "HKCU\Software\Classes\Applications\python.exe", or "HKCU\Software\Classes\py_auto_file". Delete these keys if they exist. From python at bdurham.com Fri Nov 9 19:44:40 2018 From: python at bdurham.com (Malcolm Greene) Date: Fri, 09 Nov 2018 17:44:40 -0700 Subject: Anyone running Python on MS Azure? Message-ID: <1541810680.1176887.1571967048.2DB5998C@webmail.messagingengine.com> Curious to hear if any of you are running Python scripts/apps on MS Azure cloud services? What services are you using and what has your experience been? Advice? Background: Customer migrating to Azure. I'm trying to get ahead of the curve regarding how Python-friendly the Azure platform is. Thanks! From h.chauhan1795 at hotmail.com Sat Nov 10 03:06:03 2018 From: h.chauhan1795 at hotmail.com (Hemant Chauhan) Date: Sat, 10 Nov 2018 08:06:03 +0000 Subject: Error in installing "pyperclip" module In-Reply-To: References: Message-ID: Hi team, I?m having trouble in installing pyperclip module through command line. I just upgraded to the latest version. Here?s the SS of command line showing error. Peace. Regards, Hemant P.S. ? I?m a beginner in Python , it?s the first programming language I started with. [cid:image002.png at 01D478F2.412C2D60] From formisc at gmail.com Sat Nov 10 11:21:37 2018 From: formisc at gmail.com (Andrew Z) Date: Sat, 10 Nov 2018 11:21:37 -0500 Subject: Cloud platform with GPU In-Reply-To: References: Message-ID: Denis, ..none of them was very satisfactory. Sharing your requirements will be a good first step for getting good answers. On Sat, Nov 10, 2018, 02:26 denis meng Good day all, > > I am looking for a good cloud platform to do all my python development for > machine learning with GPU availability, so far I have used Amazon ec2, > google colab, kaggle etc but none of them was very satisfactory. > > Anyone has good experience with other options? please share and TIA > > Denis > -- > https://mail.python.org/mailman/listinfo/python-list > From robertvstepp at gmail.com Sat Nov 10 12:28:06 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 10 Nov 2018 11:28:06 -0600 Subject: Error in installing "pyperclip" module In-Reply-To: References: Message-ID: Greetings Hemant! On Sat, Nov 10, 2018 at 10:31 AM Hemant Chauhan wrote: > > Hi team, > I?m having trouble in installing pyperclip module through command line. > I just upgraded to the latest version. > Here?s the SS of command line showing error. Unfortunately this is a text only mailing list, which disallows attachments. So no one will see your screenshot. Instead you should copy and paste into a *plain text* email what you entered on the command line and likewise copy and paste the resulting error messages into the email. Please state your operating system and version of Python that you are using. With that information I am sure someone here will be able to help you. > P.S. ? I?m a beginner in Python , it?s the first programming language I started with. If you are just starting out, a better forum for a new learner to programming and Python would be the Python Tutor mailing list. Subscription information can be found at https://mail.python.org/mailman/listinfo/tutor However, people on the this main list are quite friendly and helpful to newbies as well. In fact many here actively monitor and help out on the Tutor list. -- boB From joel.goldstick at gmail.com Sat Nov 10 12:43:25 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 10 Nov 2018 12:43:25 -0500 Subject: Error in installing "pyperclip" module In-Reply-To: References: Message-ID: On Sat, Nov 10, 2018 at 12:29 PM boB Stepp wrote: > > Greetings Hemant! > > On Sat, Nov 10, 2018 at 10:31 AM Hemant Chauhan > wrote: > > > > Hi team, > > I?m having trouble in installing pyperclip module through command line. > > I just upgraded to the latest version. > > Here?s the SS of command line showing error. > > Unfortunately this is a text only mailing list, which disallows > attachments. One maybe small quibble. I don't think it is unfortunate at all that this mailing list is text only. Coding is text. It is not screen shots. If a questioner is first thinking of pasting screen shots or attaching files to a mailing list like this, they should be informed what a useless method this is, and how they can provide information that is useful, and that can help others help them. This is what this response does. So, I don't mean to be snarky So no one will see your screenshot. Instead you should > copy and paste into a *plain text* email what you entered on the > command line and likewise copy and paste the resulting error messages > into the email. Please state your operating system and version of > Python that you are using. With that information I am sure someone > here will be able to help you. > > > P.S. ? I?m a beginner in Python , it?s the first programming language I started with. > > If you are just starting out, a better forum for a new learner to > programming and Python would be the Python Tutor mailing list. > Subscription information can be found at > https://mail.python.org/mailman/listinfo/tutor However, people on the > this main list are quite friendly and helpful to newbies as well. In > fact many here actively monitor and help out on the Tutor list. > -- > boB > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From robertvstepp at gmail.com Sat Nov 10 12:49:43 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 10 Nov 2018 11:49:43 -0600 Subject: Error in installing "pyperclip" module In-Reply-To: References: Message-ID: On Sat, Nov 10, 2018 at 11:45 AM Joel Goldstick wrote: > > On Sat, Nov 10, 2018 at 12:29 PM boB Stepp wrote: > > Unfortunately this is a text only mailing list, which disallows > > attachments. > > One maybe small quibble. I don't think it is unfortunate at all that > this mailing list is text only... Hi, Joel! Since we are being _precise_ my "Unfortunately" was meant to be viewed from the OP's perspective, not mine. Sorry that I was not clear about that. -- boB From cabkarian at gmail.com Sat Nov 10 21:16:50 2018 From: cabkarian at gmail.com (Cris Medina) Date: Sat, 10 Nov 2018 21:16:50 -0500 Subject: Anyone running Python on MS Azure? In-Reply-To: <1541810680.1176887.1571967048.2DB5998C@webmail.messagingengine.com> References: <1541810680.1176887.1571967048.2DB5998C@webmail.messagingengine.com> Message-ID: The python azure lib that MS maintains wraps all Azure services like boto3 does for AWS. However, be prepared for constant changes that are incompatible across versions. They do provide a mechanism for you to stick with an API version for backwards compatibility that allows an upgrade of the python module while keeping with the interfaces you use. The main problem I've had with Azure is not the python module, it's the reliability of the services themselves. Be prepared for endless retries and moments in which you've made a change that service accepted, but doesn't actually take effect for a long time (several mins to half hour). You'll also receive sporadic internal error responses from the servers when making API calls. Services I use almost daily: spin up, manage (including remote execution) and destroy compute and network resources (including express route, virtual gateways and connections). Hope this helps.- On Fri, Nov 9, 2018, 7:44 PM Malcolm Greene wrote: > Curious to hear if any of you are running Python scripts/apps on MS > Azure cloud services? What services are you using and what has your > experience been? Advice? > Background: Customer migrating to Azure. I'm trying to get ahead of the > curve regarding how Python-friendly the Azure platform is. > Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list > From bluebox03 at gmail.com Sat Nov 10 22:49:34 2018 From: bluebox03 at gmail.com (tommy yama) Date: Sun, 11 Nov 2018 12:49:34 +0900 Subject: Error in installing "conda-build" Message-ID: Hi there, Anyone encountered the same problem? ommand "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-ReWrqJ/conda-build/ Your advices would be appreciated. From diolu.remove_this_part at bigfoot.com Sun Nov 11 04:14:51 2018 From: diolu.remove_this_part at bigfoot.com (Olive) Date: Sun, 11 Nov 2018 10:14:51 +0100 Subject: Good editor for python Message-ID: <20181111101451.3b563a3b@bigfoot.com> I am not a professional programmer but I use Python regularly for custom scripts (and plot with matplotlib). I have just learned VBA for Excel: what I found amazing was their editor: it is able to suggest on the spot all the methods an object support and there is a well-integrated debugger. I wonder if something similar exists for Python. For now I just use emacs with the command line pdb. What do people use here? Ideally I would like to have something that is cross platform Windows/Linux. Olivier From guru at digitalfantasy.it Sun Nov 11 05:59:00 2018 From: guru at digitalfantasy.it (Daniele Forghieri) Date: Sun, 11 Nov 2018 11:59:00 +0100 Subject: Good editor for python In-Reply-To: <20181111101451.3b563a3b@bigfoot.com> References: <20181111101451.3b563a3b@bigfoot.com> Message-ID: <59f1084d-718d-4826-2d66-2c72486d1a9f@digitalfantasy.it> Il 11/11/2018 10:14, Olive ha scritto: > I am not a professional programmer but I use Python regularly for custom scripts (and plot with matplotlib). I have just learned VBA for Excel: what I found amazing was their editor: it is able to suggest on the spot all the methods an object support and there is a well-integrated debugger. I wonder if something similar exists for Python. For now I just use emacs with the command line pdb. What do people use here? Ideally I would like to have something that is cross platform Windows/Linux. > > Olivier > ??? I use eclipse with pydev (the liclipse bundle, really, that is not free and is made up by the pydev author): it's multi platform and really powerful (but probably not the simple one to use or setup). Is constantly updated and lets you works with different interpreters, different python version or different virtualenved python (yiu can have a project made with python 2.7, another one with python 3.7 and gtk 3, another one with the same 3.7 python but different libraries and so on. ??? The liclipse installer is simpler to deploy (for window is a single .exe file) and you can use it freely for 30 day to see if the system suits your need: at the end you can choose to buy it or switch to the Eclipse/Pydev and configure/install the stuff you need: git or svn extension to work with your version control system, install dBeaver in Eclipse (or in Liclipse) to work with database in the same environment you use for programming, ... ??? There are also some other IDE that I don't use directly but I see when I worked with other python developers, namely PyCharm & Wing IDE ??? For windows only there are some Visual Studio extension to work with Python (if you are used to Microsoft stuff this can be easier) and also the Microsoft VS Code editor (this should be multi platform) has the python extensions with intellisense but I never used them (I started to use Python before this stuff came out). ??? With best regards ??? Daniele Forghieri From tjol at tjol.eu Sun Nov 11 06:18:12 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 11 Nov 2018 12:18:12 +0100 Subject: Good editor for python In-Reply-To: <20181111101451.3b563a3b@bigfoot.com> References: <20181111101451.3b563a3b@bigfoot.com> Message-ID: <9df3795f-2d58-ac74-d09a-ac9e45904c75@tjol.eu> On 11/11/2018 10:14, Olive wrote: > I am not a professional programmer but I use Python regularly for custom scripts (and plot with matplotlib). I have just learned VBA for Excel: what I found amazing was their editor: it is able to suggest on the spot all the methods an object support and there is a well-integrated debugger. I wonder if something similar exists for Python. For now I just use emacs with the command line pdb. What do people use here? Ideally I would like to have something that is cross platform Windows/Linux. There are several popular full-featured IDEs, like PyCharm and Spyder. AFAIK both also have some special support for a scientific workflow with matplotlib integration. If you're mainly using Python for scripts you invoke interactively to create plots and such you might enjoy Jupyter Notebook or JupyterLab. Completion works great, debugging with ipdb is, well, adequate. For actual "editors", I'm sure there are ways to make vim or emacs everything you could possibly want, but there are two popular, modern, cross-platform programmers' editors that, to my mind, stand out at the moment: Sublime Text is a fantastic, powerful and (fairly) fast editor (proprietary, shareware, 80 USD) with good support for Python with a number of packages (plugins), chief among them "Anaconda", which gives you linting and autocompletion. Visual Studio Code (open source, from Microsoft) is younger and a bit slower and more bloated, but it has fantastic Python support, including a well-integrated visual debugger. There are of course loads and loads of other options. Everything I've mentioned runs at least on x86_64 Linux, OSX, and Windows. -- Thomas From bluebox03 at gmail.com Sun Nov 11 08:29:32 2018 From: bluebox03 at gmail.com (tommy yama) Date: Sun, 11 Nov 2018 22:29:32 +0900 Subject: Error in installing "conda-build" In-Reply-To: References: Message-ID: sorry, this is solved. On Sun, Nov 11, 2018 at 12:49 PM tommy yama wrote: > Hi there, > > Anyone encountered the same problem? > > ommand "python setup.py egg_info" failed with error code 1 in > /private/tmp/pip-install-ReWrqJ/conda-build/ > > > Your advices would be appreciated. > > From formisc at gmail.com Sun Nov 11 09:11:41 2018 From: formisc at gmail.com (Andrew Z) Date: Sun, 11 Nov 2018 09:11:41 -0500 Subject: Good editor for python In-Reply-To: <20181111101451.3b563a3b@bigfoot.com> References: <20181111101451.3b563a3b@bigfoot.com> Message-ID: If you do scripts - emacs/vi is the way to go. If you need something more (like creating libraries, classes) go with pycharm. It is a professionally made IDE. Over past 2 years ive been trying to "downgrade" myself to something with less belts and whistles, but come back to it all the time. On the other hand , if you already use emacs - u should not need anything else. On Sun, Nov 11, 2018, 04:15 Olive I am not a professional programmer but I use Python regularly for custom > scripts (and plot with matplotlib). I have just learned VBA for Excel: what > I found amazing was their editor: it is able to suggest on the spot all the > methods an object support and there is a well-integrated debugger. I wonder > if something similar exists for Python. For now I just use emacs with the > command line pdb. What do people use here? Ideally I would like to have > something that is cross platform Windows/Linux. > > Olivier > > -- > https://mail.python.org/mailman/listinfo/python-list > From spencer.graves at effectivedefense.org Sun Nov 11 09:45:36 2018 From: spencer.graves at effectivedefense.org (Spencer Graves) Date: Sun, 11 Nov 2018 08:45:36 -0600 Subject: Good editor for python In-Reply-To: References: <20181111101451.3b563a3b@bigfoot.com> Message-ID: ????? People rave about Jupyter Notebooks, which reportedly allow you to mix narrative with code describing what you are doing and why. ????? I primarily program in R, and RMarkdown Documents in RStudio allow me to mix narrative with R and Python code.? I explain what I'm doing and why, then write "```{python}" ... "```" to encapsulate a Python code snippet and "```{r}" ... "```" for an R code snippet. Or I just use the Idle editor that comes with Python. ????? Someone suggested that Apache Zeppelin? and / or BeakerX might be able to do this also, but I've not tried or verified them. ????? Spencer Graves On 2018-11-11 08:11, Andrew Z wrote: > If you do scripts - emacs/vi is the way to go. > If you need something more (like creating libraries, classes) go with > pycharm. It is a professionally made IDE. > > Over past 2 years ive been trying to "downgrade" myself to something with > less belts and whistles, but come back to it all the time. > > On the other hand , if you already use emacs - u should not need anything > else. > > On Sun, Nov 11, 2018, 04:15 Olive >> I am not a professional programmer but I use Python regularly for custom >> scripts (and plot with matplotlib). I have just learned VBA for Excel: what >> I found amazing was their editor: it is able to suggest on the spot all the >> methods an object support and there is a well-integrated debugger. I wonder >> if something similar exists for Python. For now I just use emacs with the >> command line pdb. What do people use here? Ideally I would like to have >> something that is cross platform Windows/Linux. >> >> Olivier >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From brian.j.oney at googlemail.com Sun Nov 11 10:46:34 2018 From: brian.j.oney at googlemail.com (Brian J. Oney) Date: Sun, 11 Nov 2018 16:46:34 +0100 Subject: Good editor for python In-Reply-To: References: <20181111101451.3b563a3b@bigfoot.com> Message-ID: <1541951194.4346.3.camel@gmail.com> Hi Olivier I am glad you did not trigger an editor war. I don't know how familiar you are with emacs. The answer depends alot on your preference and future work. Emacs and vi have been around for a long time for good reasons. If you prefer an extensible and futureproof editor, I can wholeheartedly recommend emacs or vi. I went from a happy emacs user to an even happier spacemacs user. Spacemacs is a batteries-included emacs configuration which lets you choose between emacs-like or vi keybindings, which are mnemonic, efficient, consistent, and, above all, discoverable. Discoverability allows a person who has been using something for a while to find out even more tricks in the moment that those tricks would be useful. Spacemacs has tons of bells and whistles and still manages to be fast (through lazy configuration loading). If you are looking at literate programming, Jupyter Notebooks are hard to beat, especially if you want to share code with novices. In case you want a medusa that eats everything else for lunch, look further. Such a beast can be harnessed with org-mode, an emacs mode which can be just about anything you want it to be. You can do literate devops, literate programming, mix programming languages, export to your grandma's toaster, and feed the dog with org-mode, if you want to play. Org-mode's syntax and power is unmatched, to my knowledge. That all depends on how far down the rabbit hole you want to dive. Emacs with pdb is pretty good though. To get the functionality you miss is pretty simple with spacemacs.??For more information and platform-specific instructions, please see the following link. https://github.com/syl20bnr/spacemacs The basic template already activates python support. That's my two cents. Cheers Brian On Sun, 2018-11-11 at 08:45 -0600, Spencer Graves wrote: > ?????? People rave about Jupyter Notebooks, which reportedly allow you? > to mix narrative with code describing what you are doing and why. >? >? > ?????? I primarily program in R, and RMarkdown Documents in RStudio? > allow me to mix narrative with R and Python code.? I explain what I'm? > doing and why, then write "```{python}" ... "```" to encapsulate a? > Python code snippet and "```{r}" ... "```" for an R code snippet. Or I? > just use the Idle editor that comes with Python. >? >? > ?????? Someone suggested that Apache Zeppelin? and / or BeakerX might be? > able to do this also, but I've not tried or verified them. >? >? > ?????? Spencer Graves >? >? > On 2018-11-11 08:11, Andrew Z wrote: > > If you do scripts - emacs/vi is the way to go. > > If you need something more (like creating libraries,??classes) go with > > pycharm. It is a professionally made IDE. > >? > > Over past 2 years ive been trying to "downgrade" myself to something with > > less belts and whistles,??but come back to it all the time. > >? > > On the other hand , if you already use emacs - u should not need anything > > else. > >? > > On Sun, Nov 11, 2018, 04:15 Olive >? > > > I am not a professional programmer but I use Python regularly for custom > > > scripts (and plot with matplotlib). I have just learned VBA for Excel: what > > > I found amazing was their editor: it is able to suggest on the spot all the > > > methods an object support and there is a well-integrated debugger. I wonder > > > if something similar exists for Python. For now I just use emacs with the > > > command line pdb. What do people use here? Ideally I would like to have > > > something that is cross platform Windows/Linux. > > >? > > > Olivier > > >? > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > >? >? >? From hjp-python at hjp.at Sun Nov 11 13:15:33 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 11 Nov 2018 19:15:33 +0100 Subject: Python indentation (3 spaces) In-Reply-To: <33abc272-6c8a-34ae-b33f-108a338682cb@vub.be> References: <20181008174322.oudxrqahwicuu6rv@hjp.at> <20181013073744.kpemgmae7wkarvrr@hjp.at> <20181015193154.5gm64rasvigp2ess@hjp.at> <20181020123819.i2lkgraqvdf7ryex@hjp.at> <33abc272-6c8a-34ae-b33f-108a338682cb@vub.be> Message-ID: <20181111181533.7z3eejpk26arpv4f@hjp.at> On 2018-10-25 12:59:18 +0200, Antoon Pardon wrote: > On 20-10-18 14:38, Peter J. Holzer wrote: > > On 2018-10-16 06:37:56 +1100, Chris Angelico wrote: > >> On Tue, Oct 16, 2018 at 6:34 AM Peter J. Holzer wrote: > >>> On 2018-10-15 14:12:54 +0200, Antoon Pardon wrote: > >>>> On 13-10-18 09:37, Peter J. Holzer wrote: > >>>>> On 2018-10-09 09:55:34 +0200, Antoon Pardon wrote: > >>>>>> On 08-10-18 19:43, Peter J. Holzer wrote: > >>>>>>> In practice it doesn't work in my experience. There is always someone in > >>>>>>> a team who was "just testing that new editor" and replaced all tabs > >>>>>>> with spaces (or vice versa) or - worse - just some of them. > >>>>>> Isn't that caugth in the process of commiting to version control? > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > Underlined to emphasize the context. > > [...] > >> If there's a change, it shows up. If there's no change, it doesn't show up. > >> > >> Ergo, if you accidentally replace a tab with spaces, it's a change, > >> and it shows up. > > If any change "shows up" (i.e., is rejected by the pre-commit hook of > > your version control system) you can't change anything which makes using > > a version control system rather pointless. > > I just do a diff between the local version and the "latest" commited version. > If lines show up in the diff that don't looked changed, then there is a high > probablity someone replaced tabs with spaces. (Especially if there are a lot > of those lines.) I misunderstood what you meant by "the process of commiting to version control". For me this is the series of steps the version control software (e.g. git) performs when you issue its commit command, including executing pre-commit and post-commit hooks. This process is non-interactive and either succeeds or not. You apparently include some actions that the person committing the changes does manually before actually issuing the commit command, e.g. checking diffs for plausibility. > Maybe for some reason you don't consider this MO as easily catching spaces that > accidently replaced tabs. But it is easy enough for me. It may or may not be viable, depending on how disciplined your colleagues are (the question is not: "Do you do this?", but "does everyone on your team always do it?"). 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 formisc at gmail.com Sun Nov 11 16:04:11 2018 From: formisc at gmail.com (Andrew Z) Date: Sun, 11 Nov 2018 16:04:11 -0500 Subject: Good editor for python In-Reply-To: <1541951194.4346.3.camel@gmail.com> References: <20181111101451.3b563a3b@bigfoot.com> <1541951194.4346.3.camel@gmail.com> Message-ID: Brian, thank you for sharing. Looks very interesting. On Sun, Nov 11, 2018, 10:46 Brian J. Oney via Python-list < python-list at python.org wrote: > Hi Olivier > > I am glad you did not trigger an editor war. I don't know how familiar you > are > with emacs. The answer depends alot on your preference and future work. > Emacs > and vi have been around for a long time for good reasons. > > If you prefer an extensible and futureproof editor, I can wholeheartedly > recommend emacs or vi. I went from a happy emacs user to an even happier > spacemacs user. Spacemacs is a batteries-included emacs configuration which > lets you choose between emacs-like or vi keybindings, which are mnemonic, > efficient, consistent, and, above all, discoverable. Discoverability > allows a > person who has been using something for a while to find out even more > tricks > in the moment that those tricks would be useful. Spacemacs has tons of > bells > and whistles and still manages to be fast (through lazy configuration > loading). > > If you are looking at literate programming, Jupyter Notebooks are hard to > beat, especially if you want to share code with novices. In case you want a > medusa that eats everything else for lunch, look further. Such a beast can > be > harnessed with org-mode, an emacs mode which can be just about anything you > want it to be. You can do literate devops, literate programming, mix > programming languages, export to your grandma's toaster, and feed the dog > with > org-mode, if you want to play. Org-mode's syntax and power is unmatched, > to my > knowledge. > > That all depends on how far down the rabbit hole you want to dive. Emacs > with > pdb is pretty good though. To get the functionality you miss is pretty > simple > with spacemacs. For more information and platform-specific instructions, > please see the following link. > > https://github.com/syl20bnr/spacemacs > > The basic template already activates python support. > > That's my two cents. > > Cheers > Brian > > On Sun, 2018-11-11 at 08:45 -0600, Spencer Graves wrote: > > People rave about Jupyter Notebooks, which reportedly allow you > > to mix narrative with code describing what you are doing and why. > > > > > > I primarily program in R, and RMarkdown Documents in RStudio > > allow me to mix narrative with R and Python code. I explain what I'm > > doing and why, then write "```{python}" ... "```" to encapsulate a > > Python code snippet and "```{r}" ... "```" for an R code snippet. Or I > > just use the Idle editor that comes with Python. > > > > > > Someone suggested that Apache Zeppelin and / or BeakerX might be > > able to do this also, but I've not tried or verified them. > > > > > > Spencer Graves > > > > > > On 2018-11-11 08:11, Andrew Z wrote: > > > If you do scripts - emacs/vi is the way to go. > > > If you need something more (like creating libraries, classes) go with > > > pycharm. It is a professionally made IDE. > > > > > > Over past 2 years ive been trying to "downgrade" myself to something > with > > > less belts and whistles, but come back to it all the time. > > > > > > On the other hand , if you already use emacs - u should not need > anything > > > else. > > > > > > On Sun, Nov 11, 2018, 04:15 Olive wrote: > > > > > > > I am not a professional programmer but I use Python regularly for > custom > > > > scripts (and plot with matplotlib). I have just learned VBA for > Excel: what > > > > I found amazing was their editor: it is able to suggest on the spot > all the > > > > methods an object support and there is a well-integrated debugger. I > wonder > > > > if something similar exists for Python. For now I just use emacs > with the > > > > command line pdb. What do people use here? Ideally I would like to > have > > > > something that is cross platform Windows/Linux. > > > > > > > > Olivier > > > > > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From bluebox03 at gmail.com Sun Nov 11 19:55:44 2018 From: bluebox03 at gmail.com (tommy yama) Date: Mon, 12 Nov 2018 09:55:44 +0900 Subject: Good editor for python In-Reply-To: References: <20181111101451.3b563a3b@bigfoot.com> <1541951194.4346.3.camel@gmail.com> Message-ID: Komodo edit is enchanting personally, On Mon, 12 Nov 2018, 06:06 Andrew Z Brian, thank you for sharing. Looks very interesting. > > On Sun, Nov 11, 2018, 10:46 Brian J. Oney via Python-list < > python-list at python.org wrote: > > > Hi Olivier > > > > I am glad you did not trigger an editor war. I don't know how familiar > you > > are > > with emacs. The answer depends alot on your preference and future work. > > Emacs > > and vi have been around for a long time for good reasons. > > > > If you prefer an extensible and futureproof editor, I can wholeheartedly > > recommend emacs or vi. I went from a happy emacs user to an even happier > > spacemacs user. Spacemacs is a batteries-included emacs configuration > which > > lets you choose between emacs-like or vi keybindings, which are mnemonic, > > efficient, consistent, and, above all, discoverable. Discoverability > > allows a > > person who has been using something for a while to find out even more > > tricks > > in the moment that those tricks would be useful. Spacemacs has tons of > > bells > > and whistles and still manages to be fast (through lazy configuration > > loading). > > > > If you are looking at literate programming, Jupyter Notebooks are hard to > > beat, especially if you want to share code with novices. In case you > want a > > medusa that eats everything else for lunch, look further. Such a beast > can > > be > > harnessed with org-mode, an emacs mode which can be just about anything > you > > want it to be. You can do literate devops, literate programming, mix > > programming languages, export to your grandma's toaster, and feed the dog > > with > > org-mode, if you want to play. Org-mode's syntax and power is unmatched, > > to my > > knowledge. > > > > That all depends on how far down the rabbit hole you want to dive. Emacs > > with > > pdb is pretty good though. To get the functionality you miss is pretty > > simple > > with spacemacs. For more information and platform-specific instructions, > > please see the following link. > > > > https://github.com/syl20bnr/spacemacs > > > > The basic template already activates python support. > > > > That's my two cents. > > > > Cheers > > Brian > > > > On Sun, 2018-11-11 at 08:45 -0600, Spencer Graves wrote: > > > People rave about Jupyter Notebooks, which reportedly allow you > > > to mix narrative with code describing what you are doing and why. > > > > > > > > > I primarily program in R, and RMarkdown Documents in RStudio > > > allow me to mix narrative with R and Python code. I explain what I'm > > > doing and why, then write "```{python}" ... "```" to encapsulate a > > > Python code snippet and "```{r}" ... "```" for an R code snippet. Or I > > > just use the Idle editor that comes with Python. > > > > > > > > > Someone suggested that Apache Zeppelin and / or BeakerX might > be > > > able to do this also, but I've not tried or verified them. > > > > > > > > > Spencer Graves > > > > > > > > > On 2018-11-11 08:11, Andrew Z wrote: > > > > If you do scripts - emacs/vi is the way to go. > > > > If you need something more (like creating libraries, classes) go > with > > > > pycharm. It is a professionally made IDE. > > > > > > > > Over past 2 years ive been trying to "downgrade" myself to something > > with > > > > less belts and whistles, but come back to it all the time. > > > > > > > > On the other hand , if you already use emacs - u should not need > > anything > > > > else. > > > > > > > > On Sun, Nov 11, 2018, 04:15 Olive < > diolu.remove_this_part at bigfoot.com > > wrote: > > > > > > > > > I am not a professional programmer but I use Python regularly for > > custom > > > > > scripts (and plot with matplotlib). I have just learned VBA for > > Excel: what > > > > > I found amazing was their editor: it is able to suggest on the spot > > all the > > > > > methods an object support and there is a well-integrated debugger. > I > > wonder > > > > > if something similar exists for Python. For now I just use emacs > > with the > > > > > command line pdb. What do people use here? Ideally I would like to > > have > > > > > something that is cross platform Windows/Linux. > > > > > > > > > > Olivier > > > > > > > > > > -- > > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Mon Nov 12 03:28:19 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 12 Nov 2018 09:28:19 +0100 Subject: Issue in parsing the strings in python code Message-ID: Dear Python Experts team, This question might be very simple for you, As am newbie to python, could you please how to parse the below strings 1. Could you please do the needful in guiding me, that how can I extract the strings under the UUID column in python code in the below output (nmcli c show), I need to extract the UUID of "Funkloch" ie., "1da7d068-4548-4446-bf88-a440e49db1b1" for "TYPE" wifi and device "wlp1s0" and return this string ("1da7d068-4548-4446-bf88-a440e49db1b1") to the robotframework? root:~/qa/robot_tests# nmcli c show NAME UUID TYPE DEVICE Funkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet enp0s21f0u4 Funkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- Funkloch 10 f4d9ce13-aab0-4485-9929-6070ad52a196 wifi -- Funkloch 100 8b48a220-1754-4988-84ad-d0f83a9b4ede wifi -- 2. Similarly, As I need to verify whether the DEVICE "wlp1s0" is connected to "Funkloch" or not? could you please help me, how can I extract the "connected" status under "STATE column for DEVICE "wlp1s0" and CONNECTION "Funkloch 1552" root:~/qa/robot_tests# nmcli dev DEVICE TYPE STATE CONNECTION enp0s21f0u4 ethernet connected Wired connection 1 wlp1s0 wifi connected Funkloch 1552 enp2s0 ethernet unavailable -- sit0 iptunnel unmanaged -- lo loopback unmanaged -- Kindly do the needful as am trying this from past two 2 days, still no clues Many thanks in advance From shakti.shrivastava13 at gmail.com Mon Nov 12 03:44:21 2018 From: shakti.shrivastava13 at gmail.com (Shakti Kumar) Date: Mon, 12 Nov 2018 14:14:21 +0530 Subject: Issue in parsing the strings in python code In-Reply-To: References: Message-ID: On Mon, 12 Nov 2018 at 14:02, srinivasan wrote: > Dear Python Experts team, > > This question might be very simple for you, As am newbie to python, could > you please how to parse the below strings > > 1. Could you please do the needful in guiding me, that how can I extract > the strings under the UUID column in python code in the below output (nmcli > c show), I need to extract the UUID of "Funkloch" ie., > "1da7d068-4548-4446-bf88-a440e49db1b1" for "TYPE" wifi and device "wlp1s0" > and return this string ("1da7d068-4548-4446-bf88-a440e49db1b1") to the > robotframework? > > root:~/qa/robot_tests# nmcli c show > NAME UUID TYPE DEVICE > > Funkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 > > Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet > enp0s21f0u4 > Funkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- > > Funkloch 10 f4d9ce13-aab0-4485-9929-6070ad52a196 wifi -- > > Funkloch 100 8b48a220-1754-4988-84ad-d0f83a9b4ede wifi -- > > > > 2. Similarly, As I need to verify whether the DEVICE "wlp1s0" is connected > to "Funkloch" or not? could you please help me, how can I extract the > "connected" status under "STATE column for DEVICE "wlp1s0" and CONNECTION > "Funkloch 1552" > > root:~/qa/robot_tests# nmcli dev > DEVICE TYPE STATE CONNECTION > enp0s21f0u4 ethernet connected Wired connection 1 > wlp1s0 wifi connected Funkloch 1552 > enp2s0 ethernet unavailable -- > sit0 iptunnel unmanaged -- > lo loopback unmanaged -- > > Kindly do the needful as am trying this from past two 2 days, still no > clues > > Many thanks in advance > -- > https://mail.python.org/mailman/listinfo/python-list > You can look into textfsm parser for the same, it was released specifically for this purpose of parsing CLI outputs. It should be the ideal solution for your scenario since I see some rows in your cli output which have spaces in the same column, so a hardcoded index after splitting each line on spaces will not work out. From tjol at tjol.eu Mon Nov 12 03:57:09 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 12 Nov 2018 09:57:09 +0100 Subject: Issue in parsing the strings in python code In-Reply-To: References: Message-ID: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> On 12/11/2018 09:28, srinivasan wrote: > Dear Python Experts team, > > This question might be very simple for you, As am newbie to python, could > you please how to parse the below strings > > [snip] > > > root:~/qa/robot_tests# nmcli c show Pro tip: many *nix tools have a flag that makes them produce machine-readable output. E.g.: from the nmcli man page: OPTIONS -t | --terse Output is terse. This mode is designed and suitable for computer (script) processing. From srinivasan.rns at gmail.com Mon Nov 12 04:23:58 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 12 Nov 2018 10:23:58 +0100 Subject: Issue in parsing the strings in python code In-Reply-To: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> Message-ID: Hi Thomas, Great to hear from you, Could you please let me know how do I get the UUID "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID "Funkloch' using "nmcli --terse" ?? Many thanks in advance, Srini On Mon, Nov 12, 2018 at 9:59 AM Thomas Jollans wrote: > On 12/11/2018 09:28, srinivasan wrote: > > Dear Python Experts team, > > > > This question might be very simple for you, As am newbie to python, could > > you please how to parse the below strings > > > > [snip] > > > > > > root:~/qa/robot_tests# nmcli c show > > Pro tip: many *nix tools have a flag that makes them produce > machine-readable output. E.g.: from the nmcli man page: > > OPTIONS > -t | --terse > Output is terse. This mode is designed and suitable for > computer (script) processing. > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Mon Nov 12 04:37:36 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 12 Nov 2018 10:37:36 +0100 Subject: Issue in parsing the strings in python code In-Reply-To: References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> Message-ID: Because the problem is every time when ever I see the output using the "nmcli c show", the below output is the weird output, so instead of connecting to SSID "NIFunkloch" it randomly connects to "NIFunkloch 1552" or sometimes to NIFunkloch 1000" or so on root:~/qa/robot_tests# nmcli c show NAME UUID TYPE DEVICE NIFunkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet enp0s21f0u4 NIFunkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- NIFunkloch 10 f4d9ce13-aab0-4485-9929-6070ad52a196 wifi -- NIFunkloch 100 8b48a220-1754-4988-84ad-d0f83a9b4ede wifi -- NIFunkloch 1000 4dd7ae61-8c10-4582-984a-600b4c6b008e wifi -- NIFunkloch 1001 2fcd1d89-1d1c-43ca-8b6a-d667fa4b0f90 wifi -- NIFunkloch 1002 c0a31697-afa9-453b-9938-811a9315e30f wifi -- NIFunkloch 1003 2dc7e148-d246-492f-94f0-88314fc0cc89 wifi -- NIFunkloch 1004 a389f24e-ef39-4886-ae13-b38932e9f00d wifi -- NIFunkloch 1005 c2ecc4f5-58b8-4488-9769-f7c3fc044134 wifi -- NIFunkloch 1006 de98d76c-22bf-4e1c-89fd-577538e8a40d wifi -- NIFunkloch 1007 0bca5d73-03e3-4bb4-a78c-98d0adabaac9 wifi -- NIFunkloch 1008 dc576c25-75c8-491b-847a-8a192e6c3869 wifi -- NIFunkloch 1009 46c8fc94-62d0-48d9-9fcb-489f646a9fbd wifi -- NIFunkloch 101 ce8a3276-016d-4101-8002-4092af9a49f3 wifi -- NIFunkloch 1010 814716b2-935c-40a3-89a8-4bfebd9a7f6d wifi -- NIFunkloch 1011 68fa4889-63a3-41f2-b6e1-1be4982e756a wifi -- NIFunkloch 1012 c47d66ff-ea8c-498c-9c04-012732078923 wifi -- NIFunkloch 1013 37b51561-f3eb-4162-a87e-7c37e495c30b wifi -- NIFunkloch 1014 ba9b30a5-c882-4e45-8882-3fe4cfcfd191 wifi -- NIFunkloch 1015 9327e4d5-d5e5-4f3b-a70a-0eeec1d5256f wifi -- NIFunkloch 1016 e24c1a9a-1f5e-4895-9656-efed574dfae2 wifi -- NIFunkloch 1017 1cf9c60f-9efd-474c-8dbc-804d9796764b wifi -- NIFunkloch 1018 ec678687-f8d4-4123-bf64-f8bf67523cb6 wifi -- NIFunkloch 1019 655579c5-74ec-4d4b-a0bc-9d31a5f40658 wifi -- NIFunkloch 102 1de1d876-37b2-40e7-9707-ced79ab2664a wifi -- NIFunkloch 1020 9e90cc37-76f2-482c-8932-3173d5f15594 wifi -- NIFunkloch 1021 1529bc15-9baa-4ee6-9603-3613be98a3c8 wifi -- NIFunkloch 1022 25f8279d-8100-4d8b-9571-4da7d3031977 wifi -- NIFunkloch 1023 43c73d01-7921-4887-92be-4054186c8b44 wifi -- NIFunkloch 1024 9f433dc9-fb07-4ad0-94c4-219e3f1dd429 wifi -- NIFunkloch 1025 d3cba1d3-3c27-4711-874a-cbfdbdc41784 wifi -- NIFunkloch 1026 066b02d6-760f-4dd1-826a-c210b20075db wifi -- NIFunkloch 1027 0f13c31b-3d4b-4b25-a3a1-6b88c6a46431 wifi -- NIFunkloch 1028 904590e5-d7e2-4cb7-8507-9838cafa411e wifi -- NIFunkloch 1029 89aa5931-82e6-4475-b445-03729d03ffd8 wifi -- NIFunkloch 103 028c7347-1933-4a26-8ff5-89fd8541c038 wifi -- NIFunkloch 1030 ba0a681b-7022-4f7b-a684-889f8560bf19 wifi -- NIFunkloch 1031 963bf13c-16e5-4b24-a71e-778b0b2ea4a8 wifi -- NIFunkloch 1032 6c32f2a6-e68b-44ee-b1b4-ef413cd6d45b wifi -- NIFunkloch 1033 da463db4-56d2-4746-aae6-63680620f7de wifi -- NIFunkloch 1034 821412fc-0c67-4fd5-b126-63434043ae48 wifi -- NIFunkloch 1035 fc6dfddf-2a4a-4477-b0fa-cd90a50f35a4 wifi -- NIFunkloch 1036 b922fef5-3c71-40cd-bb82-bea31ec15657 wifi -- NIFunkloch 1037 c4a2c4cb-3f31-494c-bf39-aa43cd9e5d29 wifi -- NIFunkloch 1038 ceaff9ba-7fb6-4eb1-943a-99c282789279 wifi -- NIFunkloch 1039 a9e790a6-b31e-4ff1-becf-78a61000a441 wifi -- NIFunkloch 104 5f2199ed-371a-4a27-872b-c945d51926de wifi -- NIFunkloch 1040 4a84f94e-46bd-47d3-b7e3-5dcf9dc5f54a wifi -- NIFunkloch 1041 9d93fe6e-6a74-4744-8edf-09160fb3583f wifi -- On Mon, Nov 12, 2018 at 10:23 AM srinivasan wrote: > Hi Thomas, > > Great to hear from you, Could you please let me know how do I get the UUID > "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID > "Funkloch' using "nmcli --terse" ?? > > Many thanks in advance, > Srini > > On Mon, Nov 12, 2018 at 9:59 AM Thomas Jollans wrote: > >> On 12/11/2018 09:28, srinivasan wrote: >> > Dear Python Experts team, >> > >> > This question might be very simple for you, As am newbie to python, >> could >> > you please how to parse the below strings >> > >> > [snip] >> > >> > >> > root:~/qa/robot_tests# nmcli c show >> >> Pro tip: many *nix tools have a flag that makes them produce >> machine-readable output. E.g.: from the nmcli man page: >> >> OPTIONS >> -t | --terse >> Output is terse. This mode is designed and suitable for >> computer (script) processing. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From benedikt.kroll at der-arbeitende.de Mon Nov 12 04:39:40 2018 From: benedikt.kroll at der-arbeitende.de (Benedikt Kroll) Date: Mon, 12 Nov 2018 10:39:40 +0100 (CET) Subject: passing value from Python3 script back to RewriteMap MapType prg in Apache24 Message-ID: <948708831.225531.1542015580535@email.ionos.de> Hi, using a Python script as a Rewrite Map with MapType prg in Apache 2.4, I'm having trouble passing the value back to Apache. The log says "map lookup OK", but the value is empty. According to the Apache documentation (https://httpd.apache.org/docs/current/rewrite/rewritemap.html#prg), the script "should return one new-line terminated response string on STDOUT" which is then used as the rewrite target. I have tried to do this using: sys.stdout.write(newValue + "/n") sys.stdout.flush() However, Apache receives only an empty return value (with no error). On Stackoverflow and others, I found and tried out some examples, which in some cases where quite old, so probably written for older versions. The following is what I extracted from the more current hints I could find. *.conf RewriteEngine On RewriteMap extrw "prg:/opt/extrw.py" RewriteRule "^(.*)" "${extrw:%{REQUEST_URI}}" /opt/extrw.py import sys while True: newValue = "/index.html" # placeholder for testing sys.stdout.write(newValue + "/n") sys.stdout.flush() log for curl 127.0.0.1/abc init rewrite engine with requested uri /abc applying pattern '^(.*)' to uri '/abc' map lookup OK: map=extrw key=/abc -> val= rewrite '/abc' -> '' local path result: The expected result would be to have "map lookup OK: map=extrw key=/abc -> val=/index.html" in the third line. Any help would be appreciated! Thanks! Benedikt From tjol at tjol.eu Mon Nov 12 05:30:20 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 12 Nov 2018 11:30:20 +0100 Subject: Issue in parsing the strings in python code In-Reply-To: References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> Message-ID: <8e932f2c-03cc-5250-150b-b9d7597ce434@tjol.eu> On 2018-11-12 10:23, srinivasan wrote: > Hi Thomas, > > Great to hear from you, Could you please let me know how do I get the UUID > "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID > "Funkloch' using "nmcli --terse" ?? Have a look at the output. It appears to me that the fields are separated by colons, so you should be able to split each line on ':'. If you're stuck, let us see what you've tried! From as at sci.fi Mon Nov 12 07:19:08 2018 From: as at sci.fi (Anssi Saari) Date: Mon, 12 Nov 2018 14:19:08 +0200 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: Chris Angelico writes: > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: >> >> Chris Angelico writes: >> >> > No helper needed. Safe against command injection. Uses the known >> > format of the command's output; if you want other information as well >> > as the type, you could get that too. >> >> Can someone let me in on this secret helper module? Doesn't seem to >> match the helper module in PyPI at least. >> > > What helper? Helper module used in the original post. I assumed you know what it is since you declared it's not needed. > I said you don't need one. Just use subprocess directly. This part was clear. From dvl at psu.edu Mon Nov 12 07:58:58 2018 From: dvl at psu.edu (Christman, Roger Graydon) Date: Mon, 12 Nov 2018 12:58:58 +0000 Subject: IDLE Default Working Directory Message-ID: Could anyone tell me how to set up IDLE's default working directory, so that it would be in the same place for each startup? (Like C:\Users\myname\Python) I teach a course that mounts a lot of file space across the network and the default directory for all my students is a readonly directory, which means they have to adjust anytime they want to save a new program or use a complete path name to write to a new output file. I would prefer that they wouldn't continually have to fight the system to save their code. I looked in IDLE's own configuration menu, and didn't see anything there -- and I fear that I might have to fight some Windows settings somewhere else instead. I think this is Windows 10. Roger Christman Pennsylvania State University From rosuav at gmail.com Mon Nov 12 08:56:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Nov 2018 00:56:25 +1100 Subject: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python In-Reply-To: References: <007301d47648$e3f2f3a0$abd8dae0$@verizon.net> <1541585401.1731.1.camel@gmail.com> Message-ID: On Mon, Nov 12, 2018 at 11:20 PM Anssi Saari wrote: > > Chris Angelico writes: > > > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: > >> > >> Chris Angelico writes: > >> > >> > No helper needed. Safe against command injection. Uses the known > >> > format of the command's output; if you want other information as well > >> > as the type, you could get that too. > >> > >> Can someone let me in on this secret helper module? Doesn't seem to > >> match the helper module in PyPI at least. > >> > > > > What helper? > > Helper module used in the original post. I assumed you know what it is > since you declared it's not needed. Oh! I see what you mean. I wasn't referring to an entire module, just a helper *function*. Look at the OP's code at this function: def execute_cmd_output_string(self, cmd, enable_shell=False): This is a function whose sole purpose is to make it easier to write other functions. That's what's often referred to as a "helper function". (It's also dangerously written, as it turns other failures into AssertionError.) By simplifying the code and removing the need for this helper, we can make it more consistent with the rest of the Python ecosystem, less buggy [1], and probably easier to read. ChrisA [1] It's generally true that a programmer's bugs-per-lines-of-code metric is fairly stable, so having less code usually means less bugs. Not certain by any means, but consider: non-code cannot have bugs in it, and code usually does. It's a good rule of thumb. From rhodri at kynesim.co.uk Mon Nov 12 09:17:17 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 12 Nov 2018 14:17:17 +0000 Subject: Issue in parsing the strings in python code In-Reply-To: References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> Message-ID: <45bf76ca-25fa-3434-c443-65981841ea8e@kynesim.co.uk> On 12/11/2018 09:37, srinivasan wrote: > Because the problem is every time when ever I see the output using the > "nmcli c show", the below output is the weird output, so instead of > connecting to SSID "NIFunkloch" it randomly connects to "NIFunkloch 1552" > or sometimes to NIFunkloch 1000" or so on > > root:~/qa/robot_tests# nmcli c show > NAME UUID TYPE DEVICE > > NIFunkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 > > Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet > enp0s21f0u4 > NIFunkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- [snipped for brevity] That looks conveniently aligned. Can't you just slice each line to get the entries you are after? -- Rhodri James *-* Kynesim Ltd From brian.j.oney at googlemail.com Mon Nov 12 09:34:25 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 12 Nov 2018 15:34:25 +0100 Subject: Issue in parsing the strings in python code In-Reply-To: <45bf76ca-25fa-3434-c443-65981841ea8e@kynesim.co.uk> References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> <45bf76ca-25fa-3434-c443-65981841ea8e@kynesim.co.uk> Message-ID: <1542033265.1580.2.camel@gmail.com> On Mon, 2018-11-12 at 14:17 +0000, Rhodri James wrote: > On 12/11/2018 09:37, srinivasan wrote: > > Because the problem is every time when ever I see the output using the > > "nmcli c show", the below output is the weird output, so instead of > > connecting to SSID "NIFunkloch" it randomly connects to "NIFunkloch 1552" > > or sometimes to NIFunkloch 1000" or so on > > > > root:~/qa/robot_tests# nmcli c show > > NAME UUID TYPE DEVICE > > > > NIFunkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 > > > > Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet > > enp0s21f0u4 > > NIFunkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- > > [snipped for brevity] > > That looks conveniently aligned. Can't you just slice each line to get > the entries you are after? > I believe the idea is to allow the help seeker to piece the following puzzle together. $ nmcli -t NAME,SOMETHINGELSE c show >>> help(subprocess.Popen) >>> text.split(':') >>> aarrr.shiver_me(timbers) if "I am" in "the Bermuda triangle" else help("where") From eryksun at gmail.com Mon Nov 12 10:16:14 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 12 Nov 2018 09:16:14 -0600 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: On 11/12/18, Christman, Roger Graydon wrote: > > I looked in IDLE's own configuration menu, and didn't see anything there -- > and I fear that I might have to fight some Windows settings somewhere else > instead. I think this is Windows 10. Modify the "Start in" field of the IDLE shortcut. You can use environment variables, e.g. "%UserProfile%\Documents". From countryone77 at gmail.com Mon Nov 12 10:35:56 2018 From: countryone77 at gmail.com (Bev in TX) Date: Mon, 12 Nov 2018 09:35:56 -0600 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> On Nov 12, 2018, at 9:16 AM, eryk sun wrote: > > On 11/12/18, Christman, Roger Graydon > wrote: >> >> I looked in IDLE's own configuration menu, and didn't see anything there -- >> and I fear that I might have to fight some Windows settings somewhere else >> instead. I think this is Windows 10. > > Modify the "Start in" field of the IDLE shortcut. You can use > environment variables, e.g. "%UserProfile%\Documents". I am not the OP and I?m on macOS ? no shortcuts. How would one do the same thing on other platforms? Bev in TX From brian.j.oney at googlemail.com Mon Nov 12 11:07:29 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 12 Nov 2018 17:07:29 +0100 Subject: IDLE Default Working Directory In-Reply-To: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> Message-ID: <1542038849.5527.1.camel@gmail.com> On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote: > On Nov 12, 2018, at 9:16 AM, eryk sun wrote: > > On 11/12/18, Christman, Roger Graydon > wrote: > > > I looked in IDLE's own configuration menu, and didn't see anything there -- > > > and I fear that I might have to fight some Windows settings somewhere else > > > instead. I think this is Windows 10. > > > > Modify the "Start in" field of the IDLE shortcut. You can use > > environment variables, e.g. "%UserProfile%\Documents". > > I am not the OP and I?m on macOS ? no shortcuts. How would one do the same thing on other platforms? > Bev in TX > > > > Hello there, I am not an IDLE user. You may try a startup script from python, as per the following. oney at oney:~$ cat pyhelp/change_to_current_dir.py?#!/usr/bin/env python3 import osimport sys print("Current directory is:")print(os.path.abspath(os.path.curdir))print("Path to this file is:")print(os.path.abspath(__file__))# Changing current directory to this file's directoryos.chdir(os.path.dirname(os.path.abspath(__file__)))print("Current directory now is:")print(os.path.abspath(os.path.curdir))# sys.path.append(os.path.abspath(__file__))# os.curdir()oney at oney:~$ python3Python 3.5.3 (default, Sep 27 2018, 17:25:39)?[GCC 6.3.0 20170516] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import pyhelp.change_to_current_dirCurrent directory is:/home/oneyDirectory of this file is:/home/oney/pyhelp/change_to_current_dir.pyCurrent directory now is:/home/oney/pyhelp>>>? HTH From juan.cristobal.qg at gmail.com Mon Nov 12 11:40:17 2018 From: juan.cristobal.qg at gmail.com (=?UTF-8?Q?Juan_Crist=C3=B3bal_Quesada?=) Date: Mon, 12 Nov 2018 17:40:17 +0100 Subject: distribute python interpreter and dependencies Message-ID: Hello, this is my first mail. I resorted to the list after some prior struggling. Im facing the need to distribute a python installation folder and interpreter in a shared network drive. Im also distributing the application's source code that would lie also in another network drive. For this, my attempts have gone towards replicating the python installation folder created after installing python27 in one machine and copy all the files and directories to the network drive. After that, copied the python27.dll of the C:/Windows/System32 file and set all the Python27/lib;Python27/DLLs/Python27/Scripts....... to the PATH environment variable through a launcher script. This works on my machine and a couple others....BUT, not in some other machines running as well windows 10 pro..... So i investigated a bit and discovered that if i install the python27 (2.7.11 same version) in one of those failing machines... the "ctypes.pyd" module's filesize is different.... So i replaced the original python27 folders with those of the new installed python and now it works on those machines..........havent tried yet if it still works on the first ones... Why is this behaviour? Im guessing the python27 installer generates some dlls "on the fly" that are tied to the windows operating system........... I dont want to create a windows executable via py2exe or pyinstaller.......... What are the best steps to make a python interpreter available to all windows based different machines? Am i missing something else? What are the steps the python windows installer performs in order? From dvl at psu.edu Mon Nov 12 13:28:45 2018 From: dvl at psu.edu (Christman, Roger Graydon) Date: Mon, 12 Nov 2018 18:28:45 +0000 Subject: IDLE Default Working Directory Message-ID: eryk sun responded: ________________________________ On 11/12/18, Christman, Roger Graydon wrote: > > I looked in IDLE's own configuration menu, and didn't see anything there -- > and I fear that I might have to fight some Windows settings somewhere else > instead. I think this is Windows 10. Modify the "Start in" field of the IDLE shortcut. You can use environment variables, e.g. "%UserProfile%\Documents". Unfortunately, since I do not have any administrative privileges, I do not think I have the ability to modify any of these shortcuts. Nor do I know off hand how to set environment variables in a manner that would work consistently throughout the term, so that they persist for all logins. Since this is Windows-y system, I can't just tell my students to edit a .cshrc. Any other ideas? Roger Christman Pennsylvania State University From eryksun at gmail.com Mon Nov 12 14:28:12 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 12 Nov 2018 13:28:12 -0600 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: On 11/12/18, Christman, Roger Graydon wrote: > eryk sun responded: > ________________________________ > On 11/12/18, Christman, Roger Graydon wrote: >> >> I looked in IDLE's own configuration menu, and didn't see anything there >> -- >> and I fear that I might have to fight some Windows settings somewhere >> else >> instead. I think this is Windows 10. > > Modify the "Start in" field of the IDLE shortcut. You can use > environment variables, e.g. "%UserProfile%\Documents". > > > Unfortunately, since I do not have any administrative privileges, I do not > think I have the ability to modify any of these shortcuts. Nor do I know > off hand how to set environment variables in a manner that would work > consistently throughout the term, so that they persist for all logins. If Python is installed for all users, then the shortcut should be a file named like "IDLE (Python 3.x [32|64]-bit).lnk" in the directory "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Python 3.x". Copy it to the user's desktop, where you'll have the right to modify it. Or instead you can just create a new shortcut on the desktop that runs "C:\path\to\python\installation\pythonw.exe" "C:\path\to\python\installation\Lib\idlelib\idle.pyw". As to environment variables to use in "Start in", %UserProfile% is a built-in variable for the current user's profile directory; you don't have to add it. From srinivasan.rns at gmail.com Mon Nov 12 14:37:06 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 13 Nov 2018 01:07:06 +0530 Subject: Unable to get the gateway IP of wlan interface using python code Message-ID: Dear Python Experts, *First method:* I need to get the IP address basically the gateway IP in my setup I get it as "192.168.178.1" when I run the below standalone python code. * def get_gateway_ip(self):* * """* * Get the IP address to the WIFI module from the AP* * """* * cmd = 'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3'* * f = os.popen(cmd)* * return str(f.read().strip())* I am trying to log the IP in the robot framework script and ensure that my router is able to ping but "*${SSID_GATEWAY_IP}*" doesn't seem to get collected from the above python code and pass this value to my custom method "*Wait Until Device Is Pingable"* * ${RET} = Wait Until Device Is Pingable ${SSID_GATEWAY_IP}* * Should Be True ${RET}* But whenever I hardcode the "*${SSID_GATEWAY_IP} 192.168.178.1*" in the robot framework, it seems to be working with "*Wait Until Device Is Pingable ${SSID_GATEWAY_IP}*" But the below robot framework script doesn't seems to work with the return value received from the above python script, could you please do the needful? *Get Gateway IP of SSID* * ${SSID_GATEWAY_IP} = Get Gateway Ip* * Log ${SSID_GATEWAY_IP}* * ${RET} = Wait Until Device Is Pingable ${SSID_GATEWAY_IP}* * Should Be True ${RET}* *SECOND METHOD:* When I use the subprocess I see the below issue: def get_gateway_ip(self): """ Get the IP address to the WIFI module from the AP """ #cmd = 'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3' # f = os.popen(cmd) # return str(f.read().strip()) p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3', stdout=subprocess.PIPE) result = p.communicate()[0] print(result) #list = os.popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3').read() # p = Popen(cmd, shell=True, stdout=PIPE) # out, err = p.communicate() # #return (p.returncode, out, err) # return out # #print('returncode: %s' % result[0]) # #print('output: %s' % result[1]) # #print('error: %s' % result[2]) #return self._helper.execute_cmd_output_string(cmd) Error: root:~/qa/test_library# python3 wifi.py Enabling wifi Verify wifi connectivity True Get gateway wifi ip Traceback (most recent call last): File "wifi.py", line 134, in print(m.get_gateway_ip()) File "wifi.py", line 76, in get_gateway_ip p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3', stdout=subprocess.PIPE) File "/usr/lib/python3.5/subprocess.py", line 676, in __init__ restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1289, in _execute_child raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\\ -f3' root:~/qa/test_library# As I am stuck with this issue from past 2 days, wondering for any clues Kindly do the needful as early as possible Many Thanks in adavnce From srinivasan.rns at gmail.com Mon Nov 12 14:52:23 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 13 Nov 2018 01:22:23 +0530 Subject: Issue in parsing the strings in python code In-Reply-To: <8e932f2c-03cc-5250-150b-b9d7597ce434@tjol.eu> References: <48660abb-d31d-ffe7-dabd-9b71ab9e89c5@tjol.eu> <8e932f2c-03cc-5250-150b-b9d7597ce434@tjol.eu> Message-ID: Hi Thomas, I have Implemented as below, please let me know if you forsee any issues in the below code snippet? as I have just started learning python from last week def wifi_connect_verify(self): """ Verify Connectivity of WIFI module to the Access. :return: command output as True or False. """ * cmd = 'nmcli dev | grep "wlp1s0" | grep "connected"'* * f = os.popen(cmd)* * if 'connected' in f.read().strip():* * return True* * else:* * return False* Kindly do the needful Srini On Mon, Nov 12, 2018 at 4:02 PM Thomas Jollans wrote: > On 2018-11-12 10:23, srinivasan wrote: > > Hi Thomas, > > > > Great to hear from you, Could you please let me know how do I get the > UUID > > "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID > > "Funkloch' using "nmcli --terse" ?? > > > Have a look at the output. It appears to me that the fields are > separated by colons, so you should be able to split each line on ':'. > > If you're stuck, let us see what you've tried! > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Mon Nov 12 16:17:16 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Nov 2018 21:17:16 +0000 Subject: Unable to get the gateway IP of wlan interface using python code In-Reply-To: References: Message-ID: <8334aad3-3f6c-772d-7fc1-bafc6292fcac@mrabarnett.plus.com> On 2018-11-12 19:37, srinivasan wrote: > Dear Python Experts, > [snip] > > *SECOND METHOD:* > > When I use the subprocess I see the below issue: > > > > def get_gateway_ip(self): > """ > Get the IP address to the WIFI module from the AP > """ > > #cmd = 'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3' > # f = os.popen(cmd) > # return str(f.read().strip()) > > > p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ > -f3', stdout=subprocess.PIPE) > result = p.communicate()[0] > print(result) > > [snip] > > Error: > > root:~/qa/test_library# python3 wifi.py > Enabling wifi > Verify wifi connectivity > True > Get gateway wifi ip > Traceback (most recent call last): > File "wifi.py", line 134, in > print(m.get_gateway_ip()) > File "wifi.py", line 76, in get_gateway_ip > p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ > -f3', stdout=subprocess.PIPE) > File "/usr/lib/python3.5/subprocess.py", line 676, in __init__ > restore_signals, start_new_session) > File "/usr/lib/python3.5/subprocess.py", line 1289, in _execute_child > raise child_exception_type(errno_num, err_msg) > FileNotFoundError: [Errno 2] No such file or directory: 'ip route show > 0.0.0.0/0 dev wlp1s0 | cut -d\\ -f3' > root:~/qa/test_library# > > > As I am stuck with this issue from past 2 days, wondering for any clues > 'Popen' thinks that the string you gave it is the path to a command. It's not; it's a command line with arguments. You can tell it that the string is a command line by also passing the keyword argument 'shell=True': p = subprocess.Popen(r'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ -f3', stdout=subprocess.PIPE, shell=True) From python at mrabarnett.plus.com Mon Nov 12 17:57:14 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Nov 2018 22:57:14 +0000 Subject: passing value from Python3 script back to RewriteMap MapType prg in Apache24 In-Reply-To: <948708831.225531.1542015580535@email.ionos.de> References: <948708831.225531.1542015580535@email.ionos.de> Message-ID: On 2018-11-12 09:39, Benedikt Kroll wrote: > Hi, > > using a Python script as a Rewrite Map with MapType prg in Apache 2.4, I'm having trouble > passing the value back to Apache. > > The log says "map lookup OK", but the value is empty. > > According to the Apache documentation (https://httpd.apache.org/docs/current/rewrite/rewritemap.html#prg), the script "should return one new-line terminated response string on STDOUT" which is then used as the rewrite target. > > I have tried to do this using: > sys.stdout.write(newValue + "/n") > sys.stdout.flush() > > However, Apache receives only an empty return value (with no error). > > On Stackoverflow and others, I found and tried out some examples, which > in some cases where quite old, so probably written for older versions. > > The following is what I extracted from the more current hints I could find. > > > *.conf > RewriteEngine On > RewriteMap extrw "prg:/opt/extrw.py" > RewriteRule "^(.*)" "${extrw:%{REQUEST_URI}}" > > > /opt/extrw.py > import sys > while True: > newValue = "/index.html" # placeholder for testing > sys.stdout.write(newValue + "/n") > sys.stdout.flush() > > > log for curl 127.0.0.1/abc > init rewrite engine with requested uri /abc > applying pattern '^(.*)' to uri '/abc' > map lookup OK: map=extrw key=/abc -> val= > rewrite '/abc' -> '' > local path result: > > > The expected result would be to have "map lookup OK: map=extrw key=/abc > -> val=/index.html" in the third line. > > Any help would be appreciated! > The examples I've found are also reading from stdin, so I'd suggest trying that: import sys while True: arg = sys.stdin.readline() newValue = "/index.html" # placeholder for testing sys.stdout.write(newValue + "/n") sys.stdout.flush() From tjreedy at udel.edu Mon Nov 12 18:45:32 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Nov 2018 18:45:32 -0500 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: On 11/12/2018 2:28 PM, eryk sun wrote: > On 11/12/18, Christman, Roger Graydon wrote: >> eryk sun responded: >> ________________________________ >> On 11/12/18, Christman, Roger Graydon wrote: >>> >>> I looked in IDLE's own configuration menu, and didn't see anything there >>> -- >>> and I fear that I might have to fight some Windows settings somewhere >>> else >>> instead. I think this is Windows 10. >> >> Modify the "Start in" field of the IDLE shortcut. You can use >> environment variables, e.g. "%UserProfile%\Documents". >>> >> Unfortunately, since I do not have any administrative privileges, I do not >> think I have the ability to modify any of these shortcuts. Nor do I know >> off hand how to set environment variables in a manner that would work >> consistently throughout the term, so that they persist for all logins. > > If Python is installed for all users, then the shortcut should be a > file named like "IDLE (Python 3.x [32|64]-bit).lnk" in the directory > "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Python 3.x". Copy > it to the user's desktop, where you'll have the right to modify it. Or > instead you can just create a new shortcut on the desktop that runs > "C:\path\to\python\installation\pythonw.exe" > "C:\path\to\python\installation\Lib\idlelib\idle.pyw". > > As to environment variables to use in "Start in", %UserProfile% is a > built-in variable for the current user's profile directory; you don't > have to add it. On Windows, a simple alternate is a .bat file. I belive the folloiwing should work. cd c:/desired/startup/directory py -x.y -m idlelib The default for x.y is latest 3.x or latest 2.x if no 3.x. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 12 18:50:05 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Nov 2018 18:50:05 -0500 Subject: IDLE Default Working Directory In-Reply-To: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> Message-ID: On 11/12/2018 10:35 AM, Bev in TX wrote: > On Nov 12, 2018, at 9:16 AM, eryk sun wrote: >> >> On 11/12/18, Christman, Roger Graydon > wrote: >>> >>> I looked in IDLE's own configuration menu, and didn't see anything there -- >>> and I fear that I might have to fight some Windows settings somewhere else >>> instead. I think this is Windows 10. >> >> Modify the "Start in" field of the IDLE shortcut. You can use >> environment variables, e.g. "%UserProfile%\Documents". > > I am not the OP and I?m on macOS ? no shortcuts. How would one do the same thing on other platforms? > Bev in TX For me, open (command-O) opens 'Documents'. I presume it should be easy enough to move into a 'py' subfolder. -- Terry Jan Reedy From bill at celestial.net Mon Nov 12 18:54:19 2018 From: bill at celestial.net (Bill Campbell) Date: Mon, 12 Nov 2018 15:54:19 -0800 Subject: [Tutor] Unable to get the gateway IP of wlan interface using python code In-Reply-To: References: Message-ID: <20181112235419.GA2250@ayn.mi.celestial.com> On Tue, Nov 13, 2018, srinivasan wrote: >Dear Python Experts, > >*First method:* > >I need to get the IP address basically the gateway IP in my setup I get it >as "192.168.178.1" when I run the below standalone python code. > > >* def get_gateway_ip(self):* >* """* >* Get the IP address to the WIFI module from the AP* >* """* > >* cmd = 'ip route show 0.0.0.0/0 dev wlp1s0 | cut >-d\ -f3'* >* f = os.popen(cmd)* >* return str(f.read().strip())* This command should get the gateway IP. Linux: cmd = "ip route list | awk '/^default/{print $3}'" or perhaps Linux: cmd = "netstat -rn | awk '/^0.0.0.0/{print $2}'" OSX: cmd = "netstat -rn | awk '/^default/{print $2}'" I don't have a freebsd system available to test this, but I think this pattern should work: re.compile(r'^(default|0\.0\.0\.0)\s+(\S+)') Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www2.celestial.com/ PO Box 820; 6641 E. Mercer Way Mobile: (206) 947-5591 Mercer Island, WA 98040-0820 Fax: (206) 232-9186 Skype: jwccsllc On the free market, everyone earns according to his productive value in satisfying consumer desires. Under statist distribution, everyone earns in proportion to the amount he can plunder from the producers. -- Murray N. Rothbard From tjol at tjol.eu Mon Nov 12 19:10:34 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 13 Nov 2018 01:10:34 +0100 Subject: distribute python interpreter and dependencies In-Reply-To: References: Message-ID: On 12/11/2018 17:40, Juan Crist?bal Quesada wrote: > Hello, > this is my first mail. I resorted to the list after some prior struggling. Welcome! > Im facing the need to distribute a python installation folder and > interpreter in a shared network drive. > > Im also distributing the application's source code that would lie also in > another network drive. > > For this, my attempts have gone towards replicating the python installation > folder created after installing python27 in one machine and copy all the > files and directories to the network drive. After that, copied the > python27.dll of the C:/Windows/System32 file and set all the > Python27/lib;Python27/DLLs/Python27/Scripts....... to the PATH environment > variable through a launcher script. I assume you have a good reason to want to use an old version of Python... > > This works on my machine and a couple others....BUT, not in some other > machines running as well windows 10 pro..... In what way does it not work? Is there an error message? > So i investigated a bit and > discovered that if i install the python27 (2.7.11 same version) in one of > those failing machines... the "ctypes.pyd" module's filesize is > different.... So i replaced the original python27 folders with those of the > new installed python and now it works on those machines..........havent > tried yet if it still works on the first ones... > > Why is this behaviour? Im guessing the python27 installer generates some > dlls "on the fly" that are tied to the windows operating system........... > > I dont want to create a windows executable via py2exe or > pyinstaller.......... What are the best steps to make a python interpreter > available to all windows based different machines? Am i missing something > else? What are the steps the python windows installer performs in order? I have no idea what the Python.org installer is doing here, but you could try one of the other Python distributions (e.g. miniconda)... MAYBE you'll have more luck with that (Or ActivePython, or WinPython, or whatever). -- Thomas From tjol at tjol.eu Mon Nov 12 19:15:08 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 13 Nov 2018 01:15:08 +0100 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: <66152eef-5ee2-e312-501e-c780f254efbe@tjol.eu> On 13/11/2018 00:45, Terry Reedy wrote: > > On Windows, a simple alternate is a .bat file.? I belive the folloiwing > should work. > > cd c:/desired/startup/directory > py -x.y -m idlelib > > The default for x.y is latest 3.x or latest 2.x if no 3.x. Correct me if I'm wrong, but won't that create an empty command prompt window nobody wants to see? (which you can get rid of by calling START /B on a win32 application like pythonw.exe. Is there a pyw.exe or something?) From tjreedy at udel.edu Mon Nov 12 19:42:42 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Nov 2018 19:42:42 -0500 Subject: IDLE Default Working Directory In-Reply-To: <66152eef-5ee2-e312-501e-c780f254efbe@tjol.eu> References: <66152eef-5ee2-e312-501e-c780f254efbe@tjol.eu> Message-ID: On 11/12/2018 7:15 PM, Thomas Jollans wrote: > On 13/11/2018 00:45, Terry Reedy wrote: >> >> On Windows, a simple alternate is a .bat file.? I belive the folloiwing >> should work. >> >> cd c:/desired/startup/directory >> py -x.y -m idlelib >> >> The default for x.y is latest 3.x or latest 2.x if no 3.x. > > Correct me if I'm wrong, but won't that create an empty command prompt > window nobody wants to see? (which you can get rid of by calling > START /B on a win32 application like pythonw.exe. Is there a pyw.exe or > something? Yes, thanks for the reminder. Unless the console is needed (as when user code creates subprocesses that print) 'pyw' can be used instead of 'py'. When using CommandPrompt, 'pyw -m idlelib' detaches the process from the console, which might or might not be a good thing. -- Terry Jan Reedy From david at graniteweb.com Mon Nov 12 19:55:15 2018 From: david at graniteweb.com (David Rock) Date: Mon, 12 Nov 2018 18:55:15 -0600 Subject: [Tutor] Unable to get the gateway IP of wlan interface using python code In-Reply-To: References: Message-ID: <9AF7F9C8-D4E3-4BD0-9B68-85FC66C404A6@graniteweb.com> > On Nov 12, 2018, at 13:37, srinivasan wrote: > > Dear Python Experts, > > *First method:* > > I need to get the IP address basically the gateway IP in my setup I get it > as "192.168.178.1" when I run the below standalone python code. Is there a requirement to use only what comes in the standard libraries, or can you use things from pypi? Getting interface details is exactly why netifaces was created https://pypi.org/project/netifaces/ damocles:src drock$ python3 Python 3.7.0 (default, Oct 28 2018, 22:17:08) [Clang 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import netifaces >>> gws = netifaces.gateways() >>> gws {'default': {2: ('192.168.69.1', 'en0')}, 2: [('192.168.69.1', 'en0', True)]} >>> gws['default'] {2: ('192.168.69.1', 'en0?)} ? David Rock david at graniteweb.com From cs at cskk.id.au Mon Nov 12 21:00:55 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 13 Nov 2018 13:00:55 +1100 Subject: Unable to get the gateway IP of wlan interface using python code In-Reply-To: <8334aad3-3f6c-772d-7fc1-bafc6292fcac@mrabarnett.plus.com> References: <8334aad3-3f6c-772d-7fc1-bafc6292fcac@mrabarnett.plus.com> Message-ID: <20181113020055.GA98619@cskk.homeip.net> On 12Nov2018 21:17, MRAB wrote: >On 2018-11-12 19:37, srinivasan wrote: >>When I use the subprocess I see the below issue: >> def get_gateway_ip(self): [...] >> p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | >> cut -d\ >>-f3', stdout=subprocess.PIPE) [...] >>root:~/qa/test_library# python3 wifi.py >>Enabling wifi >>Verify wifi connectivity >>True >>Get gateway wifi ip >>Traceback (most recent call last): >> File "wifi.py", line 134, in >> print(m.get_gateway_ip()) >> File "wifi.py", line 76, in get_gateway_ip >> p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ >>-f3', stdout=subprocess.PIPE) >> File "/usr/lib/python3.5/subprocess.py", line 676, in __init__ >> restore_signals, start_new_session) >> File "/usr/lib/python3.5/subprocess.py", line 1289, in _execute_child >> raise child_exception_type(errno_num, err_msg) >>FileNotFoundError: [Errno 2] No such file or directory: 'ip route show >>0.0.0.0/0 dev wlp1s0 | cut -d\\ -f3' >>root:~/qa/test_library# >> >>As I am stuck with this issue from past 2 days, wondering for any >>clues >> >'Popen' thinks that the string you gave it is the path to a command. >It's not; it's a command line with arguments. >You can tell it that the string is a command line by also passing the >keyword argument 'shell=True': > >p = subprocess.Popen(r'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\ >-f3', stdout=subprocess.PIPE, shell=True) But as someone (Chris?) mentioned, it is _better_ to use a command path. Although using shell=True lets you take a shell command you've worked out at the command prompt and use it directly in a Popen call, because such commands must include shell punctuation and may also include some string insertion, they are easy to get subtle wrong, often in ways that can be subverted by bad insertion. I want to repeat Chris' recommendation to run things like the "ip" command directly: p = subprocess.Popen(['ip', 'route', 'show', '0.0.0.0/0', 'dev', 'wlp1s0'], ...) because it bypasses the shell entirely and lets you insert any string (such as the interface name above) directly. Then do the logic which the "cut" command is providing directly in Python: it is more debuggable and more flexible. Cheers, Cameron Simpson From eryksun at gmail.com Mon Nov 12 21:21:23 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 12 Nov 2018 20:21:23 -0600 Subject: IDLE Default Working Directory In-Reply-To: <66152eef-5ee2-e312-501e-c780f254efbe@tjol.eu> References: <66152eef-5ee2-e312-501e-c780f254efbe@tjol.eu> Message-ID: On 11/12/18, Thomas Jollans wrote: > On 13/11/2018 00:45, Terry Reedy wrote: >> >> On Windows, a simple alternate is a .bat file. I belive the folloiwing >> should work. >> >> cd c:/desired/startup/directory >> py -x.y -m idlelib >> >> The default for x.y is latest 3.x or latest 2.x if no 3.x. > > Correct me if I'm wrong, but won't that create an empty command prompt > window nobody wants to see? (which you can get rid of by calling > START /B on a win32 application like pythonw.exe. Is there a pyw.exe or > something?) It should be something like `start "IDLE" pyw.exe -3.x -m idlelib`. This assumes pyw.exe is in a PATH directory, which it should be if Python 3.x was installed for all users. We need the START command to prevent waiting for the pyw.exe command to exit. If CMD waits, then its console window will be displayed while IDLE is running. Even with START, CMD's console window will display briefly, which is ugly and distracting, so ideally the OP should use a .lnk shortcut instead of a batch script. Note that the START command's /B option is irrelevant since pyw.exe isn't a console application. This option makes the CreateProcess call use the flag CREATE_NEW_PROCESS_GROUP instead of CREATE_NEW_CONSOLE. Without the latter flag, a console application inherits the parent's console, and as a new process group it will have Ctrl+C disabled by default. This allows running a console application in the [B]ackground. (I recommend redirecting its stdin to NUL as well.) From best_lay at yahoo.com Mon Nov 12 23:11:15 2018 From: best_lay at yahoo.com (Wildman) Date: Mon, 12 Nov 2018 22:11:15 -0600 Subject: Unable to get the gateway IP of wlan interface using python code References: Message-ID: I tried posting this already but it didn't make it. I am trying again... On Tue, 13 Nov 2018 01:07:06 +0530, srinivasan wrote: > Dear Python Experts, > > *First method:* > > I need to get the IP address basically the gateway IP I am assuming your platform is Linux. If I am incorrect then ignore this post. The code below reads /proc/net/route to obtain the gateway and then prints it. It can be run as-is from a terminal. ######################### #!/usr/bin/env python import socket import struct def get_gateway_ip(): try: with open("/proc/net/route", "r") as f: route = f.readlines() except IOError: return None for line in route: fields = line.strip().split() if fields[1] != "00000000" or not int(fields[3], 16) & 2: continue gateway = socket.inet_ntoa(struct.pack(" GNU/Linux user #557453 The cow died so I don't need your bull! From torriem at gmail.com Mon Nov 12 23:24:24 2018 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Nov 2018 21:24:24 -0700 Subject: [Tutor] Unable to get the gateway IP of wlan interface using python code In-Reply-To: <9AF7F9C8-D4E3-4BD0-9B68-85FC66C404A6@graniteweb.com> References: <9AF7F9C8-D4E3-4BD0-9B68-85FC66C404A6@graniteweb.com> Message-ID: <647adb42-a77c-1a52-35a2-675d5f56bfc1@gmail.com> On 11/12/2018 05:55 PM, David Rock wrote: > Is there a requirement to use only what comes in the standard libraries, or can you use things from pypi? > Getting interface details is exactly why netifaces was created > > https://pypi.org/project/netifaces/ Also if working with NetworkManager is required, nm has a python api: https://pythonhosted.org/python-networkmanager/ Grepping command-line tools is a time-honored unix tradition, but it can be fragile. From dieter at handshake.de Tue Nov 13 00:58:38 2018 From: dieter at handshake.de (dieter) Date: Tue, 13 Nov 2018 06:58:38 +0100 Subject: passing value from Python3 script back to RewriteMap MapType prg in Apache24 References: <948708831.225531.1542015580535@email.ionos.de> Message-ID: <87muqdmsc1.fsf@handshake.de> Benedikt Kroll writes: > Hi, > > using a Python script as a Rewrite Map with MapType prg in Apache 2.4, I'm having trouble > passing the value back to Apache. > > The log says "map lookup OK", but the value is empty. > > According to the Apache documentation (https://httpd.apache.org/docs/current/rewrite/rewritemap.html#prg), the script "should return one new-line terminated response string on STDOUT" which is then used as the rewrite target. > > I have tried to do this using: > sys.stdout.write(newValue + "/n") Should this not be "\n" rather than "/n"? > sys.stdout.flush() From srinivasan.rns at gmail.com Tue Nov 13 04:11:54 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 13 Nov 2018 10:11:54 +0100 Subject: Unable to get the gateway IP of wlan interface using python code In-Reply-To: References: Message-ID: Hi Wildman, The below snippet seems to be fine, how can I specify to get the specific wlan0 interface gateway IP in the below code snippet? ######################### #!/usr/bin/env python import socket import struct def get_gateway_ip(): try: with open("/proc/net/route", "r") as f: route = f.readlines() except IOError: return None for line in route: fields = line.strip().split() if fields[1] != "00000000" or not int(fields[3], 16) & 2: continue gateway = socket.inet_ntoa(struct.pack(" wrote: > I tried posting this already but it didn't make it. I am > trying again... > > On Tue, 13 Nov 2018 01:07:06 +0530, srinivasan wrote: > > > Dear Python Experts, > > > > *First method:* > > > > I need to get the IP address basically the gateway IP > > I am assuming your platform is Linux. If I am incorrect then > ignore this post. > > The code below reads /proc/net/route to obtain the gateway and > then prints it. It can be run as-is from a terminal. > > ######################### > #!/usr/bin/env python > > import socket > import struct > > def get_gateway_ip(): > try: > with open("/proc/net/route", "r") as f: > route = f.readlines() > except IOError: > return None > for line in route: > fields = line.strip().split() > if fields[1] != "00000000" or not int(fields[3], 16) & 2: > continue > gateway = socket.inet_ntoa(struct.pack(" break > return gateway > > print get_gateway_ip() > ######################### > > -- > GNU/Linux user #557453 > The cow died so I don't need your bull! > -- > https://mail.python.org/mailman/listinfo/python-list > From info at egenix.com Tue Nov 13 05:17:07 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 13 Nov 2018 11:17:07 +0100 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_07.11.2018?= Message-ID: [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG PyDDF Python Herbst Sprint 2018 in D?sseldorf Samstag, 17.11.2018, 10:00-18:00 Uhr Sonntag, 18.11.2018, 10:00-18:00 Uhr trivago N.V., Kesselstrasse 5-7, 40221 D?sseldorf Python Meeting D?sseldorf https://www.pyddf.de/sprint2018-11/ ________________________________________________________________________ INFORMATION Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher Unterst?tzung der *trivago N.V.* ein Python Sprint Wochenende. Der Sprint findet am Wochenende 17./18.11.2018 in der trivago Niederlassung im Medienhafen D?sseldorf statt (Achtung: Nicht mehr am Karl-Arnold-Platz). * Google Maps: https://goo.gl/maps/dGM6ThfkLiJ2 Folgende Themengebiete haben wir als Anregung angedacht: * Openpyxl - https://pythonhosted.org/openpyxl/ * SMS Forwarder - SMS an Email Adresse oder Chat weiterleiten * Python auf einem Raspberry Pi - Cluster * Django for Runners Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen. Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: https://www.pyddf.de/sprint2018-11/ WICHTIG: Ohne Anmeldung k?nnen wir kein Badge f?r den Geb?udezugang bereitstellen lassen. Eine spontane Anmeldung am Sprint Tag wird daher vermutlich nicht funktionieren. Also bitte unbedingt mit vollen Namen bis sp?testens Freitag, 16.11., anmelden. Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir uns dort koordinieren: https://www.egenix.com/mailman/listinfo/pyddf ________________________________________________________________________ ?BER UNS Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * https://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Nov 13 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From mystirk at gmail.com Tue Nov 13 07:54:46 2018 From: mystirk at gmail.com (Alex Kaye) Date: Tue, 13 Nov 2018 05:54:46 -0700 Subject: =?UTF-8?Q?Re=3A_ANN=3A_Python_Meeting_D=C3=BCsseldorf_=2D_07=2E11=2E2018?= In-Reply-To: References: Message-ID: Is anyone conducting Python webinars ? It would be helpful to us beginners. It could become a worldwide connector for Python users. Alex On Tue, Nov 13, 2018 at 3:21 AM eGenix Team: M.-A. Lemburg wrote: > > [This announcement is in German since it targets a local user group > meeting in D?sseldorf, Germany] > > ________________________________________________________________________ > > ANK?NDIGUNG > > PyDDF Python Herbst Sprint 2018 in > D?sseldorf > > > Samstag, 17.11.2018, 10:00-18:00 Uhr > Sonntag, 18.11.2018, 10:00-18:00 Uhr > > trivago N.V., Kesselstrasse 5-7, 40221 D?sseldorf > > Python Meeting D?sseldorf > https://www.pyddf.de/sprint2018-11/ > > ________________________________________________________________________ > > INFORMATION > > Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher > Unterst?tzung der *trivago N.V.* ein Python Sprint Wochenende. > > Der Sprint findet am Wochenende 17./18.11.2018 in der trivago > Niederlassung im Medienhafen D?sseldorf statt (Achtung: Nicht mehr am > Karl-Arnold-Platz). > > * Google Maps: https://goo.gl/maps/dGM6ThfkLiJ2 > > Folgende Themengebiete haben wir als Anregung angedacht: > > * Openpyxl - https://pythonhosted.org/openpyxl/ > * SMS Forwarder - SMS an Email Adresse oder Chat weiterleiten > * Python auf einem Raspberry Pi - Cluster > * Django for Runners > > Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen. > > Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: > > https://www.pyddf.de/sprint2018-11/ > > WICHTIG: Ohne Anmeldung k?nnen wir kein Badge f?r den Geb?udezugang > bereitstellen lassen. Eine spontane Anmeldung am Sprint Tag wird daher > vermutlich nicht funktionieren. Also bitte unbedingt mit vollen Namen > bis sp?testens Freitag, 16.11., anmelden. > > Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir > uns dort koordinieren: > > https://www.egenix.com/mailman/listinfo/pyddf > > ________________________________________________________________________ > > ?BER UNS > > Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung > in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: > > * https://pyddf.de/ > > Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, > auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: > > * http://www.youtube.com/pyddf/ > > Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, > in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: > > * http://www.egenix.com/ > * http://www.clark-consulting.eu/ > > Mit freundlichen Gr??en, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Experts (#1, Nov 13 2018) > >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ > >>> Python Database Interfaces ... http://products.egenix.com/ > >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ > ________________________________________________________________________ > > ::: We implement business ideas - efficiently in both time and costs ::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > http://www.malemburg.com/ > > > -- > https://mail.python.org/mailman/listinfo/python-list > From David.Raymond at tomtom.com Tue Nov 13 09:13:40 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 13 Nov 2018 14:13:40 +0000 Subject: Windows file associations fix In-Reply-To: References: Message-ID: Thank you for the detailed info. HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell only had "Edit with Pythonwin", and didn't have an "open" key. I added that in, along with one for the Python.NoConFile which was also missing "open", and it seems to be working happily now. Again, many thanks for the replies. -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of eryk sun Sent: Friday, November 09, 2018 6:43 PM To: Python Subject: Re: Windows file associations fix On 11/9/18, David Raymond wrote: > > And why does the Python installer have a check box for "Associate files with > Python" if it then promptly proceeds to destroy all those associations? > Could we maybe get that part of the installer fixed for future versions? The installer configures the HKCR setting to associate .py[w] files; however, it doesn't delete a user-choice setting in the shell. You should be able to restore the user choice to the launcher via the open-with -> choose another app dialog. Select the Python icon with a rocket on it (for py.exe; the python.exe icon has no rocket), enable the option to always use this application, and click ok. If that doesn't restore the association, you'll have to manually inspect and modify the settings. The following lists the shell's cached association for the .py file extension, including the user choice, if any: set "winkey=HKCU\Software\Microsoft\Windows\CurrentVersion" reg query %winkey%\Explorer\FileExts\.py /s Output: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\OpenWithList a REG_SZ py.exe MRUList REG_SZ a HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\OpenWithProgids Python.File REG_NONE HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.py\UserChoice Hash REG_SZ aA7ZxnDmUdM= ProgId REG_SZ Python.File Currently I have a UserChoice setting locked in. The permissions and hash value prevent us from modifying this key, but we can delete it, in which case the shell reverts to using the cached OpenWith* associations. Here's a command to delete this key (or use regedit if you prefer a GUI), where %winkey% was previously defined above: reg delete %winkey%\Explorer\FileExts\.py\UserChoice If we instead delete the FileExts\.py key, the shell recomputes the association from the underlying HKCR settings, where HKCR is a merged view of [HKLM | HKCU]\Software\Classes. If that doesn't solve the problem, check the default value of [HKCU | HKLM]\Software\Classes\.py, and its OpenWithProgIds subkey if defined. Python's installer associates .py files with the "Python.File" program identifier (progid). If that's set correctly, check [HKCU | HKLM]\Software\Classes\Python.File to ensure it's set up to use the py.exe launcher. For example, the following displays the default "open" command for the local-machine Python.File progid: reg query HKLM\Software\Classes\Python.File\shell\open\command Output: HKEY_LOCAL_MACHINE\Software\Classes\Python.File\shell\open\command (Default) REG_SZ "C:\Windows\py.exe" "%1" %* "%1" (or sometimes "%L") is the fully-qualified path of the target .py script, and %* has the command-line arguments, if any. As a side note, you've probably seen examples that use CMD's assoc and ftype commands (from NT 4.0, circa 1996). These commands work with HKLM\Software\Classes, which is fine for classic file associations configured for all users. However, they do not show or modify HKCU settings, and they're unaware of updates to how the shell works since XP/Vista such as HKCR\Applications, HKCR\SystemFileAssociations, and application capability file associations linked in [HKCU | HKLM]\Software\RegisteredApplications. > Currently: Windows 7. Attempting to run a .py file opens up the "Open with" > dialog with a bunch of other programs listed. Clicking browse to manually > select the new python.exe doesn't add it to the list and won't let me do the > association. You shouldn't manually associate .py files by browsing for py.exe or python.exe. If you do this, the system creates an automatic progid that only includes the "%1" target, without the %* command-line arguments. Typically this broken progid will be "HKCU\Software\Classes\Applications\py.exe", or "HKCU\Software\Classes\Applications\python.exe", or "HKCU\Software\Classes\py_auto_file". Delete these keys if they exist. -- https://mail.python.org/mailman/listinfo/python-list From info at egenix.com Tue Nov 13 09:26:30 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 13 Nov 2018 15:26:30 +0100 Subject: =?UTF-8?Q?Re:_[egenix-info]_Re:_ANN:_Python_Meeting_D=c3=bcsseldorf?= =?UTF-8?Q?_-_07.11.2018?= In-Reply-To: References: Message-ID: <40cb7641-cfff-726a-6144-59f096f39f81@egenix.com> On 13.11.2018 13:54, Alex Kaye wrote: > Is anyone conducting? > Python webinars ? It would be helpful > to us beginners. It could become a worldwide > connector for Python users. This page should provide some good entry points: https://wiki.python.org/moin/BeginnersGuide You can also have a look at the training page: https://wiki.python.org/moin/PythonTraining https://wiki.python.org/moin/PythonTraining/Events Cheers, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Nov 13 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ > Alex > > On Tue, Nov 13, 2018 at 3:21 AM eGenix Team: M.-A. Lemburg > > wrote: > > > [This announcement is in German since it targets a local user group > ?meeting in D?sseldorf, Germany] > > ________________________________________________________________________ > > ANK?NDIGUNG > > ? ? ? ? ? ? ? ? ? PyDDF Python Herbst Sprint 2018 in > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? D?sseldorf > > > ? ? ? ? ? ? ? ? ?Samstag, 17.11.2018, 10:00-18:00 Uhr > ? ? ? ? ? ? ? ? ?Sonntag, 18.11.2018, 10:00-18:00 Uhr > > ? ? ? ? ? trivago N.V., Kesselstrasse 5-7, 40221 D?sseldorf > > ? ? ? ? ? ? ? ? ? ? ? Python Meeting D?sseldorf > ? ? ? ? ? ? ? ? ?https://www.pyddf.de/sprint2018-11/ > > ________________________________________________________________________ > > INFORMATION > > Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher > Unterst?tzung der *trivago N.V.* ein Python Sprint Wochenende. > > Der Sprint findet am Wochenende 17./18.11.2018 in der trivago > Niederlassung im Medienhafen D?sseldorf statt (Achtung: Nicht mehr am > Karl-Arnold-Platz). > > ?* Google Maps: https://goo.gl/maps/dGM6ThfkLiJ2 > > Folgende Themengebiete haben wir als Anregung angedacht: > > ?* Openpyxl - https://pythonhosted.org/openpyxl/ > ?* SMS Forwarder - SMS an Email Adresse oder Chat weiterleiten > ?* Python auf einem Raspberry Pi - Cluster > ?* Django for Runners > > Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen. > > Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: > > ? ? https://www.pyddf.de/sprint2018-11/ > > WICHTIG: Ohne Anmeldung k?nnen wir kein Badge f?r den Geb?udezugang > bereitstellen lassen. Eine spontane Anmeldung am Sprint Tag wird daher > vermutlich nicht funktionieren. Also bitte unbedingt mit vollen Namen > bis sp?testens Freitag, 16.11., anmelden. > > Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir > uns dort koordinieren: > > ? ? https://www.egenix.com/mailman/listinfo/pyddf > > ________________________________________________________________________ > > ?BER UNS > > Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung > in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: > > ?* https://pyddf.de/ > > Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, > auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: > > ?* http://www.youtube.com/pyddf/ > > Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, > in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: > > ?* http://www.egenix.com/ > ?* http://www.clark-consulting.eu/ > > Mit freundlichen Gr??en, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Experts (#1, Nov 13 2018) > >>> Python Projects, Coaching and Consulting ...? http://www.egenix.com/ > >>> Python Database Interfaces ...? ? ? ? ? ?http://products.egenix.com/ > >>> Plone/Zope Database Interfaces ...? ? ? ? ? ?http://zope.egenix.com/ > ________________________________________________________________________ > > ::: We implement business ideas - efficiently in both time and costs ::: > > ? ?eGenix.com Software, Skills and Services GmbH? Pastor-Loeh-Str.48 > ? ? D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > ? ? ? ? ? ?Registered at Amtsgericht Duesseldorf: HRB 46611 > ? ? ? ? ? ? ? ?http://www.egenix.com/company/contact/ > ? ? ? ? ? ? ? ? ? ? ? http://www.malemburg.com/ > > > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Tue Nov 13 09:47:40 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 13 Nov 2018 15:47:40 +0100 Subject: Unable to get the gateway IP of wlan interface using python code In-Reply-To: References: Message-ID: As am a beginner with the python Syntax, I was able to parse the gateway IP as below, Please do let me know if anyone forsee any issues in the below?: def get_gateway_ip(self): """ Get the Gateway IP address of the AP. :return: Gateway IP. """ cmd = '/sbin/ifconfig wlp1s0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1' f = os.popen(cmd) ip_address = f.read().strip() list_ = ip_address.split('.') assert len(list_) == 4 list_[3] = '1' return '.'.join(list_) With the above return value I was able to pass the gateway IP to my robot framework, and process further Many Thanks in advance, Srini On Tue, Nov 13, 2018 at 10:11 AM srinivasan wrote: > Hi Wildman, > > The below snippet seems to be fine, how can I specify to get the specific > wlan0 interface gateway IP in the below code snippet? > > ######################### > #!/usr/bin/env python > > import socket > import struct > > def get_gateway_ip(): > try: > with open("/proc/net/route", "r") as f: > route = f.readlines() > except IOError: > return None > for line in route: > fields = line.strip().split() > if fields[1] != "00000000" or not int(fields[3], 16) & 2: > continue > gateway = socket.inet_ntoa(struct.pack(" break > return gateway > > print get_gateway_ip() > ######################### > > > Many Thanks in advance, > Srini > > > On Tue, Nov 13, 2018 at 5:16 AM Wildman via Python-list < > python-list at python.org> wrote: > >> I tried posting this already but it didn't make it. I am >> trying again... >> >> On Tue, 13 Nov 2018 01:07:06 +0530, srinivasan wrote: >> >> > Dear Python Experts, >> > >> > *First method:* >> > >> > I need to get the IP address basically the gateway IP >> >> I am assuming your platform is Linux. If I am incorrect then >> ignore this post. >> >> The code below reads /proc/net/route to obtain the gateway and >> then prints it. It can be run as-is from a terminal. >> >> ######################### >> #!/usr/bin/env python >> >> import socket >> import struct >> >> def get_gateway_ip(): >> try: >> with open("/proc/net/route", "r") as f: >> route = f.readlines() >> except IOError: >> return None >> for line in route: >> fields = line.strip().split() >> if fields[1] != "00000000" or not int(fields[3], 16) & 2: >> continue >> gateway = socket.inet_ntoa(struct.pack("> break >> return gateway >> >> print get_gateway_ip() >> ######################### >> >> -- >> GNU/Linux user #557453 >> The cow died so I don't need your bull! >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From countryone77 at gmail.com Tue Nov 13 10:51:34 2018 From: countryone77 at gmail.com (Bev in TX) Date: Tue, 13 Nov 2018 09:51:34 -0600 Subject: IDLE Default Working Directory In-Reply-To: References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> Message-ID: <7FB351A4-327B-4DFA-89F3-53DEEF6F0B37@gmail.com> > On Nov 12, 2018, at 5:50 PM, Terry Reedy wrote: > > For me, open (command-O) opens 'Documents'. I presume it should be easy enough to move into a 'py' subfolder. The whole point is for Idle -> File -> Open (or command-O) to automatically open to a specific folder. Bev in TX From countryone77 at gmail.com Tue Nov 13 11:33:07 2018 From: countryone77 at gmail.com (Bev in TX) Date: Tue, 13 Nov 2018 10:33:07 -0600 Subject: IDLE Default Working Directory In-Reply-To: <1542038849.5527.1.camel@gmail.com> References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> <1542038849.5527.1.camel@gmail.com> Message-ID: > On Nov 12, 2018, at 10:07 AM, Brian Oney wrote: > > On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote: >> I am not the OP and I?m on macOS ? no shortcuts. How would one do the same thing on other platforms? >> Bev in TX > Hello there, > > I am not an IDLE user. You may try a startup script from python, as per the following. > > oney at oney :~$ cat pyhelp/change_to_current_dir.py > #!/usr/bin/env python3 > > import os > import sys > > os.chdir(os.path.dirname(os.path.abspath(__file__))) > Thanks so much for taking the time and effort to provide that script. I experimented with it, but it does not work as desired in Idle. I tried: * Changed to project directory and then opened Idle Idle -> File-> Open still opens ~/Documents ? not the project folder. * Placed the change folder script in ~/Documents, opened it in Idle and ran it Idle did not change to the project folder ? it stayed in whichever folder the change folder script resided. Unless someone can come up with a better option for macOS, the best that I can think of is to add the project folder to the side bar so that it is easier to access it in Idle -> File -> Open. Bev in TX From benedikt.kroll at der-arbeitende.de Tue Nov 13 16:05:25 2018 From: benedikt.kroll at der-arbeitende.de (Benedikt Kroll) Date: Tue, 13 Nov 2018 22:05:25 +0100 Subject: passing value from Python3 script back to RewriteMap MapType prg in Apache24 In-Reply-To: References: <948708831.225531.1542015580535@email.ionos.de> Message-ID: Thank you for your responses! The solution I just found is the following: Even though the python script has the necessary execute permissions, the RewriteMap definition required that the python interpreter is included in the Apache config file: RewriteMap extrw "prg:/usr/bin/python3 /opt/extrw.py" Now it worked using this script: while True: arg = sys.stdin.readline() # makes sense, but will work without newValue = "/index.html" # placeholder for testing sys.stdout.write(newValue + "\n") sys.stdout.flush() Am 12.11.18 um 23:57 schrieb MRAB: > On 2018-11-12 09:39, Benedikt Kroll wrote: >> Hi, >> >> using a Python script as a Rewrite Map with MapType prg in Apache 2.4, >> I'm having trouble >> passing the value back to Apache. >> >> The log says "map lookup OK", but the value is empty. >> >> According to the Apache documentation >> (https://httpd.apache.org/docs/current/rewrite/rewritemap.html#prg), >> the script "should return one new-line terminated response string on >> STDOUT" which is then used as the rewrite target. >> >> I have tried to do this using: >> sys.stdout.write(newValue + "/n") >> sys.stdout.flush() >> >> However, Apache receives only an empty return value (with no error). >> >> On Stackoverflow and others, I found and tried out some examples, which >> in some cases where quite old, so probably written for older versions. >> >> The following is what I extracted from the more current hints I could >> find. >> >> >> *.conf >> RewriteEngine On >> RewriteMap extrw "prg:/opt/extrw.py" >> RewriteRule "^(.*)" "${extrw:%{REQUEST_URI}}" >> >> >> /opt/extrw.py >> import sys >> while True: >> ??? newValue = "/index.html" # placeholder for testing >> ??? sys.stdout.write(newValue + "/n") >> ??? sys.stdout.flush() >> >> >> log for curl 127.0.0.1/abc >> init rewrite engine with requested uri /abc >> applying pattern '^(.*)' to uri '/abc' >> map lookup OK: map=extrw key=/abc -> val= >> rewrite '/abc' -> '' >> local path result: >> >> >> The expected result would be to have "map lookup OK: map=extrw key=/abc >> -> val=/index.html" in the third line. >> >> Any help would be appreciated! >> > The examples I've found are also reading from stdin, so I'd suggest > trying that: > > import sys > > while True: > ??? arg = sys.stdin.readline() > ??? newValue = "/index.html" # placeholder for testing > ??? sys.stdout.write(newValue + "/n") > ??? sys.stdout.flush() From kai.peters at gmail.com Tue Nov 13 19:35:10 2018 From: kai.peters at gmail.com (TUA) Date: Tue, 13 Nov 2018 16:35:10 -0800 (PST) Subject: Peewee ORM questions Message-ID: <1962c367-22b5-43fd-9345-4f2f18025bc5@googlegroups.com> Hi all, couldn't find a group for Peewee, so here I am: Given a table structure of {'id': , 'username': , 'password': , 'created': , 'updated': } Using playhouse.shortcuts: def ListAll(model): for row in model.select(): print(model_to_dict(row, exclude = (row.created, row.updated))) still returns the created and updated columns.... Broken? Or - way more likely - something I am doing wrong? Thanks for all help! Tua From kai.peters at gmail.com Tue Nov 13 20:08:58 2018 From: kai.peters at gmail.com (TUA) Date: Tue, 13 Nov 2018 17:08:58 -0800 (PST) Subject: Peewee ORM questions In-Reply-To: <1962c367-22b5-43fd-9345-4f2f18025bc5@googlegroups.com> References: <1962c367-22b5-43fd-9345-4f2f18025bc5@googlegroups.com> Message-ID: <817e13c0-a12d-438e-9efe-a598c81038c1@googlegroups.com> Brainfart has left the building print(model_to_dict(row, exclude = (row.created, row.updated))) should have been print(model_to_dict(row, exclude = (model.created, model.updated))) From plucena24 at gmail.com Tue Nov 13 20:43:00 2018 From: plucena24 at gmail.com (Pablo Lucena) Date: Tue, 13 Nov 2018 17:43:00 -0800 Subject: distribute python interpreter and dependencies In-Reply-To: References: Message-ID: After changing PATH variable; are you ensuring that the failed hosts are using the new PATH vs the old one? I've seen different behavior on different Windows versions for what it takes to "refresh" the env. System vs User defined env may also affect this, depending on the user invoking your program (windows versions have different behaviors from my experience) Also may depend on 32 vs 64 bit? But sounds like this isn't the issue. Also seen issues related to having the same Visual Studio files on client machines as was used to compile the version of python your distributing. Just a few thoughts. On Mon, Nov 12, 2018 at 4:11 PM Thomas Jollans wrote: > On 12/11/2018 17:40, Juan Crist?bal Quesada wrote: > > Hello, > > this is my first mail. I resorted to the list after some prior > struggling. > > Welcome! > > > Im facing the need to distribute a python installation folder and > > interpreter in a shared network drive. > > > > Im also distributing the application's source code that would lie also in > > another network drive. > > > > For this, my attempts have gone towards replicating the python > installation > > folder created after installing python27 in one machine and copy all the > > files and directories to the network drive. After that, copied the > > python27.dll of the C:/Windows/System32 file and set all the > > Python27/lib;Python27/DLLs/Python27/Scripts....... to the PATH > environment > > variable through a launcher script. > > I assume you have a good reason to want to use an old version of Python... > > > > > This works on my machine and a couple others....BUT, not in some other > > machines running as well windows 10 pro..... > > In what way does it not work? Is there an error message? > > > So i investigated a bit and > > discovered that if i install the python27 (2.7.11 same version) in one of > > those failing machines... the "ctypes.pyd" module's filesize is > > different.... So i replaced the original python27 folders with those of > the > > new installed python and now it works on those machines..........havent > > tried yet if it still works on the first ones... > > > > Why is this behaviour? Im guessing the python27 installer generates some > > dlls "on the fly" that are tied to the windows operating > system........... > > > > I dont want to create a windows executable via py2exe or > > pyinstaller.......... What are the best steps to make a python > interpreter > > available to all windows based different machines? Am i missing something > > else? What are the steps the python windows installer performs in order? > > I have no idea what the Python.org installer is doing here, but you > could try one of the other Python distributions (e.g. miniconda)... > MAYBE you'll have more luck with that (Or ActivePython, or WinPython, or > whatever). > > > -- Thomas > -- > https://mail.python.org/mailman/listinfo/python-list > -- *Pablo Lucena* From dvl at psu.edu Tue Nov 13 21:04:34 2018 From: dvl at psu.edu (Christman, Roger Graydon) Date: Wed, 14 Nov 2018 02:04:34 +0000 Subject: IDLE Default Working Directory Message-ID: On 13 Nov 2018, at 09:51, Bev in TX wrote: ________________________________ > On Nov 12, 2018, at 5:50 PM, Terry Reedy wrote: > > For me, open (command-O) opens 'Documents'. I presume it should be easy enough to move into a 'py' subfolder. The whole point is for Idle -> File -> Open (or command-O) to automatically open to a specific folder. Bev in TX Thank you, Bev in TX for clarifying my question. That is indeed what I seek. My course has proved cumbersome every time a student created a new program in class, since they would have to change folders. And when I got to working with data files, I ended up with a little punt to avoid having to specify a complete path name to get to a workable directory. My students are not programmers. I have English majors, Education majors, and students in their first year at a University. I won't say they are completely computer-illiterate, they can use a browser well enough. But I expect none of them to have ever seen the command line, so I really don't want to go that route. As far as activating IDLE on this Windows 10 system, I go down to the search bar at the bottom left, type 'IDLE', and then up comes a list of various installations we have lying around, including 2.7, 3.4, and 3.6 versions. I have them just select the 3.6 version from the list to launch IDLE. I don't consider that quite the same as using a 'shortcut', since we are not clicking on any icon on the desktop. I am not on the campus-wide labs right now, so I cannot really say much further -- and I haven't tried right-clicking on those items to see if configuration options show up, to talk to the %AppData% path, etc. The Penn State computer labs are networked -- each computer has a C: drive, which I presume might be local to each machine -- but in any case, I think it is read-only to the students. And since they could easily sit down at a different machine on any day, I wouldn't want to rely on any configuration file or anything on the C drive anyway. There is a networked U: drive (for users) that is campus wide, which is useful. There is also a virtual V: drive, which simply maps to each individual's folder set aside for them on the U: drive. That place would be ideal for my purposes as a place to save code and data files. But the default directory is somewhere else. I would have to get back on campus before I can quote exactly, but wherever it is a readonly file space that's not the Desktop or My Documents, or who knows what. I'd preferably like to reset the default to the V: drive (or even create a Python folder on that virtual V: drive). And the real challenge is to come up with the simplest solution that I can explain or show to first-time programming students in under a minute, which therefore does not involve the command-line interface. I don't want to scare half the students away in the very first class, just trying to configure their development environment. If that's impossible, then I guess I'll have to fire a note off to the university tech support requesting them to play with that "Start In" option through %AppData%, or whatever it was. Roger Christman Pennsylvania State University From prosperogreat at gmail.com Wed Nov 14 02:06:36 2018 From: prosperogreat at gmail.com (Prospero Akai) Date: Wed, 14 Nov 2018 08:06:36 +0100 Subject: Unable to install Python on my windows 8 PC Message-ID: I forgot to check the 'Add To Path' box while installing python from www.python.org. I uninstalled then try to install again but I have been getting this error message since then: one or more issues caused the setup to fail. please fix the issues and then retry setup. for more info see the log file. 0x80072ee7-Unspecified error I will appreciate your response. (Akai, Nigeria) From brian.j.oney at googlemail.com Wed Nov 14 03:43:13 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 14 Nov 2018 09:43:13 +0100 Subject: IDLE Default Working Directory In-Reply-To: References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> <1542038849.5527.1.camel@gmail.com> Message-ID: <1542184993.2752.1.camel@gmail.com> On Tue, 2018-11-13 at 10:33 -0600, Bev in TX wrote: > > On Nov 12, 2018, at 10:07 AM, Brian Oney wrote: > > On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote: > > > I am not the OP and I?m on macOS ? no shortcuts. How would one do the same thing on other platforms? > > > Bev in TX > > Hello there, > > I am not an IDLE user. You may try a startup script from python, as per the following. > > oney at oney:~$ cat pyhelp/change_to_current_dir.py?#!/usr/bin/env python3 > > import osimport sys > > os.chdir(os.path.dirname(os.path.abspath(__file__))) > > Thanks so much for taking the time and effort to provide that script. ?I experimented with it, but it does not work as desired in Idle. ?I tried:* Changed to project directory and then opened Idle > ? ? ?Idle -> File-> Open still opens ~/Documents ? not the project folder. > * Placed the change folder script in ~/Documents, opened it in Idle and ran it? > ? ? ?Idle did not change to the project folder ? it stayed in whichever folder the change folder script resided. > > Unless someone can come up with a better option for macOS, the best that I can think of is to add the project folder to the side bar so that it is easier to access it in Idle -> File -> Open. > ? ? ? Hi Bev The idea is to put that script in the project folder. You could begin your lecture with an introduction to the import system and command line. The script needs to reside in the desired directory. Once that is the case you would import it: import path.to.script.sans.py.ending It may be to much to ask of students. It's easiest to put that script in the project folder. You know have everthing in the same place, where students can copy that directory, take it whereever there is python installed, run that script, and pick up where they left off. If you want to control where the directory changes to do this: #!/usr/bin/env python3 import os os.chdir('path/to/project/directory') That is brittle though. What if the student don't all have access to that directory? What if they fail to put the project directory in the right place? What if the network drives are down and you end up working locally? You could send them a zip-file of everything including my first suggestion and it would just work. HTH From srinivasan.rns at gmail.com Wed Nov 14 03:47:08 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 14 Nov 2018 09:47:08 +0100 Subject: All of a sudden code started throwing errors Message-ID: Dear Python Experts Could you please let me know why am I seeing the following errors as before this it was working consistently? root:~/qa/robot_tests# python3 -m robot --variable SIGNAL_LEVEL_THRESHOLD:-60 wifi_testing.robot ============================================================================== Wifi Testing :: This is the Maschine Native OS Build Wi-Fi Test. ============================================================================== Initialize Wi-Fi Module | PASS | ------------------------------------------------------------------------------ Enable Wi-Fi Module | PASS | ------------------------------------------------------------------------------ Connect Wi-Fi Module to SSID | PASS | ------------------------------------------------------------------------------ Check for Wi-Fi Connectivity | PASS | ------------------------------------------------------------------------------ Log Wi-Fi Module IP | PASS | ------------------------------------------------------------------------------ Get Gateway IP and Check Whether Wi-Fi is Pingable | PASS | ------------------------------------------------------------------------------ Check for Wi-Fi Signal Strength with Threshold | FAIL | '-68 >= -60' should be true. ------------------------------------------------------------------------------ Wifi Testing :: This is the Maschine Native OS Build Wi-Fi Test. | FAIL | 7 critical tests, 6 passed, 1 failed 7 tests total, 6 passed, 1 failed ============================================================================== Output: /home/root/qa/robot_tests/output.xml Log: /home/root/qa/robot_tests/log.html Report: /home/root/qa/robot_tests/report.html root:~/qa/robot_tests# cat /proc/net/wireless Inter-| sta-| Quality | Discarded packets | Missed | WE face | tus | link level noise | nwid crypt frag retry misc | beacon | 22 wlp1s0: 0000 44. -66. -256 0 0 0 0 9 0 Errors: ===== root:~/qa/robot_tests# python3 -m robot --variable SIGNAL_LEVEL_THRESHOLD:-70 wifi_testing.robot Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.5/runpy.py", line 142, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details __import__(pkg_name) File "/usr/lib/python3.5/site-packages/robot/__init__.py", line 41, in from robot.rebot import rebot, rebot_cli File "/usr/lib/python3.5/site-packages/robot/rebot.py", line 40, in from robot.conf import RebotSettings File "/usr/lib/python3.5/site-packages/robot/conf/__init__.py", line 27, in from .settings import RobotSettings, RebotSettings File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 33, in class _BaseSettings(object): File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 46, in _BaseSettings 'OutputDir' : ('outputdir', abspath('.')), File "/usr/lib/python3.5/site-packages/robot/utils/robotpath.py", line 84, in abspath return normpath(_abspath(path), case_normalize) File "/usr/lib/python3.5/posixpath.py", line 362, in abspath cwd = os.getcwd() FileNotFoundError: [Errno 2] No such file or directory root:~/qa/robot_tests# cat /proc/net/wireless Inter-| sta-| Quality | Discarded packets | Missed | WE face | tus | link level noise | nwid crypt frag retry misc | beacon | 22 wlp1s0: 0000 45. -65. -256 0 0 0 0 12 0 root:~/qa/robot_tests# python3 -m robot wifi_testing.robot Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.5/runpy.py", line 142, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details __import__(pkg_name) File "/usr/lib/python3.5/site-packages/robot/__init__.py", line 41, in from robot.rebot import rebot, rebot_cli File "/usr/lib/python3.5/site-packages/robot/rebot.py", line 40, in from robot.conf import RebotSettings File "/usr/lib/python3.5/site-packages/robot/conf/__init__.py", line 27, in from .settings import RobotSettings, RebotSettings File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 33, in class _BaseSettings(object): File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 46, in _BaseSettings 'OutputDir' : ('outputdir', abspath('.')), File "/usr/lib/python3.5/site-packages/robot/utils/robotpath.py", line 84, in abspath return normpath(_abspath(path), case_normalize) File "/usr/lib/python3.5/posixpath.py", line 362, in abspath cwd = os.getcwd() FileNotFoundError: [Errno 2] No such file or directory root:~/qa/robot_tests# From brian.j.oney at googlemail.com Wed Nov 14 04:34:17 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 14 Nov 2018 10:34:17 +0100 Subject: All of a sudden code started throwing errors In-Reply-To: References: Message-ID: <1542188057.3826.1.camel@gmail.com> On Wed, 2018-11-14 at 09:47 +0100, srinivasan wrote: > -68 >= -60 It's a problem with your test of wifi strength. Good job of making informative output and running tests! From countryone77 at gmail.com Wed Nov 14 07:02:54 2018 From: countryone77 at gmail.com (Bev in TX) Date: Wed, 14 Nov 2018 06:02:54 -0600 Subject: IDLE Default Working Directory In-Reply-To: <1542184993.2752.1.camel@gmail.com> References: <5399B4EE-1E99-44C1-BDB5-0EC403FDC047@gmail.com> <1542038849.5527.1.camel@gmail.com> <1542184993.2752.1.camel@gmail.com> Message-ID: Thanks for taking the time to respond, but I?m not certain that we are on the same page. Every time you start Idle, its File -> Open dialog points to the same default location (on MacOS that is ~/Documents). When you open a project?s file from another location, Idle remembers that new folder the next time that you use File -> Open. However, it only does so during the current Idle session. The next time you start Idle, you again have to traverse to your project?s folder. The question is how to change Idle?s default File -> Open folder, so that one doesn?t have to traverse to the project?s folder every time one starts Idle. The OP is teaching a class on Windows. A possible solution of modifying Idle?s startup folder in a shortcut was pointed out to the OP -- that was Windows specific. Given my own little experiments, I?m not sure that Idle even pays attention to its startup folder, but that may work differently on Windows, so I can?t say for certain. I only use macOS, so I wondered how to make Idle do the something similar on macOS (hence one reply to me mentioning using command-O, rather than ctrl-O, as would probably be used on Windows). On macOS, I suggested adding the project folder to the side bar so that it is easier to access it in theIdle -> File -> Open dialog. One could alternatively add an alias to the project folder in ~/Documents. That would cut folder traversal down to one easily accessed level. I suppose a similar thing could be done on Windows by adding a shortcut to the project folder in whatever the default File -> Open folder is on that platform. > On Nov 14, 2018, at 2:43 AM, Brian Oney wrote: > ... > The idea is to put that script in the project folder. > > You could begin your lecture with an introduction to the import system and command line. The script needs to reside in the desired directory. Once that is the case you would import it: > > import path.to.script.sans.py.ending > AFAIK, one cannot specify a path on the import statement? The following discussion indicates it?s not so straight forward... https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path I?m also not sure as to how this affects Idle?s File -> Open dialog? > It may be to much to ask of students. It's easiest to put that script in the project folder. You know have everthing in the same place, where students can copy that directory, take it whereever there is python installed, run that script, and pick up where they left off. > > If you want to control where the directory changes to do this: > > #!/usr/bin/env python3 > > import os > os.chdir('path/to/project/directory') > Again, doing this has no affect in Idle -> File -> Open > That is brittle though. What if the student don't all have access to that directory? What if they fail to put the project directory in the right place? What if the network drives are down and you end up working locally? > > You could send them a zip-file of everything including my first suggestion and it would just work. Bev in TX From __peter__ at web.de Wed Nov 14 08:51:59 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Nov 2018 14:51:59 +0100 Subject: All of a sudden code started throwing errors References: Message-ID: srinivasan wrote: > Dear Python Experts > > Could you please let me know why am I seeing the following errors as > before this it was working consistently? > cwd = os.getcwd() > FileNotFoundError: [Errno 2] No such file or directory > root:~/qa/robot_tests# Steps to reproduce the problem: $ mkdir ~/foo $ cd foo $ python3.4 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath(".") '/home/peter/foo' >>> os.rmdir("/home/peter/foo") >>> os.path.abspath(".") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/posixpath.py", line 361, in abspath cwd = os.getcwd() FileNotFoundError: [Errno 2] No such file or directory Diagnosis: you managed to remove your current working directory, probably because you used os.chdir() to switch to a temporary directory and then forgot to switch back. Solution: don't do that ;) I recommend that you avoid chdir() in your code and instead always include the directory into the filename. From srinivasan.rns at gmail.com Wed Nov 14 10:15:57 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Wed, 14 Nov 2018 16:15:57 +0100 Subject: Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) Message-ID: Dear Python Experts, As am newbie to python, I am planning to automate BT functionality test using Bluez "bluetoothctl" utility by writing python wrapper and robot framework integrated with Jenkins I came across the below link: https://www.reddit.com/r/raspberry_pi/comments/4bxu2o/bluetoothctl_in_python_program/ In the above link, I saw the below code snippet *code:* *from sh import bluetoothctl* *mac = "AA:BB:CC:DD:EE"* *bluetoothctl("connect",mac)* And firstly I wanted to verify BT functionality with my PC and the bluetooth device (basically turned on BT option in my phone and trying to discover my phone as a BT device) And I have installed the below packages in my ubuntu 18.04 desktop PC $* pip3 install sh* Collecting sh Downloading https://files.pythonhosted.org/packages/4a/22/17b22ef5b049f12080f5815c41bf94de3c229217609e469001a8f80c1b3d/sh-1.12.14-py2.py3-none-any.whl Installing collected packages: sh Successfully installed sh-1.12.14 *$ pip3 install bluetoothctl* *Collecting bluetoothctl* * Could not find a version that satisfies the requirement bluetoothctl (from versions: )* *No matching distribution found for bluetoothctl* $ *pip3 install pexpect* Collecting pexpect Downloading https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl (57kB) 100% |????????????????????????????????| 61kB 1.5MB/s Collecting ptyprocess>=0.5 (from pexpect) Downloading https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl Installing collected packages: ptyprocess, pexpect Successfully installed pexpect-4.6.0 ptyprocess-0.6.0 $ When I try to paste the below code on pycharm and try to point on the word "bluetoothctl" in the beginning of the line "*from sh import bluetoothctl*" *from sh import bluetoothctl* *mac = "your bluetooth mac"* *bluetoothctl("connect", mac)* In the pycharm, I see the below error message : *Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) * *Inspection info: This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.* Could you please help me to resolve the above issue, like why am I seeing the above issue it seems to be some importing "bluetoothhctl" module issue (sorry if my understanding is wrong) Kindly do the needful Many Thanks in advance From m at funkyhat.org Wed Nov 14 15:10:42 2018 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 14 Nov 2018 20:10:42 +0000 Subject: All of a sudden code started throwing errors In-Reply-To: References: Message-ID: <49C5C430-ECEE-4EA2-BE53-D6FB2615AFD1@funkyhat.org> > On 14 Nov 2018, at 13:51, Peter Otten <__peter__ at web.de> wrote: > > Diagnosis: you managed to remove your current working directory, probably > because you used os.chdir() to switch to a temporary directory and then > forgot to switch back. > > Solution: don't do that ;) > > I recommend that you avoid chdir() in your code and instead always include > the directory into the filename. A pattern I find myself using frequently, when I do need to ?cd?, is to write a tiny context manager: ``` import os from contextlib import context manager @contextmanager def pushd(path): old_dir = os.getcwd() os.chdir(path) try: yield finally: os.chdir(old_dir) ``` (I tend to just copy this into projects where I need it (or write it again), as a whole dependency for something so tiny seems like it would be overkill :) -- Matt Wheeler http://funkyh.at From Irv at furrypants.com Wed Nov 14 19:20:07 2018 From: Irv at furrypants.com (Irv Kalb) Date: Wed, 14 Nov 2018 16:20:07 -0800 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: <887966BA-DF07-4B00-8EFB-95BF9BF89B7F@furrypants.com> > On Nov 13, 2018, at 6:04 PM, Christman, Roger Graydon wrote: > > On 13 Nov 2018, at 09:51, Bev in TX wrote: > ________________________________ >> On Nov 12, 2018, at 5:50 PM, Terry Reedy wrote: >> >> For me, open (command-O) opens 'Documents'. I presume it should be easy enough to move into a 'py' subfolder. > > The whole point is for Idle -> File -> Open (or command-O) to automatically open to a specific folder. > > Bev in TX > > > Thank you, Bev in TX for clarifying my question. That is indeed what I seek. My course has proved cumbersome every time a student created a new program in class, since they would have to change folders. And when > > I got to working with data files, I ended up with a little punt to avoid having to specify a complete path name to get to a workable directory. > > > My students are not programmers. I have English majors, Education majors, and students in their first year at a University. I won't say they are completely computer-illiterate, they can use a browser well enough. But I expect none of them to have ever seen the command line, so I really don't want to go that route. > > > > > And the real challenge is to come up with the simplest > > solution that I can explain or show to first-time programming students in under a minute, which therefore does not involve the command-line interface. > I teach a similar set of students, using IDLE. (Most have never seen or want to see a command line.) I teach in both Mac and Windows classrooms. I rarely, if ever use Command/Control O to open a Python file. On Windows systems, I ask students to find the file that they want to open in the Windows Explorer, right click, and select Edit with IDLE (usually the second item in the context menu). On a Mac, the computers are often set up to open Xcode as the default. I show the whole class how to select any Python source file sing the Finder, do a Get Info (Command I), change the default application to IDLE, and do a Change All. Once that is done, students just double click on any file with a .py extension and opens it in IDLE. When working with data files, I tell students to put their project (their main program and any other related files) in a folder. Then, in their calls to "open", I tell them to just give the name of the data file e.g., 'MyData.txt', or a path relative from the current folder, e.g., 'MyData/DataFile.txt'. That makes things simple in a teaching environment and works on both Macs and Windows. Maybe not what you were looking for, but I hope it helps, Irv From dieter at handshake.de Thu Nov 15 01:08:32 2018 From: dieter at handshake.de (dieter) Date: Thu, 15 Nov 2018 07:08:32 +0100 Subject: Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) References: Message-ID: <87ftw2rhy7.fsf@handshake.de> srinivasan writes: > As am newbie to python, I am planning to automate BT functionality test > using Bluez "bluetoothctl" utility by writing python wrapper and robot > framework integrated with Jenkins > ... > *$ pip3 install bluetoothctl* > *Collecting bluetoothctl* > * Could not find a version that satisfies the requirement bluetoothctl > (from versions: )* > *No matching distribution found for bluetoothctl* "pip[*]" is a tool to install Python packages -- typically from the Python package index (-->"https://pypi.org"). The error message above indicates that "bluetoothctl" is not managed by this package index. I assume that it is not a Python package at all (but rather some command line utility in some operating system package). At least on my Ubuntu 18.04, "bluetoothctl" is an operating system utility. *from sh import bluetoothctl* *mac = "your bluetooth mac"* *bluetoothctl("connect", mac)* > In the pycharm, I see the below error message : > > *Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) * > *Inspection info: This inspection detects names that should resolve but > don't. Due to dynamic dispatch and duck typing, this is possible in a > limited but useful number of cases. Top-level and class-level items are > supported better than instance items.* > > Could you please help me to resolve the above issue, like why am I seeing > the above issue it seems to be some importing "bluetoothhctl" module issue > (sorry if my understanding is wrong) I do not know the "sh" package. It might be a utility that turns a command line utility into a Python callable -- implicitely on "import" of the corresponding name. If this is the case, it may confuse "PyCharm" (which does not expect such dynamism). You could then safely ignore this confusion. Try to execute your code. Should you get an exception (e.g. an `ImportError: cannot import "bluetoothctl" from module "sh"`), then come back. From dieter at handshake.de Thu Nov 15 01:10:37 2018 From: dieter at handshake.de (dieter) Date: Thu, 15 Nov 2018 07:10:37 +0100 Subject: Unable to install Python on my windows 8 PC References: Message-ID: <87bm6qrhuq.fsf@handshake.de> Prospero Akai writes: > I forgot to check the 'Add To Path' box while installing python from > www.python.org. I uninstalled then try to install again but I have been > getting this error message since then: > > one or more issues caused the setup to fail. please fix the issues and then > retry setup. for more info see the log file. > > 0x80072ee7-Unspecified error When I remember right, then modern Python versions require Windows 10. Check the installation requirements for the Python version you try to install. Older Python versions supported older Windows versions. Again, the installation requirements should tell you which. From prosperogreat at gmail.com Thu Nov 15 01:16:09 2018 From: prosperogreat at gmail.com (Prospero Akai) Date: Thu, 15 Nov 2018 07:16:09 +0100 Subject: Python Setup failed on Windows 8 Message-ID: I forgot to check the 'Add To Path' box while installing python from www.python.org on my windows 8 PC. I uninstalled then try to install again but I have been getting this error message: 0x80072ee7-Unspecified error I will appreciate your kind help. (Akai, Nigeria) From bluebox03 at gmail.com Thu Nov 15 08:05:24 2018 From: bluebox03 at gmail.com (tommy yama) Date: Thu, 15 Nov 2018 22:05:24 +0900 Subject: Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) In-Reply-To: <87ftw2rhy7.fsf@handshake.de> References: <87ftw2rhy7.fsf@handshake.de> Message-ID: Hello there Have you tried it with npm? https://www.npmjs.com/package/bluetoothctl On Thu, 15 Nov 2018, 15:10 dieter srinivasan writes: > > As am newbie to python, I am planning to automate BT functionality test > > using Bluez "bluetoothctl" utility by writing python wrapper and robot > > framework integrated with Jenkins > > ... > > *$ pip3 install bluetoothctl* > > *Collecting bluetoothctl* > > * Could not find a version that satisfies the requirement bluetoothctl > > (from versions: )* > > *No matching distribution found for bluetoothctl* > > "pip[*]" is a tool to install Python packages -- typically from > the Python package index (-->"https://pypi.org"). > The error message above indicates that "bluetoothctl" is not > managed by this package index. > > I assume that it is not a Python package at all (but rather some > command line utility in some operating system package). At least > on my Ubuntu 18.04, "bluetoothctl" is an operating system utility. > > *from sh import bluetoothctl* > > *mac = "your bluetooth mac"* > *bluetoothctl("connect", mac)* > > > In the pycharm, I see the below error message : > > > > *Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) * > > *Inspection info: This inspection detects names that should resolve but > > don't. Due to dynamic dispatch and duck typing, this is possible in a > > limited but useful number of cases. Top-level and class-level items are > > supported better than instance items.* > > > > Could you please help me to resolve the above issue, like why am I seeing > > the above issue it seems to be some importing "bluetoothhctl" module > issue > > (sorry if my understanding is wrong) > > I do not know the "sh" package. It might be a utility > that turns a command line utility into a Python callable -- > implicitely on "import" of the corresponding name. > > If this is the case, it may confuse "PyCharm" (which does not > expect such dynamism). You could then safely ignore this confusion. > > Try to execute your code. Should you get an exception > (e.g. an `ImportError: cannot import "bluetoothctl" from module "sh"`), > then come back. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From eryksun at gmail.com Thu Nov 15 15:47:45 2018 From: eryksun at gmail.com (eryk sun) Date: Thu, 15 Nov 2018 14:47:45 -0600 Subject: Unable to install Python on my windows 8 PC In-Reply-To: <87bm6qrhuq.fsf@handshake.de> References: <87bm6qrhuq.fsf@handshake.de> Message-ID: On 11/15/18, dieter wrote: > Prospero Akai writes: >> I forgot to check the 'Add To Path' box while installing python from >> www.python.org. I uninstalled then try to install again but I have been >> getting this error message since then: >> >> one or more issues caused the setup to fail. please fix the issues and >> then retry setup. for more info see the log file. >> >> 0x80072ee7-Unspecified error This is an HRESULT error (i.e. 0x8???????) wrapping the Windows subsystem (i.e. 0x8007????) error code ERROR_WINHTTP_NAME_NOT_RESOLVED (0x2EE7, the server name cannot be resolved). Try installing the offline version: https://www.python.org/ftp/python/3.7.1/python-3.7.1-amd64.exe > When I remember right, then modern Python versions require Windows 10. > Check the installation requirements for the Python version you try > to install. A feature release of Python supports Windows releases that have at least extended support (e.g. free security updates) from Microsoft [PEP 11]. Extended support for Windows 7 ends on 2020-01-14. Python 3.8 will be released on 2019-10-20 [PEP 569], so it's the last version to support Windows 7. Extended support for Windows 8.1 ends on 2023-01-10. I suppose 3.9 will be released mid 2021 and 3.10 in late 2022, so probably 3.10 will be the last version to support Windows 8.1. Extended support for Windows 10 ends on 2025-10-14. Depending on release timing, the last version to support Windows 10 probably will be either 3.11 (mid 2024) or 3.12 (late 2025). From eryksun at gmail.com Thu Nov 15 17:44:19 2018 From: eryksun at gmail.com (eryk sun) Date: Thu, 15 Nov 2018 16:44:19 -0600 Subject: IDLE Default Working Directory In-Reply-To: <887966BA-DF07-4B00-8EFB-95BF9BF89B7F@furrypants.com> References: <887966BA-DF07-4B00-8EFB-95BF9BF89B7F@furrypants.com> Message-ID: On 11/14/18, Irv Kalb wrote: > > When working with data files, I tell students to put their project (their > main program and any other related files) in a folder. Then, in their calls > to "open", I tell them to just give the name of the data file e.g., > 'MyData.txt', or a path relative from the current folder, e.g., > 'MyData/DataFile.txt'. That makes things simple in a teaching environment > and works on both Macs and Windows. I hope you provide code to change the working directory to the script directory (e.g. based on __file__, assuming it's not a frozen script). Don't let them assume that these are the same. A process can be started with any valid working directory. If you double click on a script in Explorer, it happens to set the working directory to the script directory. That's not necessarily the case for the Win+R run dialog, a shell command line, or generally any call that runs the script (e.g. system, spawnl, or WinAPI ShellExecuteEx and CreateProcess). From tjreedy at udel.edu Thu Nov 15 19:53:51 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Nov 2018 19:53:51 -0500 Subject: IDLE Default Working Directory In-Reply-To: References: Message-ID: On 11/13/2018 9:04 PM, Christman, Roger Graydon wrote: > On 13 Nov 2018, at 09:51, Bev in TX wrote: > ________________________________ >> On Nov 12, 2018, at 5:50 PM, Terry Reedy wrote: >> >> For me, open (command-O) opens 'Documents'. I presume it should be easy enough to move into a 'py' subfolder. > > The whole point is for Idle -> File -> Open (or command-O) to automatically open to a specific folder. > > Bev in TX > > > Thank you, Bev in TX for clarifying my question. That is indeed what I seek. The problem is that having Open and SaveAs always opening in one specific directory is not always the right thing to do. The OS, OS user settings, the method of starting IDLE, and the active window when Open or SaveAs is invoked. https://bugs.python.org/issue22121 is about changing the installation default Shell directory on Windows, which is the closest thing to an application or session directory. The current rules seems not to be documented, but I worked out some of them in msg224587. https://bugs.python.org/issue28775 is about adding a user option to set the startup (Shell) directory in IDLE (when not overriden by the startup method). I believe that this is what you are asking for, or at least the closest thing thereto. > My course has proved cumbersome every time a student created a new program in class, since they would have to change folders. And when > > I got to working with data files, I ended up with a little punt to avoid having to specify a complete path name to get to a workable directory. > > > My students are not programmers. I have English majors, Education majors, and students in their first year at a University. I won't say they are completely computer-illiterate, they can use a browser well enough. But I expect none of them to have ever seen the command line, so I really don't want to go that route. > > As far as activating IDLE on this Windows 10 system, > > I go down to the search bar at the bottom left, type 'IDLE', and then up comes a list of various installations > > we have lying around, including 2.7, 3.4, and 3.6 versions. I have them just select the 3.6 version from the list to launch IDLE. I don't consider that quite the same as using a 'shortcut', since we are not clicking on any icon on the desktop. If you right-click an IDLE search result and select 'open file location', you see a directory of shortcuts, any of which can be copied to desktop and then edited by selecting 'properties'. > I am not on the campus-wide labs right now, so I cannot really say much further -- and I haven't tried right-clicking on those items to see if configuration options show up, to talk to the %AppData% path, etc. > > > The Penn State computer labs are networked -- each computer has a C: drive, which I presume might be local to each machine -- but in any case, I think it is read-only > to the students. And since they could easily sit down at a different machine on any day, I wouldn't want to rely on any configuration file or anything on the C drive anyway. > > There is a networked U: drive (for users) that is campus wide, which is useful. There is also a virtual V: drive, which simply maps to each individual's folder set aside for them on the U: drive. That place would be ideal for my purposes as a place to save code and data files. In this configuration, can users use Options => Configure IDLE => Settings (dialog) to set user options (such as the font size) and have their changes persist to another session, possibly on another machine? > > But the default directory is somewhere else. I would > have to get back on campus before I can quote exactly, > but wherever it is a readonly file space that's not the > Desktop or My Documents, or who knows what. > > I'd preferably like to reset the default to the V: drive > (or even create a Python folder on that virtual V: drive). We ran into this on #22121. Although the startup directory should be a subdirectory of the home directory, there is typically no standard name for such, even across users on one machine. > And the real challenge is to come up with the simplest > solution that I can explain or show to first-time programming students in under a minute, which therefore does not involve the command-line interface. > > I don't want to scare half the students away in the very first class, just trying to configure their development environment. > > > If that's impossible, then I guess I'll have to fire a note off to the university tech support requesting them to play with that "Start In" option through %AppData%, or whatever it was. -- Terry Jan Reedy From keller at no.invalid Fri Nov 16 09:51:26 2018 From: keller at no.invalid (Steve Keller) Date: Fri, 16 Nov 2018 15:51:26 +0100 Subject: Why do integers compare equal to booleans? Message-ID: Why do the integers 0 and 1 compare equal to the boolean values False and True and all other integers to neither of them? $ python3 Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 0 == False True >>> 1 == True True >>> 2 == False False >>> 2 == True False >>> -1 == False False >>> -1 == True False >>> Since these are objects of different types I would expect they cannot be equal. I know that 0 means false and != 0 means true in C, C++, etc. but in Python that surprises me. Steve From keller at no.invalid Fri Nov 16 09:52:14 2018 From: keller at no.invalid (Steve Keller) Date: Fri, 16 Nov 2018 15:52:14 +0100 Subject: Generators, generator expressions, and loops Message-ID: I have looked at generators, generator expressions, and iterators and I try to get more familiar with these. 1. How would I loop over all (with no upper bound) integers or all powers of two, for example? In C it would be for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... } In Python, I could define a generator def powers(): i = 1 while True: yield(i) i *= 2 for i in powers(): ... More elegant are generator expressions but I cannot think of a way without giving an upper limit: for i in (2 ** i for i in range(1000000)): ... which looks ugly. Also, the double for-loop (and also the two loops in the above exmaple, for + while in the generator) look unnatural, somehow, i.e. loop over all elements which are created by a loop. Is there a more beautyful way? Steve From keller at no.invalid Fri Nov 16 09:54:23 2018 From: keller at no.invalid (Steve Keller) Date: Fri, 16 Nov 2018 15:54:23 +0100 Subject: Generators, generator expressions, and loops Message-ID: I have looked at generators, generator expressions, and iterators and I try to get more familiar with these. 1. How would I loop over all (with no upper bound) integers or all powers of two, for example? In C it would be for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... } In Python, I could define a generator def powers(): i = 1 while True: yield(i) i *= 2 for i in powers(): ... More elegant are generator expressions but I cannot think of a way without giving an upper limit: for i in (2 ** i for i in range(1000000)): ... which looks ugly. Also, the double for-loop (and also the two loops in the above exmaple, for + while in the generator) look unnatural, somehow, i.e. loop over all elements which are created by a loop. Is there a more beautyful way? Steve From keller at no.invalid Fri Nov 16 09:54:36 2018 From: keller at no.invalid (Steve Keller) Date: Fri, 16 Nov 2018 15:54:36 +0100 Subject: Iterators of iterators Message-ID: I wonder why iterators do have an __iter__() method? I thought iterable objects would have an __iter__() method (but no __next__()) to create an iterator for it, and that would have the __next__() method but no __iter__(). $ python3 Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> l = [1,2,3] >>> next(l) Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not an iterator This is expected, of course. >>> iter(l) >>> iter(iter(l)) >>> iter(iter(iter(l))) >>> i = iter(iter(iter(l))) >>> list(i) [1, 2, 3] Is there any reason or usage for this? Steve From keller at no.invalid Fri Nov 16 10:01:44 2018 From: keller at no.invalid (Steve Keller) Date: Fri, 16 Nov 2018 16:01:44 +0100 Subject: Generators, generator expressions, and loops Message-ID: Cancel ill-formated article From jon+usenet at unequivocal.eu Fri Nov 16 10:07:43 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 16 Nov 2018 15:07:43 -0000 (UTC) Subject: Why do integers compare equal to booleans? References: Message-ID: On 2018-11-16, Steve Keller wrote: > Why do the integers 0 and 1 compare equal to the boolean values False > and True and all other integers to neither of them? Because Python used not to have a boolean type and used the integers 0 and 1 instead, so when the boolean type was introduced True and False were made to behave very much like 1 and 0 for backwards compatibility reasons. From duncan at invalid.invalid Fri Nov 16 10:17:28 2018 From: duncan at invalid.invalid (duncan smith) Date: Fri, 16 Nov 2018 15:17:28 +0000 Subject: Why do integers compare equal to booleans? In-Reply-To: References: Message-ID: On 16/11/18 14:51, Steve Keller wrote: > Why do the integers 0 and 1 compare equal to the boolean values False > and True and all other integers to neither of them? > > $ python3 > Python 3.5.2 (default, Nov 12 2018, 13:43:14) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 0 == False > True > >>> 1 == True > True > >>> 2 == False > False > >>> 2 == True > False > >>> -1 == False > False > >>> -1 == True > False > >>> > > Since these are objects of different types I would expect they cannot > be equal. I know that 0 means false and != 0 means true in C, C++, > etc. but in Python that surprises me. > > Steve > >>> isinstance(False, int) True >>> isinstance(True, int) True >>> False.real 0 >>> True.real 1 >>> At least in recent Pythons. Duncan From David.Raymond at tomtom.com Fri Nov 16 10:30:57 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Fri, 16 Nov 2018 15:30:57 +0000 Subject: Why do integers compare equal to booleans? In-Reply-To: References: Message-ID: A boolean type didn't come about until version 2.3, and even now they still inherit from integers. Some links for you: https://docs.python.org/3.7/whatsnew/2.3.html#pep-285-a-boolean-type https://docs.python.org/3.7/library/stdtypes.html#boolean-values https://docs.python.org/3.7/reference/datamodel.html#the-standard-type-hierarchy -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Steve Keller Sent: Friday, November 16, 2018 9:51 AM To: python-list at python.org Subject: Why do integers compare equal to booleans? Why do the integers 0 and 1 compare equal to the boolean values False and True and all other integers to neither of them? $ python3 Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 0 == False True >>> 1 == True True >>> 2 == False False >>> 2 == True False >>> -1 == False False >>> -1 == True False >>> Since these are objects of different types I would expect they cannot be equal. I know that 0 means false and != 0 means true in C, C++, etc. but in Python that surprises me. Steve -- https://mail.python.org/mailman/listinfo/python-list From santiago at rmotr.com Fri Nov 16 10:33:14 2018 From: santiago at rmotr.com (Santiago Basulto) Date: Fri, 16 Nov 2018 12:33:14 -0300 Subject: Why do integers compare equal to booleans? In-Reply-To: References: Message-ID: > Because Python used not to have a boolean type and used the integers 0 and 1 instead Exactly as Jon says. I wrote a post some time ago with more info about it: https://blog.rmotr.com/those-tricky-python-booleans-2100d5df92c On Fri, Nov 16, 2018 at 12:23 PM duncan smith wrote: > On 16/11/18 14:51, Steve Keller wrote: > > Why do the integers 0 and 1 compare equal to the boolean values False > > and True and all other integers to neither of them? > > > > $ python3 > > Python 3.5.2 (default, Nov 12 2018, 13:43:14) > > [GCC 5.4.0 20160609] on linux > > Type "help", "copyright", "credits" or "license" for more > information. > > >>> 0 == False > > True > > >>> 1 == True > > True > > >>> 2 == False > > False > > >>> 2 == True > > False > > >>> -1 == False > > False > > >>> -1 == True > > False > > >>> > > > > Since these are objects of different types I would expect they cannot > > be equal. I know that 0 means false and != 0 means true in C, C++, > > etc. but in Python that surprises me. > > > > Steve > > > > >>> isinstance(False, int) > True > >>> isinstance(True, int) > True > >>> False.real > 0 > >>> True.real > 1 > >>> > > At least in recent Pythons. > > Duncan > -- > https://mail.python.org/mailman/listinfo/python-list > -- Santiago Basulto.- Co-founder @ rmotr.com From ian.g.kelly at gmail.com Fri Nov 16 10:33:41 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Nov 2018 08:33:41 -0700 Subject: Iterators of iterators In-Reply-To: References: Message-ID: On Fri, Nov 16, 2018 at 8:01 AM Steve Keller wrote: > > I wonder why iterators do have an __iter__() method? I thought > iterable objects would have an __iter__() method (but no __next__()) > to create an iterator for it, and that would have the __next__() > method but no __iter__(). > > $ python3 > Python 3.5.2 (default, Nov 12 2018, 13:43:14) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> l = [1,2,3] > >>> next(l) > Traceback (most recent call last): > File "", line 1, in > TypeError: 'list' object is not an iterator > > This is expected, of course. > > >>> iter(l) > > >>> iter(iter(l)) > > >>> iter(iter(iter(l))) > > >>> i = iter(iter(iter(l))) > >>> list(i) > [1, 2, 3] > > Is there any reason or usage for this? Iterators are required to have an __iter__ method that just returns self. The reason is so that iterators can be used in places where an iterable is required; e.g. so that code that is handed an iterator can loop over it. From santiago at rmotr.com Fri Nov 16 10:34:56 2018 From: santiago at rmotr.com (Santiago Basulto) Date: Fri, 16 Nov 2018 12:34:56 -0300 Subject: Generators, generator expressions, and loops In-Reply-To: References: Message-ID: Try itertools.count() . On Fri, Nov 16, 2018 at 12:08 PM Steve Keller wrote: > Cancel ill-formated article > -- > https://mail.python.org/mailman/listinfo/python-list > -- Santiago Basulto.- Co-founder @ rmotr.com From ian.g.kelly at gmail.com Fri Nov 16 10:44:06 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Nov 2018 08:44:06 -0700 Subject: Generators, generator expressions, and loops In-Reply-To: References: Message-ID: On Fri, Nov 16, 2018 at 7:57 AM Steve Keller wrote: > > I have looked at generators, generator expressions, and iterators and > I try to get more familiar with these. > > 1. How would I loop over all (with no upper bound) integers or all > powers of two, for example? > > In C it would be > > for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... } > > In Python, I could define a generator > > def powers(): > i = 1 > while True: > yield(i) > i *= 2 > > for i in powers(): > ... > > More elegant are generator expressions but I cannot think of a way > without giving an upper limit: > > for i in (2 ** i for i in range(1000000)): > ... > > which looks ugly. Also, the double for-loop (and also the two loops > in the above exmaple, for + while in the generator) look unnatural, > somehow, i.e. loop over all elements which are created by a loop. > > Is there a more beautyful way? Some options: from itertools import count def powers(): for i in count(): yield 2 ** i for i in (2 ** i for i in count()): ... for i in map(lambda x: 2 ** x, count()): ... from functools import partial from operator import pow for i in map(partial(pow, 2), count()): ... Take your pick. From m at funkyhat.org Fri Nov 16 12:26:24 2018 From: m at funkyhat.org (Matt Wheeler) Date: Fri, 16 Nov 2018 17:26:24 +0000 Subject: Generators, generator expressions, and loops In-Reply-To: References: Message-ID: > On 16 Nov 2018, at 14:54, Steve Keller wrote: > More elegant are generator expressions but I cannot think of a way > without giving an upper limit: > > for i in (2 ** i for i in range(1000000)): > ... > > which looks ugly. Also, the double for-loop (and also the two loops > in the above exmaple, for + while in the generator) look unnatural, > somehow, i.e. loop over all elements which are created by a loop. > > Is there a more beautyful way? from itertools import count for i in (2**n for n in count()): .... In general itertools includes a lot of useful stuff, it's worth reading the whole docs page: https://docs.python.org/3/library/itertools.html From Irv at furrypants.com Fri Nov 16 13:09:19 2018 From: Irv at furrypants.com (Irv Kalb) Date: Fri, 16 Nov 2018 10:09:19 -0800 Subject: IDLE Default Working Directory In-Reply-To: References: <887966BA-DF07-4B00-8EFB-95BF9BF89B7F@furrypants.com> Message-ID: > On Nov 15, 2018, at 2:44 PM, eryk sun wrote: > > On 11/14/18, Irv Kalb wrote: >> >> When working with data files, I tell students to put their project (their >> main program and any other related files) in a folder. Then, in their calls >> to "open", I tell them to just give the name of the data file e.g., >> 'MyData.txt', or a path relative from the current folder, e.g., >> 'MyData/DataFile.txt'. That makes things simple in a teaching environment >> and works on both Macs and Windows. > > I hope you provide code to change the working directory to the script > directory (e.g. based on __file__, assuming it's not a frozen script). > Don't let them assume that these are the same. A process can be > started with any valid working directory. If you double click on a > script in Explorer, it happens to set the working directory to the > script directory. That's not necessarily the case for the Win+R run > dialog, a shell command line, or generally any call that runs the > script (e.g. system, spawnl, or WinAPI ShellExecuteEx and > CreateProcess). > -- > https://mail.python.org/mailman/listinfo/python-list > Actually, I do not provide code to change the working directory. As with the original poster, I teach students who *never* use the command line. All work is done using IDLE, which simplifies their environment. IDLE (and PyCharm) apparently set the working directory appropriately and relative paths always work properly. Irv From jaxson.baerg at gmail.com Fri Nov 16 15:08:00 2018 From: jaxson.baerg at gmail.com (Jaxson Baerg) Date: Fri, 16 Nov 2018 13:08:00 -0700 Subject: Python Interpreters In Eclipse Message-ID: Hey, I'm attempting to use python in eclipse and am having trouble with the python interpreter. I am using Eclipse 2018-09 and the latest PyDev and Python 3.7.1. When declaring python-3.7.1.exe as an interpreter it gives an error saying it was unable to get info on the interpreter. It also says a possibility to why could be using an unsupported version. I don't know where to go from here, another piece of information is that I am doing this on a school computer with teacher permission but I don't know if that could be causing an issue or not? Any help would be appreciated, thanks! From digitalfantasy.it86559 at digitalfantasy.it Fri Nov 16 16:21:45 2018 From: digitalfantasy.it86559 at digitalfantasy.it (Liste guru) Date: Fri, 16 Nov 2018 22:21:45 +0100 Subject: Python Interpreters In Eclipse In-Reply-To: References: Message-ID: <64f6eec0-13c9-be37-8c9a-7291de067895@digitalfantasy.it> Il 16/11/2018 21:08, Jaxson Baerg ha scritto: > Hey, I'm attempting to use python in eclipse and am having trouble with the > python interpreter. I am using Eclipse 2018-09 and the latest PyDev and > Python 3.7.1. When declaring python-3.7.1.exe as an interpreter it gives an > error saying it was unable to get info on the interpreter. It also says a > possibility to why could be using an unsupported version. I don't know > where to go from here, another piece of information is that I am doing this > on a school computer with teacher permission but I don't know if that could > be causing an issue or not? Any help would be appreciated, thanks! ??? When setting a pydev interpreter for the standard Pyrthon you should point it to a file named python.exe (I suppose you are on windows) on an installed (or virtualenved) python, so probabably you just have to install it on windows , launching (outside eclipse) the python-3.7.1.exe and following the instruction. ??? With best regards ??? Daniele Forghieri From pacqa100 at yahoo.com.au Fri Nov 16 21:02:01 2018 From: pacqa100 at yahoo.com.au (Peter) Date: Sat, 17 Nov 2018 13:02:01 +1100 Subject: Generators, generator expressions, and loops In-Reply-To: References: Message-ID: <065c21ac-6fda-64b5-bb17-0043b3855ab0@yahoo.com.au> Lovely, succinct answers. On 17/11/2018 2:44 AM, Ian Kelly wrote: > On Fri, Nov 16, 2018 at 7:57 AM Steve Keller wrote: >> I have looked at generators, generator expressions, and iterators and >> I try to get more familiar with these. >> >> 1. How would I loop over all (with no upper bound) integers or all >> powers of two, for example? >> >> In C it would be >> >> for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... } >> >> In Python, I could define a generator >> >> def powers(): >> i = 1 >> while True: >> yield(i) >> i *= 2 >> >> for i in powers(): >> ... >> >> More elegant are generator expressions but I cannot think of a way >> without giving an upper limit: >> >> for i in (2 ** i for i in range(1000000)): >> ... >> >> which looks ugly. Also, the double for-loop (and also the two loops >> in the above exmaple, for + while in the generator) look unnatural, >> somehow, i.e. loop over all elements which are created by a loop. >> >> Is there a more beautyful way? > Some options: > > from itertools import count > > def powers(): > for i in count(): > yield 2 ** i > > > for i in (2 ** i for i in count()): > ... > > > for i in map(lambda x: 2 ** x, count()): > ... > > > from functools import partial > from operator import pow > > for i in map(partial(pow, 2), count()): > ... > > > Take your pick. > From marko at pacujo.net Sat Nov 17 14:03:47 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 17 Nov 2018 21:03:47 +0200 Subject: Enums: making a single enum References: Message-ID: <877ehb7ch8.fsf@elektro.pacujo.net> Ian Kelly : > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >>> class State(Enum): >>> Maybe = 2 >> >> # Tri-state logic >> Maybe = object() > > The enum has a nice __str__ though. That's why I usually use string sentinels: Maybe = "Maybe" Marko From pengyu.ut at gmail.com Sat Nov 17 22:21:06 2018 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Nov 2018 21:21:06 -0600 Subject: Conversion between basic regular expression and extended regular expression Message-ID: Hi, I'd like to use a program to convert between basic regular expression (BRE) and extended regular expression (ERE). (see man grep for the definition of BRE and ERE). Does python has a module for this purpose? Thanks. -- Regards, Peng From martin.schoon at gmail.com Sun Nov 18 07:42:57 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 18 Nov 2018 12:42:57 GMT Subject: Reading 'scientific' csv using Pandas? Message-ID: I am in this project where I try to get an overview of a bunch of computer generated (finite element program) data. I have it stored in a number of csv files. Reading the data into spreadsheet programs works fine but is very labour intensive so I am working with Pandas in Jupyter notebooks which I find much more efficient. Now I hit a bump in the road when some of the data is not in plain decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation. I use read.csv and I read its documentation and poke around for information on this but so far I have failed. Either I have found it already but I don't understand or I ask the wrong question to the search engines. My experience of Pandas is limited and I would appreciate some guidance. /Martin From shakti.shrivastava13 at gmail.com Sun Nov 18 09:03:27 2018 From: shakti.shrivastava13 at gmail.com (Shakti Kumar) Date: Sun, 18 Nov 2018 19:33:27 +0530 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: On Sun, 18 Nov 2018 at 18:18, Martin Sch??n wrote: > > I am in this project where I try to get an overview of a bunch of > computer generated (finite element program) data. I have it stored in a > number of csv files. > > Reading the data into spreadsheet programs works fine but is very labour > intensive so I am working with Pandas in Jupyter notebooks which I find > much more efficient. > > Now I hit a bump in the road when some of the data is not in plain > decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation. > Martin, I believe this should be done by pandas itself while reading the csv file, I took an example in scientific notation and checked this out, my sample.csv file is, col1,col2 1.1,0 10.24e-05,1 9.492e-10,2 and then I execute, In [29]: a= pd.read_csv('sample.csv') In [30]: a.values Out [30]: array([[1.100e+00, 0.000e+00], [1.024e-04, 1.000e+00], [9.492e-10, 2.000e+00]]) In [31]: a.values[1][0] Out[31]: 0.0001024 As you can see, pandas has converted scientific notation to float, even the data type of these values is numpy.float64 What best I can guess is a problem with your pandas version, there were some updates with the 0.17.x coming in, maybe give a shot upgrading your pandas with, pip install --upgrade pandas or in case you?re using anaconda then, conda update pandas > [snipped for brevity] > /Martin > -- > https://mail.python.org/mailman/listinfo/python-list -- Shakti. From srinivasan.rns at gmail.com Sun Nov 18 09:59:11 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Sun, 18 Nov 2018 20:29:11 +0530 Subject: Issue in parsing the string output from the command using "subprocess" Message-ID: Dear Python Experts Team, As am newbie to python and learning python, working on embedded linux platform, my intention is to delete all the SSID's before connecting my Wi-Fi module to specific SSID., I am trying to parse command output using the "subprocess" with wrapper "execute_cmd_output_string" written on it described as below, using the nmcli commands "*nmcli -t -f TYPE,UUID con" and "**"nmcli connection delete uuid ".* Could you please help me, what could be the bug in the below method "*def wifi_disconnect_reconnect(self, ssid, pw):" *using the method "execute_cmd_output_string" (in-turn uses "subprocess") which is failing to give correct output of., UUID's for *"nmcli connection delete uuid "* ? But which works fine with "commands.getstatusoutput" (res = commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want to include "commands.getstatusoutput" which costs me for including one more python module in my rootfs Typical output for "nmcli -t -f TYPE,UUID con" ~$ nmcli -t -f TYPE,UUID con 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877 802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc ~$ *Python Code Snipeet:* *------------------------------* * def wifi_disconnect_reconnect(self, ssid, pw):* * """* * Connect to Access point using SSID and PW.* * :param ssid: SSID of the ACCESS POINT.* * :param pw: password for connecting to the access point.* * :return: command output as True or False.* * """* * cmd = "nmcli -t -f TYPE,UUID con"* * res = self._helper.execute_cmd_output_string(cmd)* * print(res)* * lines = res[1].split('\n') ------------------------> I suspect the issue might be here* * print(lines)* * for line in lines:* * parts = line.split(":")* * print(parts)* * print(parts[1])* * if (parts[0] == "802-11-wireless"):* * print("nmcli connection delete uuid "+ parts[1])* * os.system("nmcli connection delete uuid "+ parts[1])* * cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)* * exit_code = self._helper.execute_cmd_return_code(cmd)* * return True if exit_code == 0 else False* def execute_cmd_output_string(self, cmd, enable_shell=False): """ Execute a command and return its output as a string. :param cmd: abs path of the command with arguments :param enable_shell : force the cmd to be run as shell script :return: a string. """ try: result = subprocess.check_output(split(cmd), stderr=subprocess.STDOUT, shell=enable_shell) except subprocess.CalledProcessError as e: s = """While executing '{}' something went wrong. Return code == '{}' Return output:\n'{}' """.format(cmd, e.returncode, e.output, shell=enable_shell) raise AssertionError(s) return result.strip().decode("utf-8") if __name__ == "__main__": m = wifi() print("disconnect and reconnect") print(m.wifi_disconnect_reconnect("NaWiFi", "abcds")) *Errors:* ----------- Traceback (most recent call last): 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 File "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", line 153, in 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c print(m.wifi_connect("NI WiFi", "T.f.o.s.1996!")) 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 File "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", line 77, in wifi_connect 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 print(parts[1]) 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 *IndexError: list index out of range* 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc [u'0'] [u'0'] Process finished with exit code 1 But when I execute the below the command using the python module "commands". I am able to successfully parse the multi line string output and extarct the UUID's from the command "nmcli -t -f TYPE,UUID con" and pass it to *"nmcli connection delete uuid " for* deleting all the SSID's before connecting Wi-Fi to specific SSID. * def wifi_disconnect_reconnect(self, ssid, pw):* * """* * Connect to Access point using SSID and PW.* * :param ssid: SSID of the ACCESS POINT.* * :param pw: password for connecting to the access point.* * :return: command output as True or False.* * """* * res = commands.getstatusoutput("nmcli -t -f TYPE,UUID con")* * lines = res[1].split('\n')* * for line in lines:* * parts = line.split(":")* * if (parts[0] == "802-11-wireless"):* * os.system("nmcli connection delete uuid "+ parts[1])* Kindly do the needful, as I am wandering for any clues what's going wrong with error and the highlighted code snippet... Many Thanks in advance From a24061 at ducksburg.com Sun Nov 18 12:50:55 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Sun, 18 Nov 2018 17:50:55 +0000 Subject: bottledaemon stop/start doesn't work if killed elsewhere Message-ID: Hi, I'm using bottledaemon to run a little REST service on a Pi that takes input from other machines on the LAN and stores stuff in a database. I have a cron job to call 'stop' and 'start' on it daily, just in case of problems. Occasionally the oom-killer runs overnight and kills the process using bottledaemon; when this happens (unlike properly stopping the daemon), the pidfile and its lockfile are left on the filesystem, so the 'stop' does nothing and the 'start' gets refusedq because the old pidfile and lockfile are present. At the moment, I eventually notice something wrong with the output data, ssh into the Pi, and rm the two files then call 'start' on the daemon again. Is there a recommended or good way to handle this situation automatically? Thanks, Adam From martin.schoon at gmail.com Sun Nov 18 13:22:07 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 18 Nov 2018 18:22:07 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Den 2018-11-18 skrev Shakti Kumar : > On Sun, 18 Nov 2018 at 18:18, Martin Sch??n wrote: >> >> Now I hit a bump in the road when some of the data is not in plain >> decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation. >> > > Martin, I believe this should be done by pandas itself while reading > the csv file, > I took an example in scientific notation and checked this out, > > my sample.csv file is, > col1,col2 > 1.1,0 > 10.24e-05,1 > 9.492e-10,2 > That was a quick answer! My pandas is up to date. In your example you use the US convention of using "." for decimals and "," to separate data. This works perfect for me too. However, my data files use European conventions: decimal "," and TAB to separate data: col1 col2 1,1 0 10,24e-05 1 9,492e-10 2 I use EUData = pd.read_csv('file.csv', skiprows=1, sep='\t', decimal=',', engine='python') to read from such files. This works so so. 'Common floats' (3,1415 etc) works just fine but 'scientific' stuff (1,6023e23) does not work. /Martin From python at mrabarnett.plus.com Sun Nov 18 14:15:26 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 18 Nov 2018 19:15:26 +0000 Subject: Issue in parsing the string output from the command using "subprocess" In-Reply-To: References: Message-ID: <7d83783f-ac0c-dbc1-4e71-5d412830011f@mrabarnett.plus.com> On 2018-11-18 14:59, srinivasan wrote: > Dear Python Experts Team, > > As am newbie to python and learning python, working on embedded linux > platform, my intention is to delete all the SSID's before connecting my > Wi-Fi module to specific SSID., I am trying to parse command output using > the "subprocess" with wrapper "execute_cmd_output_string" written on > it described > as below, using the nmcli commands "*nmcli -t -f TYPE,UUID con" and "**"nmcli > connection delete uuid ".* > > Could you please help me, what could be the bug in the below method "*def > wifi_disconnect_reconnect(self, ssid, pw):" *using the method > "execute_cmd_output_string" (in-turn uses "subprocess") which is failing to > give correct output of., UUID's for *"nmcli connection delete uuid "* ? > > But which works fine with "commands.getstatusoutput" (res = > commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want to > include "commands.getstatusoutput" which costs me for including one more > python module in my rootfs > > Typical output for "nmcli -t -f TYPE,UUID con" > > ~$ nmcli -t -f TYPE,UUID con > 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 > 802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877 > 802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d > 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 > 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 > 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c > 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 > 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 > 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 > 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 > 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 > 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc > ~$ > > *Python Code Snipeet:* > *------------------------------* > * def wifi_disconnect_reconnect(self, ssid, pw):* > * """* > * Connect to Access point using SSID and PW.* > > * :param ssid: SSID of the ACCESS POINT.* > * :param pw: password for connecting to the access point.* > * :return: command output as True or False.* > * """* > > * cmd = "nmcli -t -f TYPE,UUID con"* > * res = self._helper.execute_cmd_output_string(cmd)* > * print(res)* > * lines = res[1].split('\n') ------------------------> I suspect the > issue might be here* > * print(lines)* > > * for line in lines:* > * parts = line.split(":")* > * print(parts)* > * print(parts[1])* > * if (parts[0] == "802-11-wireless"):* > * print("nmcli connection delete uuid "+ parts[1])* > * os.system("nmcli connection delete uuid "+ parts[1])* > > * cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)* > * exit_code = self._helper.execute_cmd_return_code(cmd)* > > * return True if exit_code == 0 else False* > > > def execute_cmd_output_string(self, cmd, enable_shell=False): > """ > Execute a command and return its output as a string. > > :param cmd: abs path of the command with arguments > :param enable_shell : force the cmd to be run as shell script > :return: a string. > """ > > try: > result = subprocess.check_output(split(cmd), > stderr=subprocess.STDOUT, > shell=enable_shell) > > except subprocess.CalledProcessError as e: > s = """While executing '{}' something went wrong. > Return code == '{}' > Return output:\n'{}' > """.format(cmd, e.returncode, e.output, shell=enable_shell) > raise AssertionError(s) > > return result.strip().decode("utf-8") > > > if __name__ == "__main__": > m = wifi() > print("disconnect and reconnect") > print(m.wifi_disconnect_reconnect("NaWiFi", "abcds")) > > > *Errors:* > ----------- > Traceback (most recent call last): > 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 > 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 > 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 > File > "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", > line 153, in > 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c > print(m.wifi_connect("NI WiFi", "T.f.o.s.1996!")) > 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 > 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 > File > "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", > line 77, in wifi_connect > 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 > print(parts[1]) > 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 > *IndexError: list index out of range* > 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 > 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc > [u'0'] > [u'0'] > [snip] execute_cmd_output_string returns a string, so 'res' will be a string. For example, res == u'802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2'. That means that res[1] == u'0'. So res[1].split('\n') == [u'0']. If you follow the code from there, so you'll see that it'll eventually raise IndexError. From python at mrabarnett.plus.com Sun Nov 18 14:21:14 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 18 Nov 2018 19:21:14 +0000 Subject: bottledaemon stop/start doesn't work if killed elsewhere In-Reply-To: References: Message-ID: <44aca1ba-2bf2-15de-565b-d30be3606148@mrabarnett.plus.com> On 2018-11-18 17:50, Adam Funk wrote: > Hi, > > I'm using bottledaemon to run a little REST service on a Pi that takes > input from other machines on the LAN and stores stuff in a database. > I have a cron job to call 'stop' and 'start' on it daily, just in case > of problems. > > Occasionally the oom-killer runs overnight and kills the process using > bottledaemon; when this happens (unlike properly stopping the daemon), > the pidfile and its lockfile are left on the filesystem, so the 'stop' > does nothing and the 'start' gets refusedq because the old pidfile and > lockfile are present. At the moment, I eventually notice something > wrong with the output data, ssh into the Pi, and rm the two files then > call 'start' on the daemon again. > > Is there a recommended or good way to handle this situation > automatically? > Could you write a watchdog daemon that checks whether bottledaemon is running, and deletes those files if it isn't (or hasn't been for a while)? From srinivasan.rns at gmail.com Sun Nov 18 14:27:14 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 19 Nov 2018 00:57:14 +0530 Subject: Issue in parsing the string output from the command using "subprocess" In-Reply-To: <7d83783f-ac0c-dbc1-4e71-5d412830011f@mrabarnett.plus.com> References: <7d83783f-ac0c-dbc1-4e71-5d412830011f@mrabarnett.plus.com> Message-ID: Thanks a lot for your quick responses I tried to fix the issue as below, I verified in my desktop ubuntu environment, but tomorrow once I can verify on my embedded target, please let me know if you foresee any issues with the below fix? def wifi_disconnect(self, timeout=10): """ Connect to Access point using SSID and PW. :param ssid: SSID of the ACCESS POINT. :param pw: password for connecting to the access point. :return: command output as True or False. """ cmd = "nmcli -t -f TYPE,UUID con" res = self._helper.execute_cmd_output_string(cmd) print(res) lines = res.split("\n") print(lines) for line in lines: parts = line.split(":") print(parts) print(parts[0]) if (parts[0] == "802-11-wireless"): print("------------------------------------------------------") print("nmcli connection delete uuid " + parts[1]) cmd = "nmcli connection delete uuid '%s'" % parts[1] for i in range(timeout // 2): exit_code = self._helper.execute_cmd_return_code(cmd) print(exit_code) time.sleep(1) print "%d seconds have passed" % i if exit_code == 0: return True return False On Mon, Nov 19, 2018 at 12:50 AM MRAB wrote: > On 2018-11-18 14:59, srinivasan wrote: > > Dear Python Experts Team, > > > > As am newbie to python and learning python, working on embedded linux > > platform, my intention is to delete all the SSID's before connecting my > > Wi-Fi module to specific SSID., I am trying to parse command output using > > the "subprocess" with wrapper "execute_cmd_output_string" written on > > it described > > as below, using the nmcli commands "*nmcli -t -f TYPE,UUID con" and > "**"nmcli > > connection delete uuid ".* > > > > Could you please help me, what could be the bug in the below method "*def > > wifi_disconnect_reconnect(self, ssid, pw):" *using the method > > "execute_cmd_output_string" (in-turn uses "subprocess") which is failing > to > > give correct output of., UUID's for *"nmcli connection delete uuid "* ? > > > > But which works fine with "commands.getstatusoutput" (res = > > commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want > to > > include "commands.getstatusoutput" which costs me for including one more > > python module in my rootfs > > > > Typical output for "nmcli -t -f TYPE,UUID con" > > > > ~$ nmcli -t -f TYPE,UUID con > > 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 > > 802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877 > > 802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d > > 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 > > 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 > > 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c > > 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 > > 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 > > 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 > > 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 > > 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 > > 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc > > ~$ > > > > *Python Code Snipeet:* > > *------------------------------* > > * def wifi_disconnect_reconnect(self, ssid, pw):* > > * """* > > * Connect to Access point using SSID and PW.* > > > > * :param ssid: SSID of the ACCESS POINT.* > > * :param pw: password for connecting to the access point.* > > * :return: command output as True or False.* > > * """* > > > > * cmd = "nmcli -t -f TYPE,UUID con"* > > * res = self._helper.execute_cmd_output_string(cmd)* > > * print(res)* > > * lines = res[1].split('\n') ------------------------> I suspect > the > > issue might be here* > > * print(lines)* > > > > * for line in lines:* > > * parts = line.split(":")* > > * print(parts)* > > * print(parts[1])* > > * if (parts[0] == "802-11-wireless"):* > > * print("nmcli connection delete uuid "+ parts[1])* > > * os.system("nmcli connection delete uuid "+ parts[1])* > > > > * cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)* > > * exit_code = self._helper.execute_cmd_return_code(cmd)* > > > > * return True if exit_code == 0 else False* > > > > > > def execute_cmd_output_string(self, cmd, enable_shell=False): > > """ > > Execute a command and return its output as a string. > > > > :param cmd: abs path of the command with arguments > > :param enable_shell : force the cmd to be run as shell > script > > :return: a string. > > """ > > > > try: > > result = subprocess.check_output(split(cmd), > > stderr=subprocess.STDOUT, > > shell=enable_shell) > > > > except subprocess.CalledProcessError as e: > > s = """While executing '{}' something went wrong. > > Return code == '{}' > > Return output:\n'{}' > > """.format(cmd, e.returncode, e.output, > shell=enable_shell) > > raise AssertionError(s) > > > > return result.strip().decode("utf-8") > > > > > > if __name__ == "__main__": > > m = wifi() > > print("disconnect and reconnect") > > print(m.wifi_disconnect_reconnect("NaWiFi", "abcds")) > > > > > > *Errors:* > > ----------- > > Traceback (most recent call last): > > 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2 > > 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837 > > 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303 > > File > > > "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", > > line 153, in > > 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c > > print(m.wifi_connect("NI WiFi", "T.f.o.s.1996!")) > > 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6 > > 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128 > > File > > > "/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py", > > line 77, in wifi_connect > > 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6 > > print(parts[1]) > > 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5 > > *IndexError: list index out of range* > > 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136 > > 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc > > [u'0'] > > [u'0'] > > > [snip] > execute_cmd_output_string returns a string, so 'res' will be a string. > > For example, res == > u'802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2'. > > That means that res[1] == u'0'. > > So res[1].split('\n') == [u'0']. > > If you follow the code from there, so you'll see that it'll eventually > raise IndexError. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bdurham.com Sun Nov 18 14:33:22 2018 From: python at bdurham.com (Malcolm Greene) Date: Sun, 18 Nov 2018 12:33:22 -0700 Subject: What Python related git pre-commit hooks are you using? Message-ID: <1542569602.3037800.1581073424.34F786B7@webmail.messagingengine.com> Curious to learn what Python related git pre-commit hooks people are using? What hooks have you found useful and which hooks have you tried and abandoned? Appreciate any suggestions for those new to this process. Background: Window, macOS, and Linux dev environments, PyCharm professional edition IDE, 64-bit Python 3.6, private Github repos. Considering black (standardize formatting), pylamas (multiple static code tests) and possibly a hook into our pytest test runner. Thanks! From rosuav at gmail.com Sun Nov 18 15:00:48 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Nov 2018 07:00:48 +1100 Subject: What Python related git pre-commit hooks are you using? In-Reply-To: <1542569602.3037800.1581073424.34F786B7@webmail.messagingengine.com> References: <1542569602.3037800.1581073424.34F786B7@webmail.messagingengine.com> Message-ID: On Mon, Nov 19, 2018 at 6:34 AM Malcolm Greene wrote: > > Curious to learn what Python related git pre-commit hooks people are > using? What hooks have you found useful and which hooks have you tried > and abandoned? Appreciate any suggestions for those new to this process. > Background: Window, macOS, and Linux dev environments, PyCharm professional edition IDE, 64-bit Python 3.6, private Github repos. Considering black (standardize formatting), pylamas (multiple static code tests) and possibly a hook into our pytest test runner. > Thanks! Here are a few that I've written and actively use. This hook isn't written in Python, but I use it with my Python projects: https://github.com/Rosuav/shed/blob/master/githook.pike Whenever you make a commit that affects only a single file, it automatically prepopulates the message with a tag, based on previous commits affecting that file. This one is written in Python, but is less for Python projects and more for my git-managed config directories (like my /etc on most computers): https://github.com/Rosuav/shed/blob/master/git-watch Once configured, it notifies me any time there are uncommitted changes. For a typical source code repo, that's not particularly likely, but when the files can be edited by other programs (or by running system updates), it's good to be told. Another one written in Python, but not a hook per se: https://github.com/Rosuav/shed/blob/master/git-triangle Triangle cloning is a variant of git clone designed for a pull-request model. And this one is just a convenient tool. https://github.com/Rosuav/shed/blob/master/git-ignore Type "git ignore __pycache__" after you notice that you committed a bunch of pyc files. Adds the line to .gitignore and then removes (from the repo, but not your disk) every file that ought to be ignored. Feel free to snag any parts you like, or to use them as inspiration. The code is all MIT-licensed so have fun. I'm also interested to see what tools other people use! Thanks for starting this discussion. ChrisA From PythonList at danceswithmice.info Sun Nov 18 15:11:32 2018 From: PythonList at danceswithmice.info (David Neil) Date: Mon, 19 Nov 2018 09:11:32 +1300 Subject: Generators, generator expressions, and loops In-Reply-To: References: Message-ID: <4d8ea8f5-f399-49bf-ec04-0e6ee67d754a@danceswithmice.info> Steve, On 17/11/18 03:52, Steve Keller wrote: > I have looked at generators, generator expressions, and iterators and > I try to get more familiar with these. > > 1. How would I loop over all (with no upper bound) integers or all > powers of two, for example? > > In C it would be > > for (int i = 0; ; i++) { ... } or for (int i = 1; ; i *= 2) { ... } > > In Python, I could define a generator > > def powers(): > i = 1 > while True: > yield(i) > i *= 2 > > for i in powers(): > ... Is there a fundamental error here? Is the attempt to start from C (or whatever) and reproduce C-code in Python? Whilst it can be a useful early-learning path to translate "commands" from one language to another, in order to commence actual usage quickly; one should not try to use such kindergarten techniques to discuss philosophy! First, learn the new language's idioms - a combination of language-vocabulary and its underlying culture. In this case, the comparison is between the for-command of a for-loop (C), with Python's for-in structure. Python's idiom is to loop over the contents of something: the characters within a string of characters, the elements of a list, etc. The C languages (and many others) have an idiom which controls the repetition of a loop without regard to the data being processed, ie for index = start-value, end-value, incremental-amount. This works regardless of what the code is looping 'over', if indeed, anything. In Python, we don't look at the "index", this is provided (ie "batteries included"). Python looks at an instance of a collection object (previously "sequence members") which is also an iterator (see your previous questions). The mention of an iterable within a for-in statement causes the production of an appropriate element-value at each loop of the construct. Whereas with C one uses the index to choose which item of data to consider during this iteration of the loop, eg array[index]. In C the 'subject' of the loop is the index (or "offset"). In Python it is the collection, and iteratively, its elements. This idiom removes a significant proportion of C (etc) programming errors caused by the necessity to use "pointers" or indices, eg the famous "out by one" error. Whereas in C it is necessary to use a pointer to loop over the two choices, in Python we can immediately use, eg for gender in [ "male", "female" ]: with no pointer and direct access to the label-values, cf (define genders_array earlier, and then for index = 1, 2; this_loops_gender = genders_array( index ); use this_loops_gender. To directly answer the narrow coding-question posed: in Python one achieves "counting loops" using a while-construct, eg count = 0 #or start-value while ( count < maximum ): etc count += 1 The set-up, condition, and increment corresponding directly with the descriptions of "start-value, end-value, and increment-amount" in C (etc). In the case of "infinite loops: a common Python idiom is: while True: etc with attendant start/increment code. In which case you enjoy all of the benefits of a generator (eg no need to generate (and store) all of the index values before looping commences) but without the abstraction in the example code - simplicity before complexity! Python also offers a second-level answer in the Python Standard Library. The basic concepts of an iterator and/or the underlying technologies are made available in "itertools" - just as you will find with many other facilities within and around the language. There are a couple of specific edge-cases (a deliberate, never-ending loop) within that library. Enjoy! Is it a valid approach to first solve a problem by 'thinking in C' and only then trying to translate that 'solution' into Python? This approach is where Star Wars' concept behind Yoda-speak comes from: some languages sequence the words in a sentence quite differently from the preferred subject-verb-object order of English: Jack hits the ball. Jack the ball hits. The ball hit (by) Jack. IMHO Python is NOT a 'better version of C' - for any definition of "better", and regardless of anyone's enthusiastic preferences. There are situations where it would be 'better' to use one in preference to the other. Both ways! To write in Python, use Pythonic thinking, Python constructs (one author talks of "Python's beautiful heart"), and the idioms of Python; to realise its power! -- Regards =dn From sjeik_appie at hotmail.com Sun Nov 18 16:32:37 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 18 Nov 2018 21:32:37 +0000 Subject: What Python related git pre-commit hooks are you using? In-Reply-To: <1542569602.3037800.1581073424.34F786B7@webmail.messagingengine.com> Message-ID: On 18 Nov 2018 20:33, Malcolm Greene wrote: >Curious to learn what Python related git >pre-commit hooks people are using? What >hooks have you found useful and which >hooks have you tried I use Python to reject large commits (pre-commit hook): http://code.activestate.com/recipes/578883-git-pre-commit-hook-to-reject-large-files-using-py/ I've also used hooks to trigger a Sphinx doc build, and for tox. From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Nov 18 16:33:47 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sun, 18 Nov 2018 15:33:47 -0600 Subject: bottledaemon stop/start doesn't work if killed elsewhere In-Reply-To: <44aca1ba-2bf2-15de-565b-d30be3606148@mrabarnett.plus.com> References: <44aca1ba-2bf2-15de-565b-d30be3606148@mrabarnett.plus.com> Message-ID: On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote: >> Hi, >> >> I'm using bottledaemon to run a little REST service on a Pi that takes >> input from other machines on the LAN and stores stuff in a database. >> I have a cron job to call 'stop' and 'start' on it daily, just in case >> of problems. >> >> Occasionally the oom-killer runs overnight and kills the process using >> bottledaemon; when this happens (unlike properly stopping the daemon), >> the pidfile and its lockfile are left on the filesystem, so the 'stop' >> does nothing and the 'start' gets refusedq because the old pidfile and >> lockfile are present. At the moment, I eventually notice something >> wrong with the output data, ssh into the Pi, and rm the two files then >> call 'start' on the daemon again. >> >> Is there a recommended or good way to handle this situation >> automatically? >> > Could you write a watchdog daemon that checks whether bottledaemon is > running, and deletes those files if it isn't (or hasn't been for a while)? What if the oom-killer kills the watchdog? Whatever runs in response to the start command has to be smarter: if the pid and lock files exist, then check whether they refer to a currently running bottledaemon. If so, then all is well, and refuse to start a redundant daemon. If not, then remove the pid and lock files and start the daemon. From shakti.shrivastava13 at gmail.com Mon Nov 19 05:33:26 2018 From: shakti.shrivastava13 at gmail.com (Shakti Kumar) Date: Mon, 19 Nov 2018 16:03:26 +0530 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: Hi Martin, On Sun, 18 Nov 2018 at 23:59, Martin Sch??n wrote: > > Den 2018-11-18 skrev Shakti Kumar : > > On Sun, 18 Nov 2018 at 18:18, Martin Sch??n wrote: > >> > >> Now I hit a bump in the road when some of the data is not in plain > >> decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation. > >> > > > > Martin, I believe this should be done by pandas itself while reading > > the csv file, > > I took an example in scientific notation and checked this out, > > > > my sample.csv file is, > > col1,col2 > > 1.1,0 > > 10.24e-05,1 > > 9.492e-10,2 > > > That was a quick answer! > > My pandas is up to date. > > In your example you use the US convention of using "." for decimals > and "," to separate data. This works perfect for me too. > > However, my data files use European conventions: decimal "," and TAB > to separate data: > > col1 col2 > 1,1 0 > 10,24e-05 1 > 9,492e-10 2 > A quick fix would be to replace all commas in your file with stops (.) In case you have other stops in your file not necessarily in your scientific notation columns only, you may do this replace process only for your interested columns. Meanwhile I should be looking for a cleaner way of loading this csv in pandas, never came through this comma notation :) Members of @python-list at python.org, any better solution? > I use > > EUData = pd.read_csv('file.csv', skiprows=1, sep='\t', > decimal=',', engine='python') > > to read from such files. This works so so. 'Common floats' (3,1415 etc) > works just fine but 'scientific' stuff (1,6023e23) does not work. > > /Martin > -- > https://mail.python.org/mailman/listinfo/python-list -- Shakti. From __peter__ at web.de Mon Nov 19 06:32:35 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Nov 2018 12:32:35 +0100 Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Martin Sch??n wrote: > My pandas is up to date. > > In your example you use the US convention of using "." for decimals > and "," to separate data. This works perfect for me too. > > However, my data files use European conventions: decimal "," and TAB > to separate data: > > col1 col2 > 1,1 0 > 10,24e-05 1 > 9,492e-10 2 > > I use > > EUData = pd.read_csv('file.csv', skiprows=1, sep='\t', > decimal=',', engine='python') > > to read from such files. This works so so. 'Common floats' (3,1415 etc) > works just fine but 'scientific' stuff (1,6023e23) does not work. With >>> with open("file.csv", "w") as f: ... f.write("col1\tcol2\n" ... "1,1\t0\n" ... "10,24e-05\t1\n" ... "9,492e-10\t2\n") ... 40 the following works on my system: >>> pd.read_csv("file.csv", delimiter="\t", decimal=",") col1 col2 0 1.100000e+00 0 1 1.024000e-04 1 2 9.492000e-10 2 [3 rows x 2 columns] The version is a bit old, though: >>> pd.__version__ '0.13.1' The engine="python" produces an exception over here: """ ValueError: The 'decimal' option is not supported with the 'python' engine """ Maybe you can try and omit that option? If that doesn't work you can specify a converter: >>> pd.read_csv("file.csv", sep="\t", converters={0: lambda s: float(s.replace(",", "."))}) col1 col2 0 1.100000e+00 0 1 1.024000e-04 1 2 9.492000e-10 2 [3 rows x 2 columns] From jon+usenet at unequivocal.eu Mon Nov 19 07:50:24 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 19 Nov 2018 12:50:24 -0000 (UTC) Subject: What Python related git pre-commit hooks are you using? References: <1542569602.3037800.1581073424.34F786B7@webmail.messagingengine.com> Message-ID: On 2018-11-18, Malcolm Greene wrote: > Curious to learn what Python related git pre-commit hooks people are > using? What hooks have you found useful and which hooks have you tried > and abandoned? Appreciate any suggestions for those new to this process. > Background: Window, macOS, and Linux dev environments, PyCharm professional edition IDE, 64-bit Python 3.6, private Github repos. Considering black (standardize formatting), pylamas (multiple static code tests) and possibly a hook into our pytest test runner. I wrote the following pre-commit hook, which is fairly specific to my requirements but also fairly easy to customize. It (configurably) checks text-type files for tabs, trailing whitespace and non-Unix line endings, python files for syntax and with flake8 and pylint, and JavaScript files with 'standard'. It works with Python 2 or 3. https://github.com/jribbens/voting/blob/master/.githooks/pre-commit From tjol at tjol.eu Mon Nov 19 08:08:28 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 19 Nov 2018 14:08:28 +0100 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: On 2018-11-18 19:22, Martin Sch??n wrote: > Den 2018-11-18 skrev Shakti Kumar : >> On Sun, 18 Nov 2018 at 18:18, Martin Sch??n wrote: >>> >>> Now I hit a bump in the road when some of the data is not in plain >>> decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation. >>> >> >> Martin, I believe this should be done by pandas itself while reading >> the csv file, >> I took an example in scientific notation and checked this out, >> >> my sample.csv file is, >> col1,col2 >> 1.1,0 >> 10.24e-05,1 >> 9.492e-10,2 >> > That was a quick answer! > > My pandas is up to date. > > In your example you use the US convention of using "." for decimals > and "," to separate data. This works perfect for me too. > > However, my data files use European conventions: decimal "," and TAB > to separate data: > > col1 col2 > 1,1 0 > 10,24e-05 1 > 9,492e-10 2 > > I use > > EUData = pd.read_csv('file.csv', skiprows=1, sep='\t', > decimal=',', engine='python') > > to read from such files. This works so so. 'Common floats' (3,1415 etc) > works just fine but 'scientific' stuff (1,6023e23) does not work. > > /Martin > This looks like a bug in the 'python' engine specifically. I suggest you write a bug report at https://github.com/pandas-dev/pandas/issues (conda:nb) /tmp 0:jollans at mn70% cat test.csv Index Value 0 1,674 1 3,48e+3 2 8,1834e-10 3 3984,109 4 2830812370 (conda:nb) /tmp 0:jollans at mn70% ipython Python 3.7.0 (default, Oct 9 2018, 10:31:47) Type 'copyright', 'credits' or 'license' for more information IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: import pandas as pd In [2]: pd.read_csv('test.csv', header=[0], index_col=0, decimal=',', sep='\t') Out[2]: Value Index 0 1.674000e+00 1 3.480000e+03 2 8.183400e-10 3 3.984109e+03 4 2.830812e+09 In [3]: pd.read_csv('test.csv', header=[0], index_col=0, decimal=',', sep='\t', engine='python') Out[3]: Value Index 0 1.674 1 3,48e+3 2 8,1834e-10 3 3984.109 4 2830812370 In [4]: pd.__version__ Out[4]: '0.23.4' -- Cheers, Thomas From iwoherka at gmail.com Mon Nov 19 09:08:18 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Mon, 19 Nov 2018 14:08:18 +0000 Subject: Question about the definition of the value of an object Message-ID: Hello everyone, I've been looking for something in the documentation (https://docs.python.org/3.8/reference/datamodel.html) recently and I've noticed something weird. Documentation states that every object has a value, but doesn?t provide any definition whatsoever of what the value is. Now, I'm sure that every reasonably fluent Python programmer has an intuitive understanding of the term, nonetheless, I would expect the documentation defines it somehow (not necessarily in a formal fashion), especially considering that "the value of an object" is used to explain other concepts, such as mutability: > The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. So, why is documentation silent on this? One reason I can think of is to avoid answering inconvenient questions. For example, while it is trivial that the value of an object of type "bool" (either object "True" or object "False") is either truth or falsity, but what about tuples? For the tuple "(a, b, c)", is the value {"a", "b", "c"} or ("a", "b", "c")? In another words, does the value retain information about the order? I would think so, since "(a, b, c) != (a, c, b)" but it's not obvious if we define value as "all the data the object holds" or something similar. Same question can be extended to things such as lists, dictionaries or - even more problematic - user-defined types. Moreover, there are paragraphs in the documentation where the word "value" is used in different, seemingly confusing, contexts: > Ellipsis > This type has a single value. There is a single object with this value. This object is accessed through the literal ... or the built-in name Ellipsis. Its truth value is true. This would suggest that: 1. Value of a type is an object of that type (this one is pretty standard). 2. There is a single value of type "Ellipsis", which is the object accessed via built-in name "Ellipsis". 3. Value of the object "Ellipsis" is a unique value denoting the omission from speech or writing. Do I have it all backwards or am I missing something obvious here? Thank you. Sincerely, Iwo Herka From skybuck2000 at hotmail.com Mon Nov 19 11:42:16 2018 From: skybuck2000 at hotmail.com (skybuck2000 at hotmail.com) Date: Mon, 19 Nov 2018 08:42:16 -0800 (PST) Subject: Extend NTFS with "version" of file and "version" of folder, also optionally GIT integration or something like it. Message-ID: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> As far as I know currently NTFS is missing a key feature for code development and compare: "versioning information" per file and per folder. This sucks badly. Currently I have files as follows: folder version 0.01\ some_source_code_file_version_1.pas some_other_source_code_file_version1.pas and folder version 0.02\ some_source_code_file_version_2.pas some_other_source_code_file_version2.pas Now it's impossible to "code compare" these files with "code compare" tool. It does not recgonize these files. For code compare to work it would have to be: folder version 0.01\ some_source_code_file_version_1.pas some_other_source_code_file_version1.pas and folder version 0.02\ some_source_code_file_version_1.pas some_other_source_code_file_version1.pas However losing versioning information per file is dangerous in case folders are renamed or files are moved. Encoding versioning information in project files is also highly undesired in case project files are lost or corrupted. There is a very clear and distinct need to include versioning in folders and files. I hope to see NTFS extended in the future to incorporate these changes/additional features. I also highly recommend to include some GIT like versioning system integration with windows explorer. It would be highly desireable to "view/browse" and even edit or change previous GIT versions via a windows explorer and also to be able to open different version folders/branches for code compare purposes and other editing tools. Currently this GIT integration is missing, tortuise GIT does offer some integration/icon overlays but that's about it, advanced browsing of NTFS/GIT related folder tree structure is currently not possible cause ofcourse this functionality is missing. Furthermore deep branching is desireable to allow very deep folders. Also file path and folder path lengths must be incredibly large to allow deep branching and deep versioning of source code files. GIT on top of NTFS would currently never be possible because of very limited path and folders length. A little bit of branching and it hits limits. Also for a next-generation GIT version the following features are desired: 1A. Splitting of original source code file into multiple small files. + 1B. Rebasing changes in original split file into multiple small files. Currently GIT is too limited in this and does not recgonize these changes in original to be copied/rebased into split files. A very serious GIT limitation. This is "pattern recgonition" technology that must be advanced to the next level of technology. Perhaps DEEP learning might offer some possibilities here or new algorithms to detect "movements and code changes" of 1 file into multiple files. This feature will allow: 1.1. Splitting files into multiple files, without approval of original fork maintainer by "rebel" fork maintainer. 1.2. Continueing to work on multiple files by "rebel" fork, and rebasing changes of original fork maintainer, without original fork maintainer to commit these changes (from "rebel fork"). For as long as the pattern recgonizer can handle these differences it would be nice to have. Currently GIT is limitted to splitting files by maintainer, forks cannot split files and then continue to benefit from original unsplitted source, if original source does not split. Splitting files is in my oppinion necessary to keep software projects maintainable and functioning. Compilers/Editors/Analyzers/Visualizers/Parsers these are allow limited in their technology and implementation and can handle only so much due to limitations and especially bugs. The larger the source file the more like it is to contain some weird text which bugs out these tools, especially if the large file was written by a person that does not know the tools or the language well, strange bugs will occur especially but these kinds of programmers not knowing tool limitations and bugs. Splitting off files can reduce these problems and solve them one by one better and offer more possibility for diagnosis of tool-related bugs and problems, plus possibly higher recompile times since not entire file needs to be re-compiled. Also splitting files in relation to history and changing history/rebasing works bad currently in git as already indicated, somebody did write a script to try and solve it via branching per file, but as far as I know this script did not work. In principle I am against changing history in a versioning system, though the re-base feature itself could be interesting if it works. Think of this as "applieing a change in history towards the future", like time travel or something, perhaps a different term could be used for it. "Apply change in past to future". 2. Better visualization of history/branches. Currently I cannot make sense of how branches are merged, this would be nice if this was better indicated, ofcourse visualizating history of different time-related branches is more difficult because of more time/versions past and these "lines will run longer" especially in a multi-user/programmer project. Though I still feel GIT currently falls a bit short in this, another contributing factor to confusion is the "hashing" approach. Commits are numbered by "hash number", this kinda makes it harder to follow what branch is integrated/merged with what branch. For guy like me being used to seeing 0.01 and 1.03 and such this is not so ideal. I would like to see something like: version 0.01 and version 0.05 were integrated/merged. However this is not a branch by slight changes moved from 0.01 to 0.05 which would be a bit weird. Better example: version 0.05 main branch version 0.05 alternative branch integrate these two branches into version 0.06 or even back into version 0.05 main branch. Versions should be indicated as follows: version Other example: version 0.10 based on version 0.03 of some other folder. version This way branches can be based on a base version. It's kinda thinking the other way around. The branch could and probably will become the main branch, and instead the version which it was based off is now history. Therefore re-merging is not required, and the branch can continue to run as main branch. This resembles evolution more appriorately and naturally then currently GIT does. In git a branch can be created of of a version number... but it will never become the main branch until it is merged back into main, this is wrong in some ways. However perhaps this example was more ment for creating new software based of older/different software and re-using it's source code base, so in that sense GIT may not be wrong, but does lack tracking of these "bases" so to speak. It can be done but it's a bit weird. Re-basing is dangerous also downloading and doing pull requests is dangerous, especially if maintainer screwed up the git respository. I do not like this at all, and want to keep my local versions 100% intact. Therefore there must be a disconnect between the remote and the local. A download from a remote must always re-create a local new version, to then continue work on perhaps. Re-incorporating changes from a remote to new local copy, to final destination copy where my work was done will have to be "supervised" to some degree, it can be partially automated, but user must indicate first that this is desired. This way there will always be 3 copies: 1. the remote 2. the local working remote, whose changes cannot be changed by a download from remote with supervisor, this download should not be possible at all. 3. the local download from remote, this one can be downloaded and then applied to the local 2. For multi-user branching approach a better way might be to use the following: version 0.05-Jack version 0.08-Skybuck version 0.06-Jason The branches created by the users are indicated by their username. However this doesn't really describe what the branch functionality is about but at least it does give some sense who worked on it but this is not the most important part. So a description of the branch is possible: version 0.05-Jack - New feature version 0.08-Skybuck - Further development of main version 0.06-Jason - Bug fixes Eventually these branches can and may be integrated into main 0.08 or 0.09. This branch description is very important and must be part of the windows explorer view/visibility. Creating branches should be as simply as a copy & paste operation in windows explorer, and then renaming the copy. This functionality could be integrated into the windows explorer pop-up menu. For example: "Rename version to branch" (this allows to copy main first and then decide if to branch it) "Create branch" (when sure it must be a branch, create branch directly) Eventually a branch can also be made main again. "Turn branch into main version" And some automation might also be nice: "Apply branch to main version" This would work by "copy" a branch by selecting it and then click copy, the instead of pasting it, it will be pasted into main. So it can also be called: "Paste branch into main" Or simply into folder or merge "Merge with" or "Merge changes with" for a slightly better description for new users. Windows Explorer and NTFS should evolve in such a way that it is more suited for "evolution like development of files" That would be very nice. This definetly means deep branching and perhaps some splitting and merging capabilities and change tracking plus history visualization. I hope to see some of this in a next version of windows, this will also make it more competitive with linux and git in general. Bye, Skybuck. From rhodri at kynesim.co.uk Mon Nov 19 11:57:30 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 19 Nov 2018 16:57:30 +0000 Subject: Question about the definition of the value of an object In-Reply-To: References: Message-ID: <40f92270-b108-7446-b27b-17b5924d6b52@kynesim.co.uk> On 19/11/2018 14:08, Iwo Herka wrote: > I've been looking for something in the documentation > (https://docs.python.org/3.8/reference/datamodel.html) recently > and I've noticed something weird. Documentation states that every > object has a value, but doesn?t provide any definition > whatsoever of what the value is. Now, I'm sure that every reasonably > fluent Python programmer has an intuitive > understanding of the term, nonetheless, I would expect the > documentation defines it somehow (not necessarily > in a formal fashion), especially considering that "the value of an > object" is used to explain other concepts, such as > mutability: I don't think it's weird at all. "Value" is a complex concept, just ask a philosopher next time you have a few weeks free :-) You even demonstrated as much, when you noted that ordering is part of the value of a tuple. Attempting to define value here would be at best a massive distraction from the concepts the documentation is trying to get across. -- Rhodri James *-* Kynesim Ltd From ethan at stoneleaf.us Mon Nov 19 12:06:31 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 19 Nov 2018 09:06:31 -0800 Subject: Extend NTFS with "version" of file and "version" of folder, also optionally GIT integration or something like it. In-Reply-To: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> References: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> Message-ID: <19586aa1-fc43-69c5-4486-7ea61fa9e668@stoneleaf.us> On 11/19/2018 08:42 AM, skybuck2000 at hotmail.com wrote: > As far as I know currently NTFS is missing a key feature for code development and compare: "versioning information" per file and per folder. This is not a mailing list for the purpose of discussing Microsoft Windows enhancements. How is this related to Python? -- ~Ethan~ From a24061 at ducksburg.com Mon Nov 19 12:07:16 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Mon, 19 Nov 2018 17:07:16 +0000 Subject: bottledaemon stop/start doesn't work if killed elsewhere References: <44aca1ba-2bf2-15de-565b-d30be3606148@mrabarnett.plus.com> <1rh4vdtfgs0nsg9p4hklf5njknnlrc0mne@4ax.com> Message-ID: <477bcfx45t.ln2@news.ducksburg.com> On 2018-11-19, Dennis Lee Bieber wrote: > On Sun, 18 Nov 2018 15:33:47 -0600, Dan Sommers ><2QdxY4RzWzUUiLuE at potatochowder.com> declaimed the following: > >> >>What if the oom-killer kills the watchdog? >> > > Then you have TWO processes with out-of-control memory growth. > > The out-of-memory killer should only be killing processes that are > requesting obscene amounts of memory. You could put a USB hard-drive on the > system and create a swap partition on the hard drive (you don't want to > swap to an SD card, it will rapidly kill the card). This pi has an external USB drive (with its own power supply) for everything except /boot, including a 46 GB swap partition! > More important -- try to find out what your daemon is doing that is > increasing its memory usage (Firefox on Windows is a known hog; I have to > kill it periodically as it grows to 1.5GB [it's the 32-bit version due to > my favored plug-ins that are no longer supported in 64-bit, so has a 2GB > process limit]). AFAICT the oom-killer only fires when the nightly texpire cron job (a component of the leafnode local news server) is running, & even then only once a week or so. Usually when that happens, it kills texpire, which doesn't really matter, since that runs again the next night. Occasionally it kills some other thing. I don't see how this bottledaemon could be the memory hog --- it has one endpoint that accepts a few hundred bytes of JSON, validates it, & then appends a line to a TSV file. Thanks, Adam From rhodri at kynesim.co.uk Mon Nov 19 12:37:11 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 19 Nov 2018 17:37:11 +0000 Subject: Extend NTFS with "version" of file and "version" of folder, also optionally GIT integration or something like it. In-Reply-To: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> References: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> Message-ID: <50f52926-b340-e3f7-dcab-24b12dba9ddb@kynesim.co.uk> On 19/11/2018 16:42, skybuck2000 at hotmail.com wrote: > As far as I know currently NTFS is missing a key feature for code development and compare: "versioning information" per file and per folder. While I appreciate your desire for Files-11 (the OpenVMS filing system), I'm struggling to see how this is relevant to Python. -- Rhodri James *-* Kynesim Ltd From r at dev.null Mon Nov 19 12:51:13 2018 From: r at dev.null (Robert Girault) Date: Mon, 19 Nov 2018 15:51:13 -0200 Subject: on the prng behind random.random() Message-ID: <86wop9ez1q.fsf@dev.null> Looking at its source code, it seems the PRNG behind random.random() is Mersenne Twister, but I'm not sure. It also seems that random.random() is using /dev/urandom. Can someone help me to read that source code? I'm talking about CPython, by the way. I'm reading https://github.com/python/cpython/blob/master/Lib/random.py The initial comment clearly says it's Mersenne Twister, but the only random() function there seems to call _urandom(), which I suppose is an interface to /dev/urandom. What am I missing here? From __peter__ at web.de Mon Nov 19 13:30:37 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Nov 2018 19:30:37 +0100 Subject: on the prng behind random.random() References: <86wop9ez1q.fsf@dev.null> Message-ID: Robert Girault wrote: > Looking at its source code, it seems the PRNG behind random.random() is > Mersenne Twister, but I'm not sure. It also seems that random.random() > is using /dev/urandom. Can someone help me to read that source code? > > I'm talking about CPython, by the way. I'm reading > > https://github.com/python/cpython/blob/master/Lib/random.py > > The initial comment clearly says it's Mersenne Twister, but the only > random() function there seems to call _urandom(), which I suppose is an > interface to /dev/urandom. > > What am I missing here? There's a class random.Random which is instantiated at the end of the file, and random() is bound to the corresponding method: _inst = Random() ... random = _inst.random The Random class inherits from _random.Random which is implemented in C and does most of the actual work. If you can read C: https://github.com/python/cpython/blob/master/Modules/_randommodule.c The most relevant part seems to be genrand_int32() which is wrapped by random_random() that actually implenents the _random.Random.random() method. From tjreedy at udel.edu Mon Nov 19 14:19:06 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 19 Nov 2018 14:19:06 -0500 Subject: Question about the definition of the value of an object In-Reply-To: References: Message-ID: On 11/19/2018 9:08 AM, Iwo Herka wrote: > Hello everyone, > > I've been looking for something in the documentation > (https://docs.python.org/3.8/reference/datamodel.html) recently > and I've noticed something weird. Documentation states that every > object has a value, but doesn?t provide any definition > whatsoever of what the value is. Python is a language for manipulating information stored in Python objects. Abstractly, object values are the mostly implementation- and even language-independent information that we wish to manipulate. Note that concrete types are somewhat implementation dependent and ids are implementation and session dependent. Bools represent binary choices, not 'truth' per se. We call the choices 'True' and 'False' because that (with or without capitals) is the default binary choice in propositional logic. For numbers, 0 versus not 0 is often an important choice. Ditto for 'empty' versus 'not empty' for collections. -- Terry Jan Reedy From skybuck2000 at hotmail.com Mon Nov 19 14:27:01 2018 From: skybuck2000 at hotmail.com (skybuck2000 at hotmail.com) Date: Mon, 19 Nov 2018 11:27:01 -0800 (PST) Subject: Extend NTFS with "version" of file and "version" of folder, also optionally GIT integration or something like it. In-Reply-To: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> References: <862fe55b-7e5e-46d7-a69a-49b63f96a68f@googlegroups.com> Message-ID: <674ce5e3-cab6-41fe-b5d9-bd732696b1f7@googlegroups.com> Described also as: (Versioning System Integration with Windows Explorer) Anyway Googling NTFS and GIT turned up this: https://blogs.msdn.microsoft.com/devops/2017/02/03/announcing-gvfs-git-virtual-file-system/ The objective of this project seems to be a bit different. To handle very large projects. Which in itself is great. But for small projects like mine this is perhaps somewhat overkill. But the people working on this project do have some experience integrating GIT with a file system and creating some virtual file system. I highly recommend Microsoft to expand these kinds of projects massively or to expand this project in a big way and to involve Windows Explorer programmers to get on on this action and to expand windows explorer to also work with this file system and versioning system and to perhaps provide some slight new features for windows explorer to work in tandem with such a new file system. I want something like this to be usuable for small projects too Perhaps it's already usuable not sure... would be nice if this software could be made available for windows 7, only microsoft sort out the troubles with windows 10 updates ;) I think this continous windows 10 updating approach might be a bit too much for people to handle. Perhaps it's better to have an older version and a new version, so people don't be bother with new version f*ck ups. I sure don't have to to mess with windows updates and troubles, except very urgent security fixes. Bye, Skybuck. From rosuav at gmail.com Mon Nov 19 14:46:35 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Nov 2018 06:46:35 +1100 Subject: Question about the definition of the value of an object In-Reply-To: References: Message-ID: On Tue, Nov 20, 2018 at 3:08 AM Iwo Herka wrote: > > Hello everyone, > > I've been looking for something in the documentation > (https://docs.python.org/3.8/reference/datamodel.html) recently > and I've noticed something weird. Documentation states that every > object has a value, but doesn?t provide any definition > whatsoever of what the value is. Now, I'm sure that every reasonably > fluent Python programmer has an intuitive > understanding of the term, nonetheless, I would expect the > documentation defines it somehow (not necessarily > in a formal fashion), especially considering that "the value of an > object" is used to explain other concepts, such as > mutability: > > > The value of some objects can change. Objects whose value can change are said to be mutable; objects whose > value is unchangeable once they are created are called immutable. > > So, why is documentation silent on this? One reason I can think of is > to avoid answering inconvenient questions. Sorta kinda, yeah. There is one very simple definition of "value" which is entirely accurate, but probably not helpful, and that is: An object's value is whatever it is equal to. That is to say, you can ask two basic questions about an object: x is y # identity: are x and y the SAME object? x == y # equality: do x and y have the same value? Value and equality are intrinsically linked, but unfortunately that doesn't really explain what either one actually IS. As Rhodri says, you can ask a philosopher about that, and will be stuck for weeks :) The concept of "immutable" vs "mutable" object, therefore, is that some objects may compare equal now and unequal later. Since the same object is able to change in "value" over time, it may become (un)equal to something while still being the same object. Thus mutable objects can't be used as dict keys, as their values could change, and dict lookups have to match based on equality. (Imagine putting two keys into a dict while they have different values, and then mutating one of them to have the same value. Now try to look up that new value using a third object. The Logic Police will arrest you before you can say "hashability"!) Generally, Python objects have their values defined by an abstract concept that is being represented. For instance, the integer 32 and the float 32.0 have the same value, even though they're different types; they both represent the abstract number equal to two-to-the-fifth. But right here in that sentence, you can see how hard it is to actually *define* that value. At best, all you can really say is that the value is equal to the value of int("32") or some other way of getting an object with that value. Yep, it's hard. But the cool thing is, it usually doesn't matter - you can say "x has the value 32" without worrying about representations, data types, etc. ChrisA From r at dev.null Mon Nov 19 15:26:11 2018 From: r at dev.null (Robert Girault) Date: Mon, 19 Nov 2018 18:26:11 -0200 Subject: on the prng behind random.random() References: <86wop9ez1q.fsf@dev.null> Message-ID: <86r2fgg6fw.fsf@dev.null> Peter Otten <__peter__ at web.de> writes: > Robert Girault wrote: > >> Looking at its source code, it seems the PRNG behind random.random() is >> Mersenne Twister, but I'm not sure. It also seems that random.random() >> is using /dev/urandom. Can someone help me to read that source code? >> >> I'm talking about CPython, by the way. I'm reading >> >> https://github.com/python/cpython/blob/master/Lib/random.py >> >> The initial comment clearly says it's Mersenne Twister, but the only >> random() function there seems to call _urandom(), which I suppose is an >> interface to /dev/urandom. >> >> What am I missing here? > > There's a class random.Random which is instantiated at the end of the file, > and random() is bound to the corresponding method: > > _inst = Random() > ... > random = _inst.random > > The Random class inherits from _random.Random [...] Thanks. I missed that. > which is implemented in C and does most of the actual work. If you can > read C: > > https://github.com/python/cpython/blob/master/Modules/_randommodule.c > > The most relevant part seems to be genrand_int32() which is wrapped by > random_random() that actually implenents the _random.Random.random() method. Nice. So Python's random.random() does indeed use mt19937. Since it's been broken for years, why isn't it replaced by something newer like ChaCha20? Is it due to backward compatibility? That would make sense. Do you know who broke mt19937 and when? I'd love to read the reference. Thank you! From iwoherka at gmail.com Mon Nov 19 15:31:40 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Mon, 19 Nov 2018 21:31:40 +0100 Subject: Question about the definition of the value of an object In-Reply-To: References: Message-ID: > Attempting to define value here would be at best a massive > distraction from the concepts the documentation is trying > to get across. > There is one very simple definition of "value" which is entirely > accurate, but probably not helpful, and that is: An object's > value is whatever it is equal to. > Generally, Python objects have their values defined by an abstract > concept that is being represented. That confirms my intuition. Thank you for the responses. Sincerely, Iwo Herka pon., 19 lis 2018 o 20:46 Chris Angelico napisa?(a): > > On Tue, Nov 20, 2018 at 3:08 AM Iwo Herka wrote: > > > > Hello everyone, > > > > I've been looking for something in the documentation > > (https://docs.python.org/3.8/reference/datamodel.html) recently > > and I've noticed something weird. Documentation states that every > > object has a value, but doesn?t provide any definition > > whatsoever of what the value is. Now, I'm sure that every reasonably > > fluent Python programmer has an intuitive > > understanding of the term, nonetheless, I would expect the > > documentation defines it somehow (not necessarily > > in a formal fashion), especially considering that "the value of an > > object" is used to explain other concepts, such as > > mutability: > > > > > The value of some objects can change. Objects whose value can change are said to be mutable; objects whose > > value is unchangeable once they are created are called immutable. > > > > So, why is documentation silent on this? One reason I can think of is > > to avoid answering inconvenient questions. > > Sorta kinda, yeah. There is one very simple definition of "value" > which is entirely accurate, but probably not helpful, and that is: An > object's value is whatever it is equal to. That is to say, you can ask > two basic questions about an object: > > x is y # identity: are x and y the SAME object? > x == y # equality: do x and y have the same value? > > Value and equality are intrinsically linked, but unfortunately that > doesn't really explain what either one actually IS. As Rhodri says, > you can ask a philosopher about that, and will be stuck for weeks :) > > The concept of "immutable" vs "mutable" object, therefore, is that > some objects may compare equal now and unequal later. Since the same > object is able to change in "value" over time, it may become (un)equal > to something while still being the same object. Thus mutable objects > can't be used as dict keys, as their values could change, and dict > lookups have to match based on equality. (Imagine putting two keys > into a dict while they have different values, and then mutating one of > them to have the same value. Now try to look up that new value using a > third object. The Logic Police will arrest you before you can say > "hashability"!) > > Generally, Python objects have their values defined by an abstract > concept that is being represented. For instance, the integer 32 and > the float 32.0 have the same value, even though they're different > types; they both represent the abstract number equal to > two-to-the-fifth. But right here in that sentence, you can see how > hard it is to actually *define* that value. At best, all you can > really say is that the value is equal to the value of int("32") or > some other way of getting an object with that value. > > Yep, it's hard. But the cool thing is, it usually doesn't matter - you > can say "x has the value 32" without worrying about representations, > data types, etc. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Nov 19 15:38:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Nov 2018 07:38:01 +1100 Subject: on the prng behind random.random() In-Reply-To: <86r2fgg6fw.fsf@dev.null> References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> Message-ID: On Tue, Nov 20, 2018 at 7:31 AM Robert Girault wrote: > Nice. So Python's random.random() does indeed use mt19937. Since it's > been broken for years, why isn't it replaced by something newer like > ChaCha20? Is it due to backward compatibility? That would make sense. What exactly do you mean by "broken"? If you're generating random numbers for any sort of security purpose, you probably should look at this: https://docs.python.org/3/library/secrets.html (New in 3.6, though, hence the "probably". If you need to support 3.5 or older - including 2.7 - then you can't use that.) ChrisA From martin.schoon at gmail.com Mon Nov 19 15:41:38 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 19 Nov 2018 20:41:38 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Den 2018-11-18 skrev Stefan Ram : > Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?= writes: >>to read from such files. This works so so. 'Common floats' (3,1415 etc) >>works just fine but 'scientific' stuff (1,6023e23) does not work. > > main.py > > import sys > import pandas > import locale > print( sys.version ) > print( pandas.__version__ ) > with open( 'schoon20181118232102.csv', 'w' ) as file: > print( 'col0\tcol1', file=file, flush=True ) > print( '1,1\t0', file=file, flush=True ) > print( '10,24e-05\t1', file=file, flush=True ) > print( '9,492e-10\t2', file=file, flush=True ) > EUData = pandas.read_csv\ > ( 'schoon20181118232102.csv', sep='\t', decimal=',', engine='python' ) > locale.setlocale( locale.LC_ALL, 'de' ) > print( 2 * locale.atof( EUData[ 'col0' ][ 1 ])) > > transcript > > 3.7.0 > 0.23.4 > 0.0002048 > Thanks, I just tried this. The line locale.setlocale... throws an error: "locale.Error: unsupported locale setting" Trying other ideas instead of 'de' results in more of the same. '' results in no errors. The output I get is this: 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] 0.22.0 0.0002048 Scratching my head and speculating: I run this in a Virtualenv I have created for Jupyter and pandas and whatever I feel I need for this. Could locale be undefined or something that causes this? /Martin From martin.schoon at gmail.com Mon Nov 19 15:44:04 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 19 Nov 2018 20:44:04 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Too many files to go through them with an editor :-( /Martin From rosuav at gmail.com Mon Nov 19 15:48:34 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Nov 2018 07:48:34 +1100 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: On Tue, Nov 20, 2018 at 7:46 AM Martin Sch??n wrote: > Thanks, I just tried this. The line locale.setlocale... throws an > error: > > "locale.Error: unsupported locale setting" > > Trying other ideas instead of 'de' results in more of the same. > '' results in no errors. Haven't been reading in detail, but maybe "de_DE" will work better, assuming you have that locale installed. ChrisA From martin.schoon at gmail.com Mon Nov 19 15:59:44 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 19 Nov 2018 20:59:44 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Den 2018-11-19 skrev Peter Otten <__peter__ at web.de>: > Martin Sch??n wrote: > >> My pandas is up to date. >> > > The engine="python" produces an exception over here: > > """ > ValueError: The 'decimal' option is not supported with the 'python' engine > """ > > Maybe you can try and omit that option? Bingo! No, I don't remember why I added that engine thing. It was two days ago! > If that doesn't work you can specify a converter: > >>>> pd.read_csv("file.csv", sep="\t", converters={0: lambda s: > float(s.replace(",", "."))}) > col1 col2 > 0 1.100000e+00 0 > 1 1.024000e-04 1 > 2 9.492000e-10 2 > > [3 rows x 2 columns] > I save that one for later. One never nows... /Martin From r at dev.null Mon Nov 19 16:05:44 2018 From: r at dev.null (Robert Girault) Date: Mon, 19 Nov 2018 19:05:44 -0200 Subject: on the prng behind random.random() References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> Message-ID: <86d0r0g4lz.fsf@dev.null> Chris Angelico writes: > On Tue, Nov 20, 2018 at 7:31 AM Robert Girault wrote: >> Nice. So Python's random.random() does indeed use mt19937. Since it's >> been broken for years, why isn't it replaced by something newer like >> ChaCha20? Is it due to backward compatibility? That would make sense. > > What exactly do you mean by "broken"? I mean the fact that with 624 samples from the generator, you can determine the rest of the sequence completely. Sorry about mentioning ChaCha20. That was misleading. I should've said something newer like mrtg32k3a or xorshift*. > If you're generating random numbers for any sort of security purpose, > you probably should look at this: > > https://docs.python.org/3/library/secrets.html > > (New in 3.6, though, hence the "probably". If you need to support 3.5 > or older - including 2.7 - then you can't use that.) Thanks for the reference! I'm not particularly interested in security at the moment, but I would like an expert's confirmation that some of these algorithms arent't replaced due to backward compatibility. We could easily replace them, but I think we shouldn't: some people still depend on these algorithms for their experiment. Are there other reasons? From martin.schoon at gmail.com Mon Nov 19 16:32:07 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 19 Nov 2018 21:32:07 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Den 2018-11-19 skrev Martin Sch??n : > Den 2018-11-19 skrev Peter Otten <__peter__ at web.de>: >> >> The engine="python" produces an exception over here: >> >> """ >> ValueError: The 'decimal' option is not supported with the 'python' engine >> """ >> >> Maybe you can try and omit that option? > > Bingo! > No, I don't remember why I added that engine thing. It was two days ago! > >> If that doesn't work you can specify a converter: >> >>>>> pd.read_csv("file.csv", sep="\t", converters={0: lambda s: >> float(s.replace(",", "."))}) >> col1 col2 >> 0 1.100000e+00 0 >> 1 1.024000e-04 1 >> 2 9.492000e-10 2 >> >> [3 rows x 2 columns] > I spoke too early. Upon closer inspection I get the first column with decimal '.' and the rest with decimal ','. I have tried the converter thing to no avail :-( /Martin From ian.g.kelly at gmail.com Mon Nov 19 17:07:27 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 19 Nov 2018 15:07:27 -0700 Subject: on the prng behind random.random() In-Reply-To: <86d0r0g4lz.fsf@dev.null> References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> <86d0r0g4lz.fsf@dev.null> Message-ID: On Mon, Nov 19, 2018 at 2:12 PM Robert Girault wrote: > > Chris Angelico writes: > > > On Tue, Nov 20, 2018 at 7:31 AM Robert Girault wrote: > >> Nice. So Python's random.random() does indeed use mt19937. Since it's > >> been broken for years, why isn't it replaced by something newer like > >> ChaCha20? Is it due to backward compatibility? That would make sense. > > > > What exactly do you mean by "broken"? > > I mean the fact that with 624 samples from the generator, you can > determine the rest of the sequence completely. > > Sorry about mentioning ChaCha20. That was misleading. I should've said > something newer like mrtg32k3a or xorshift*. If you wish to propose replacing it, that topic is probably best brought up at python-dev. From python at mrabarnett.plus.com Mon Nov 19 18:36:41 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Nov 2018 23:36:41 +0000 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: <477631cc-d33d-c850-1a54-f586cbe48eef@mrabarnett.plus.com> On 2018-11-19 21:32, Martin Sch??n wrote: > Den 2018-11-19 skrev Martin Sch??n : >> Den 2018-11-19 skrev Peter Otten <__peter__ at web.de>: >>> >>> The engine="python" produces an exception over here: >>> >>> """ >>> ValueError: The 'decimal' option is not supported with the 'python' engine >>> """ >>> >>> Maybe you can try and omit that option? >> >> Bingo! >> No, I don't remember why I added that engine thing. It was two days ago! >> >>> If that doesn't work you can specify a converter: >>> >>>>>> pd.read_csv("file.csv", sep="\t", converters={0: lambda s: >>> float(s.replace(",", "."))}) >>> col1 col2 >>> 0 1.100000e+00 0 >>> 1 1.024000e-04 1 >>> 2 9.492000e-10 2 >>> >>> [3 rows x 2 columns] >> > I spoke too early. Upon closer inspection I get the first column with > decimal '.' and the rest with decimal ','. I have tried the converter > thing to no avail :-( > You passed {0: lambda s: float(s.replace(",", "."))} as the converters argument, which means that it applies only to column 0. From python at mrabarnett.plus.com Mon Nov 19 18:39:21 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Nov 2018 23:39:21 +0000 Subject: Reading 'scientific' csv using Pandas? In-Reply-To: References: Message-ID: <0eed7185-a462-24cf-5a69-8a3bb614fc3c@mrabarnett.plus.com> On 2018-11-19 20:44, Martin Sch??n wrote: > Too many files to go through them with an editor :-( > If only Python could read and write files... :-) From r at dev.null Mon Nov 19 18:49:42 2018 From: r at dev.null (Robert Girault) Date: Mon, 19 Nov 2018 21:49:42 -0200 Subject: on the prng behind random.random() References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> <86d0r0g4lz.fsf@dev.null> <66f6vdha0ri11rpi9mpqgi1aqaoh0dthrg@4ax.com> Message-ID: <864lccfx0p.fsf@dev.null> Dennis Lee Bieber writes: > On Mon, 19 Nov 2018 19:05:44 -0200, Robert Girault declaimed > the following: > >>I mean the fact that with 624 samples from the generator, you can >>determine the rest of the sequence completely. > > Being able to predict the sequence after a large sampling does not mean > that the /distribution of values/ is not (pseudo-) random. The problem with determining its sequence is that it might defeat its purpose. If you use mt19937 to select a pivot in random Quicksort for example (where you plan to spend n lg n time in sorting), we can frustrate your plans and force it into n^2 every time, an effective DoS attack on your software. > After all, pretty much all random number generators will produce the > same sequence if given the same starting seed... You are, in effect, > treating your 624 samples as a very large seed... I think I disagree with your take here. With mt19937, given ANY seed, I can eventually predict all the sequence without having to query the oracle any further. If you're just writing a toy software, even K&R PRNG works just fine. If you're writing a weather simulation, I suppose you need real random-like properties and still need your generator to be reproducible. If you're using random Quicksort, you do need unpredictability and reproducibility. If you're writing a crypto application, then you need something way stronger. We need all of them. But mt19937 is now useful only in toy software. From rosuav at gmail.com Mon Nov 19 19:01:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Nov 2018 11:01:45 +1100 Subject: on the prng behind random.random() In-Reply-To: <864lccfx0p.fsf@dev.null> References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> <86d0r0g4lz.fsf@dev.null> <66f6vdha0ri11rpi9mpqgi1aqaoh0dthrg@4ax.com> <864lccfx0p.fsf@dev.null> Message-ID: On Tue, Nov 20, 2018 at 10:51 AM Robert Girault wrote: > If you're just writing a toy software, even K&R PRNG works just fine. > If you're writing a weather simulation, I suppose you need real > random-like properties and still need your generator to be reproducible. > If you're using random Quicksort, you do need unpredictability and > reproducibility. If you're writing a crypto application, then you need > something way stronger. We need all of them. But mt19937 is now useful > only in toy software. I disagree. Yes, in a crypto-sensitive situation, you can't depend on the Twister... but you shouldn't be relying on *any* PRNG for that. There are plenty of situations where you need something unpredictable but it doesn't have to be THAT safe. Your example of picking a random pivot for quicksort is a perfect example. Let's suppose I am sorting by that method... how are you going to get 624 consecutive outputs? If you can provide a custom comparison function, you can DOS the search just by making that inefficient. If you can't, how are you going to reconstruct the randomness? Is this REALLY a viable attack vector? It's different if, say, you're operating a virtual casino, and letting people watch the roulette wheel spins. (Though even then, reconstructing the twister's state from a series of 1-in-38 results isn't going to be trivial.) But it's overly paranoid to say that every single PRNG needs to be cryptographically secure. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Nov 19 19:07:47 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Mon, 19 Nov 2018 19:07:47 -0500 Subject: on the prng behind random.random() In-Reply-To: <864lccfx0p.fsf@dev.null> References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> <86d0r0g4lz.fsf@dev.null> <66f6vdha0ri11rpi9mpqgi1aqaoh0dthrg@4ax.com> <864lccfx0p.fsf@dev.null> Message-ID: <1d6ad4cb-00c3-78a7-2f73-b40ca339412b@potatochowder.com> On 11/19/18 6:49 PM, Robert Girault wrote: > I think I disagree with your take here. With mt19937, given ANY seed, > I can eventually predict all the sequence without having to query the > oracle any further. Even if that's true, and I use mt19937 inside my program, you don't [usually|necessarily] have access to the raw output from it. > If you're just writing a toy software, even K&R PRNG works just fine. > If you're writing a weather simulation, I suppose you need real > random-like properties and still need your generator to be reproducible. > If you're using random Quicksort, you do need unpredictability and > reproducibility. If you're writing a crypto application, then you need > something way stronger. We need all of them ... Agreed. Mostly. IIRC, though, your question was about *replacing* mt19937, not adding a new RNG. Please use the right tool for the job at hand. > ... But mt19937 is now useful only in toy software. It has "real random-like" properties (for certain definitions of "real" and "random-like") and it's reproducible. Therefore, it's good for weather simulations, too. From vandys at vsta.org Mon Nov 19 20:26:25 2018 From: vandys at vsta.org (Andy Valencia) Date: Mon, 19 Nov 2018 17:26:25 -0800 Subject: pdb which handles threads Message-ID: <154267718537.25647.1600907459243900104@pacman.vsta.org> I had yet another program where I accidentally had more than one thread enter pdb at once, leaving me with the "pdb's battling for the keyboard" syndrome. So I extended pdb to recognize and handle threads. I added: "jobs" List threads, with one current one being the only one involved with the keyboard. All others wait politely. "fg " To switch to a different thread. I welcome comments (it's for Python 2), under: http://sources.vsta.org/ Regards, Andy Valencia From auriocus at gmx.de Tue Nov 20 03:47:38 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 20 Nov 2018 09:47:38 +0100 Subject: on the prng behind random.random() In-Reply-To: <86d0r0g4lz.fsf@dev.null> References: <86wop9ez1q.fsf@dev.null> <86r2fgg6fw.fsf@dev.null> <86d0r0g4lz.fsf@dev.null> Message-ID: Am 19.11.18 um 22:05 schrieb Robert Girault: > Chris Angelico writes: > >> On Tue, Nov 20, 2018 at 7:31 AM Robert Girault wrote: >>> Nice. So Python's random.random() does indeed use mt19937. Since it's >>> been broken for years, why isn't it replaced by something newer like >>> ChaCha20? Is it due to backward compatibility? That would make sense. >> >> What exactly do you mean by "broken"? > > I mean the fact that with 624 samples from the generator, you can > determine the rest of the sequence completely. As far as I understand it, this is true only if you see the full 32bit output number from the Mersenne Twister for those 624 outputs. If however you create a list: [random.randrange(10) for i in range(624)] I don't think you can predict what follows. Christian From o1bigtenor at gmail.com Tue Nov 20 08:37:24 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Tue, 20 Nov 2018 07:37:24 -0600 Subject: question on the 'calendar' function Message-ID: Greetings I am in the process of learning my first computer programming language (unless g-code counts and then it is my second - - - grin). It definitely is a big world out there. The calendar function has a lot of versatility and shows care in its development. There is one area where I don't understand if I even could use this function or if I need to look to something(s) else to achieve what I need. For planning I need to be able to easily look backward 6 months and forward at least 12 and better 18 months and would prefer perhaps even a total of 36 (and even 60 might be useful) months of calendar available. It could be useful to see the longer time spans as weeks rather than as days but seeing the larger time frames only as months would enable the planning that I need to do. Do I need to (somehow and I have no idea how) extend the calendar function? Is there some other way of displaying dates/calendars that would allow me to achieve my needed span? TIA From a24061 at ducksburg.com Tue Nov 20 11:21:34 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 20 Nov 2018 16:21:34 +0000 Subject: Suggestions for plotting slide rule & sector scales? References: Message-ID: On 2018-11-08, Stefan Ram wrote: > Adam Funk writes: >>and get a line 100 mm long with a log scale on the top and a linear >>scale on the bottom. > > From what I have heard, > > pyqt.sourceforge.net/Docs/PyQt4/qx11info.html#appDpiX > > will give you the dots per inch (link not validated). > > matplotlib.axis.Axis handles drawing of t tick lines, > grid lines, tick and axis label (information not verified). I hadn't thought of using matplotlib to do axes only, without the rest of the graph --- interesting idea. I've also found pynomo, which looks more appropriate, but I'm having problems with that (see other post). -- Physics is like sex. Sure, it may give some practical results, but that's not why we do it. ---Richard Feynman From a24061 at ducksburg.com Tue Nov 20 11:25:47 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 20 Nov 2018 16:25:47 +0000 Subject: Basic pynomo instructions not working Message-ID: Hi, I'm trying to use the basic stuff in pynomo which I've installed with pip3, but I run into this problem trying to the basic stuff in the documentation: #v+ $ python3 Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from pynomo.nomographer import * Traceback (most recent call last): File "", line 1, in File "/home/adam/.local/lib/python3.6/site-packages/pynomo/nomographer.py", line 16, in from nomo_wrapper import * ModuleNotFoundError: No module named 'nomo_wrapper' >>> import pynomo >>> import pynomo.nomographer Traceback (most recent call last): File "", line 1, in File "/home/adam/.local/lib/python3.6/site-packages/pynomo/nomographer.py", line 16, in from nomo_wrapper import * ModuleNotFoundError: No module named 'nomo_wrapper' >>> #v- Any ideas? Thanks. From best_lay at yahoo.com Tue Nov 20 11:34:39 2018 From: best_lay at yahoo.com (Wildman) Date: Tue, 20 Nov 2018 10:34:39 -0600 Subject: Have I Been Banned? Message-ID: <8a-dnbxGX8cCqmnGnZ2dnUU7-fWdnZ2d@giganews.com> In the past I have participated in the group without any problems. I access the forum through the usenet mirror and I am still using the same newsreader and account. Recently I made some followup posts to the group and they never showed up. Have I been banned? If so, I would appreciate it to know why? Of course I am not sure if this post will make it to the server. -- GNU/Linux user #557453 Restricted area! Authorized trespassers only. From a24061 at ducksburg.com Tue Nov 20 11:39:39 2018 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 20 Nov 2018 16:39:39 +0000 Subject: bottledaemon stop/start doesn't work if killed elsewhere References: <44aca1ba-2bf2-15de-565b-d30be3606148@mrabarnett.plus.com> Message-ID: On 2018-11-18, Dan Sommers wrote: > On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote: > >> Hi, > >> > >> I'm using bottledaemon to run a little REST service on a Pi that takes > >> input from other machines on the LAN and stores stuff in a database. > >> I have a cron job to call 'stop' and 'start' on it daily, just in case > >> of problems. > >> > >> Occasionally the oom-killer runs overnight and kills the process using > >> bottledaemon; when this happens (unlike properly stopping the daemon), > >> the pidfile and its lockfile are left on the filesystem, so the 'stop' > >> does nothing and the 'start' gets refusedq because the old pidfile and > >> lockfile are present. At the moment, I eventually notice something > >> wrong with the output data, ssh into the Pi, and rm the two files then > >> call 'start' on the daemon again. > >> > >> Is there a recommended or good way to handle this situation > >> automatically? > >> > > Could you write a watchdog daemon that checks whether bottledaemon is > > running, and deletes those files if it isn't (or hasn't been for a > while)? > > What if the oom-killer kills the watchdog? > > Whatever runs in response to the start command has to be smarter: if > the pid and lock files exist, then check whether they refer to a > currently running bottledaemon. If so, then all is well, and refuse to > start a redundant daemon. If not, then remove the pid and lock files > and start the daemon. I've reported this as an issue on github. It seems to me that the 'stop' subcommand should delete the pidfile and lockfile if the pid is no longer running. -- It's like a pair of eyes. You're looking at the umlaut, and it's looking at you. ---David St. Hubbins From jon+usenet at unequivocal.eu Tue Nov 20 11:39:39 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 20 Nov 2018 16:39:39 -0000 (UTC) Subject: Have I Been Banned? References: <8a-dnbxGX8cCqmnGnZ2dnUU7-fWdnZ2d@giganews.com> Message-ID: On 2018-11-20, Wildman wrote: > In the past I have participated in the group without any > problems. I access the forum through the usenet mirror > and I am still using the same newsreader and account. > Recently I made some followup posts to the group and they > never showed up. Have I been banned? If so, I would > appreciate it to know why? If you mean you made posts to the comp.lang.python group and they did not show up on your news server then the problem is either at your end or with your news server - unlike the mailing list, the group is unmoderated and therefore nobody can be banned from it. From best_lay at yahoo.com Tue Nov 20 11:58:01 2018 From: best_lay at yahoo.com (Wildman) Date: Tue, 20 Nov 2018 10:58:01 -0600 Subject: Have I Been Banned? References: <8a-dnbxGX8cCqmnGnZ2dnUU7-fWdnZ2d@giganews.com> Message-ID: <8a-dnb9GX8eEoGnGnZ2dnUU7-fWdnZ2d@giganews.com> On Tue, 20 Nov 2018 16:39:39 +0000, Jon Ribbens wrote: > On 2018-11-20, Wildman wrote: >> In the past I have participated in the group without any >> problems. I access the forum through the usenet mirror >> and I am still using the same newsreader and account. >> Recently I made some followup posts to the group and they >> never showed up. Have I been banned? If so, I would >> appreciate it to know why? > > If you mean you made posts to the comp.lang.python group and they did > not show up on your news server then the problem is either at your > end or with your news server - unlike the mailing list, the group is > unmoderated and therefore nobody can be banned from it. Yes, I make posts to comp.lang.python. My newsreader's log says the posts are accepted by the server. I will contact Giganews to see if they can shed some light on the subject. -- GNU/Linux user #557453 The cow died so I don't need your bull! From Joseph.Schachner at Teledyne.com Tue Nov 20 12:50:45 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Tue, 20 Nov 2018 17:50:45 +0000 Subject: question on the 'calendar' function In-Reply-To: References: Message-ID: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. Example: import calendar print( calendar.monthcalendar(2022, 12) ) Prints lists of dates in each week of December 2022. It prints: [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]] So, Dec 1 is a Wednesday; Dec 31 is a Saturday. That's 49 months ahead of this month. Change the year and month to any (valid) number, and it will do what it does. The only caveat is that if the moon's orbit slows down as it gets farther away from the earth and the earth's rotation speed changes, then the calculations done by calendar for leap years may not be correct about the distant future. --- Joseph S. -----Original Message----- From: o1bigtenor Sent: Tuesday, November 20, 2018 8:37 AM To: python-list at python.org Subject: question on the 'calendar' function Greetings I am in the process of learning my first computer programming language (unless g-code counts and then it is my second - - - grin). It definitely is a big world out there. The calendar function has a lot of versatility and shows care in its development. There is one area where I don't understand if I even could use this function or if I need to look to something(s) else to achieve what I need. For planning I need to be able to easily look backward 6 months and forward at least 12 and better 18 months and would prefer perhaps even a total of 36 (and even 60 might be useful) months of calendar available. It could be useful to see the longer time spans as weeks rather than as days but seeing the larger time frames only as months would enable the planning that I need to do. Do I need to (somehow and I have no idea how) extend the calendar function? Is there some other way of displaying dates/calendars that would allow me to achieve my needed span? TIA From o1bigtenor at gmail.com Tue Nov 20 13:07:10 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Tue, 20 Nov 2018 12:07:10 -0600 Subject: question on the 'calendar' function In-Reply-To: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph wrote: > > It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. > > Example: > import calendar > print( calendar.monthcalendar(2022, 12) ) > > Prints lists of dates in each week of December 2022. It prints: > [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]] > > So, Dec 1 is a Wednesday; Dec 31 is a Saturday. > > That's 49 months ahead of this month. Change the year and month to any (valid) number, and it will do what it does. > The only caveat is that if the moon's orbit slows down as it gets farther away from the earth and the earth's rotation speed changes, then the calculations done by calendar for leap years may not be correct about the distant future. > Greetings If my syntax or commands are wrong - - - - I've just started so something is likely to NOT be correct - - - grin - - - I'sa noob! # calendar 2019 that is to show the year 2019 How could I show June 2018 to Dec 2019, inclusive? Or June 2018 to Dec 2021, inclusive? Or June 2018 to Dec 2023 by week (June wk 1,2,3,4 2018; July wk 1,2,3,4,5 2018; . . . Dec wk 1,2,3,4,5 2023 or maybe even by dates), inclusive? Note that the time frame is ALWAYS more than 1 year. AIUI there isn't a way to do that, at least not that I can see, and I would like to be able to do that. A friend suggested using a script wrapped around the command. I thought maybe there might we a way of doing what I need to do without using 2 levels of programming. Regards From ben+python at benfinney.id.au Tue Nov 20 13:07:22 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 21 Nov 2018 05:07:22 +1100 Subject: question on the 'calendar' function References: Message-ID: <86va4r1v39.fsf@benfinney.id.au> o1bigtenor writes: > I am in the process of learning my first computer programming language > (unless g-code counts and then it is my second - - - grin). It > definitely is a big world out there. Welcome, and congratulations on starting with Python! > The calendar function has a lot of versatility and shows care in its > development. I assume we are here talking about the standard library ?calendar? module , and the function is ?calendar.calendar? to generate a whole year calendar . > For planning I need to be able to easily look backward 6 months and > forward at least 12 and better 18 months and would prefer perhaps even > a total of 36 (and even 60 might be useful) months of calendar > available. It could be useful to see the longer time spans as weeks > rather than as days but seeing the larger time frames only as months > would enable the planning that I need to do. Have you looked through the rest of the documentation of that module? Does ?calendar.monthcalendar? come close to what you need ? > Do I need to (somehow and I have no idea how) extend the calendar > function? It's quite feasible you may get to that point, at which time you will want to learn about composing functions by calling other functions; eventually you will learn a different technique, of creating a class by inheriting from an existing class. But all that may be in the future! Try just using the existing functions from that library module and see how far that gets you. Good hunting. -- \ ?I have the simplest tastes. I am always satisfied with the | `\ best.? ?Oscar Wilde, quoted in _Chicago Brothers of the Book_, | _o__) 1917 | Ben Finney From o1bigtenor at gmail.com Tue Nov 20 14:05:27 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Tue, 20 Nov 2018 13:05:27 -0600 Subject: question on the 'calendar' function In-Reply-To: <86va4r1v39.fsf@benfinney.id.au> References: <86va4r1v39.fsf@benfinney.id.au> Message-ID: On Tue, Nov 20, 2018 at 12:09 PM Ben Finney wrote: > > o1bigtenor writes: > > > I am in the process of learning my first computer programming language > > (unless g-code counts and then it is my second - - - grin). It > > definitely is a big world out there. > > Welcome, and congratulations on starting with Python! > > > The calendar function has a lot of versatility and shows care in its > > development. > > I assume we are here talking about the standard library ?calendar? > module , and the > function is ?calendar.calendar? to generate a whole year calendar > . These are the documents that I was examining before I asked my question. > > > For planning I need to be able to easily look backward 6 months and > > forward at least 12 and better 18 months and would prefer perhaps even > > a total of 36 (and even 60 might be useful) months of calendar > > available. It could be useful to see the longer time spans as weeks > > rather than as days but seeing the larger time frames only as months > > would enable the planning that I need to do. > > Have you looked through the rest of the documentation of that module? > Does ?calendar.monthcalendar? come close to what you need > ? No - - - the limit is still one year (of 12 months) and my minimum would be 18 months and preferably quite a bit more. > > > Do I need to (somehow and I have no idea how) extend the calendar > > function? > > It's quite feasible you may get to that point, at which time you will > want to learn about composing functions by calling other functions; > eventually you will learn a different technique, of creating a class by > inheriting from an existing class. Hmmmmmmmmmm - - - this sounds like what I'm going to have to do. let's see if I can find docs on this. > > But all that may be in the future! Try just using the existing functions > from that library module and see how far that gets you. The calendar function as it exists just quite spread its wings far enough for my needs but this extension by inheritance is intriguing! Thanks for the ideas. From martin.schoon at gmail.com Tue Nov 20 15:06:50 2018 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 20 Nov 2018 20:06:50 GMT Subject: Reading 'scientific' csv using Pandas? References: Message-ID: Den 2018-11-19 skrev Martin Sch??n : > I spoke too early. Upon closer inspection I get the first column with > decimal '.' and the rest with decimal ','. I have tried the converter > thing to no avail :-( > Problem solved! This morning I woke up with the idea of testing if all this fuss may be caused by the fact that the 'objectional' files missed some data in their first few rows. I tested by replacing the blank spaces in one file with zeros. Bingo! For real this time! Missing data threw read_csv off course. Fortunately, only a few files needed a handful of zeros to work so I could do it manually without breaking too much sweat. Thanks for the keen interest shown. /Martin From ben+python at benfinney.id.au Tue Nov 20 20:59:27 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 21 Nov 2018 12:59:27 +1100 Subject: question on the 'calendar' function References: <86va4r1v39.fsf@benfinney.id.au> Message-ID: <86r2ff198g.fsf@benfinney.id.au> o1bigtenor writes: > On Tue, Nov 20, 2018 at 12:09 PM Ben Finney wrote: > > o1bigtenor writes: > > > It could be useful to see the longer time spans as weeks rather > > > than as days but seeing the larger time frames only as months > > > would enable the planning that I need to do. > > > > Does ?calendar.monthcalendar? come close to what you need > > ? > > No - - - the limit is still one year (of 12 months) and my minimum > would be 18 months and preferably quite a bit more. That doesn't match what I understand from the module documentation. Can you show a (small, self-contained) example that demonstrates the ?limit is still one year? when you try to use ?calendar.monthcalendar? for the purpose you described above? -- \ ?I have yet to see any problem, however complicated, which, | `\ when you looked at it in the right way, did not become still | _o__) more complicated.? ?Paul Anderson | Ben Finney From marco.nawijn at colosso.nl Wed Nov 21 03:34:11 2018 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Wed, 21 Nov 2018 00:34:11 -0800 (PST) Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote: > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph > wrote: > > > > It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. > > > > Example: > > import calendar > > print( calendar.monthcalendar(2022, 12) ) > > > > Prints lists of dates in each week of December 2022. It prints: > > [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]] > > > > So, Dec 1 is a Wednesday; Dec 31 is a Saturday. > > > > That's 49 months ahead of this month. Change the year and month to any (valid) number, and it will do what it does. > > The only caveat is that if the moon's orbit slows down as it gets farther away from the earth and the earth's rotation speed changes, then the calculations done by calendar for leap years may not be correct about the distant future. > > > > Greetings > > If my syntax or commands are wrong - - - - I've just started so > something is likely to NOT be correct - - - grin - - - I'sa noob! > > # calendar 2019 > > that is to show the year 2019 > > How could I show June 2018 to Dec 2019, inclusive? > Or June 2018 to Dec 2021, inclusive? > Or June 2018 to Dec 2023 by week (June wk 1,2,3,4 2018; July wk > 1,2,3,4,5 2018; . . . Dec wk 1,2,3,4,5 2023 or maybe even by dates), > inclusive? > > Note that the time frame is ALWAYS more than 1 year. > AIUI there isn't a way to do that, at least not that I can see, and I > would like to be able to do that. > A friend suggested using a script wrapped around the command. I > thought maybe there might we a way of doing what I need to do without > using 2 levels of programming. > > Regards >From what you post it seems like you are on a Linux kind of system and you are running the `calendar` command in the bash terminal. If that is correct, try the following: In the bash terminal type (without the literal #): # python This will put you in the Python prompt (marked with >>>). Check that the first line starts with Python 3. If not, I highly recommend you install Python 3. If it is Python two, the following will work, but you have to drop the outer parentheses for print (thus print calendar.calendar()) Then type the following: >>> import calendar >>> print(calendar.calendar(2020)) This will show: 2020 January February March Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 1 6 7 8 9 10 11 12 3 4 5 6 7 8 9 2 3 4 5 6 7 8 13 14 15 16 17 18 19 10 11 12 13 14 15 16 9 10 11 12 13 14 15 20 21 22 23 24 25 26 17 18 19 20 21 22 23 16 17 18 19 20 21 22 27 28 29 30 31 24 25 26 27 28 29 23 24 25 26 27 28 29 30 31 April May June Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7 6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14 13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21 20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28 27 28 29 30 25 26 27 28 29 30 31 29 30 July August September Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 1 2 1 2 3 4 5 6 6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13 13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20 20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27 27 28 29 30 31 24 25 26 27 28 29 30 28 29 30 31 October November December Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 1 1 2 3 4 5 6 5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13 12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20 19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27 26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31 30 Now look at the documentation of the calendar module to find out about other options. Marco From o1bigtenor at gmail.com Wed Nov 21 07:27:08 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 21 Nov 2018 06:27:08 -0600 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On Wed, Nov 21, 2018 at 2:37 AM wrote: > > On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote: > > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph > > wrote: > > > > > > It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. > > > > > > Example: > > > import calendar > > > print( calendar.monthcalendar(2022, 12) ) > > > > > > Prints lists of dates in each week of December 2022. It prints: > > > [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]] > > > > > > So, Dec 1 is a Wednesday; Dec 31 is a Saturday. > > > > > > That's 49 months ahead of this month. Change the year and month to any (valid) number, and it will do what it does. > > > The only caveat is that if the moon's orbit slows down as it gets farther away from the earth and the earth's rotation speed changes, then the calculations done by calendar for leap years may not be correct about the distant future. > > > > > > > Greetings > > > > If my syntax or commands are wrong - - - - I've just started so > > something is likely to NOT be correct - - - grin - - - I'sa noob! > > > > # calendar 2019 > > > > that is to show the year 2019 > > > > How could I show June 2018 to Dec 2019, inclusive? > > Or June 2018 to Dec 2021, inclusive? > > Or June 2018 to Dec 2023 by week (June wk 1,2,3,4 2018; July wk > > 1,2,3,4,5 2018; . . . Dec wk 1,2,3,4,5 2023 or maybe even by dates), > > inclusive? > > > > Note that the time frame is ALWAYS more than 1 year. > > AIUI there isn't a way to do that, at least not that I can see, and I > > would like to be able to do that. > > A friend suggested using a script wrapped around the command. I > > thought maybe there might we a way of doing what I need to do without > > using 2 levels of programming. > > > > Regards > > From what you post it seems like you are on a Linux kind of system and you are running the `calendar` command in the bash terminal. If that is correct, try the following: > > In the bash terminal type (without the literal #): > # python > > This will put you in the Python prompt (marked with >>>). > Check that the first line starts with Python 3. If not, I highly recommend > you install Python 3. If it is Python two, the following will work, but you > have to drop the outer parentheses for print (thus print calendar.calendar()) > > Then type the following: > >>> import calendar > >>> print(calendar.calendar(2020)) > Now look at the documentation of the calendar module to find out about > other options. > Thank you very much Mr Marco - - - that got me to being able to do something (will need time to figure out how to do the rest! grin!!). I have read through the documentation and there really doesn't seem to be a way to do what I would like to do - - - - in this case. What I can't do is (following your directions) >>> import calendar >>> print(calendar.calendar(Mar 2018 to Dec 2023)) What I need is to be able to have more than one calendar year options and this function seems to be limited to work with a maximum of only one year at a time. If I not reading the documentation correctly - - - please advise. (Thanking you for your generous assistance in the foregoing!) Regards From banik77061 at gmail.com Wed Nov 21 08:42:40 2018 From: banik77061 at gmail.com (Sourav Banik) Date: Wed, 21 Nov 2018 19:42:40 +0600 Subject: Need help for python on my pc. Message-ID: Hello Python team, I'm using python 3.7(32 bit) for several months on my same laptop (x64 processor). I worked on some django project very swiftly without any problem. But for a few days I am facing a serious problem. My python files are not showing properly by the file manager. It is just showing 'python source file' without any logo. When I open my cmd to work on django, it is not also working though virtualenv is working properly I think. I'm sending some screenshots of cmd and files for your reference. I've tried reinstalling (64 bit) and repairing of python but nothing is working. I want your help to sort out this issue. From Sourav Banik, Dhaka,Bangladesh. From cspealma at redhat.com Wed Nov 21 09:09:00 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Nov 2018 09:09:00 -0500 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: You really have the pieces you need here. You can print a whole year's calendar with calendar.formatyear() or a single month with calendar.monthcalendar(). If you need multiple years, call the first more than once with each year you need to print. If you need partial years, print the individual months you need with monthcalendar() Can you actually be more specific on what about the task is stumping you? On Wed, Nov 21, 2018 at 7:28 AM o1bigtenor wrote: > On Wed, Nov 21, 2018 at 2:37 AM wrote: > > > > On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote: > > > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph > > > wrote: > > > > > > > > It's possible I don't understand the question. The calendar > functions are NOT limited to this year or any limited range. > > > > > > > > Example: > > > > import calendar > > > > print( calendar.monthcalendar(2022, 12) ) > > > > > > > > Prints lists of dates in each week of December 2022. It prints: > > > > [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, > 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 0]] > > > > > > > > So, Dec 1 is a Wednesday; Dec 31 is a Saturday. > > > > > > > > That's 49 months ahead of this month. Change the year and month to > any (valid) number, and it will do what it does. > > > > The only caveat is that if the moon's orbit slows down as it gets > farther away from the earth and the earth's rotation speed changes, then > the calculations done by calendar for leap years may not be correct about > the distant future. > > > > > > > > > > Greetings > > > > > > If my syntax or commands are wrong - - - - I've just started so > > > something is likely to NOT be correct - - - grin - - - I'sa noob! > > > > > > # calendar 2019 > > > > > > that is to show the year 2019 > > > > > > How could I show June 2018 to Dec 2019, inclusive? > > > Or June 2018 to Dec 2021, inclusive? > > > Or June 2018 to Dec 2023 by week (June wk 1,2,3,4 2018; July wk > > > 1,2,3,4,5 2018; . . . Dec wk 1,2,3,4,5 2023 or maybe even by dates), > > > inclusive? > > > > > > Note that the time frame is ALWAYS more than 1 year. > > > AIUI there isn't a way to do that, at least not that I can see, and I > > > would like to be able to do that. > > > A friend suggested using a script wrapped around the command. I > > > thought maybe there might we a way of doing what I need to do without > > > using 2 levels of programming. > > > > > > Regards > > > > From what you post it seems like you are on a Linux kind of system and > you are running the `calendar` command in the bash terminal. If that is > correct, try the following: > > > > In the bash terminal type (without the literal #): > > # python > > > > This will put you in the Python prompt (marked with >>>). > > Check that the first line starts with Python 3. If not, I highly > recommend > > you install Python 3. If it is Python two, the following will work, but > you > > have to drop the outer parentheses for print (thus print > calendar.calendar()) > > > > Then type the following: > > >>> import calendar > > >>> print(calendar.calendar(2020)) > > > Now look at the documentation of the calendar module to find out about > > other options. > > > > Thank you very much Mr Marco - - - that got me to being able to do > something > (will need time to figure out how to do the rest! grin!!). > I have read through the documentation and there really doesn't seem to be > a way > to do what I would like to do - - - - in this case. > > What I can't do is (following your directions) > > >>> import calendar > >>> print(calendar.calendar(Mar 2018 to Dec 2023)) > > What I need is to be able to have more than one calendar year options and > this > function seems to be limited to work with a maximum of only one year at a > time. > > If I not reading the documentation correctly - - - please advise. > (Thanking you for your generous assistance in the foregoing!) > > Regards > -- > https://mail.python.org/mailman/listinfo/python-list > From iwoherka at gmail.com Wed Nov 21 11:45:11 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Wed, 21 Nov 2018 16:45:11 +0000 Subject: Question about implementing immutability Message-ID: Hello, Let's say I want to implement immutability for user-defined class. More precisely, a class that can be modified only in its (or its super-class') __init__ method. My initial idea was to do it the following fashion: def __setattr__(self, *args, **kwargs): if sys._getframe(1).f_code.co_name == '__init__': return super().__setattr__(*args, **kwargs) raise AttributeError() What do you think of this approach? Is there a better one? Thanks. Sincerely, Iwo Herka From o1bigtenor at gmail.com Wed Nov 21 12:00:41 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 21 Nov 2018 11:00:41 -0600 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On Wed, Nov 21, 2018 at 8:09 AM Calvin Spealman wrote: > > You really have the pieces you need here. You can print a whole year's calendar with calendar.formatyear() or a single month with calendar.monthcalendar(). If you need multiple years, call the first more than once with each year you need to print. If you need partial years, print the individual months you need with monthcalendar() > > Can you actually be more specific on what about the task is stumping you? OK so there needs to be a 2 level request, as I'm thinking of it, rather than being able to write something like (using human speak): print 36 months starting from 2017.06 or print 60 months starting from 2017.03 with possible formatting instructions. There seem to be a severe limit in the function in that a year is a maximum single time frame. I need to function within a time range of 2 to 3 or 4 years. That means that I move between the week/month and the longer frame lots and most software seems to be hard limited to a single year as the limit on the macro scale. Oh well - - - - guess I can't do what I want then - - - thanks for the assistance. Regards From none at invalid.com Wed Nov 21 12:01:31 2018 From: none at invalid.com (mm0fmf) Date: Wed, 21 Nov 2018 17:01:31 +0000 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On 21/11/2018 12:27, o1bigtenor wrote: [Stuff clipped] > > What I need is to be able to have more than one calendar year options and this > function seems to be limited to work with a maximum of only one year at a time. > > If I not reading the documentation correctly - - - please advise. > (Thanking you for your generous assistance in the foregoing!) > > Regards > You need to write a program (in Python) to do that using the methods in the calendar module. HINT: print out the calendar for each month you are interested in and use a loop of some kind to generate the year/month data to feed to calendar methods from a starting and stopping date. There will be many other ways of doing this but a solution that works, even if ugly, is better than no solution. From python at bladeshadow.org Wed Nov 21 14:18:22 2018 From: python at bladeshadow.org (Python) Date: Wed, 21 Nov 2018 13:18:22 -0600 Subject: Odd truth result with in and == Message-ID: <20181121191822.GC32735@bladeshadow.org> $ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 in [1,2,3] == True False >>> 1 in ([1,2,3] == True) Traceback (most recent call last): File "", line 1, in TypeError: argument of type 'bool' is not iterable >>> (1 in [1,2,3]) == True True How is the first not equivalent to either one of the second or third? My expectation is it should produce the same result as the second. It *seems* like Python is ignoring the '1 in' part and just giving the result for '[1,2,3] == True'... Is this just a bug? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: From python at bladeshadow.org Wed Nov 21 14:31:23 2018 From: python at bladeshadow.org (Python) Date: Wed, 21 Nov 2018 13:31:23 -0600 Subject: Odd truth result with in and == In-Reply-To: <20181121191822.GC32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> Message-ID: <20181121193123.GD32735@bladeshadow.org> On Wed, Nov 21, 2018 at 01:18:22PM -0600, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 in [1,2,3] == True > False > >>> 1 in ([1,2,3] == True) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable > >>> (1 in [1,2,3]) == True > True > > How is the first not equivalent to either one of the second or third? > My expectation is it should produce the same result as the second. It > *seems* like Python is ignoring the '1 in' part and just giving the > result for '[1,2,3] == True'... Is this just a bug? FWIW I meant my expectation is it should be the same as #3 (I confused the 2nd item with the second subsequent thing that it did not match) since "in" and "==" have the same precedence, and should be evaluated in order left to right. IOW, it should evaluate to True. From rosuav at gmail.com Wed Nov 21 14:33:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 06:33:54 +1100 Subject: Odd truth result with in and == In-Reply-To: <20181121191822.GC32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> Message-ID: On Thu, Nov 22, 2018 at 6:23 AM Python wrote: > > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 in [1,2,3] == True > False > >>> 1 in ([1,2,3] == True) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable > >>> (1 in [1,2,3]) == True > True > > How is the first not equivalent to either one of the second or third? > My expectation is it should produce the same result as the second. It > *seems* like Python is ignoring the '1 in' part and just giving the > result for '[1,2,3] == True'... Is this just a bug? > Don't jump to assume it's a bug, because that kind of bug is extremely unlikely compared to a misunderstanding :) In Python, chained comparisons behave as if the middle term is shared. A common and useful example is: 1 < x < 10 1 < x and x < 10 apart from the fact that x is only evaluated once. It's not common to use "in" and "==" in this way, but it's perfectly legal. What you wrote is equivalent to: 1 in [1, 2, 3] and [1, 2, 3] == True which should explain the result you got. It's only confusing because you added a redundant "== True" to the end of an otherwise simple comparison :) ChrisA From rosuav at gmail.com Wed Nov 21 14:36:59 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 06:36:59 +1100 Subject: Odd truth result with in and == In-Reply-To: <20181121193123.GD32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> <20181121193123.GD32735@bladeshadow.org> Message-ID: On Thu, Nov 22, 2018 at 6:33 AM Python wrote: > FWIW I meant my expectation is it should be the same as #3 (I confused > the 2nd item with the second subsequent thing that it did not match) > since "in" and "==" have the same precedence, and should be evaluated > in order left to right. IOW, it should evaluate to True. Good call on expecting operator precedence. But as mentioned in my other post (which crossed with your followup), comparisons don't follow simple associativity. https://docs.python.org/3/reference/expressions.html#operator-precedence https://docs.python.org/3/reference/expressions.html#comparisons ChrisA From python at mrabarnett.plus.com Wed Nov 21 14:40:23 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 21 Nov 2018 19:40:23 +0000 Subject: Odd truth result with in and == In-Reply-To: <20181121191822.GC32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> Message-ID: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> On 2018-11-21 19:18, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> 1 in [1,2,3] == True > False >>>> 1 in ([1,2,3] == True) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable >>>> (1 in [1,2,3]) == True > True > > How is the first not equivalent to either one of the second or third? > My expectation is it should produce the same result as the second. It > *seems* like Python is ignoring the '1 in' part and just giving the > result for '[1,2,3] == True'... Is this just a bug? > It's a chained comparison. It applies to '<', '<=', '>', '>=', '==' and '!=', but also to 'in', although I've never seen a chained comparison using 'in' in practice. You can write: 1 <= x <= 10 which is equivalent to: 1 <= x and x <= 10 except that the 'x' part is evaluated only once (this matters if you have, say, a function call there). From cs at cskk.id.au Wed Nov 21 15:17:52 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 22 Nov 2018 07:17:52 +1100 Subject: Odd truth result with in and == In-Reply-To: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> Message-ID: <20181121201752.GA14037@cskk.homeip.net> On 21Nov2018 19:40, MRAB wrote: >On 2018-11-21 19:18, Python wrote: >>>>>1 in [1,2,3] == True >>False >> >It's a chained comparison. It applies to '<', '<=', '>', '>=', '==' >and '!=', but also to 'in', although I've never seen a chained >comparison using 'in' in practice. Me either. In fact, I was as stumped as the OP. I've never really considered "in" as a comparison; in my mind comparisons are between like items: numbers vs numbers, and so forth. Not elements versus a collection of elements. Can someone show me a real world, or failing that - sane looking, chained comparison using "in"? Cheers, Cameron Simpson From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Nov 21 15:22:02 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Wed, 21 Nov 2018 15:22:02 -0500 Subject: Question about implementing immutability In-Reply-To: References: Message-ID: <0cb7dd51-c11d-8d2b-036d-d51654d767ac@potatochowder.com> On 11/21/18 11:45 AM, Iwo Herka wrote: > Hello, > > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def __setattr__(self, *args, **kwargs): > if sys._getframe(1).f_code.co_name == '__init__': > return super().__setattr__(*args, **kwargs) > raise AttributeError() > > What do you think of this approach? Is there a better one? > Thanks. That depends on your definition of immutability. If an instance of your class contains a list, and you change one of the elements of that list, then the instance's __setattr__ never comes into play: x = AllegedlyImmutableObject(list('a', 'b', 'c')) x.some_list[4] = 0 From cspealma at redhat.com Wed Nov 21 15:36:15 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Nov 2018 15:36:15 -0500 Subject: Question about implementing immutability In-Reply-To: References: Message-ID: If you want to create your own immutable class, maybe inherit from a namedtuple? On Wed, Nov 21, 2018 at 11:45 AM Iwo Herka wrote: > Hello, > > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def __setattr__(self, *args, **kwargs): > if sys._getframe(1).f_code.co_name == '__init__': > return super().__setattr__(*args, **kwargs) > raise AttributeError() > > What do you think of this approach? Is there a better one? > Thanks. > > Sincerely, > Iwo Herka > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bladeshadow.org Wed Nov 21 15:45:03 2018 From: python at bladeshadow.org (Python) Date: Wed, 21 Nov 2018 14:45:03 -0600 Subject: Odd truth result with in and == In-Reply-To: <20181121201752.GA14037@cskk.homeip.net> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> Message-ID: <20181121204503.GE32735@bladeshadow.org> On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote: > On 21Nov2018 19:40, MRAB wrote: > >On 2018-11-21 19:18, Python wrote: > >>>>>1 in [1,2,3] == True > >>False > >> > >It's a chained comparison. It applies to '<', '<=', '>', '>=', > >'==' and '!=', but also to 'in', although I've never seen a > >chained comparison using 'in' in practice. > > Me either. In fact, I was as stumped as the OP. I've never really > considered "in" as a comparison; in my mind comparisons are between > like items: numbers vs numbers, and so forth. Not elements versus a > collection of elements. Well, I actually do... "in" is essentially shorthand for something like: def in(item, list): for i in list: if i == item: # comparison return true return false i.e. a series of comparisons. So while I certainly didn't expect this, I do think it makes sense after the explanation. I was, even after years of Python coding, unfamiliar with comparison chaining. Not sure I love it, but I'll admit that it makes sense with 1 < x < 100 comparisons, and I've even wanted to do that on occasion. I just wasn't aware that python actually lets you. > Can someone show me a real world, or failing that - sane looking, > chained comparison using "in"? Here I'll admit that this was not my code, and I would never write that, though I can imagine that someone might want to write something roughly equivalent, conceptually, like: if item in list == item_should_be_in_list(): # "good" state, i.e. is true if item is in list and should be, or isn't and shouldn't. ... ...though I myself would most likely never create such a construct. So I'm not very surprised that I've never come across this before. Mostly, I was just at a loss to explain it to someone who asked about it. From cspealma at redhat.com Wed Nov 21 15:45:54 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Nov 2018 15:45:54 -0500 Subject: Need help for python on my pc. In-Reply-To: References: Message-ID: Hi, I'm afraid attachments are stripped out of e-mails sent to this list. Anything you sent was not included, so you'll need to share them in some other way if you'd like to ask for help. On Wed, Nov 21, 2018 at 1:18 PM Sourav Banik wrote: > Hello Python team, > I'm using python 3.7(32 bit) for several months on my same laptop (x64 > processor). I worked on some django project very swiftly without any > problem. But for a few days I am facing a serious problem. My python files > are not showing properly by the file manager. It is just showing 'python > source file' without any logo. When I open my cmd to work on django, it is > not also working though virtualenv is working properly I think. I'm sending > some screenshots of cmd and files for your reference. > I've tried reinstalling (64 bit) and repairing of python but nothing is > working. I want your help to sort out this issue. > From > Sourav Banik, > Dhaka,Bangladesh. > -- > https://mail.python.org/mailman/listinfo/python-list > From cspealma at redhat.com Wed Nov 21 15:47:45 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Nov 2018 15:47:45 -0500 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: Python and the standard library are all tools, but you still need to *use* those tools to accomplish something. On Wed, Nov 21, 2018 at 12:01 PM o1bigtenor wrote: > On Wed, Nov 21, 2018 at 8:09 AM Calvin Spealman > wrote: > > > > You really have the pieces you need here. You can print a whole year's > calendar with calendar.formatyear() or a single month with > calendar.monthcalendar(). If you need multiple years, call the first more > than once with each year you need to print. If you need partial years, > print the individual months you need with monthcalendar() > > > > Can you actually be more specific on what about the task is stumping you? > > OK so there needs to be a 2 level request, as I'm thinking of it, > rather than being able to > write something like (using human speak): > > print 36 months starting from 2017.06 or > print 60 months starting from 2017.03 with possible formatting > instructions. > > There seem to be a severe limit in the function in that a year is a > maximum single > time frame. I need to function within a time range of 2 to 3 or 4 > years. That means > that I move between the week/month and the longer frame lots and most > software > seems to be hard limited to a single year as the limit on the macro scale. > > Oh well - - - - guess I can't do what I want then - - - thanks for the > assistance. > > Regards > From rosuav at gmail.com Wed Nov 21 15:54:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 07:54:06 +1100 Subject: Odd truth result with in and == In-Reply-To: <20181121204503.GE32735@bladeshadow.org> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> <20181121204503.GE32735@bladeshadow.org> Message-ID: On Thu, Nov 22, 2018 at 7:47 AM Python wrote: > > On Thu, Nov 22, 2018 at 07:17:52AM +1100, Cameron Simpson wrote: > > On 21Nov2018 19:40, MRAB wrote: > > >On 2018-11-21 19:18, Python wrote: > > >>>>>1 in [1,2,3] == True > > >>False > > >> > > >It's a chained comparison. It applies to '<', '<=', '>', '>=', > > >'==' and '!=', but also to 'in', although I've never seen a > > >chained comparison using 'in' in practice. > > > > Me either. In fact, I was as stumped as the OP. I've never really > > considered "in" as a comparison; in my mind comparisons are between > > like items: numbers vs numbers, and so forth. Not elements versus a > > collection of elements. > > Well, I actually do... "in" is essentially shorthand for something > like: > > def in(item, list): > for i in list: > if i == item: # comparison > return true > return false > > i.e. a series of comparisons. > More or less. There are some subtleties (for instance, the check is usually "if i is item or i == item"), and not all containers do it by iteration (a dictionary will directly grab the item in question as a fast check), but broadly speaking, that is correct. > if item in list == item_should_be_in_list(): > # "good" state, i.e. is true if item is in list and should be, or isn't and shouldn't. > ... If I saw this in _any_ language, I would want it to be parenthesized for clarity. This kind of comparison is extremely unusual, and benefits from not making assumptions about how comparisons chain. And parenthesized, it will work the same way in any language. ChrisA From python at bladeshadow.org Wed Nov 21 16:00:01 2018 From: python at bladeshadow.org (Python) Date: Wed, 21 Nov 2018 15:00:01 -0600 Subject: Odd truth result with in and == In-Reply-To: Message-ID: <20181121210001.GF32735@bladeshadow.org> On Thu, Nov 22, 2018 at 06:33:54AM +1100, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 6:23 AM Python wrote: > > How is the first not equivalent to either one of the second or third? > > My expectation is it should produce the same result as the second. It > > *seems* like Python is ignoring the '1 in' part and just giving the > > result for '[1,2,3] == True'... Is this just a bug? > > > > Don't jump to assume it's a bug, because that kind of bug is extremely > unlikely compared to a misunderstanding :) Not assuming, just asking the question, FWIW... > > In Python, chained comparisons behave as if the middle term is shared. > A common and useful example is: > > 1 < x < 10 > 1 < x and x < 10 That's kind of cool, but also a bit mind-breaking, if you're generally familiar with how other languages evaluate expressions, but not aware of this feature of Python. [Hi!] It's less clear this is useful with "in" but since python considers it a comparison operator, it's at least consistent, which is good. > apart from the fact that x is only evaluated once. It's not common to > use "in" and "==" in this way, but it's perfectly legal. What you > wrote is equivalent to: > > 1 in [1, 2, 3] and [1, 2, 3] == True > > which should explain the result you got. It's only confusing because > you added a redundant "== True" to the end of an otherwise simple > comparison :) The "redundant" comparison is not the reason for the confusion... I wasn't familiar with chaining comparisons. I imagine it should be obvious that this was a simplified example constructed to illustrate the problem most simply, rather than real code. After all, a comparison between two hard-coded constant-value expressions need never be evaluated, since the value is itself known and constant. Thanks for the explanation. From o1bigtenor at gmail.com Wed Nov 21 16:09:01 2018 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 21 Nov 2018 15:09:01 -0600 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: On Wed, Nov 21, 2018 at 2:47 PM Calvin Spealman wrote: > > Python and the standard library are all tools, but you still need to use those tools to accomplish something. > This is am understanding. What I'm doing is making tools to make tools to make tools to make tools to make decisions and I'm finding that a very large amount of my time is spent making tools. Wanted to curtail that time amount but not having much luck! Regards From python at bladeshadow.org Wed Nov 21 16:20:22 2018 From: python at bladeshadow.org (Python) Date: Wed, 21 Nov 2018 15:20:22 -0600 Subject: Odd truth result with in and == In-Reply-To: References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> <20181121204503.GE32735@bladeshadow.org> Message-ID: <20181121212022.GG32735@bladeshadow.org> On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote: > > if item in list == item_should_be_in_list(): > > # "good" state, i.e. is true if item is in list and should be, or isn't and shouldn't. > > ... > > If I saw this in _any_ language, I would want it to be parenthesized > for clarity. This kind of comparison is extremely unusual, and > benefits from not making assumptions about how comparisons chain. And > parenthesized, it will work the same way in any language. I tend to agree in practice, but the idealist in me wants to say that's poppycock--every language has rules for expression evaluation and operator precedence, and that is all the clarity that should be required. If you don't know them, parens or not, you're going to get it wrong some of the time, and writing superfluous code to compensate for other people's inadequacies is irksome. The pragmatist in me admits that there's no good argument here, and sometimes (as in this case) "other people" is me. :( From cspealma at redhat.com Wed Nov 21 16:31:59 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 21 Nov 2018 16:31:59 -0500 Subject: question on the 'calendar' function In-Reply-To: References: <403a2b31a5154bd9b99dc7acf603bf09@Teledyne.com> Message-ID: Sorry, but, that is largely what programming is. On Wed, Nov 21, 2018 at 4:09 PM o1bigtenor wrote: > On Wed, Nov 21, 2018 at 2:47 PM Calvin Spealman > wrote: > > > > Python and the standard library are all tools, but you still need to use > those tools to accomplish something. > > > > This is am understanding. > What I'm doing is making tools to make tools to make tools to make > tools to make decisions > and I'm finding that a very large amount of my time is spent making tools. > Wanted to curtail that time amount but not having much luck! > > Regards > From rosuav at gmail.com Wed Nov 21 16:40:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 08:40:51 +1100 Subject: Odd truth result with in and == In-Reply-To: <20181121212022.GG32735@bladeshadow.org> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> <20181121204503.GE32735@bladeshadow.org> <20181121212022.GG32735@bladeshadow.org> Message-ID: On Thu, Nov 22, 2018 at 8:22 AM Python wrote: > > On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote: > > > if item in list == item_should_be_in_list(): > > > # "good" state, i.e. is true if item is in list and should be, or isn't and shouldn't. > > > ... > > > > If I saw this in _any_ language, I would want it to be parenthesized > > for clarity. This kind of comparison is extremely unusual, and > > benefits from not making assumptions about how comparisons chain. And > > parenthesized, it will work the same way in any language. > > I tend to agree in practice, but the idealist in me wants to say > that's poppycock--every language has rules for expression evaluation > and operator precedence, and that is all the clarity that should be > required. If you don't know them, parens or not, you're going to get > it wrong some of the time, and writing superfluous code to compensate > for other people's inadequacies is irksome. Not every language does, just most languages. And they aren't all the same. Remember: Code should be written first and foremost for other humans to read, and only secondarily for a machine to read. We use descriptive variable names, spaces around operators, etc, etc, etc, not because the Python interpreter needs the information, but because the humans need it. If you see code like you quoted, you can follow a set of algorithmic rules to figure out how the interpreter will parse it. But you can't follow those rules to determine how the original programmer INTENDED it to be parsed. Can you assume that the code is bug-free? I usually can't, whether it's my code or someone else's. ChrisA From storchaka at gmail.com Wed Nov 21 16:50:40 2018 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 21 Nov 2018 23:50:40 +0200 Subject: Odd truth result with in and == In-Reply-To: <20181121201752.GA14037@cskk.homeip.net> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> Message-ID: 21.11.18 22:17, Cameron Simpson ????: > Can someone show me a real world, or failing that - sane looking, > chained comparison using "in"? s[0] == s[-1] in '\'"' Tests that string s starts and ends with a single or double quote. It can be also used with sets: elem in set1 <= set2 From PythonList at DancesWithMice.info Wed Nov 21 17:04:30 2018 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 22 Nov 2018 11:04:30 +1300 Subject: Odd truth result with in and == In-Reply-To: References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> Message-ID: <234c2c3c-3883-defe-31be-409609519489@DancesWithMice.info> Serhiy, On 22/11/18 10:50, Serhiy Storchaka wrote: > 21.11.18 22:17, Cameron Simpson ????: >> Can someone show me a real world, or failing that - sane looking, >> chained comparison using "in"? > > ??? s[0] == s[-1] in '\'"' > > Tests that string s starts and ends with a single or double quote. Am admiring this solution. Don't most people resort immediately to regular expressions? Did you just 'come up with' this idea, or have you performed any testing to say that this is the most efficient/not too much more expensive...? -- Please advise =dn From tjol at tjol.eu Wed Nov 21 17:22:00 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 21 Nov 2018 23:22:00 +0100 Subject: Odd truth result with in and == In-Reply-To: <20181121191822.GC32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> Message-ID: On 21/11/2018 20:18, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> 1 in [1,2,3] == True > False >>>> 1 in ([1,2,3] == True) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable >>>> (1 in [1,2,3]) == True > True > See: https://github.com/cosmologicon/pywat ;-) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 228 bytes Desc: OpenPGP digital signature URL: From drvucanovic at gmail.com Wed Nov 21 18:10:14 2018 From: drvucanovic at gmail.com (drvucanovic at gmail.com) Date: Wed, 21 Nov 2018 15:10:14 -0800 (PST) Subject: Python-remove duplicate output Message-ID: How to remove duplicate lines and store output into one ine reservations = ec.describe_instances().get('Reservations', []) for reservation in reservations: for instance in reservation['Instances']: tags = {} for tag in instance['Tags']: tags[tag['Key']] = tag['Value'] if tag['Key'] == 'Name': name=tag['Value'] if not 'Owner' in tags or tags['Owner']=='unknown' or tags['Owner']=='Unknown': print name Current Output: aws-opsworks aws-opsworks Ansible Desired output: aws-opsworks Ansible From ike at koeln.ccc.de Wed Nov 21 18:13:06 2018 From: ike at koeln.ccc.de (ike at koeln.ccc.de) Date: Thu, 22 Nov 2018 00:13:06 +0100 Subject: Asyncio tasks getting cancelled In-Reply-To: References: <20181104192531.GA6642@ma.tura-home.de> <14963fea-4d61-aa34-9a92-e8894ae8520b@superlel.me> <20181105153817.GA4165@ma.tura-home.de> <20181105234436.GA15200@ma.tura-home.de> <20181106034051.GA27582@ma.tura-home.de> Message-ID: <20181121231306.GA3138@ma.tura-home.de> Sorry for the latency. On Tue, Nov 06, 2018 at 03:39:24PM -0700, Ian Kelly wrote: > > What I meant was, the error message is specific to futures in the > > 'PENDING' state. Which should be set to 'RUNNING' before any actions > > occur. So it appears the tasks weren't started at all. > > Ah. I don't think asyncio uses a RUNNING state. There's nothing about > it in the docs; tasks are either done or they're not: > https://docs.python.org/3/library/asyncio-task.html#task-object > > And inspecting the current task also shows PENDING: > > py> from asyncio import * > py> async def main(): > ... print(current_task()._state) > ... > py> run(main()) > PENDING Yes, you're right. I was confused and looked at futures, not asyncio.futures. :/ > > Also the cleanup happens instantly, ie before the loop exits (as the > > main loop has an asyncio.sleep timeout. Printing a message also clearly > > shows this happens way before main returns. > > Okay, that wasn't clear from the log you posted. It's not obvious to > me why that would be happening. although it does sound like the tasks > are getting created and then immediately garbage-collected for some > reason. It could be a bug in asyncio, or it could be a bug in the way > the tasks are created, e.g. on a separate event loop that gets dropped > on the floor. Yes, I should have mentioned that earlier, sorry. Hmm, I guess this will need some debugging incorporating the asyncio module. Oh well, let's see if I come around to that. Anyway thanks for the input. From robertvstepp at gmail.com Wed Nov 21 18:20:55 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Wed, 21 Nov 2018 17:20:55 -0600 Subject: Need help for python on my pc. In-Reply-To: References: Message-ID: On Wed, Nov 21, 2018 at 12:19 PM Sourav Banik wrote: > > Hello Python team, > I'm using python 3.7(32 bit) for several months on my same laptop (x64 > processor). I worked on some django project very swiftly without any > problem. But for a few days I am facing a serious problem. My python files > are not showing properly by the file manager. It is just showing 'python > source file' without any logo. When I open my cmd to work on django, it is > not also working though virtualenv is working properly I think. Are you on Windows 10? There have been reports of a recent update breaking Windows 10 file associations. One such article reporting this behavior: https://www.howtogeek.com/fyi/microsoft-broke-windows-10s-file-associations-with-a-botched-update/ which refers to this Microsoft update: https://support.microsoft.com/en-us/help/4462919/windows-10-update-kb4462919 In this, it says: After installing this update, some users cannot set Win32 program defaults for certain app and file type combinations using the Open with? command or Settings > Apps > Default apps. In some cases, Microsoft Notepad or other Win32 programs cannot be set as the default. In some cases, attempting to set application defaults again will succeed. Microsoft is working on a resolution and estimates a solution will be available in late November 2018. -- boB From ian.g.kelly at gmail.com Wed Nov 21 18:45:32 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 21 Nov 2018 16:45:32 -0700 Subject: Odd truth result with in and == In-Reply-To: References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> Message-ID: On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: > > 21.11.18 22:17, Cameron Simpson ????: > > Can someone show me a real world, or failing that - sane looking, > > chained comparison using "in"? > > s[0] == s[-1] in '\'"' > > Tests that string s starts and ends with a single or double quote. Clever, but too esoteric to use in practice. I'd rather make the chaining explicit. > It can be also used with sets: > > elem in set1 <= set2 I like this one better. From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Nov 21 19:02:51 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Wed, 21 Nov 2018 19:02:51 -0500 Subject: Odd truth result with in and == In-Reply-To: References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> Message-ID: <65899e17-b2de-cfac-f3e2-7dd954243205@potatochowder.com> On 11/21/18 6:45 PM, Ian Kelly wrote: > On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: >> >> 21.11.18 22:17, Cameron Simpson ????: >>> Can someone show me a real world, or failing that - sane looking, >>> chained comparison using "in"? >> >> s[0] == s[-1] in '\'"' >> >> Tests that string s starts and ends with a single or double quote. > > Clever, but too esoteric to use in practice. I'd rather make the > chaining explicit. > >> It can be also used with sets: >> >> elem in set1 <= set2 > > I like this one better. LOL: I had exactly the opposite reaction. The first one expresses exactly the idea that the first and last elements of the string match and are quotation characters, as if I'd written: (s[0] == s[-1]) and (s[0] in '\'"') (Arguably too esoteric to be used in practice, *unless* profiling indicates a necessary (before) and noticable (after) speed improvement.) But the second one has to do an expensive subset operation. If I think "is elem in both sets," then I'd never write: (elem in set1) and (set1 <= set2) From rosuav at gmail.com Wed Nov 21 19:09:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 11:09:04 +1100 Subject: Odd truth result with in and == In-Reply-To: <65899e17-b2de-cfac-f3e2-7dd954243205@potatochowder.com> References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> <65899e17-b2de-cfac-f3e2-7dd954243205@potatochowder.com> Message-ID: On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > But the second one has to do an expensive subset operation. If I think > "is elem in both sets," then I'd never write: > > (elem in set1) and (set1 <= set2) Yes, but that doesn't mean "is elem in both sets". It means "is elem in set 1, which needs to be a subset of set 2". I'm not sure where that would come up though. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Nov 21 19:30:21 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Wed, 21 Nov 2018 19:30:21 -0500 Subject: Odd truth result with in and == In-Reply-To: References: <3a7382d4-b825-90c3-75a0-3565755bdf64@mrabarnett.plus.com> <20181121201752.GA14037@cskk.homeip.net> <65899e17-b2de-cfac-f3e2-7dd954243205@potatochowder.com> Message-ID: On 11/21/18 7:09 PM, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers > <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> But the second one has to do an expensive subset operation. If I think >> "is elem in both sets," then I'd never write: >> >> (elem in set1) and (set1 <= set2) > > Yes, but that doesn't mean "is elem in both sets". It means "is elem > in set 1, which needs to be a subset of set 2" ... Then I was right about not mapping "is elem in both sets" to that expression! ;-) But I did make the leap from Serhiy's original expression to "is elem in both sets," which *may* mean that Serhiy's original expression is confusing, but it's probably just further evidence that I'm not actually as sharp as I think I am. > ... I'm not sure where that would come up though. Me neither. From banik77061 at gmail.com Wed Nov 21 23:24:32 2018 From: banik77061 at gmail.com (Sourav Banik) Date: Thu, 22 Nov 2018 10:24:32 +0600 Subject: Need help for python on my pc. Message-ID: Hello Python team, I'm using python 3.7(32 bit) for several months on my same laptop (x64 processor). I worked on some django project very swiftly without any problem. But for a few days I am facing a serious problem. My python files are not showing properly by the file manager. It is just showing 'python source file' without any logo. When I open my cmd to work on django, it is not also working though virtualenv is working properly I think. I'm sending some screenshots of cmd and files for your reference. I've tried reinstalling (64 bit) and repairing of python but nothing is working. I want your help to sort out this issue. From Sourav Banik, Dhaka,Bangladesh. From dieter at handshake.de Thu Nov 22 01:07:48 2018 From: dieter at handshake.de (dieter) Date: Thu, 22 Nov 2018 07:07:48 +0100 Subject: Basic pynomo instructions not working References: Message-ID: <874lc9d4qz.fsf@handshake.de> Adam Funk writes: > I'm trying to use the basic stuff in pynomo > > > > which I've installed with pip3, but I run into this problem trying to > the basic stuff in the documentation: > > #v+ > $ python3 > Python 3.6.7 (default, Oct 22 2018, 11:32:17) > [GCC 8.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> from pynomo.nomographer import * > Traceback (most recent call last): > File "", line 1, in > File "/home/adam/.local/lib/python3.6/site-packages/pynomo/nomographer.py", line 16, in > from nomo_wrapper import * > ModuleNotFoundError: No module named 'nomo_wrapper' >>>> import pynomo >>>> import pynomo.nomographer > Traceback (most recent call last): > File "", line 1, in > File "/home/adam/.local/lib/python3.6/site-packages/pynomo/nomographer.py", line 16, in > from nomo_wrapper import * > ModuleNotFoundError: No module named 'nomo_wrapper' >>>> > #v- > > Any ideas? The "pynomo" version you have installed may have been developped for Python 2 and not run in "python3". In Python 2, you have implicit relative imports. As an example, it allows modules in the package "pynomo" to use "import nomo_wrapper" to import the submodule "nomo_wrapper". Python 3 has discarded implicit relative imports. In the example above, "import nomo_wrapper" must become "from . import nomo_wrapper" (explicit relative import) or "import pynomo.nomo_wrapper as nomo_wrapper" (absolute import). For the time being, you still find many packages which run only under Python 2. Failing relative imports or syntax errors are a frequent indication towards this. > > Thanks. From dieter at handshake.de Thu Nov 22 01:42:59 2018 From: dieter at handshake.de (dieter) Date: Thu, 22 Nov 2018 07:42:59 +0100 Subject: Question about implementing immutability References: Message-ID: <87zhu1bojw.fsf@handshake.de> Iwo Herka writes: > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def __setattr__(self, *args, **kwargs): > if sys._getframe(1).f_code.co_name == '__init__': > return super().__setattr__(*args, **kwargs) > raise AttributeError() > > What do you think of this approach? Is there a better one? This is not easy to achieve in Python: Most instances of classes store their attributes in the so called "instance dict", accessed via ".__dict__". Thus, usually, it is quite easy to avoid `__setattr__": just modify the instance dict directly. If your aim is to ensure that "normal use" will not inadvertantly modify your instance (not to enforce immutability even facing people ready to use implementation details to break it), then you might consider the use of a so called "metaclass". The "metaclass" is responsible to create the class object; thus, it can modify (add or delete) methods for the class to be constructed. The main problem in your task is to recognize when the initial "__init__" call has finished. Your approach above does not work, should "__init__" call other functions or methods. With a metaclass, you could ensure, that all "__init__" methods for classes constructed by it are instrumented. The instrumentation would ensure that the initial "__init__" call sets an instance attribute (say) "_initializing_" (to itself) (using implementation details) at its beginning and remove it at the end. This way, a "__setattr__" has an easy way to recognize the initialization phase. The approach above, would not work for recursively called "__init__" methods - but hopefully, such "__init__" implementations are extremely rare. From dieter at handshake.de Thu Nov 22 02:20:21 2018 From: dieter at handshake.de (dieter) Date: Thu, 22 Nov 2018 08:20:21 +0100 Subject: Python-remove duplicate output References: Message-ID: <87va4pbmtm.fsf@handshake.de> drvucanovic at gmail.com writes: > How to remove duplicate lines and store output into one ine I do not understand "into one ine". > ... > Current Output: > aws-opsworks > aws-opsworks Ansible > > Desired output: > aws-opsworks Ansible Looks for me as if you do not want to remove duplicate lines: in your example, there are no duplicate lines - there is only a duplicate word. To get the task done, it is vital to clearly understand it. If "into one ine" should in fact mean "into one line", then your task *MIGHT* in fact be: * split each input line into words (at space boundaries) * omit duplicate words * return a line containing the unique words Then the solution could somehow look like: * you have a list "words", initially empty. * you iterate over your input - you split the input line into words - for each word, you check whether it is already in "words" and otherwise append it * you join "words" together to form the result line From rosuav at gmail.com Thu Nov 22 03:58:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Nov 2018 19:58:01 +1100 Subject: Odd truth result with in and == In-Reply-To: References: <20181121191822.GC32735@bladeshadow.org> Message-ID: On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote: > > On 21/11/2018 20:18, Python wrote: > > $ python3 > > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > > [GCC 5.4.0 20160609] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> 1 in [1,2,3] == True > > False > >>>> 1 in ([1,2,3] == True) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: argument of type 'bool' is not iterable > >>>> (1 in [1,2,3]) == True > > True > > > > See: https://github.com/cosmologicon/pywat ;-) > I find it fascinating that quite a few of the Wats given on the landing page are specifically poking fun at IEEE floating point (completely documented and intended behaviour that exists across many languages), yet the "Wat Quiz", also in that repository, specifically excludes floats. TRWTF is inconsistently poking fun at a language's consistencies. ChrisA From tjol at tjol.eu Thu Nov 22 04:05:22 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 22 Nov 2018 10:05:22 +0100 Subject: Question about implementing immutability In-Reply-To: References: Message-ID: <1ec2cc2c-287a-f081-dc9d-e979f514ebf4@tjol.eu> On 2018-11-21 21:36, Calvin Spealman wrote: > If you want to create your own immutable class, maybe inherit from a > namedtuple? If you're tempted to go down that route and can require Python 3.7, use dataclasses! > > On Wed, Nov 21, 2018 at 11:45 AM Iwo Herka wrote: > >> Hello, >> >> Let's say I want to implement immutability for user-defined class. >> More precisely, a class that can be modified only in its (or its >> super-class') __init__ method. My initial idea was to do it the >> following fashion: >> >> def __setattr__(self, *args, **kwargs): >> if sys._getframe(1).f_code.co_name == '__init__': >> return super().__setattr__(*args, **kwargs) >> raise AttributeError() >> >> What do you think of this approach? Is there a better one? >> Thanks. >> >> Sincerely, >> Iwo Herka >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From tjol at tjol.eu Thu Nov 22 04:13:15 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 22 Nov 2018 10:13:15 +0100 Subject: Odd truth result with in and == In-Reply-To: References: <20181121191822.GC32735@bladeshadow.org> Message-ID: <7dd217e1-faf0-f2bc-3936-51a21d10853e@tjol.eu> On 2018-11-22 09:58, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans wrote: >> >> On 21/11/2018 20:18, Python wrote: >>> $ python3 >>> Python 3.5.2 (default, Nov 23 2017, 16:37:01) >>> [GCC 5.4.0 20160609] on linux >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> 1 in [1,2,3] == True >>> False >>>>>> 1 in ([1,2,3] == True) >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: argument of type 'bool' is not iterable >>>>>> (1 in [1,2,3]) == True >>> True >>> >> >> See: https://github.com/cosmologicon/pywat ;-) >> > > I find it fascinating that quite a few of the Wats given on the > landing page are specifically poking fun at IEEE floating point > (completely documented and intended behaviour that exists across many > languages), yet the "Wat Quiz", also in that repository, specifically > excludes floats. TRWTF is inconsistently poking fun at a language's > consistencies. Clearly the author was struggling to find "wat"s of the sort you get in Ruby or JavaScript. From iwoherka at gmail.com Thu Nov 22 04:19:16 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Thu, 22 Nov 2018 09:19:16 +0000 Subject: Question about implementing immutability In-Reply-To: <87zhu1bojw.fsf@handshake.de> References: <87zhu1bojw.fsf@handshake.de> Message-ID: Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > If an instance of your class contains a list, and you change one > of the elements of that list, then the instance's __setattr__ > never comes into play: I think that's within the bounds of what is understood as "immutable" in Python. Tuples possesses that same property: you can modify members of the tuple (if mutable), but not the tuple itself.: >>> t = (1, []) >>> t[1].append(2) >>> t (1, [2]) dieter wrote: > Most instances of classes store their attributes in the > so called "instance dict", accessed via ".__dict__". > Thus, usually, it is quite easy to avoid `__setattr__": > just modify the instance dict directly. I don't think that's a problem. I'm willing to consider direct __dict__ access as "breaking the rules" on the part of the user. > The instrumentation would ensure that the initial "__init__" call > sets an instance attribute (say) "_initializing_" (to itself) > (using implementation details) at its beginning and remove it at the end. > This way, a "__setattr__" has an easy way to recognize the initialization > phase. The approach above, would not work for recursively called > "__init__" methods - but hopefully, such "__init__" implementations > are extremely rare. Instrumentation seems more tricky, but I didn't think of this edge-case. Thank you for pointing this out. Sincerely, Iwo Herka From iwoherka at gmail.com Thu Nov 22 06:03:41 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Thu, 22 Nov 2018 11:03:41 +0000 Subject: Question about implementing immutability In-Reply-To: <1ec2cc2c-287a-f081-dc9d-e979f514ebf4@tjol.eu> References: <1ec2cc2c-287a-f081-dc9d-e979f514ebf4@tjol.eu> Message-ID: czw., 22 lis 2018 o 10:53 Thomas Jollans napisa?(a): > If you're tempted to go down that route and can require Python 3.7, use > dataclasses! I'm aware of them, thanks. :) Dataclasses are great for certain use-cases; I was just wondering how hard would it be to implement something approximating generic solution for arbitrary user-defined classes. Sincerely, Iwo Herka From tjol at tjol.eu Thu Nov 22 06:14:16 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 22 Nov 2018 12:14:16 +0100 Subject: Question about implementing immutability In-Reply-To: References: Message-ID: On 2018-11-21 17:45, Iwo Herka wrote: > Hello, > > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def __setattr__(self, *args, **kwargs): > if sys._getframe(1).f_code.co_name == '__init__': > return super().__setattr__(*args, **kwargs) I don't like this. First of all, it's needlessly cryptic, and secondly this allows other classes' __init__s to set attributes. I might try setting a self._fixed flag at the end of init and do a check if getattr(self, '_fixed', False): raise TypeError(f"'{type(self)}' is immutable") but this presumably comes with other problems. > raise AttributeError() This should be TypeError. From iwoherka at gmail.com Thu Nov 22 06:28:40 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Thu, 22 Nov 2018 11:28:40 +0000 Subject: Question about implementing immutability In-Reply-To: References: Message-ID: czw., 22 lis 2018 o 11:14 Thomas Jollans napisa?(a): > [..] this allows other classes' __init__s to set attributes. Fair point. > I might try setting a self._fixed flag at the end of init and do a check > > if getattr(self, '_fixed', False): > raise TypeError(f"'{type(self)}' is immutable") > > but this presumably comes with other problems. Yes, I think so. For example, in order to allow mutations in own __init__, this would require unsetting the flag before the call and setting it afterwards. Naive implementation wouldn't work with super-classes because of recursion, i.e. I would unset the flag, call super and super would set the flag back on its way out. Sincerely, Iwo Herka From marco.nawijn at colosso.nl Thu Nov 22 08:47:14 2018 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Thu, 22 Nov 2018 05:47:14 -0800 (PST) Subject: Python-remove duplicate output In-Reply-To: References: Message-ID: <128fcaec-6fd4-4992-9d25-89df7b78f1a3@googlegroups.com> On Thursday, November 22, 2018 at 12:10:28 AM UTC+1, drvuc... at gmail.com wrote: > How to remove duplicate lines and store output into one ine > > reservations = ec.describe_instances().get('Reservations', []) > > for reservation in reservations: > for instance in reservation['Instances']: > tags = {} > for tag in instance['Tags']: > tags[tag['Key']] = tag['Value'] > if tag['Key'] == 'Name': > name=tag['Value'] > > if not 'Owner' in tags or tags['Owner']=='unknown' or tags['Owner']=='Unknown': > print name > > Current Output: > > aws-opsworks > > aws-opsworks Ansible > > Desired output: > > aws-opsworks Ansible You can use a set to do the job. Remember that members in the set are unique, duplicate members are ignored. Before you start the for loop, create a set: names = set() Instead of `print name`, you add the name to the set: names.add(name) Note that if name already exists, because members of a set are unique, the name is (at least conceptually) ignored. Once the for loop is completed, you print the remaining names. print names (Python 2) or print(names) (Python 3) Marco From bgailer at gmail.com Thu Nov 22 10:42:10 2018 From: bgailer at gmail.com (Bob Gailer) Date: Thu, 22 Nov 2018 10:42:10 -0500 Subject: Python-remove duplicate output In-Reply-To: <128fcaec-6fd4-4992-9d25-89df7b78f1a3@googlegroups.com> References: <128fcaec-6fd4-4992-9d25-89df7b78f1a3@googlegroups.com> Message-ID: On Nov 22, 2018 8:50 AM, wrote: > > On Thursday, November 22, 2018 at 12:10:28 AM UTC+1, drvuc... at gmail.com wrote: > > How to remove duplicate lines and store output into one ine > > > > reservations = ec.describe_instances().get('Reservations', []) > > > > for reservation in reservations: > > for instance in reservation['Instances']: > > tags = {} > > for tag in instance['Tags']: > > tags[tag['Key']] = tag['Value'] > > if tag['Key'] == 'Name': > > name=tag['Value'] > > > > if not 'Owner' in tags or tags['Owner']=='unknown' or tags['Owner']=='Unknown': > > print name > > > > Current Output: > > > > aws-opsworks > > > > aws-opsworks Ansible > > > > Desired output: > > > > aws-opsworks Ansible > > You can use a set to do the job. Remember that members in the set are unique, > duplicate members are ignored. > > Before you start the for loop, create a set: > > names = set() > > Instead of `print name`, you add the name to the set: > > names.add(name) > > Note that if name already exists, because members of a set are unique, > the name is (at least conceptually) ignored. > > Once the for loop is completed, you print the remaining names. > > print names (Python 2) > or > print(names) (Python 3) It is actually sufficient to just say print)names) since that works equally well in 2 or 3. Bob From konsyme at gmail.com Fri Nov 23 02:47:34 2018 From: konsyme at gmail.com (konsyme at gmail.com) Date: Thu, 22 Nov 2018 23:47:34 -0800 (PST) Subject: py2exe, program has stoped working!? In-Reply-To: <9dad2754-b584-49da-8c19-ececa9389c3a@w8g2000prd.googlegroups.com> References: <9dad2754-b584-49da-8c19-ececa9389c3a@w8g2000prd.googlegroups.com> Message-ID: On Sunday, April 13, 2008 at 4:52:06 PM UTC+3, skan... at yahoo.se wrote: > so i used py2exe and i have the build and the dist-folders. > > in the distfolder there is a Calculator.exe file. > > when i run it it just says "Calculator.exe has stopped working" in a > popup but the program itself never shows up. > > > wtf!? > > and when im distributing my program i have to include both catalogues > right? Hello there, i have the same issue with an executable that i created recently. My code has been written with python 2.7 / Windows 8.1 / Tkinter / py2exe. I also hadn't any problems when i run the code via my source code console, but when i convert it in ".exe" file it would not work. After a lot of search i am still unable to find what is exactly the problem, but i have a serious suspect that might help you. Well my script is about a simple parse of information from Url sites. In case when i parse information from an "http://" website i have no problem at all and my executable is running perfectly, but in case when i try to parse from an "https://" website it stop working. This issue is causing by a python SSL certificate check. In my source code it gave me back error messages, but after some search in Google i found some ways to suppress and disable the SSL certification checks and also hide all error messages in console and it is running fine now in console even in "https://" parses, but it seems in executable format it still gives me the "stop working" message. Note: My dialog windows text box of Tkinter, where i insert the URL information are appearing normally without any problems while i run the ".exe" file, but stops working right after this. So i suspect 1) there might be a simple error message that causing the application to stop working, or 2) There might be a need for some extra ".dll" files to be excludes on creation of the executable in setup.py that py2exe uses and then manually copy/paste them in the same directory of your ".exe. file. From sayan.kundu564 at gmail.com Fri Nov 23 03:14:35 2018 From: sayan.kundu564 at gmail.com (Sayan Kundu) Date: Fri, 23 Nov 2018 13:44:35 +0530 Subject: Improvement Request Message-ID: *** Please make "Table of Contents" an independent scrolling panel* For a long documentation, users have to scroll up all the way to navigate a different sub-topic. From beyourselfsophie at gmail.com Fri Nov 23 06:11:50 2018 From: beyourselfsophie at gmail.com (hello! ) Date: Fri, 23 Nov 2018 16:41:50 +0530 Subject: can you please help me in opening the python programming. Message-ID: <5bf7e077.1c69fb81.1dbe5.b979@mx.google.com> Sent from Mail for Windows 10 From popko at verizon.net Fri Nov 23 06:51:55 2018 From: popko at verizon.net (Edward Popko) Date: Fri, 23 Nov 2018 06:51:55 -0500 Subject: Unable to find newly installed Python 3.7.1 Message-ID: <000001d48322$ef334b70$cd99e250$@verizon.net> Snake people: I'm a Java person and thought to try Python for Windows. I installed Python 3.7.1 (64-bit) hoping for an IDE, documentation and even a sample or two. The python-3.7.1-amd64.exe unpacks and installs fine. Only problem is I cannot find it. There was no install option to add an shortcut to the desktop, there is no C:\ folder, no folder added to Program Files or Program Files (x86). I have Windows 10, 64 bit professional Where did it go? Where is the IDE? From ganesh1pal at gmail.com Fri Nov 23 08:41:45 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 23 Nov 2018 19:11:45 +0530 Subject: Intitalize values for a class Message-ID: Hello team, I am a python 2.7 user on Linux. I will need feedback on the below program as I'm new to oops . #!/usr/bin/python class System(object): '''Doc - Inside Class ''' def __init__(self, params=None): if params is None: self.params = {'id': '1', 'name': 's-1'} print self.params if type(params) is dict and params.get('id') == '0': raise ValueError('ERROR: id 0 is reserved !! ') #print self.params else: self.params = params print self.params # Test all conditions #case 0 - Default should create {'id': '1','name': 's-1'} #s0 = System() #Case 1 (id has value '0') #test1_params = {'id': '0', 'name': 's-0'} #s1 = System(params=test1_params) #Case 2 (id has some other values) #test2_params = {'id': '10', 'name': 's-10'} #s2 = System(params=test2_params) Question: I have to initialize the values the below class such that 1. Intitalize default values if nothing is supplied by the username i.e self.params = {'id': '1', 'name': 's-1'} 2. I need to raise an Exception if the value for the key params[id] is '0'. 3. It should work if params[I'd] has values other than (1) and (2) Regards, Ganesh From bgailer at gmail.com Fri Nov 23 08:48:44 2018 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 23 Nov 2018 08:48:44 -0500 Subject: can you please help me in opening the python programming. In-Reply-To: References: <5bf7e077.1c69fb81.1dbe5.b979@mx.google.com> Message-ID: We would be glad to help. I can't tell from your question what kind of help you need so please give us more information. Have you tried to install python? If so has the installation succeeded? What do you mean by "open the programming"? What have you tried? What do you expect to see? From bgailer at gmail.com Fri Nov 23 08:50:56 2018 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 23 Nov 2018 08:50:56 -0500 Subject: Install In-Reply-To: <5bf7c485.1c69fb81.eef36.6f59@mx.google.com> References: <5bf7c485.1c69fb81.eef36.6f59@mx.google.com> Message-ID: OK. On Nov 23, 2018 8:08 AM, "Salomon Chavarin" wrote: > > > Sent from Mail for Windows 10 > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > -- > https://mail.python.org/mailman/listinfo/python-list > From ganesh1pal at gmail.com Fri Nov 23 08:52:21 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 23 Nov 2018 19:22:21 +0530 Subject: initialize the values of the class Message-ID: Sorry for reposting, typo in the subject line ! On Fri, Nov 23, 2018, 19:11 Ganesh Pal Hello team, > > I am a python 2.7 user on Linux. I will need feedback on the below program > as I'm new to oops . > > #!/usr/bin/python > > > class System(object): > > '''Doc - Inside Class ''' > > def __init__(self, params=None): > > if params is None: > > self.params = {'id': '1', > > 'name': 's-1'} > > print self.params > > if type(params) is dict and params.get('id') == '0': > > raise ValueError('ERROR: id 0 is reserved !! ') > > #print self.params > > else: > > self.params = params > > print self.params > > # Test all conditions > > #case 0 - Default should create {'id': '1','name': 's-1'} > #s0 = System() > > #Case 1 (id has value '0') > #test1_params = {'id': '0', 'name': 's-0'} > #s1 = System(params=test1_params) > > > #Case 2 (id has some other values) > #test2_params = {'id': '10', 'name': 's-10'} > #s2 = System(params=test2_params) > > > Question: > > I have to initialize the values the below class such that > > 1. Intitalize default values if nothing is supplied by the username > i.e self.params = {'id': '1', 'name': 's-1'} > > 2. I need to raise an Exception if the value for the key params[id] is '0'. > > 3. It should work if params[I'd] has values other than (1) and (2) > > Regards, > Ganesh > > > > From bgailer at gmail.com Fri Nov 23 09:00:36 2018 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 23 Nov 2018 09:00:36 -0500 Subject: Intitalize values for a class In-Reply-To: References: Message-ID: On Nov 23, 2018 8:42 AM, "Ganesh Pal" wrote: > > Hello team, > > I am a python 2.7 user on Linux. I will need feedback on the below program > as I'm new to oops . What kind of feedback do you want? > > #!/usr/bin/python > > > class System(object): > > '''Doc - Inside Class ''' > > def __init__(self, params=None): > > if params is None: > > self.params = {'id': '1', > > 'name': 's-1'} > > print self.params > > if type(params) is dict and params.get('id') == '0': > > raise ValueError('ERROR: id 0 is reserved !! ') > > #print self.params > > else: > > self.params = params > > print self.params > > # Test all conditions > > #case 0 - Default should create {'id': '1','name': 's-1'} > #s0 = System() > > #Case 1 (id has value '0') > #test1_params = {'id': '0', 'name': 's-0'} > #s1 = System(params=test1_params) > > > #Case 2 (id has some other values) > #test2_params = {'id': '10', 'name': 's-10'} > #s2 = System(params=test2_params) > > > Question: > > I have to initialize the values the below class such that > > 1. Intitalize default values if nothing is supplied by the username i.e > self.params = {'id': '1', 'name': 's-1'} > > 2. I need to raise an Exception if the value for the key params[id] is '0'. > > 3. It should work if params[I'd] has values other than (1) and (2) > > Regards, > Ganesh > -- > https://mail.python.org/mailman/listinfo/python-list From bgailer at gmail.com Fri Nov 23 09:11:01 2018 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 23 Nov 2018 09:11:01 -0500 Subject: Intitalize values for a class In-Reply-To: References: Message-ID: On Nov 23, 2018 8:42 AM, "Ganesh Pal" wrote: > > Hello team, > > I am a python 2.7 user on Linux. I will need feedback on the below program > as I'm new to oops . My feedback is: Firstly there's a blank line between every line of program text which makes it hard to read. Also some statements are spread out over more than one line which also makes it hard to read. Secondly this sounds like a homework assignment. Is that true? If so be aware that we will be glad to help if you tell us where you are stuck but we won't write the code for you. Please learn how to write effective questions. You can Google that and find several good resources. Bob Gailer From salomonbarr at gmail.com Fri Nov 23 12:12:34 2018 From: salomonbarr at gmail.com (Salomon Chavarin) Date: Fri, 23 Nov 2018 09:12:34 -0800 Subject: Install Message-ID: <5bf7c485.1c69fb81.eef36.6f59@mx.google.com> Sent from Mail for Windows 10 --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From pacqa100 at yahoo.com.au Fri Nov 23 16:11:27 2018 From: pacqa100 at yahoo.com.au (Peter) Date: Sat, 24 Nov 2018 08:11:27 +1100 Subject: Unable to find newly installed Python 3.7.1 In-Reply-To: <000001d48322$ef334b70$cd99e250$@verizon.net> References: <000001d48322$ef334b70$cd99e250$@verizon.net> Message-ID: On 23/11/2018 10:51 PM, Edward Popko wrote: > Snake people: > > > I'm a Java person and thought to try Python for Windows. > I installed Python 3.7.1 (64-bit) hoping for an IDE, documentation and even > a sample or two. > The python-3.7.1-amd64.exe unpacks and installs fine. > Only problem is I cannot find it. There was no install option to add an > shortcut to the > desktop, there is no C:\ folder, no folder added to Program Files or Program > Files (x86). > > I have Windows 10, 64 bit professional > > Where did it go? Where is the IDE? > You can find out where the executable is with: >>> import sys >>> sys.executable 'C:\\Program Files (x86)\\Python37-32\\python.exe' (Your location may well be different) Peter From henrik.bengtsson at gmail.com Fri Nov 23 18:55:03 2018 From: henrik.bengtsson at gmail.com (Henrik Bengtsson) Date: Fri, 23 Nov 2018 15:55:03 -0800 Subject: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux) Message-ID: I ran into an interesting problem where calling `subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE)` hangs and never returns. $ python Python 2.7.9 (default, Apr 23 2015, 22:07:47) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p = subprocess.Popen(['/sbin/ldconfig', '-p'], stdout=subprocess.PIPE) ^CTraceback (most recent call last): File "", line 1, in File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line 1316, in _execute_child data = _eintr_retry_call(os.read, errpipe_read, 1048576) File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call return func(*args) KeyboardInterrupt >>> Note how I have to send a user interrupt to break out of `subprocess.Popen()`. TROUBLESHOOTING: First, it's interesting to note that the following works: >>> import subprocess >>> p = subprocess.Popen(['/sbin/ldconfig -p'], stdout=subprocess.PIPE, shell=True) >>> out,err = p.communicate() >>> len(out) 102460 >>> which I believe is the same as: >>> import subprocess >>> p = subprocess.Popen(['sh', '-c', '/sbin/ldconfig -p'], stdout=subprocess.PIPE) >>> out,err = p.communicate() >>> len(out) 102460 >>> which also works. Second, calling: >>> import subprocess >>> p = subprocess.Popen(['/sbin/ldconfig', '-p']) 1562 libs found in cache `/etc/ld.so.cache' libzmq.so.1 (libc6,x86-64) => /usr/lib64/libzmq.so.1 libz.so.1 (libc6,x86-64) => /lib64/libz.so.1 [ ... all 102,460 bytes of ldconfig -p output ...] ld-linux-x86-64.so.2 (libc6,x86-64) => /lib64/ld-linux-x86-64.so.2 >>> also works, so the PIPE is my main suspect. Finally, if I do: >>> import subprocess >>> p = subprocess.Popen(['/sbin/ldconfig', '-p'], stdout=subprocess.PIPE) [ manually pkill -INT ldconfig' ] >>> out,err = p.communicate() >>> len(out) 65536 >>> then I notice that it reads exactly 65,536=2^16 bytes (out of 102,460 bytes). I suspect this is related to the default buffer-size limit of pipes set by the Linux kernel. Using `strace` on the latter Python process, reveals: [...] open("/opt/Python/Python-2.7.9/lib/python2.7/lib-dynload/cStringIO.so", O_RDONLY) = 6 read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\32\0\0\0\0\0\0"..., 832) = 832 fstat(6, {st_mode=S_IFREG|0755, st_size=49556, ...}) = 0 mmap(NULL, 2115000, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 6, 0) = 0x2ad3ca6e7000 mprotect(0x2ad3ca6eb000, 2093056, PROT_NONE) = 0 mmap(0x2ad3ca8ea000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x3000) = 0x2ad3ca8ea000 close(6) = 0 close(5) = 0 close(4) = 0 getrlimit(RLIMIT_NOFILE, {rlim_cur=64*1024, rlim_max=64*1024}) = 0 close(3) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ad3ca8ec000 write(1, "1\n", 21 ) = 2 pipe([3, 4]) = 0 fcntl(3, F_GETFD) = 0 fcntl(3, F_SETFD, FD_CLOEXEC) = 0 fcntl(4, F_GETFD) = 0 fcntl(4, F_SETFD, FD_CLOEXEC) = 0 pipe([5, 6]) = 0 fcntl(5, F_GETFD) = 0 fcntl(5, F_SETFD, FD_CLOEXEC) = 0 fcntl(6, F_GETFD) = 0 fcntl(6, F_SETFD, FD_CLOEXEC) = 0 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x2ad3c972adf0) = 239074 close(6) = 0 mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ad3ca8ed000 read(5, and `strace` on the stalled `ldconfig` process reveals: $ strace -p $(pgrep ldconfig) Process 239074 attached - interrupt to quit write(1, "ibgconfmm-2.6.so.1 (libc6,x86-64"..., 4096 RH 6.6 0:- 1:-* 2:-- That latter `write()` contains the bytes after position 65,536, i.e. bytes 65,537 and beyond (not shown, but verified after careful inspection). MY CONCLUSION: To me, this looks like a deadlock in Popen() itself - is that correct? SESSION INFORMATION: All of the above is with Python 2.7.9 (installed from EPEL), but I can also reproduce it with Python 2.7.15 installed from source. What is also useful to know, is that I'm observing this on a legacy RHEL 6 system *with a customized kernel* part of the Scyld ClusterWare (https://www.penguincomputing.com/products/software/scyld-clusterware/) that *cannot* be updated: $ uname -a Linux n6 2.6.32-504.12.2.el6.664g0000.x86_64 #1 SMP Wed Mar 11 14:20:51 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux I appreciate any suggestions to further troubleshoot this and ideally resolve it. The reason for this being an important issue is that `find_library()` of ctypes.util performs the above stalling `Popen(['/sbin/ldconfig', '-p'])` call that was introduced in Python (>= 2.7.13). This happens for instance whenever we try to create a new virtual environment using `virtualenv`. In other words, the solution is *not* really to change the code to use, say, the shell=True approach. Thanks, Henrik PS. This is my first post to this list - please let me know if I should send to another forum instead. From johnpote at jptechnical.co.uk Fri Nov 23 19:02:11 2018 From: johnpote at jptechnical.co.uk (John Pote) Date: Sat, 24 Nov 2018 00:02:11 +0000 Subject: Odd truth result with in and == In-Reply-To: <20181121191822.GC32735@bladeshadow.org> References: <20181121191822.GC32735@bladeshadow.org> Message-ID: On 21/11/2018 19:18, Python wrote: > $ python3 > Python 3.5.2 (default, Nov 23 2017, 16:37:01) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> 1 in [1,2,3] == True > False >>>> 1 in ([1,2,3] == True) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable >>>> (1 in [1,2,3]) == True > True > > How is the first not equivalent to either one of the second or third? > My expectation is it should produce the same result as the second. It > *seems* like Python is ignoring the '1 in' part and just giving the > result for '[1,2,3] == True'... Is this just a bug? > I've followed this thread with interest, as I do with threads like this, and learnt a useful detail about Python. But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box) >>> if []: print("Truthy") ... >>> if [1,2,3]: print("Truthy") ... Truthy >>> from which I concluded [] is Falsey and [1,2,3] is Truthy and the above if statements work as expected. but, >>> [1,2,3] == True False >>> is unexpected as to my mind as [1,2,3] is 'Truthy' and True has ultimate 'Truthiness'. Any ideas? Is there an implicit 'casting' taking place and if so is this documented somewhere? I interpret the above comparison as >>> bool([1,2,3]) == bool(True) True >>> Thanks everyone. From rosuav at gmail.com Fri Nov 23 19:32:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 Nov 2018 11:32:12 +1100 Subject: Odd truth result with in and == In-Reply-To: References: <20181121191822.GC32735@bladeshadow.org> Message-ID: On Sat, Nov 24, 2018 at 11:28 AM John Pote wrote: > But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box) > > >>> if []: print("Truthy") > ... > >>> if [1,2,3]: print("Truthy") > ... > Truthy > >>> > > from which I concluded [] is Falsey and [1,2,3] is Truthy and the above > if statements work as expected. This is correct. Empty collections are falsey, non-empty collections are truthy. > but, > > >>> [1,2,3] == True > False > >>> > > is unexpected as to my mind as [1,2,3] is 'Truthy' and True has ultimate > 'Truthiness'. This is also correct, because now you're asking if this is EQUAL TO the specific value "True". It is true to say that Python is a programming language. It is true to say that a python is a snake. It is NOT true to say that these statements are equivalent. > Any ideas? Is there an implicit 'casting' taking place and if so is this > documented somewhere? > > I interpret the above comparison as > > >>> bool([1,2,3]) == bool(True) > True > >>> If you want to check if two values have the same truthiness, then this would be how you do it. (Or you could say "not [1,2,3] == not True", but that's a bit less clear.) An equality check is not the same. You would not expect 4 to be equal to 5, but both of them are truthy values (since they're both nonzero). ChrisA From ganesh1pal at gmail.com Fri Nov 23 21:05:20 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 24 Nov 2018 07:35:20 +0530 Subject: Intitalize values for a class In-Reply-To: References: Message-ID: On Fri, Nov 23, 2018, 19:30 Bob Gailer What kind of feedback do you want? > Wanted to know if there is any problem in the code and if you can review it :-) > From songofacandy at gmail.com Fri Nov 23 21:46:54 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Sat, 24 Nov 2018 11:46:54 +0900 Subject: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux) In-Reply-To: References: Message-ID: Thank you for a very informative report. > PS. This is my first post to this list - please let me know if I > should send to another forum instead. Would you send this report to the issue tracker? https://bugs.python.org/ -- INADA Naoki From alan at csail.mit.edu Fri Nov 23 22:57:03 2018 From: alan at csail.mit.edu (Alan Bawden) Date: 23 Nov 2018 22:57:03 -0500 Subject: Odd truth result with in and == References: <20181121191822.GC32735@bladeshadow.org> Message-ID: <8636rr3z74.fsf@richard.bawden.org> Chris Angelico writes: > Or you could say "not [1,2,3] == not True", > but that's a bit less clear.... It's less clear in more ways than one: 3.6> not [1,2,3] == not True File "", line 1 not [1,2,3] == not True ^ SyntaxError: invalid syntax 3.6> not [1,2,3] == (not True) True 3.6> not [] == (not True) True 3.6> (not []) == (not True) False -- Alan Bawden From henrik.bengtsson at gmail.com Fri Nov 23 23:37:43 2018 From: henrik.bengtsson at gmail.com (Henrik Bengtsson) Date: Fri, 23 Nov 2018 20:37:43 -0800 Subject: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux) In-Reply-To: References: Message-ID: Ok, thanks. I've just created https://bugs.python.org/issue35305. /Henrik On Fri, Nov 23, 2018 at 6:47 PM INADA Naoki wrote: > > Thank you for a very informative report. > > > PS. This is my first post to this list - please let me know if I > > should send to another forum instead. > > Would you send this report to the issue tracker? > https://bugs.python.org/ > > -- > INADA Naoki From frank at chagford.com Sat Nov 24 00:33:51 2018 From: frank at chagford.com (Frank Millman) Date: Sat, 24 Nov 2018 07:33:51 +0200 Subject: Odd truth result with in and == In-Reply-To: References: <20181121191822.GC32735@bladeshadow.org> Message-ID: "John Pote" wrote in message news:e0a8e1bc-6e03-e42b-d6e8-d690e2d5a10f at jptechnical.co.uk... > > I interpret the above comparison as > > >>> bool([1,2,3]) == bool(True) > True > >>> > A tiny addition to what has already been said. As True is by definition a boolean, you can write this as >>> bool([1, 2, 3]) == True True >>> I have on vary rare occasions had to convert 'truthiness' to an actual boolean, and this is how I do it. Frank Millman From jasminamrutia007 at gmail.com Sat Nov 24 01:33:17 2018 From: jasminamrutia007 at gmail.com (jasminamrutia007 at gmail.com) Date: Fri, 23 Nov 2018 22:33:17 -0800 (PST) Subject: help me in a program in python to implement Railway Reservation System using file handling technique. Message-ID: hello all, please hepl me in the above program. python to implement Railway Reservation System using file handling technique. System should perform below operations. a. Reserve a ticket for a passenger. b. List information all reservations done for today?s trains. From rosuav at gmail.com Sat Nov 24 01:43:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 Nov 2018 17:43:56 +1100 Subject: help me in a program in python to implement Railway Reservation System using file handling technique. In-Reply-To: References: Message-ID: On Sat, Nov 24, 2018 at 5:36 PM wrote: > > hello all, > please hepl me in the above program. python to implement Railway Reservation System using file handling technique. > > System should perform below operations. > a. Reserve a ticket for a passenger. > b. List information all reservations done for today?s trains. We won't do your homework for you. Have a shot at writing it yourself first, and then if you need help, bring specific questions to the list. ChrisA From giuseppecostanzi at gmail.com Sat Nov 24 14:08:49 2018 From: giuseppecostanzi at gmail.com (Beppe) Date: Sat, 24 Nov 2018 11:08:49 -0800 (PST) Subject: [ANN] Biovarase ver 2.8 Message-ID: <531be956-664b-4e71-b4a9-eab8dd0e64b9@googlegroups.com> Biovarase has been updated to version 2.8 Biovarase is an application to manage clinical quality control data. The purpose of Quality Control Assurance in a clinical laboratory is to allow the control of the performances of an analytical procedure showing an alarm as soon as the trial doesn't result in the degree to respect the defined analytical rules. Biovarase furthermore calculates the classical statistical parameters for the quality control assurance ,e.g. sd, cv%, avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using data retrived from: Current databases on biologic variation: pros, cons and progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most recent specifications made available in 2014. It uses even the famous Westgard's rules to monitor results dataset. All the data are managed by SQLite database and matplotlib. Biovarase requires Python =>3.5 tkinter matplotlib xlwt last changelog 2018-11-24 Change the redrew mechanism, now Biovarase doesn't rebuild the graph from scratch when you select a batch, but update only the data. Add Quick Data Analysis function on the menu to analyze the last dataset for every test and relative bacth. Add histogram to plot frequency distribution of a dataset. Some minor refactoring on main.py code. We deserve an updating to version 2.8. ;) All source code on https://github.com/1966bc/Biovarase thank you for reading. regards beppe From alan at csail.mit.edu Sat Nov 24 15:31:47 2018 From: alan at csail.mit.edu (Alan Bawden) Date: 24 Nov 2018 15:31:47 -0500 Subject: Improvement Request References: Message-ID: <86wop22p58.fsf@richard.bawden.org> Gilmeh Serda writes: > On Fri, 23 Nov 2018 13:44:35 +0530, Sayan Kundu wrote: > > > *** Please make "Table of Contents" an independent scrolling panel* > > For a long documentation, users have to scroll up all the way to > > navigate a different sub-topic. > > And just what in the world are you talking about? And more to the point, > what does it have to do with the Python language? He/She is talking about the python documentation pages. See for example -- scroll down far enough and the table of contents disappears off the top. It's a reasonable request, but this probably isn't the most effective place to make it. -- Alan Bawden From torriem at gmail.com Sat Nov 24 18:35:00 2018 From: torriem at gmail.com (Michael Torrie) Date: Sat, 24 Nov 2018 16:35:00 -0700 Subject: Have I Been Banned? In-Reply-To: References: <8a-dnbxGX8cCqmnGnZ2dnUU7-fWdnZ2d@giganews.com> Message-ID: <5047195a-af93-4de3-9a83-95cf422adad0@gmail.com> On 11/20/2018 09:39 AM, Jon Ribbens wrote: > On 2018-11-20, Wildman wrote: >> In the past I have participated in the group without any >> problems. I access the forum through the usenet mirror >> and I am still using the same newsreader and account. >> Recently I made some followup posts to the group and they >> never showed up. Have I been banned? If so, I would >> appreciate it to know why? > > If you mean you made posts to the comp.lang.python group and they did > not show up on your news server then the problem is either at your > end or with your news server - unlike the mailing list, the group is > unmoderated and therefore nobody can be banned from it. True, but moderators can remove some posts from the mailing list side of the list. But there's definitely no ban on Wildman on the mailing list because I saw his post there. From francisgan9 at gmail.com Sun Nov 25 04:07:13 2018 From: francisgan9 at gmail.com (francis) Date: Sun, 25 Nov 2018 01:07:13 -0800 (PST) Subject: help me in a program in python to implement Railway Reservation System using file handling technique. In-Reply-To: References: Message-ID: <8a3246ea-b509-4fd3-973a-f09c74942836@googlegroups.com> On Saturday, 24 November 2018 14:33:29 UTC+8, jasmin amrutia wrote: > hello all, > please hepl me in the above program. python to implement Railway Reservation System using file handling technique. > > System should perform below operations. > a. Reserve a ticket for a passenger. > b. List information all reservations done for today?s trains. You could get better response by offering a reward or payment. From rizwan.ned.ee at gmail.com Sun Nov 25 10:43:42 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 07:43:42 -0800 (PST) Subject: how to match list members in py3.x Message-ID: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> for each word in each line how can we check to see if a word is already present in a list and if it is not how to append that word to a new list From alister.ware at ntlworld.com Sun Nov 25 10:59:33 2018 From: alister.ware at ntlworld.com (Alister) Date: Sun, 25 Nov 2018 15:59:33 GMT Subject: how to match list members in py3.x References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> Message-ID: On Sun, 25 Nov 2018 07:43:42 -0800, Muhammad Rizwan wrote: > for each word in each line how can we check to see if a word is already > present in a list and if it is not how to append that word to a new list the 1st step is to stay awake in class & listen to your instructor, then try to apply the principle involved We don't do homework for you when you have produced a program of you own (not necessarily working) if you post it here then we will be more than happy to provide constructive criticism -- "Show business is just like high school, except you get paid." - Martin Mull From rizwan.ned.ee at gmail.com Sun Nov 25 11:30:26 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 08:30:26 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> Message-ID: <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. From brian.j.oney at googlemail.com Sun Nov 25 11:35:54 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Sun, 25 Nov 2018 17:35:54 +0100 Subject: how to match list members in py3.x In-Reply-To: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> Message-ID: <1543163754.2498.1.camel@gmail.com> On Sun, 2018-11-25 at 07:43 -0800, Muhammad Rizwan wrote: > for each word in each line how can we check to see if a word is already present in a list and if it is not how to append that word to a new list For your problem consider a set. https://en.wikipedia.org/wiki/Set_theory For the python syntax consider the py3 tutorial. https://docs.python.org/3/tutorial/index.html HTH From rizwan.ned.ee at gmail.com Sun Nov 25 11:37:41 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 08:37:41 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <1543163754.2498.1.camel@gmail.com> Message-ID: <1f3a80c5-2b1f-4654-bc4b-aeea978b202b@googlegroups.com> Thank you From joel.goldstick at gmail.com Sun Nov 25 11:41:29 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 25 Nov 2018 11:41:29 -0500 Subject: how to match list members in py3.x In-Reply-To: <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> Message-ID: On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan wrote: > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > > > -- > https://mail.python.org/mailman/listinfo/python-list That isn't a productive way to get assistance. It is true that people here are often very knowledgeable to help with python problems, but as a rule, doing someone's homework isn't something people like to do. On to your problem. You should understand lists and sets, and for loops. Try some code and come back with what you have. Then you will get help to go further -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From lists at vanderhoff.org Sun Nov 25 11:42:27 2018 From: lists at vanderhoff.org (tony) Date: Sun, 25 Nov 2018 17:42:27 +0100 Subject: how to match list members in py3.x In-Reply-To: <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> Message-ID: On 25/11/2018 17:30, Muhammad Rizwan wrote: > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > > Why would anyone want to help you? From rizwan.ned.ee at gmail.com Sun Nov 25 11:47:14 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 08:47:14 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> Message-ID: <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> On Sunday, 25 November 2018 11:41:56 UTC-5, Joel Goldstick wrote: > On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan > <> wrote: > > > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > That isn't a productive way to get assistance. It is true that > people here are often very knowledgeable to help with python problems, > but as a rule, doing someone's homework isn't something people like > to do. > > On to your problem. You should understand lists and sets, and for > loops. Try some code and come back with what you have. Then you will > get help to go further > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays I have been trying since morning but it doesn't work. From rizwan.ned.ee at gmail.com Sun Nov 25 11:49:03 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 08:49:03 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> Message-ID: <5a7f78cf-a771-4362-a75b-a21e19be5a1e@googlegroups.com> On Sunday, 25 November 2018 10:59:46 UTC-5, Alister wrote: > On Sun, 25 Nov 2018 07:43:42 -0800, Muhammad Rizwan wrote: > > > for each word in each line how can we check to see if a word is already > > present in a list and if it is not how to append that word to a new list > > the 1st step is to stay awake in class & listen to your instructor, then > try to apply the principle involved > > We don't do homework for you > > when you have produced a program of you own (not necessarily working) if > you post it here then we will be more than happy to provide constructive > criticism > > > > > -- > "Show business is just like high school, except you get paid." > - Martin Mull IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. From srinivasan.rns at gmail.com Sun Nov 25 12:13:10 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Sun, 25 Nov 2018 22:43:10 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output Message-ID: Dear Python Experts Team, As am newbie still learning the python syntax from past 2 weeks, Excuse me, If this might be silly question, As I am trying to execute shell command (ie, nmcli) using "subprocess.Popen". 1. Am trying to improve the below code with "try" and "exception", could you please help me how "try" and "exception" can be used on the below code snippet. I hope in my code with try and exception, seems to be a bug. 2. As I am trying to execute shell commands using "subprocess.Popen", I am trying to parse the strings output by "cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing the below error as shown in "Output error logs:" Could you please let me to fix the bug in the below code snippet, where I need the collect the strings of the command output and later how to be parsed after execution of the command for example, I need to parse the string "Connection activation failed: " and compare it with the command output, could you please help me how this can be achieved? *Command:* :~$ nmcli device wifi connect 'Apartment 18' password '40672958689850014685abcdf' Error: Connection activation failed: (7) Secrets were required, but not provided. :~$ *Code:* *import sys* *import subprocess* *interface = "wlan0"* *def main(ssid, pw):* * # cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)* * #* * # proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)* * # stdout, stderr = proc.communicate()* * # retcode = proc.returncode* * #* * # print("printing stdout!!!!!!!!!!", stdout)* * # print("printing retcode!!!!!!!!!!", retcode)* * try:* * cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)* * proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)* * stdout, stderr = proc.communicate()* * retcode = proc.returncode* * print("printing stdout!!!!!!!!!!", stdout)* * print("printing retcode!!!!!!!!!!", retcode)* * except subprocess.CalledProcessError as e:* * s = """While executing '{}' something went wrong.* * Return code == '{}'* * Return output:\n'{}'* * """.format(cmd, e.returncode, e.output, shell=enable_shell)* * raise AssertionError(s)* * return proc.strip().decode("utf-8")* *main("Apartment 18", "40672958689850014685")* *Output error logs:* /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", line 38, in printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 main("Apartment 18", "40672958689850014685") File "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", line 36, in main return proc.strip().decode("utf-8") AttributeError: 'Popen' object has no attribute 'strip' Process finished with exit code 1 Kindly do the needful as am stuck with this issue from 2 days Many Thanks in advance, From joel.goldstick at gmail.com Sun Nov 25 12:14:11 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 25 Nov 2018 12:14:11 -0500 Subject: how to match list members in py3.x In-Reply-To: <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> Message-ID: On Sun, Nov 25, 2018 at 11:51 AM Muhammad Rizwan wrote: > > On Sunday, 25 November 2018 11:41:56 UTC-5, Joel Goldstick wrote: > > On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan > > <> wrote: > > > > > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > > > > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > That isn't a productive way to get assistance. It is true that > > people here are often very knowledgeable to help with python problems, > > but as a rule, doing someone's homework isn't something people like > > to do. > > > > On to your problem. You should understand lists and sets, and for > > loops. Try some code and come back with what you have. Then you will > > get help to go further > > > > -- > > Joel Goldstick > > http://joelgoldstick.com/blog > > http://cc-baseballstats.info/stats/birthdays > > I have been trying since morning but it doesn't work. The way to use this mailing list is to explain your problem, which you have done. Then, show the code you have written with the results it produces. Its good to include the operating system you are using (windows, linux, osx), and if your code produces a traceback, copy and paste it here. Its common to be frustrated learning to write and writing code, but if you want help you have to show something for others to help you with > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rizwan.ned.ee at gmail.com Sun Nov 25 12:28:05 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 09:28:05 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> Message-ID: <24fe88ad-ba60-4e63-8e00-f7747f9feea1@googlegroups.com> On Sunday, 25 November 2018 12:14:37 UTC-5, Joel Goldstick wrote: > On Sun, Nov 25, 2018 at 11:51 AM Muhammad Rizwan > <> wrote: > > > > On Sunday, 25 November 2018 11:41:56 UTC-5, Joel Goldstick wrote: > > > On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan > > > <> wrote: > > > > > > > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > > > > > > > > > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > That isn't a productive way to get assistance. It is true that > > > people here are often very knowledgeable to help with python problems, > > > but as a rule, doing someone's homework isn't something people like > > > to do. > > > > > > On to your problem. You should understand lists and sets, and for > > > loops. Try some code and come back with what you have. Then you will > > > get help to go further > > > > > > -- > > > Joel Goldstick > > > http://joelgoldstick.com/blog > > > http://cc-baseballstats.info/stats/birthdays > > > > I have been trying since morning but it doesn't work. > > The way to use this mailing list is to explain your problem, which you > have done. Then, show the code you have written with the results it > produces. Its good to include the operating system you are using > (windows, linux, osx), and if your code produces a traceback, copy and > paste it here. > > Its common to be frustrated learning to write and writing code, but if > you want help you have to show something for others to help you with > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays Below is my approach which I am sure is wrong somewhere and it doesn't work the way expected, the append doesn't do anything in my code nor does it returns any traceback all i see is a empty list printed at the end, I am using win10 x64 python 3.x atom-editor. Please take a look if you can tell me what am I doing wrong here. I want to check each list word by word if the word is not repeated in the same list it should be appended to a 'newlist'. Thanks in advance handle = open('file.txt') newlist = list() for line in handle: #line.rstrip() linewords = line.split() print(linewords) for word in linewords: newlist.append(word) if word not in linewords: continue print('new: ',newlist) From best_lay at yahoo.com Sun Nov 25 12:30:27 2018 From: best_lay at yahoo.com (Wildman) Date: Sun, 25 Nov 2018 11:30:27 -0600 Subject: Issue in using "subprocess.Popen" for parsing the command output References: Message-ID: On Sun, 25 Nov 2018 22:43:10 +0530, srinivasan wrote: > Dear Python Experts Team, > > As am newbie still learning the python syntax from past 2 weeks, Excuse me, > If this might be silly question, As I am trying to execute shell command > (ie, nmcli) using "subprocess.Popen". > > * return proc.strip().decode("utf-8")* return proc.decode("utf-8").strip() -- GNU/Linux user #557453 The cow died so I don't need your bull! From Richard at Damon-Family.org Sun Nov 25 12:41:11 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 25 Nov 2018 12:41:11 -0500 Subject: how to match list members in py3.x In-Reply-To: <24fe88ad-ba60-4e63-8e00-f7747f9feea1@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> <24fe88ad-ba60-4e63-8e00-f7747f9feea1@googlegroups.com> Message-ID: <796e47a4-14e3-41cd-5dad-43467c6752c1@Damon-Family.org> On 11/25/18 12:28 PM, Muhammad Rizwan wrote: > Below is my approach which I am sure is wrong somewhere and it doesn't work the way expected, the append doesn't do anything in my code nor does it returns any traceback all i see is a empty list printed at the end, I am using win10 x64 python 3.x atom-editor. Please take a look if you can tell me what am I doing wrong here. I want to check each list word by word if the word is not repeated in the same list it should be appended to a 'newlist'. Thanks in advance > > handle = open('file.txt') > newlist = list() > for line in handle: > #line.rstrip() > linewords = line.split() > print(linewords) > > for word in linewords: > newlist.append(word) > if word not in linewords: > continue > > > > print('new: ',newlist) The first thing I note in looking at this is that the second loop will run AFTER the first loop completes, not for each step of the loop, because you outdented the code. Also, you unconditionally add the word, and THEN check if it is in the list. -- Richard Damon From Karsten.Hilbert at gmx.net Sun Nov 25 12:41:36 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 25 Nov 2018 18:41:36 +0100 Subject: Aw: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: Message-ID: > Kindly do the needful as am stuck with this issue from 2 days How about YOU do the needful and post code that can actually be tested. Karsten From bgailer at gmail.com Sun Nov 25 12:45:52 2018 From: bgailer at gmail.com (Bob Gailer) Date: Sun, 25 Nov 2018 12:45:52 -0500 Subject: help me in a program in python to implement Railway Reservation System using file handling technique. In-Reply-To: References: Message-ID: On Nov 24, 2018 1:35 AM, wrote: > > hello all, > please hepl me in the above program. What do you mean by "the above program"? I don't see any. python to implement Railway Reservation System using file handling technique. > > System should perform below operations. > a. Reserve a ticket for a passenger. > b. List information all reservations done for today?s trains. > -- > https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sun Nov 25 12:48:00 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Nov 2018 17:48:00 +0000 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: Message-ID: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> On 2018-11-25 17:13, srinivasan wrote: > Dear Python Experts Team, > > As am newbie still learning the python syntax from past 2 weeks, Excuse me, > If this might be silly question, As I am trying to execute shell command > (ie, nmcli) using "subprocess.Popen". > > 1. Am trying to improve the below code with "try" and "exception", could > you please help me how "try" and "exception" can be used on the below code > snippet. I hope in my code with try and exception, seems to be a bug. > > 2. As I am trying to execute shell commands using "subprocess.Popen", I am > trying to parse the strings output by "cmd = "nmcli device wifi connect > '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing the > below error as shown in "Output error logs:" > > Could you please let me to fix the bug in the below code snippet, where I > need the collect the strings of the command output and later how to be > parsed after execution of the command for example, I need to parse the > string "Connection activation failed: " and compare it with the command > output, could you please help me how this can be achieved? > > *Command:* > :~$ nmcli device wifi connect 'Apartment 18' password > '40672958689850014685abcdf' > Error: Connection activation failed: (7) Secrets were required, but not > provided. > :~$ > > *Code:* > *import sys* > *import subprocess* > > *interface = "wlan0"* > > > *def main(ssid, pw):* > > * # cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)* > * #* > * # proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* > * # stdout, stderr = proc.communicate()* > * # retcode = proc.returncode* > * #* > * # print("printing stdout!!!!!!!!!!", stdout)* > * # print("printing retcode!!!!!!!!!!", retcode)* > > * try:* > * cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)* > > * proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* > * stdout, stderr = proc.communicate()* > * retcode = proc.returncode* > > * print("printing stdout!!!!!!!!!!", stdout)* > * print("printing retcode!!!!!!!!!!", retcode)* > > * except subprocess.CalledProcessError as e:* > * s = """While executing '{}' something went wrong.* > * Return code == '{}'* > * Return output:\n'{}'* > * """.format(cmd, e.returncode, e.output, > shell=enable_shell)* > * raise AssertionError(s)* > > * return proc.strip().decode("utf-8")* > > *main("Apartment 18", "40672958689850014685")* > > *Output error logs:* > > /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/venv/bin/python > /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py > Traceback (most recent call last): > File > "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", > line 38, in > printing stdout!!!!!!!!!! > printing retcode!!!!!!!!!! 0 > main("Apartment 18", "40672958689850014685") > File > "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", > line 36, in main > return proc.strip().decode("utf-8") > AttributeError: 'Popen' object has no attribute 'strip' > > Process finished with exit code 1 > > Kindly do the needful as am stuck with this issue from 2 days > > Many Thanks in advance, > Look carefully at the traceback. It's actually telling you what the problem is. You're trying to do .strip() on proc, but proc is the process itself. Instead, what you want is to do .strip() on the string that it output. From boblatest at yahoo.com Sun Nov 25 12:51:28 2018 From: boblatest at yahoo.com (Robert Latest) Date: 25 Nov 2018 17:51:28 GMT Subject: Python2.7 unicode conundrum Message-ID: Hi folks, what semmingly started out as a weird database character encoding mix-up could be boiled down to a few lines of pure Python. The source-code below is real utf8 (as evidenced by the UTF code point 'c3 a4' in the third line of the hexdump). When just printed, the string "s" is displayed correctly as '?' (a umlaut), but the string representation shows that it seems to have been converted to latin-1 'e4' somewhere on the way. How can this be avoided? dh at jenna:~/python$ cat unicode.py # -*- encoding: utf8 -*- s = u'?' print(s) print((s, )) dh at jenna:~/python$ hd unicode.py 00000000 23 20 2d 2a 2d 20 65 6e 63 6f 64 69 6e 67 3a 20 |# -*- encoding: | 00000010 75 74 66 38 20 2d 2a 2d 0a 0a 73 20 3d 20 75 27 |utf8 -*-..s = u'| 00000020 c3 a4 27 0a 0a 70 72 69 6e 74 28 73 29 0a 70 72 |..'..print(s).pr| 00000030 69 6e 74 28 28 73 2c 20 29 29 0a 0a |int((s,))..| 0000003c dh at jenna:~/python$ python unicode.py ? (u'\xe4',) dh at jenna:~/python$ From srinivasan.rns at gmail.com Sun Nov 25 12:54:11 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Sun, 25 Nov 2018 23:24:11 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: Hope now I have changed on the string output as below, could you please correct me if am still wrong? import sys import subprocess interface = "wlan0" def main(ssid, pw): try: cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) stdout, stderr = proc.communicate() retcode = proc.returncode print("printing stdout!!!!!!!!!!", stdout) print("printing retcode!!!!!!!!!!", retcode) except subprocess.CalledProcessError as e: s = """While executing '{}' something went wrong. Return code == '{}' Return output:\n'{}' """.format(cmd, e.returncode, e.output, shell=True) raise AssertionError(s) #return proc.strip().decode("utf-8") * return proc.decode("utf-8").strip()* main("Apartment 18", "40672958689850014685ad") Error: /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 30, in main("Apartment 18", "40672958689850014685") * File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 28, in main* * return proc.decode("utf-8").strip()* *AttributeError: 'Popen' object has no attribute 'decode'* printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 Process finished with exit code 1 On Sun, Nov 25, 2018 at 11:19 PM MRAB wrote: > On 2018-11-25 17:13, srinivasan wrote: > > Dear Python Experts Team, > > > > As am newbie still learning the python syntax from past 2 weeks, Excuse > me, > > If this might be silly question, As I am trying to execute shell command > > (ie, nmcli) using "subprocess.Popen". > > > > 1. Am trying to improve the below code with "try" and "exception", could > > you please help me how "try" and "exception" can be used on the below > code > > snippet. I hope in my code with try and exception, seems to be a bug. > > > > 2. As I am trying to execute shell commands using "subprocess.Popen", I > am > > trying to parse the strings output by "cmd = "nmcli device wifi connect > > '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing > the > > below error as shown in "Output error logs:" > > > > Could you please let me to fix the bug in the below code snippet, > where I > > need the collect the strings of the command output and later how to be > > parsed after execution of the command for example, I need to parse the > > string "Connection activation failed: " and compare it with the command > > output, could you please help me how this can be achieved? > > > > *Command:* > > :~$ nmcli device wifi connect 'Apartment 18' password > > '40672958689850014685abcdf' > > Error: Connection activation failed: (7) Secrets were required, but not > > provided. > > :~$ > > > > *Code:* > > *import sys* > > *import subprocess* > > > > *interface = "wlan0"* > > > > > > *def main(ssid, pw):* > > > > * # cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)* > > * #* > > * # proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* > > * # stdout, stderr = proc.communicate()* > > * # retcode = proc.returncode* > > * #* > > * # print("printing stdout!!!!!!!!!!", stdout)* > > * # print("printing retcode!!!!!!!!!!", retcode)* > > > > * try:* > > * cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, > pw)* > > > > * proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* > > * stdout, stderr = proc.communicate()* > > * retcode = proc.returncode* > > > > * print("printing stdout!!!!!!!!!!", stdout)* > > * print("printing retcode!!!!!!!!!!", retcode)* > > > > * except subprocess.CalledProcessError as e:* > > * s = """While executing '{}' something went wrong.* > > * Return code == '{}'* > > * Return output:\n'{}'* > > * """.format(cmd, e.returncode, e.output, > > shell=enable_shell)* > > * raise AssertionError(s)* > > > > * return proc.strip().decode("utf-8")* > > > > *main("Apartment 18", "40672958689850014685")* > > > > *Output error logs:* > > > > /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/venv/bin/python > > > /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py > > Traceback (most recent call last): > > File > > > "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", > > line 38, in > > printing stdout!!!!!!!!!! > > printing retcode!!!!!!!!!! 0 > > main("Apartment 18", "40672958689850014685") > > File > > > "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", > > line 36, in main > > return proc.strip().decode("utf-8") > > AttributeError: 'Popen' object has no attribute 'strip' > > > > Process finished with exit code 1 > > > > Kindly do the needful as am stuck with this issue from 2 days > > > > Many Thanks in advance, > > > Look carefully at the traceback. It's actually telling you what the > problem is. > > You're trying to do .strip() on proc, but proc is the process itself. > > Instead, what you want is to do .strip() on the string that it output. > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Sun Nov 25 12:58:43 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Sun, 25 Nov 2018 23:28:43 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: Even only with "*proc.decode("utf-8")"* in the above code still it seems to throw the error #return proc.strip().decode("utf-8") #return proc.decode("utf-8").strip() * return proc.decode("utf-8")* Error: /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 31, in main("Apartment 18", "40672958689850014685") * File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 29, in main* * return proc.decode("utf-8")* *AttributeError: 'Popen' object has no attribute 'decode'* Process finished with exit code 1 On Sun, Nov 25, 2018 at 11:24 PM srinivasan wrote: > Hope now I have changed on the string output as below, could you please > correct me if am still wrong? > > import sys > import subprocess > > interface = "wlan0" > > > def main(ssid, pw): > > try: > cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) > > proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.PIPE, shell=True, universal_newlines=True) > stdout, stderr = proc.communicate() > retcode = proc.returncode > > print("printing stdout!!!!!!!!!!", stdout) > print("printing retcode!!!!!!!!!!", retcode) > > except subprocess.CalledProcessError as e: > s = """While executing '{}' something went wrong. > Return code == '{}' > Return output:\n'{}' > """.format(cmd, e.returncode, e.output, shell=True) > raise AssertionError(s) > > #return proc.strip().decode("utf-8") > * return proc.decode("utf-8").strip()* > > main("Apartment 18", "40672958689850014685ad") > > Error: > > /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python > /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py > Traceback (most recent call last): > File > "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", > line 30, in > main("Apartment 18", "40672958689850014685") > * File > "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", > line 28, in main* > * return proc.decode("utf-8").strip()* > *AttributeError: 'Popen' object has no attribute 'decode'* > printing stdout!!!!!!!!!! > printing retcode!!!!!!!!!! 0 > > Process finished with exit code 1 > > > > On Sun, Nov 25, 2018 at 11:19 PM MRAB wrote: > >> On 2018-11-25 17:13, srinivasan wrote: >> > Dear Python Experts Team, >> > >> > As am newbie still learning the python syntax from past 2 weeks, Excuse >> me, >> > If this might be silly question, As I am trying to execute shell command >> > (ie, nmcli) using "subprocess.Popen". >> > >> > 1. Am trying to improve the below code with "try" and "exception", could >> > you please help me how "try" and "exception" can be used on the below >> code >> > snippet. I hope in my code with try and exception, seems to be a bug. >> > >> > 2. As I am trying to execute shell commands using "subprocess.Popen", I >> am >> > trying to parse the strings output by "cmd = "nmcli device wifi connect >> > '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing >> the >> > below error as shown in "Output error logs:" >> > >> > Could you please let me to fix the bug in the below code snippet, >> where I >> > need the collect the strings of the command output and later how to be >> > parsed after execution of the command for example, I need to parse the >> > string "Connection activation failed: " and compare it with the command >> > output, could you please help me how this can be achieved? >> > >> > *Command:* >> > :~$ nmcli device wifi connect 'Apartment 18' password >> > '40672958689850014685abcdf' >> > Error: Connection activation failed: (7) Secrets were required, but not >> > provided. >> > :~$ >> > >> > *Code:* >> > *import sys* >> > *import subprocess* >> > >> > *interface = "wlan0"* >> > >> > >> > *def main(ssid, pw):* >> > >> > * # cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, >> pw)* >> > * #* >> > * # proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, >> > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* >> > * # stdout, stderr = proc.communicate()* >> > * # retcode = proc.returncode* >> > * #* >> > * # print("printing stdout!!!!!!!!!!", stdout)* >> > * # print("printing retcode!!!!!!!!!!", retcode)* >> > >> > * try:* >> > * cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, >> pw)* >> > >> > * proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, >> > stderr=subprocess.PIPE, shell=True, universal_newlines=True)* >> > * stdout, stderr = proc.communicate()* >> > * retcode = proc.returncode* >> > >> > * print("printing stdout!!!!!!!!!!", stdout)* >> > * print("printing retcode!!!!!!!!!!", retcode)* >> > >> > * except subprocess.CalledProcessError as e:* >> > * s = """While executing '{}' something went wrong.* >> > * Return code == '{}'* >> > * Return output:\n'{}'* >> > * """.format(cmd, e.returncode, e.output, >> > shell=enable_shell)* >> > * raise AssertionError(s)* >> > >> > * return proc.strip().decode("utf-8")* >> > >> > *main("Apartment 18", "40672958689850014685")* >> > >> > *Output error logs:* >> > >> > /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/venv/bin/python >> > >> /home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py >> > Traceback (most recent call last): >> > File >> > >> "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", >> > line 38, in >> > printing stdout!!!!!!!!!! >> > printing retcode!!!!!!!!!! 0 >> > main("Apartment 18", "40672958689850014685") >> > File >> > >> "/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py", >> > line 36, in main >> > return proc.strip().decode("utf-8") >> > AttributeError: 'Popen' object has no attribute 'strip' >> > >> > Process finished with exit code 1 >> > >> > Kindly do the needful as am stuck with this issue from 2 days >> > >> > Many Thanks in advance, >> > >> Look carefully at the traceback. It's actually telling you what the >> problem is. >> >> You're trying to do .strip() on proc, but proc is the process itself. >> >> Instead, what you want is to do .strip() on the string that it output. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From tjol at tjol.eu Sun Nov 25 13:09:22 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 25 Nov 2018 19:09:22 +0100 Subject: Python2.7 unicode conundrum In-Reply-To: References: Message-ID: <02cbd684-f8bd-c5a4-332f-08171ad10573@tjol.eu> On 25/11/2018 18:51, Robert Latest via Python-list wrote: > Hi folks, > what semmingly started out as a weird database character encoding mix-up > could be boiled down to a few lines of pure Python. The source-code > below is real utf8 (as evidenced by the UTF code point 'c3 a4' in the > third line of the hexdump). When just printed, the string "s" is > displayed correctly as '?' (a umlaut), but the string representation > shows that it seems to have been converted to latin-1 'e4' somewhere on > the way. It's not being converted to latin-1. It's a unicode string, as evidences by the 'u'. u'\xe4' is a unicode string with one character, U+00E4 (?) > How can this be avoided? > > dh at jenna:~/python$ cat unicode.py > # -*- encoding: utf8 -*- > > s = u'?' > > print(s) > print((s, )) > > dh at jenna:~/python$ hd unicode.py > 00000000 23 20 2d 2a 2d 20 65 6e 63 6f 64 69 6e 67 3a 20 |# -*- encoding: | > 00000010 75 74 66 38 20 2d 2a 2d 0a 0a 73 20 3d 20 75 27 |utf8 -*-..s = u'| > 00000020 c3 a4 27 0a 0a 70 72 69 6e 74 28 73 29 0a 70 72 |..'..print(s).pr| > 00000030 69 6e 74 28 28 73 2c 20 29 29 0a 0a |int((s,))..| > 0000003c > dh at jenna:~/python$ python unicode.py > ? > (u'\xe4',) > dh at jenna:~/python$ > > > From Richard at Damon-Family.org Sun Nov 25 13:13:13 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 25 Nov 2018 13:13:13 -0500 Subject: Python2.7 unicode conundrum In-Reply-To: References: Message-ID: <9d993cf2-1628-63c1-63f0-f16f56b573a0@Damon-Family.org> On 11/25/18 12:51 PM, Robert Latest via Python-list wrote: > Hi folks, > what semmingly started out as a weird database character encoding mix-up > could be boiled down to a few lines of pure Python. The source-code > below is real utf8 (as evidenced by the UTF code point 'c3 a4' in the > third line of the hexdump). When just printed, the string "s" is > displayed correctly as '?' (a umlaut), but the string representation > shows that it seems to have been converted to latin-1 'e4' somewhere on > the way. > How can this be avoided? > > dh at jenna:~/python$ cat unicode.py > # -*- encoding: utf8 -*- > > s = u'?' > > print(s) > print((s, )) > > dh at jenna:~/python$ hd unicode.py > 00000000 23 20 2d 2a 2d 20 65 6e 63 6f 64 69 6e 67 3a 20 |# -*- encoding: | > 00000010 75 74 66 38 20 2d 2a 2d 0a 0a 73 20 3d 20 75 27 |utf8 -*-..s = u'| > 00000020 c3 a4 27 0a 0a 70 72 69 6e 74 28 73 29 0a 70 72 |..'..print(s).pr| > 00000030 69 6e 74 28 28 73 2c 20 29 29 0a 0a |int((s,))..| > 0000003c > dh at jenna:~/python$ python unicode.py > ? > (u'\xe4',) > dh at jenna:~/python$ > > > Why do you say it has been convert to 'Latin'. The string prints as being Unicode. Internally Python doesn't store strings as UTF-8, but as plain Unicode (UCS-2 or UCS-4 as needed), and code-point E4 is the character you want. The encoding statement tells python how your source file is encoded. -- Richard Damon From python at mrabarnett.plus.com Sun Nov 25 13:13:55 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Nov 2018 18:13:55 +0000 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: On 2018-11-25 17:54, srinivasan wrote: > Hope now I have changed on the string output as below, could you > please correct me if am still wrong? > > import sys > import subprocess > > interface = "wlan0" > > > def main(ssid, pw): > > ? ? try: > ? ? ? ? cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) > > ? ? ? ? proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.PIPE, shell=True, universal_newlines=True) > ? ? ? ? stdout, stderr = proc.communicate() > ? ? ? ? retcode = proc.returncode > > ? ? ? ? print("printing stdout!!!!!!!!!!", stdout) > ? ? ? ? print("printing retcode!!!!!!!!!!", retcode) > > ? ? except subprocess.CalledProcessError as e: > ? ? ? ? s = """While executing '{}' something went wrong. > ? ? ? ? ? ? ? ? ? ? ? ? Return code == '{}' > ? ? ? ? ? ? ? ? ? ? ? ? Return output:\n'{}' > ? ? ? ? ? ? ? ? ? ? ? ? """.format(cmd, e.returncode, e.output, > shell=True) > ? ? ? ? raise AssertionError(s) > > ? ? #return proc.strip().decode("utf-8") > *? return proc.decode("utf-8").strip()* > [snip] No. As I said in _my_ post, 'proc' is the process itself. What you want is the string that it output, which, in your code, is 'stdout', so: ??? return stdout.strip().decode("utf-8") From none at invalid.com Sun Nov 25 13:25:32 2018 From: none at invalid.com (mm0fmf) Date: Sun, 25 Nov 2018 18:25:32 +0000 Subject: how to match list members in py3.x In-Reply-To: <5a7f78cf-a771-4362-a75b-a21e19be5a1e@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <5a7f78cf-a771-4362-a75b-a21e19be5a1e@googlegroups.com> Message-ID: On 25/11/2018 16:49, Muhammad Rizwan wrote: > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS. > *plonk* From Karsten.Hilbert at gmx.net Sun Nov 25 13:25:50 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 25 Nov 2018 19:25:50 +0100 Subject: Aw: Re: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: > Even only with "*proc.decode("utf-8")"* in the above code still it seems to > throw the error No it does not. It throws the same TYPE of error due to the same SORT of mistake you made. You need to read carefully and try to think about what you read. Karsten From srinivasan.rns at gmail.com Sun Nov 25 13:26:45 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Sun, 25 Nov 2018 23:56:45 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: Thanks a lot for your quick responses Mrab and appreciate the same. I changed the snippet as below, still it seems to be an issue, I am using python3 version: def main(ssid, pw): try: cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) stdout, stderr = proc.communicate() retcode = proc.returncode print("printing stdout!!!!!!!!!!", stdout) print("printing retcode!!!!!!!!!!", retcode) except subprocess.CalledProcessError as e: s = """While executing '{}' something went wrong. Return code == '{}' Return output:\n'{}' """.format(cmd, e.returncode, e.output, shell=True) raise AssertionError(s) #return proc.strip().decode("utf-8") #return proc.decode("utf-8").strip() #return proc.decode("utf-8") * return stdout.strip().decode("utf-8")* main("Apartment 18", "40672958689850014685") /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 37, in main("Apartment 18", "40672958689850014685") File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 34, in main return stdout.strip().decode("utf-8") *AttributeError: 'str' object has no attribute 'decode'* Process finished with exit code 1 On Sun, Nov 25, 2018 at 11:49 PM MRAB wrote: > On 2018-11-25 17:54, srinivasan wrote: > > Hope now I have changed on the string output as below, could you > > please correct me if am still wrong? > > > > import sys > > import subprocess > > > > interface = "wlan0" > > > > > > def main(ssid, pw): > > > > try: > > cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) > > > > proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE, shell=True, universal_newlines=True) > > stdout, stderr = proc.communicate() > > retcode = proc.returncode > > > > print("printing stdout!!!!!!!!!!", stdout) > > print("printing retcode!!!!!!!!!!", retcode) > > > > except subprocess.CalledProcessError as e: > > s = """While executing '{}' something went wrong. > > Return code == '{}' > > Return output:\n'{}' > > """.format(cmd, e.returncode, e.output, > > shell=True) > > raise AssertionError(s) > > > > #return proc.strip().decode("utf-8") > > * return proc.decode("utf-8").strip()* > > > [snip] > > No. As I said in _my_ post, 'proc' is the process itself. What you want > is the string that it output, which, in your code, is 'stdout', so: > > return stdout.strip().decode("utf-8") > > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Sun Nov 25 13:37:45 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 26 Nov 2018 00:07:45 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: Dear Mrab, Even with "return stdout.strip().decode("utf-8")", it still seems to be an issue, I am using python 3.6, is this causing a issue? /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 37, in main("Apartment 18", "40672958689850014685") File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 34, in main return stdout.strip().decode("utf-8") AttributeError: 'str' object has no attribute 'decode' Process finished with exit code 1 Many Thanks in advance On Sun, Nov 25, 2018 at 11:49 PM MRAB wrote: > On 2018-11-25 17:54, srinivasan wrote: > > Hope now I have changed on the string output as below, could you > > please correct me if am still wrong? > > > > import sys > > import subprocess > > > > interface = "wlan0" > > > > > > def main(ssid, pw): > > > > try: > > cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw) > > > > proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE, shell=True, universal_newlines=True) > > stdout, stderr = proc.communicate() > > retcode = proc.returncode > > > > print("printing stdout!!!!!!!!!!", stdout) > > print("printing retcode!!!!!!!!!!", retcode) > > > > except subprocess.CalledProcessError as e: > > s = """While executing '{}' something went wrong. > > Return code == '{}' > > Return output:\n'{}' > > """.format(cmd, e.returncode, e.output, > > shell=True) > > raise AssertionError(s) > > > > #return proc.strip().decode("utf-8") > > * return proc.decode("utf-8").strip()* > > > [snip] > > No. As I said in _my_ post, 'proc' is the process itself. What you want > is the string that it output, which, in your code, is 'stdout', so: > > return stdout.strip().decode("utf-8") > > -- > https://mail.python.org/mailman/listinfo/python-list > From srinivasan.rns at gmail.com Sun Nov 25 13:38:33 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Mon, 26 Nov 2018 00:08:33 +0530 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: Dear Karsten, With the help of Mrab Inputs, I tried Even with "return stdout.strip().decode("utf-8")", it still seems to be an issue, I am using python 3.6, is this causing a issue? /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py printing stdout!!!!!!!!!! printing retcode!!!!!!!!!! 0 Traceback (most recent call last): File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 37, in main("Apartment 18", "40672958689850014685") File "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", line 34, in main return stdout.strip().decode("utf-8") AttributeError: 'str' object has no attribute 'decode' Process finished with exit code 1 Many Thanks in advance On Sun, Nov 25, 2018 at 11:57 PM Karsten Hilbert wrote: > > Even only with "*proc.decode("utf-8")"* in the above code still it seems > to > > throw the error > > No it does not. It throws the same TYPE of error due to the same > SORT of mistake you made. > > You need to read carefully and try to think about what you read. > > Karsten > -- > https://mail.python.org/mailman/listinfo/python-list > From alister.ware at ntlworld.com Sun Nov 25 13:48:31 2018 From: alister.ware at ntlworld.com (Alister) Date: Sun, 25 Nov 2018 18:48:31 GMT Subject: how to match list members in py3.x References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <5a7f78cf-a771-4362-a75b-a21e19be5a1e@googlegroups.com> Message-ID: <38CKD.209166$RM7.11667@fx24.am4> On Sun, 25 Nov 2018 08:49:03 -0800, Muhammad Rizwan wrote: > On Sunday, 25 November 2018 10:59:46 UTC-5, Alister wrote: >> On Sun, 25 Nov 2018 07:43:42 -0800, Muhammad Rizwan wrote: >> >> > for each word in each line how can we check to see if a word is >> > already present in a list and if it is not how to append that word to >> > a new list >> >> the 1st step is to stay awake in class & listen to your instructor, >> then try to apply the principle involved >> >> We don't do homework for you >> >> when you have produced a program of you own (not necessarily working) >> if you post it here then we will be more than happy to provide >> constructive criticism >> >> >> >> >> -- >> "Show business is just like high school, except you get paid." >> - Martin Mull > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART > ASS. with an attitude like that I will go one better & ignore ALL your posts -- Good news. Ten weeks from Friday will be a pretty good day. From rizwan.ned.ee at gmail.com Sun Nov 25 13:55:08 2018 From: rizwan.ned.ee at gmail.com (Muhammad Rizwan) Date: Sun, 25 Nov 2018 10:55:08 -0800 (PST) Subject: how to match list members in py3.x In-Reply-To: <38CKD.209166$RM7.11667@fx24.am4> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <5a7f78cf-a771-4362-a75b-a21e19be5a1e@googlegroups.com> <38CKD.209166$RM7.11667@fx24.am4> Message-ID: <0a76c154-fe6e-45be-97f3-7dcc4e6ccef9@googlegroups.com> On Sunday, 25 November 2018 13:48:42 UTC-5, Alister wrote: > On Sun, 25 Nov 2018 08:49:03 -0800, Muhammad Rizwan wrote: > > > On Sunday, 25 November 2018 10:59:46 UTC-5, Alister wrote: > >> On Sun, 25 Nov 2018 07:43:42 -0800, Muhammad Rizwan wrote: > >> > >> > for each word in each line how can we check to see if a word is > >> > already present in a list and if it is not how to append that word to > >> > a new list > >> > >> the 1st step is to stay awake in class & listen to your instructor, > >> then try to apply the principle involved > >> > >> We don't do homework for you > >> > >> when you have produced a program of you own (not necessarily working) > >> if you post it here then we will be more than happy to provide > >> constructive criticism > >> > >> > >> > >> > >> -- > >> "Show business is just like high school, except you get paid." > >> - Martin Mull > > > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART > > ASS. > > with an attitude like that I will go one better & ignore ALL your posts > > > > -- > Good news. Ten weeks from Friday will be a pretty good day. Yes please ignore. Don't need any help from you either. From rosuav at gmail.com Sun Nov 25 14:00:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 06:00:49 +1100 Subject: Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: On Mon, Nov 26, 2018 at 5:40 AM srinivasan wrote: > > Dear Karsten, > > With the help of Mrab Inputs, I tried Even with "return > stdout.strip().decode("utf-8")", it still seems to be an issue, I am using > python 3.6, is this causing a issue? No, it isn't. Two things are causing most of your issues. 1) You are trying to *get your homework done*, rather than actually gain competence. Slow down. Read some documentation. Don't fire off another request to the mailing list the moment you've tried one thing; instead, do some research. 2) You don't currently understand what decode() actually means. I don't fault you for that; a lot of people don't understand it, and it was thrown at you in a suggestion without any explanation. But encode() and decode() are not magical incantations to be inserted randomly until your code works. Read these: https://nedbatchelder.com/text/unipain.html https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ I'll leave you with those. ChrisA From iwoherka at gmail.com Sun Nov 25 14:03:56 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 20:03:56 +0100 Subject: Question on difference between LambdaType and FunctionType Message-ID: Hello, Can someone please provide a use-case for having LambdaType separate to FunctionType? Since they are equal (LambdaType == FunctionType) it seems a bit superfluous to me. For example, I cannot do the following: if type(foo) is FunctionType and not type(foo) is LambdaType: ... What am I missing? Sincerely, Iwo Herka From mats at wichmann.us Sun Nov 25 14:09:48 2018 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 25 Nov 2018 12:09:48 -0700 Subject: [Tutor] Issue in using "subprocess.Popen" for parsing the command output In-Reply-To: References: <1ba59bac-4791-760a-a9f9-3ee0d28d5ea6@mrabarnett.plus.com> Message-ID: <355a38b5-b761-8376-3a31-eaf23fa7f3b9@wichmann.us> On 11/25/18 10:58 AM, srinivasan wrote: > Even only with "*proc.decode("utf-8")"* in the above code still it seems to > throw the error > > #return proc.strip().decode("utf-8") > #return proc.decode("utf-8").strip() > * return proc.decode("utf-8")* > > Error: > /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python > /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py > printing stdout!!!!!!!!!! > printing retcode!!!!!!!!!! 0 > Traceback (most recent call last): > File > "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", > line 31, in > main("Apartment 18", "40672958689850014685") > * File > "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py", > line 29, in main* > * return proc.decode("utf-8")* > *AttributeError: 'Popen' object has no attribute 'decode'* the error tells you what is wrong. proc is a Popen object, and does not have a decode method. simple enough. strings have a decode method. You're decoding the wrong thing, you need to decode what you get back from communicating with the Popen object, not the Popen object itself. stdin is the string (or more likely, in Python 3, a bytes object) you got back from calling communicate(). decode that. From rosuav at gmail.com Sun Nov 25 14:41:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 06:41:10 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 6:06 AM Iwo Herka wrote: > > Hello, > > Can someone please provide a use-case for having LambdaType > separate to FunctionType? Clarification: This is talking about the 'types' module. > Since they are equal > (LambdaType == FunctionType) it seems a bit superfluous to me. > For example, I cannot do the following: > > if type(foo) is FunctionType and not type(foo) is LambdaType: > ... > I was actually unaware of LambdaType even existing. Obviously it has to be the same as FunctionType (even more strongly than you put it: "types.LambdaType is types.FunctionType"), so I agree, it's superfluous. Maybe it's in case some other Python implementation might distinguish?? https://docs.python.org/3/library/types.html#types.FunctionType That said, though: if you want to distinguish a lambda function from a def function, you can do so with reasonable reliability using the function's name: >>> def is_lambda(f): return f.__name__ == "" ... >>> is_lambda(is_lambda) False >>> is_lambda(lambda x: x+1) True ChrisA From iwoherka at gmail.com Sun Nov 25 14:54:13 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 20:54:13 +0100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: > That said, though: if you want to distinguish a lambda function from a > def function, you can do so with reasonable reliability using the > function's name: That's what I'm using currently, thank you for the suggestion. Nonetheless, it feels hacky - that's why I tried to use LambdaType and, to my surprise, it didn't do the job. Sincerely, Iwo Herka niedz., 25 lis 2018 o 20:41 Chris Angelico napisa?(a): > > On Mon, Nov 26, 2018 at 6:06 AM Iwo Herka wrote: > > > > Hello, > > > > Can someone please provide a use-case for having LambdaType > > separate to FunctionType? > > Clarification: This is talking about the 'types' module. > > > Since they are equal > > (LambdaType == FunctionType) it seems a bit superfluous to me. > > For example, I cannot do the following: > > > > if type(foo) is FunctionType and not type(foo) is LambdaType: > > ... > > > > I was actually unaware of LambdaType even existing. Obviously it has > to be the same as FunctionType (even more strongly than you put it: > "types.LambdaType is types.FunctionType"), so I agree, it's > superfluous. Maybe it's in case some other Python implementation might > distinguish?? > > https://docs.python.org/3/library/types.html#types.FunctionType > > That said, though: if you want to distinguish a lambda function from a > def function, you can do so with reasonable reliability using the > function's name: > > >>> def is_lambda(f): return f.__name__ == "" > ... > >>> is_lambda(is_lambda) > False > >>> is_lambda(lambda x: x+1) > True > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Nov 25 15:03:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 07:03:08 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 6:54 AM Iwo Herka wrote: > > > That said, though: if you want to distinguish a lambda function from a > > def function, you can do so with reasonable reliability using the > > function's name: > > That's what I'm using currently, thank you for the suggestion. > Nonetheless, it feels hacky - that's why I tried to use LambdaType and, > to my surprise, it didn't do the job. > Yeah, not surprised you got surprised by that! But the real question is: why do you care about the difference? What is it in your code that cares about whether a function was created with "def" or with "lambda"? My suspicion is that, in most cases, the difference actually *is* the name (for instance, you might identify 'def' functions by name, but 'lambda' functions by identity), so it's not hacky to use the __name__ to distinguish them. ChrisA From michael.stemper at gmail.com Sun Nov 25 15:16:43 2018 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Sun, 25 Nov 2018 14:16:43 -0600 Subject: how to match list members in py3.x In-Reply-To: References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> <8e501556-035e-444c-87e1-8842d73cb6ec@googlegroups.com> <24fe88ad-ba60-4e63-8e00-f7747f9feea1@googlegroups.com> <796e47a4-14e3-41cd-5dad-43467c6752c1@Damon-Family.org> Message-ID: On 25/11/2018 11.41, Richard Damon wrote: > On 11/25/18 12:28 PM, Muhammad Rizwan wrote: >> handle = open('file.txt') >> newlist = list() >> for line in handle: >> #line.rstrip() >> linewords = line.split() >> print(linewords) >> >> for word in linewords: >> newlist.append(word) >> if word not in linewords: >> continue >> >> >> >> print('new: ',newlist) > > The first thing I note in looking at this is that the second loop will > run AFTER the first loop completes, not for each step of the loop, > because you outdented the code. > > Also, you unconditionally add the word, and THEN check if it is in the list. And the first thing that I note is that he checks to see if it is in the list from which it came. -- Michael F. Stemper Economists have correctly predicted seven of the last three recessions. From iwoherka at gmail.com Sun Nov 25 15:45:27 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 21:45:27 +0100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: Chris Angelico wrote: > [...] why do you care about the difference? What is it in your code that > cares about whether a function was created with "def" or with "lambda"? In answer to my previous question on the list, (https://mail.python.org/pipermail/python-list/2018-November/738151.html), where I asked about possible implementation of immutability for user-defined types, dieter suggested a solution using metaclasses and instrumentation of the __init__method: https://mail.python.org/pipermail/python-list/2018-November/738182.html. In this solution, every __init__ method (be it in the class itself or somewhere in super), sets the flag before it starts executing its body and unsets it after it's finished. The flag then is used in __setattr__ to determine whether to raise TypeError. Therefore, I'm writing a piece of code to directly modify __init__'s AST by inserting two ast.Assign's into the tree (via the ast.NodeTransformer). (Wrapping __init__ with decorator doesn't do the job.) Everything works fine, except that I have to cover the following: foo = lambda self: None class Foo: __init__ = foo Since I'm treating FunctionType and LambdaType differently (I don't have to instrument lambdas, I can just return them), I have to know which one is it. Note: I know that there is a strong argument against using all this hackery, however, I'm partly experimenting in an attempt to learn something new. :) Sincerely, Iwo Herka From rosuav at gmail.com Sun Nov 25 15:49:16 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 07:49:16 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 7:45 AM Iwo Herka wrote: > > Everything works fine, except that I have to cover the following: > > foo = lambda self: None > > class Foo: > __init__ = foo > > Since I'm treating FunctionType and LambdaType differently (I don't have > to instrument lambdas, I can just return them), I have to know which one > is it. And this is exactly what I was wondering about - how a lambda function needs to be treated differently. So is there a difference between: class Foo: def __init__(self): ... and class Foo: def setup(self): ... __init__ = lambda self: self.setup() ? If so, what is the difference? Why are lambda functions not instrumented? ChrisA From iwoherka at gmail.com Sun Nov 25 15:52:30 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 21:52:30 +0100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: > Why are lambda functions not instrumented? Because, if I didn't forget about anything, assignment in lambdas is invalid. That is, lambda self. self.x = 1 or lambda self: (self.x = 1) will throw SyntaxError. Therefore, I don't have to worry that someone will attempt to mutate the object from lambda. Sincerely, Iwo Herka From iwoherka at gmail.com Sun Nov 25 15:54:54 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 21:54:54 +0100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: > class Foo: > def setup(self): ... > __init__ = lambda self: self.setup() Sorry, didn't address this. This is fine too, since I'm assuming that only methods named __init__ are allowed to mutate the object. Because 'setup' is not '__init__' it's disqualified. Sincerely, Iwo Herka From rosuav at gmail.com Sun Nov 25 15:55:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 07:55:08 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 7:52 AM Iwo Herka wrote: > > > Why are lambda functions not instrumented? > > Because, if I didn't forget about anything, assignment > in lambdas is invalid. That is, > > lambda self. self.x = 1 > > or > > lambda self: (self.x = 1) > > will throw SyntaxError. Therefore, I don't have to worry > that someone will attempt to mutate the object from lambda. > Ahh, so this is an optimization. The question is: Do you need to worry about the lambda function calling another function? See my example above. ChrisA From rosuav at gmail.com Sun Nov 25 15:56:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 07:56:54 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 7:55 AM Iwo Herka wrote: > > > class Foo: > > def setup(self): ... > > __init__ = lambda self: self.setup() > > Sorry, didn't address this. This is fine too, since I'm assuming that > only methods named __init__ are allowed to mutate the object. > Because 'setup' is not '__init__' it's disqualified. > Ahh, okay. In that case, yeah, you can safely ignore lambda functions... until Python 3.8, when assignment expressions become a thing. (See PEP 572.) So if you want to do something hacky like using the __name__, go for it. ChrisA From rosuav at gmail.com Sun Nov 25 16:01:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Nov 2018 08:01:55 +1100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Mon, Nov 26, 2018 at 7:56 AM Chris Angelico wrote: > > On Mon, Nov 26, 2018 at 7:55 AM Iwo Herka wrote: > > > > > class Foo: > > > def setup(self): ... > > > __init__ = lambda self: self.setup() > > > > Sorry, didn't address this. This is fine too, since I'm assuming that > > only methods named __init__ are allowed to mutate the object. > > Because 'setup' is not '__init__' it's disqualified. > > > > Ahh, okay. In that case, yeah, you can safely ignore lambda > functions... until Python 3.8, when assignment expressions become a > thing. (See PEP 572.) So if you want to do something hacky like using > the __name__, go for it. > Actually... it kinda depends on the point of the optimization. If you want a quick check, look at __name__. If it's okay to spend a bit more time figuring out whether to optimize or not, look for a STORE_ATTR opcode. If there aren't any, there can't be any "self.foo = bar". (You can't be certain of the converse, as "other_object.foo = bar" will also show up as STORE_ATTR.) This is a bit more work, but it's fundamentally non-hacky, because you're actually looking for the thing you care about. ChrisA From iwoherka at gmail.com Sun Nov 25 16:09:40 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Sun, 25 Nov 2018 22:09:40 +0100 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: Chris Angelico wrote: > look for a STORE_ATTR opcode. If there aren't any, there can't > be any "self.foo = bar". (You can't be certain of the converse, as > "other_object.foo = bar" will also show up as STORE_ATTR.) This very useful, I will look into it, thanks. Sincerely, Iwo Herka From boblatest at yahoo.com Mon Nov 26 06:29:25 2018 From: boblatest at yahoo.com (Robert Latest) Date: 26 Nov 2018 11:29:25 GMT Subject: Python2.7 unicode conundrum References: <9d993cf2-1628-63c1-63f0-f16f56b573a0@Damon-Family.org> Message-ID: Richard Damon wrote: > Why do you say it has been convert to 'Latin'. The string prints as > being Unicode. Internally Python doesn't store strings as UTF-8, but as > plain Unicode (UCS-2 or UCS-4 as needed), and code-point E4 is the > character you want. You're right, this wasn't the minimal example for my problem after all. Turns out that the actual issue is somewhere between SQLAlchemy and MySQL. I took a more specific questioon overt to stackoverflow.com Thanks robert From nimbiotics at gmail.com Mon Nov 26 09:02:09 2018 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Mon, 26 Nov 2018 06:02:09 -0800 (PST) Subject: help me in a program in python to implement Railway Reservation System using file handling technique. In-Reply-To: References: Message-ID: On Saturday, November 24, 2018 at 1:44:21 AM UTC-5, Chris Angelico wrote: > On Sat, Nov 24, 2018 at 5:36 PM wrote: > > > > hello all, > > please hepl me in the above program. python to implement Railway Reservation System using file handling technique. > > > > System should perform below operations. > > a. Reserve a ticket for a passenger. > > b. List information all reservations done for today?s trains. > > We won't do your homework for you. Have a shot at writing it yourself > first, and then if you need help, bring specific questions to the > list. > > ChrisA Specially not for an Assistant Professor at SMT.R.O.PATEL WOMEN'S MCA COLLEGE holding an MBA and a BCA... Shame on you Jasmin! From jules.lasne at gmail.com Mon Nov 26 09:19:13 2018 From: jules.lasne at gmail.com (Jules Lasne) Date: Mon, 26 Nov 2018 15:19:13 +0100 Subject: [docs] Improvement Request In-Reply-To: References: Message-ID: I thinks this is sphinx related, not the python doc team :) Regards, Jules Lasne +33640736355 jules.lasne at gmail.com juleslasne.com Le lun. 26 nov. 2018 ? 15:08, Sayan Kundu a ?crit : > *** Please make "Table of Contents" an independent scrolling panel* > For a long documentation, users have to scroll up all the way to navigate > a different sub-topic. > _______________________________________________ > docs mailing list > docs at python.org > https://mail.python.org/mailman/listinfo/docs > From ian.g.kelly at gmail.com Mon Nov 26 12:06:16 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 26 Nov 2018 10:06:16 -0700 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: On Sun, Nov 25, 2018 at 2:00 PM Chris Angelico wrote: > > On Mon, Nov 26, 2018 at 7:55 AM Iwo Herka wrote: > > > > > class Foo: > > > def setup(self): ... > > > __init__ = lambda self: self.setup() > > > > Sorry, didn't address this. This is fine too, since I'm assuming that > > only methods named __init__ are allowed to mutate the object. > > Because 'setup' is not '__init__' it's disqualified. > > > > Ahh, okay. In that case, yeah, you can safely ignore lambda > functions... until Python 3.8, when assignment expressions become a > thing. (See PEP 572.) So if you want to do something hacky like using > the __name__, go for it. What about: __init__ = lambda self: setattr(self, 'foo', 'bar') ? From ethan at stoneleaf.us Mon Nov 26 12:16:29 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 26 Nov 2018 09:16:29 -0800 Subject: how to match list members in py3.x In-Reply-To: <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> References: <1350d1e5-bcee-4136-b961-d125bd54f028@googlegroups.com> <88bbdd24-4cdc-41ac-a4f2-7dfadb7ad604@googlegroups.com> Message-ID: <0053c984-57a6-bb42-d46f-171f28223e17@stoneleaf.us> On 11/25/2018 08:30 AM, Muhammad Rizwan wrote: > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART > ASS. On 11/25/2018 08:49 AM, Muhammad Rizwan wrote: > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART > ASS. On 11/25/2018 10:55 AM, Muhammad Rizwan wrote: > Yes please ignore. Don't need any help from you either. This behavior is not acceptable. Any more posts like this and you will be suspended from Python List. -- ~Ethan~ Python List Moderator From ivo.shipkaliev at gmail.com Tue Nov 27 05:48:20 2018 From: ivo.shipkaliev at gmail.com (Ivo Shipkaliev) Date: Tue, 27 Nov 2018 10:48:20 +0000 Subject: PEP 572 -- Assignment Expressions Message-ID: Hello. Maybe it's too late for a discussion, but I just couldn't resist. I just found out about this new ":=" operator. I need to ask: What is the need for this additional ":" to the "="? Why: if (match := pattern.search(data)) is not None: # Do something with match What is wrong with: if match = pattern.search(data) is not None: # Do something with match Assignment expression or assignment statement, it's an assignment, right? It is very clear to everyone that it's an assignment! Can't it all just be a "="? Thank you very much! Kind Regards Ivo Shipkaliev From iwoherka at gmail.com Tue Nov 27 06:02:51 2018 From: iwoherka at gmail.com (Iwo Herka) Date: Tue, 27 Nov 2018 11:02:51 +0000 Subject: Question on difference between LambdaType and FunctionType In-Reply-To: References: Message-ID: Ian Kelly wrote: > What about: > > __init__ = lambda self: setattr(self, 'foo', 'bar') That's an edge-case alright. Fortunately, I've decided to not skip lambdas. That's too problematic, it's easier to parse them as a special-case. Thanks for pointing this out. Sincerely, Iwo Herka From srinivasan.rns at gmail.com Tue Nov 27 07:50:04 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Tue, 27 Nov 2018 13:50:04 +0100 Subject: Error Python version 3.6 does not support this syntax. Message-ID: Dear Python Experts, As still I am newbie and learning python, I am trying to reuse the Bluetoothctl wrapper in Python from the link ( https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6 version, In pycharm editor on the bold highlighted code snippets I see the error message "Python version 3.6 does not support this syntax.", Could you please how help me how the below highlighted lines of code can be can be ported to python3.6 version? * except BluetoothctlError, e:* * print(e)* * return None* Full Code snippet: ============== import time import pexpect import subprocess import sys class BluetoothctlError(Exception): """This exception is raised, when bluetoothctl fails to start.""" pass class Bluetoothctl: """A wrapper for bluetoothctl utility.""" def __init__(self): out = subprocess.check_output("rfkill unblock bluetooth", shell = True) self.child = pexpect.spawn("bluetoothctl", echo = False) def get_output(self, command, pause = 0): """Run a command in bluetoothctl prompt, return output as a list of lines.""" self.child.send(command + "\n") time.sleep(pause) start_failed = self.child.expect(["bluetooth", pexpect.EOF]) if start_failed: raise BluetoothctlError("Bluetoothctl failed after running " + command) return self.child.before.split("\r\n") def start_scan(self): """Start bluetooth scanning process.""" try: out = self.get_output("scan on") * except BluetoothctlError, e: print(e) return None* def make_discoverable(self): """Make device discoverable.""" try: out = self.get_output("discoverable on") * except BluetoothctlError, e: print(e) return None* def parse_device_info(self, info_string): """Parse a string corresponding to a device.""" device = {} block_list = ["[\x1b[0;", "removed"] string_valid = not any(keyword in info_string for keyword in block_list) if string_valid: try: device_position = info_string.index("Device") except ValueError: pass else: if device_position > -1: attribute_list = info_string[device_position:].split(" ", 2) device = { "mac_address": attribute_list[1], "name": attribute_list[2] } return device def get_available_devices(self): """Return a list of tuples of paired and discoverable devices.""" try: out = self.get_output("devices") * except BluetoothctlError, e: print(e) return None* else: available_devices = [] for line in out: device = self.parse_device_info(line) if device: available_devices.append(device) return available_devices def get_paired_devices(self): """Return a list of tuples of paired devices.""" try: out = self.get_output("paired-devices") * except BluetoothctlError, e: print(e) return None* else: paired_devices = [] for line in out: device = self.parse_device_info(line) if device: paired_devices.append(device) return paired_devices def get_discoverable_devices(self): """Filter paired devices out of available.""" available = self.get_available_devices() paired = self.get_paired_devices() return [d for d in available if d not in paired] def get_device_info(self, mac_address): """Get device info by mac address.""" try: out = self.get_output("info " + mac_address) * except BluetoothctlError, e: print(e) return None* else: return out def pair(self, mac_address): """Try to pair with a device by mac address.""" try: out = self.get_output("pair " + mac_address, 4) * except BluetoothctlError, e: print(e) return None* else: res = self.child.expect(["Failed to pair", "Pairing successful", pexpect.EOF]) success = True if res == 1 else False return success def remove(self, mac_address): """Remove paired device by mac address, return success of the operation.""" try: out = self.get_output("remove " + mac_address, 3) * except BluetoothctlError, e: print(e) return None* else: res = self.child.expect(["not available", "Device has been removed", pexpect.EOF]) success = True if res == 1 else False return success def connect(self, mac_address): """Try to connect to a device by mac address.""" try: out = self.get_output("connect " + mac_address, 2) * except BluetoothctlError, e: print(e) return None* else: res = self.child.expect(["Failed to connect", "Connection successful", pexpect.EOF]) success = True if res == 1 else False return success def disconnect(self, mac_address): """Try to disconnect to a device by mac address.""" try: out = self.get_output("disconnect " + mac_address, 2) * except BluetoothctlError, e: print(e) return None* else: res = self.child.expect(["Failed to disconnect", "Successful disconnected", pexpect.EOF]) success = True if res == 1 else False return success kindly do the needful, Many Thanks in advance, From brian.j.oney at googlemail.com Tue Nov 27 08:18:08 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Tue, 27 Nov 2018 14:18:08 +0100 Subject: Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: <1543324688.21447.2.camel@gmail.com> On Tue, 2018-11-27 at 13:50 +0100, srinivasan wrote: > > * except BluetoothctlError, e:* > I don't have python3.6 available, but I believe the proper syntax is: except BluetoothctlError as e: print(e) See: https://docs.python.org/3/tutorial/errors.html?highlight=exception HTW From frank at chagford.com Tue Nov 27 08:24:43 2018 From: frank at chagford.com (Frank Millman) Date: Tue, 27 Nov 2018 15:24:43 +0200 Subject: Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: "srinivasan" wrote in message news:CAFsTbWeC-wW7AgRWtOtK5Z8FhLrFa1HOcoObkV7bcydS1bEG3A at mail.gmail.com... > > As still I am newbie and learning python, I am trying to reuse the Bluetoothctl wrapper in Python from the link ( https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6 version, In pycharm editor on the bold highlighted code snippets I see the error message "Python version 3.6 does not support this syntax.", > > Could you please how help me how the below highlighted lines of code can > be can be ported to python3.6 version? > * except BluetoothctlError, e:* * print(e)* * return None* Here is a quick, untested, reply. If it does not work for you, please post again with the output. The correct syntax for Python 3.x is except BluetoothctlError as e: The line 'print(e)' should then work. In the line 'return None', it may be complaining that None is superfluous - a plain 'return' does the same thing. HTH Frank Millman From tjreedy at udel.edu Tue Nov 27 11:55:24 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Nov 2018 11:55:24 -0500 Subject: Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: On 11/27/2018 7:50 AM, srinivasan wrote: > Dear Python Experts, > > As still I am newbie and learning python, I am trying to reuse the > Bluetoothctl wrapper in Python from the link ( > https://gist.github.com/egorf/66d88056a9d703928f93 Created in 2015 > ) I am using python3.6 > version, In pycharm editor on the bold highlighted code snippets I see the > error message "Python version 3.6 does not support this syntax.", No version of Python 3 supports the the old exception statement syntax. Python 2.7, released in 2010, supports both the old and the new syntax. I am not sure about 2.6 and before. It is odd to me that someone would use both the new print syntax and old except syntax together in 2015. > Could you please how help me how the below highlighted lines of code can be > can be ported to python3.6 version? > > * except BluetoothctlError, e:* If you run the code through the lib2to3 converter it will change ', ' to ' as '. I have not > Full Code snippet: Not needed, however start_scan and make_discoverable are a bit flakey. As written, out is discarded making the assignment to out useless and the 'return None' redundant (since the function always returns None). I suspect that this is a bug. > def start_scan(self): > """Start bluetooth scanning process.""" > try: > out = self.get_output("scan on") > except BluetoothctlError, e: print(e) return None -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 27 11:58:34 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Nov 2018 11:58:34 -0500 Subject: Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: On 11/27/2018 8:24 AM, Frank Millman wrote: > In the line 'return None',? it may be complaining that None is > superfluous - a plain 'return' does the same thing. PEP 8 recommends explicit 'return None' if elsewhere in the function there is an explicit 'return something', as in if condition: return makelist(args) else: return None (though in the above, 'return []' might be better). However, in the quoted code, there is no other return (this might be a bug). -- Terry Jan Reedy From rosuav at gmail.com Tue Nov 27 12:50:52 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Nov 2018 04:50:52 +1100 Subject: PEP 572 -- Assignment Expressions In-Reply-To: References: Message-ID: On Wed, Nov 28, 2018 at 4:38 AM Ivo Shipkaliev wrote: > > Hello. > Maybe it's too late for a discussion, but I just couldn't resist. > I just found out about this new ":=" operator. I need to ask: > > What is the need for this additional ":" to the "="? > Why: > if (match := pattern.search(data)) is not None: > # Do something with match > > What is wrong with: > if match = pattern.search(data) is not None: > # Do something with match > > Assignment expression or assignment statement, it's an assignment, > right? It is very clear to everyone that it's an assignment! Can't it all > just be a "="? > Thank you very much! It's a bug magnet. https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-existing-assignment-into-an-expression ChrisA From mats at wichmann.us Tue Nov 27 13:47:46 2018 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 27 Nov 2018 11:47:46 -0700 Subject: [Tutor] Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: On 11/27/18 5:50 AM, srinivasan wrote: > Dear Python Experts, > > As still I am newbie and learning python, I am trying to reuse the > Bluetoothctl wrapper in Python from the link ( > https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6 > version, In pycharm editor on the bold highlighted code snippets I see the > error message "Python version 3.6 does not support this syntax.", once again you've posted in a way that inserts lots of extra crud, you avoided that last time. The syntax change is simple (and works on most older Pythons too): except ErrorType, e: becomes except ErrorType as e: > > Could you please how help me how the below highlighted lines of code can be > can be ported to python3.6 version? > > * except BluetoothctlError, e:* > > * print(e)* > * return None* > From bgailer at gmail.com Tue Nov 27 19:57:07 2018 From: bgailer at gmail.com (bob gailer) Date: Tue, 27 Nov 2018 19:57:07 -0500 Subject: PEP 572 -- Assignment Expressions In-Reply-To: References: Message-ID: On 11/27/2018 5:48 AM, Ivo Shipkaliev wrote: > Hello. > Maybe it's too late for a discussion, but I just couldn't resist. > I just found out about this new ":=" operator. I need to ask: > > What is the need for this additional ":" to the "="? Did you read the PEP? It answers the question. > Why: > if (match := pattern.search(data)) is not None: > # Do something with match > > What is wrong with: > if match = pattern.search(data) is not None: > # Do something with match match = pattern.search(data) is not None returns True or False, which is then assigned to match. On the other hand, in (match := pattern.search(data)) is not None match is assigned the result of the search; then that is compared to None. I am glad to see this added to python. I first encountered embedded assignment in 1969 in the fortran iv compiler for the GE 415 computer. Love at first sight. -- Bob Gailer From skip.montanaro at gmail.com Wed Nov 28 09:44:59 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 28 Nov 2018 08:44:59 -0600 Subject: What Python books to you recommend to beginners? Message-ID: I've been using Python since long before Mark Lutz's book was first released, so I've never paid much attention to what's out there. Still, every now and then, someone asks me for a recommendation (as just happened a few minutes ago). "Learning Python" was last released in 2013 (Python 3.3), so lacks many newer features of the language. What do people recommend? The target is Python 3.6 and 3.7. The audience at work is a mostly financial/statistical crowd, so exposure to things like Pandas would be nice, though I'm sure there are dedicated books for just that. Thanks, Skip From brian.j.oney at googlemail.com Wed Nov 28 10:47:54 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 28 Nov 2018 16:47:54 +0100 Subject: What Python books to you recommend to beginners? In-Reply-To: References: Message-ID: <1543420074.10187.1.camel@gmail.com> On Wed, 2018-11-28 at 08:44 -0600, Skip Montanaro wrote: > What do people recommend? The target is Python 3.6 and 3.7. The > audience at work is a mostly financial/statistical crowd, so exposure > to things like Pandas would be nice, though I'm sure there are > dedicated books for just that. Given your audience "Python for Data Analysis, 2nd Edition" by Wes McKinney would suit well. The Python tutorial should suit for basic syntax. HTH From santiago at rmotr.com Wed Nov 28 11:47:09 2018 From: santiago at rmotr.com (Santiago Basulto) Date: Wed, 28 Nov 2018 13:47:09 -0300 Subject: What Python books to you recommend to beginners? In-Reply-To: <1543420074.10187.1.camel@gmail.com> References: <1543420074.10187.1.camel@gmail.com> Message-ID: Python for Data Analysis is a great choice for sure. I think Think Python , by Allen Downey is also a great alternative for beginners. I've written a short piece with 3 free books to get started: https://blog.rmotr.com/the-3-python-books-you-need-to-get-started-for-free-9b72a2c6fb17 On Wed, Nov 28, 2018 at 12:51 PM Brian Oney via Python-list < python-list at python.org> wrote: > On Wed, 2018-11-28 at 08:44 -0600, Skip Montanaro wrote: > > What do people recommend? The target is Python 3.6 and 3.7. The > > audience at work is a mostly financial/statistical crowd, so exposure > > to things like Pandas would be nice, though I'm sure there are > > dedicated books for just that. > > Given your audience "Python for Data Analysis, 2nd Edition" by Wes > McKinney would suit well. The Python tutorial should suit for basic > syntax. > > HTH > -- > https://mail.python.org/mailman/listinfo/python-list > -- Santiago Basulto.- Co-founder @ rmotr.com From srinivasan.rns at gmail.com Thu Nov 29 14:20:49 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Fri, 30 Nov 2018 00:50:49 +0530 Subject: [Tutor] Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: Dear Python Experts, With the below code snippet, I am seeing the below error, I am using python 3.6, could you please what could be the issue? Code Snippet: ------------------- import time import pexpect import subprocess import sys class BluetoothctlError(Exception): """This exception is raised, when bluetoothctl fails to start.""" pass class Bluetoothctl: """A wrapper for bluetoothctl utility.""" def __init__(self): out = subprocess.check_output("rfkill unblock bluetooth", shell = True) self.child = pexpect.spawn("bluetoothctl", echo = False) def get_output(self, command, pause = 0): """Run a command in bluetoothctl prompt, return output as a list of lines.""" self.child.send(command + "\n") time.sleep(pause) start_failed = self.child.expect(["bluetooth", pexpect.EOF]) if start_failed: raise BluetoothctlError("Bluetoothctl failed after running " + command) return self.child.before.split("\r\n") -------------------------------------------------------------------------------> the issue seems to be here def start_scan(self): """Start bluetooth scanning process.""" try: out = self.get_output("scan on") except BluetoothctlError as e: print(e) return None if __name__ == "__main__": print("Init bluetooth...") bl = Bluetoothctl() print("Ready!") bl.start_scan() print("Scanning for 10 seconds...") for i in range(0, 10): print(i) time.sleep(1) Error Logs: ------------- /home/srinivasan/Downloads/bt_tests/qa/venv/bin/python /home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py Init bluetooth... Ready! Traceback (most recent call last): File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", line 169, in bl.start_scan() File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", line 32, in start_scan out = self.get_output("scan on") File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", line 27, in get_output return self.child.before.split("\r\n") TypeError: a bytes-like object is required, not 'str' Process finished with exit code 1 On Wed, Nov 28, 2018 at 12:17 AM Mats Wichmann wrote: > > On 11/27/18 5:50 AM, srinivasan wrote: > > Dear Python Experts, > > > > As still I am newbie and learning python, I am trying to reuse the > > Bluetoothctl wrapper in Python from the link ( > > https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6 > > version, In pycharm editor on the bold highlighted code snippets I see the > > error message "Python version 3.6 does not support this syntax.", > > once again you've posted in a way that inserts lots of extra crud, you > avoided that last time. > > The syntax change is simple (and works on most older Pythons too): > > except ErrorType, e: > > becomes > > except ErrorType as e: > > > > > > Could you please how help me how the below highlighted lines of code can be > > can be ported to python3.6 version? > > > > * except BluetoothctlError, e:* > > > > * print(e)* > > * return None* > > From mats at wichmann.us Thu Nov 29 14:48:41 2018 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 29 Nov 2018 12:48:41 -0700 Subject: [Tutor] Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: <0e1b086f-f2e5-a668-417f-78934a9c47cb@wichmann.us> On 11/29/18 12:20 PM, srinivasan wrote: > Dear Python Experts, > > With the below code snippet, I am seeing the below error, I am using > python 3.6, could you please what could be the issue? > self.child = pexpect.spawn("bluetoothctl", echo = False) ... > self.child.send(command + "\n") > time.sleep(pause) > start_failed = self.child.expect(["bluetooth", pexpect.EOF]) ... > return self.child.before.split("\r\n") > -------------------------------------------------------------------------------> > the issue seems to be here > line 27, in get_output > return self.child.before.split("\r\n") > TypeError: a bytes-like object is required, not 'str' your types don't match. it's Python 3 so what you get back from talking to an external process is a bytes object. you're calling the split method on that object, but passing it a string to split on - that's what the error is saying. It shouldn't be any more complicated to fix that than to give it a byte object: return self.child.before.split(b"\r\n") or... decode the object to a str before splitting on a string. but since you're specifically splitting on lines, you may as well use the splitlines method instead of the split method, since that's what it is designed for. From rhodri at kynesim.co.uk Thu Nov 29 14:48:51 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 29 Nov 2018 19:48:51 +0000 Subject: Bytes vs Strings (Was Re: [Tutor] Error Python version 3.6 does not support this syntax) In-Reply-To: References: Message-ID: <3911f003-34b2-e323-3747-6897869b7488@kynesim.co.uk> On 29/11/2018 19:20, srinivasan wrote: > With the below code snippet, I am seeing the below error, I am using > python 3.6, could you please what could be the issue? [snip] > Traceback (most recent call last): > File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", > line 169, in > bl.start_scan() > File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", > line 32, in start_scan > out = self.get_output("scan on") > File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", > line 27, in get_output > return self.child.before.split("\r\n") > TypeError: a bytes-like object is required, not 'str' The traceback tells you that you are expected to provide a "bytes" string rather than a unicode (normal) string. I would guess that's because pexpect is returning a byte string in self.child.before. You should: a) check the pexpect documentation to see if that's correct b) supply self.child.before.split() with a byte string c) seriously consider whether you are making life hard for yourself You appear to regard Python as a language you can use to run shell commands and parse their output. Have you looked to see if there are existing Python modules that will Just Do The Work for you and avoid all this faffing about? -- Rhodri James *-* Kynesim Ltd From srinivasan.rns at gmail.com Thu Nov 29 15:49:25 2018 From: srinivasan.rns at gmail.com (srinivasan) Date: Fri, 30 Nov 2018 02:19:25 +0530 Subject: [Tutor] Error Python version 3.6 does not support this syntax. In-Reply-To: <0e1b086f-f2e5-a668-417f-78934a9c47cb@wichmann.us> References: <0e1b086f-f2e5-a668-417f-78934a9c47cb@wichmann.us> Message-ID: Dear Mats, Thanks a lot for your quick responses, again the below line seems to be throwing the same error, is that should I again decode the line where am facing the issue to str? or could you please let me if there is any alternative solution for the same or workaround in python 3.6? Code Snippet: def parse_device_info(self, info_string): """Parse a string corresponding to a device.""" device = {} block_list = ["[\x1b[0;", "removed"] string_valid = not any(keyword in info_string for keyword in block_list) ---------------------------> Again this line seems to be the same issue if string_valid: try: device_position = info_string.index("Device") except ValueError: pass else: if device_position > -1: attribute_list = info_string[device_position:].split(" ", 2) device = { "mac_address": attribute_list[1], "name": attribute_list[2] } return device def get_paired_devices(self): """Return a list of tuples of paired devices.""" try: out = self.get_output("paired-devices") except BluetoothctlError as e: print(e) return None else: paired_devices = [] for line in out: device = self.parse_device_info(line) if device: paired_devices.append(device) return paired_devices if __name__ == "__main__": print("Init bluetooth...") bl = Bluetoothctl() print("Ready!") bl.start_scan() print("Scanning for 10 seconds...") for i in range(0, 10): print(i) time.sleep(1) bl.pair("64:A2:F9:06:63:79") print("Pairing for 10 seconds...") for i in range(0, 10): print(i) time.sleep(1) # Seems to be an issue ---------- bl.get_paired_devices() print("Getting Paired devices for 10 seconds...") for i in range(0, 10): print(i) time.sleep(1) Error Logs: Traceback (most recent call last): , in parse_device_info string_valid = not any(keyword in info_string for keyword in block_list) File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py", line 52, in string_valid = not any(keyword in info_string for keyword in block_list) TypeError: a bytes-like object is required, not 'str' On Fri, Nov 30, 2018 at 1:18 AM Mats Wichmann wrote: > > On 11/29/18 12:20 PM, srinivasan wrote: > > Dear Python Experts, > > > > With the below code snippet, I am seeing the below error, I am using > > python 3.6, could you please what could be the issue? > > > self.child = pexpect.spawn("bluetoothctl", echo = False) > ... > > self.child.send(command + "\n") > > time.sleep(pause) > > start_failed = self.child.expect(["bluetooth", pexpect.EOF]) > ... > > return self.child.before.split("\r\n") > > -------------------------------------------------------------------------------> > > the issue seems to be here > > line 27, in get_output > > return self.child.before.split("\r\n") > > TypeError: a bytes-like object is required, not 'str' > > your types don't match. it's Python 3 so what you get back from talking > to an external process is a bytes object. you're calling the split > method on that object, but passing it a string to split on - that's what > the error is saying. It shouldn't be any more complicated to fix that > than to give it a byte object: > > return self.child.before.split(b"\r\n") > > or... decode the object to a str before splitting on a string. > > but since you're specifically splitting on lines, you may as well use > the splitlines method instead of the split method, since that's what it > is designed for. > > > > > From cs at cskk.id.au Thu Nov 29 17:18:47 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 30 Nov 2018 09:18:47 +1100 Subject: [Tutor] Error Python version 3.6 does not support this syntax. In-Reply-To: References: Message-ID: <20181129221847.GA84153@cskk.homeip.net> On 30Nov2018 02:19, srinivasan wrote: >Thanks a lot for your quick responses, again the below line seems to >be throwing the same error, is that should I again decode the line >where am facing the issue to str? or could you please let me if there >is any alternative solution for the same or workaround in python 3.6? > >Code Snippet: > > def parse_device_info(self, info_string): > """Parse a string corresponding to a device.""" > device = {} > block_list = ["[\x1b[0;", "removed"] > string_valid = not any(keyword in info_string for keyword in >block_list) ---------------------------> Again this line seems to be >the same issue [...] > def get_paired_devices(self): > """Return a list of tuples of paired devices.""" > try: > out = self.get_output("paired-devices") > except BluetoothctlError as e: > print(e) > return None > else: > paired_devices = [] > for line in out: > device = self.parse_device_info(line) [...] Your problem is basicly that reading from command output gets you bytes data, not text (str) data. This is because pipes transfer bytes; that the command may issue text simply means that those bytes are an encoding of the text. Your entire process treats the output as text, because the commands issue textual output. Therefore, the most sensible thing to do at this point is to _decode_ the bytes into text as soon as you get them from the command, and then the rest of your programme can work in text (str) from then on. So I would be inclined to change: for line in out: device = self.parse_device_info(line) into (untested): for line_b in out: line = line_b.decode(errors='replace') device = self.parse_device_info(line) That will turn line_b (a bytes object holding the line) into text before you try to do any parsing. From that point onward, everything is text (str) and you do not need to put any bytes->str stuff elsewhere in your programme. Some remarks: That decode line above uses the default bytes->str decoding, which is 'utf-8'. That is probably how your system works, but if it is not you need to adjust accordingly. If the command ussues pure ASCII you'll be fine regardless. The decode uses "errors='replace'", which means that if the bytes data are _not_ correct UTF-8 encoded text, the decoder will put some replacement characters in the result instead of raising an exception. This simplifies your code, and since you're parsing the output anyway for infomation the replacements should show up to your eye. The default decode mode is 'strict', which would raise an exception on an invalid encoding. Purists might decode the output stream ("out") before the for-loop, but in most encodings including UTF-8, you can split on newlines (byte code 10, ASCII NL) safely anyway, so we just split first and decode each "bytes" line individually. In the loop I deliberately iterate over "line_b", and have the decoded text in "line", instead of doing something like: for line in out: line = line.decode(....) That way I am always sure that I intend to talk about bytes in one place (line_b) and text (line) in another. Having variable that might contain bytes _or_ text leads to confusion and difficult debugging. The core takeaway here is that you want to keep in mind whether you're working in bytes or text (str). Keep the division clean, that way all you other code can be written appropriately. So: the command pipe output is bytes. COnvert it to text before passing to your text parsing code. That way all the parsing code can work in text (str) and have no weird conversion logic. Cheers, Cameron Simpson From morphex at gmail.com Fri Nov 30 08:35:50 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Fri, 30 Nov 2018 14:35:50 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split Message-ID: Hi there. I was adding a port specification feature to my surveil project as shown here: https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4 A bit later I was surprised when the script raised an exception, and that I had to catch a ValueError instead of an IndexError: https://github.com/morphex/surveil/commit/d5c49c54d4037557aaca1f78178b76441853c7af I've been reading up on a bit of C++, Assembler etc. lately, so maybe my mind expected an IndexError because of that, but isn't it logical that the string is parsed and split, and then later the unpacking operation fails with an IndexError? Regards, Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Nov 30 09:53:10 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 30 Nov 2018 08:53:10 -0600 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: Message-ID: On 11/30/18 7:35 AM, Morten W. Petersen wrote: > ... but isn't it logical that the > string is parsed and split, and then later the unpacking operation fails > with an IndexError? With slightly simpler code and the full text of the exception, the details becomes more apparent: >>> x, y = [4] Traceback (most recent call last): File "", line 1, in ValueError: not enough values to unpack (expected 2, got 1) Python validates that the right hand side contains exactly the right number of elements before beginning to unpack, presumably to ensure a successful operation before failing part way through. Effectively, Python is saying that you can't unpack a one-element array into two pieces *before* it gets to the indexing logic. HTH, Dan From __peter__ at web.de Fri Nov 30 09:59:46 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Nov 2018 15:59:46 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split References: Message-ID: Morten W. Petersen wrote: > Hi there. > > I was adding a port specification feature to my surveil project as shown > here: > > https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4 > > A bit later I was surprised when the script raised an exception, and that > I had to catch a ValueError instead of an IndexError: > > https://github.com/morphex/surveil/commit/d5c49c54d4037557aaca1f78178b76441853c7af > > I've been reading up on a bit of C++, Assembler etc. lately, so maybe my > mind expected an IndexError because of that, but isn't it logical that the > string is parsed and split, and then later the unpacking operation fails > with an IndexError? You might think that a, b = c is equivalent to a = c[0] b = c[1] but the c above can be an arbitrary iterable: >>> a, b = iter("ab") >>> a, b ('a', 'b') >>> a, b = iter("abc") Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack (expected 2) So there is not necessarily a lookup by index. From morphex at gmail.com Fri Nov 30 10:17:43 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Fri, 30 Nov 2018 16:17:43 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: Message-ID: On Fri, Nov 30, 2018 at 4:02 PM Peter Otten <__peter__ at web.de> wrote: > Morten W. Petersen wrote: > > > I've been reading up on a bit of C++, Assembler etc. lately, so maybe my > > mind expected an IndexError because of that, but isn't it logical that > the > > string is parsed and split, and then later the unpacking operation fails > > with an IndexError? > > You might think that > > a, b = c > > is equivalent to > > a = c[0] > b = c[1] > > but the c above can be an arbitrary iterable: > > >>> a, b = iter("ab") > >>> a, b > ('a', 'b') > >>> a, b = iter("abc") > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack (expected 2) > > So there is not necessarily a lookup by index. > Ah, of course. OK, right you are. :) -Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From morphex at gmail.com Fri Nov 30 11:57:04 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Fri, 30 Nov 2018 17:57:04 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: Message-ID: On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers < 2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > On 11/30/18 7:35 AM, Morten W. Petersen wrote: > > > ... but isn't it logical that the > > string is parsed and split, and then later the unpacking operation fails > > with an IndexError? > > With slightly simpler code and the full text of the exception, > the details becomes more apparent: > > >>> x, y = [4] > Traceback (most recent call last): > File "", line 1, in > ValueError: not enough values to unpack (expected 2, got 1) > > Python validates that the right hand side contains exactly the > right number of elements before beginning to unpack, presumably > to ensure a successful operation before failing part way through. > > Effectively, Python is saying that you can't unpack a one-element > array into two pieces *before* it gets to the indexing logic. > Hm. Well I like the simplicity and abstraction of Python, it makes it a very productive language. And since iterable object can be used, I guess it makes sense to raise a ValueError. And trying >>> a,b,c = None Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not iterable >>> raises a TypeError, and this is all in-hand with the Python docs. But since you mention it, why is it necessary to ensure a successful operation? Is it so that when a,b,c = [1,2] fails, none of the variables a,b,c have been assigned to, and because of that, one avoids "rolling back" any assignment that would have been done without checking the right-hand argument first ? Regards, Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Nov 30 12:21:05 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 30 Nov 2018 11:21:05 -0600 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: Message-ID: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> On 11/30/18 10:57 AM, Morten W. Petersen wrote: > On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> Python validates that the right hand side contains exactly the right >> number of elements before beginning to unpack, presumably to ensure a >> successful operation before failing part way through. > Hm. Well I like the simplicity and abstraction of Python, it makes it > a very productive language. Agreed, and hold that thought. > But since you mention it, why is it necessary to ensure a successful > operation? > > Is it so that when > > a,b,c = [1,2] > > fails, none of the variables a,b,c have been assigned to, and because > of that, one avoids "rolling back" any assignment that would have been > done without checking the right-hand argument first ? That's what I was getting at, but apparently failed to express clearly. Yes, there are use cases for a short iterator just not assigning the rest of the variables, and for a long iterator using only what it needs, but also explicit is better than implicit, and errors should never pass silently, and other bits of wisdom learned from horrible debugging experiences. From morphex at gmail.com Fri Nov 30 13:00:17 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Fri, 30 Nov 2018 19:00:17 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On Fri, Nov 30, 2018 at 6:21 PM Dan Sommers < 2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > On 11/30/18 10:57 AM, Morten W. Petersen wrote: > > On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers > <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > [...] > > But since you mention it, why is it necessary to ensure a successful > > operation? > > > > Is it so that when > > > > a,b,c = [1,2] > > > > fails, none of the variables a,b,c have been assigned to, and because > > of that, one avoids "rolling back" any assignment that would have been > > done without checking the right-hand argument first ? > > That's what I was getting at, but apparently failed to express clearly. > > Yes, there are use cases for a short iterator just not assigning the > rest of the variables, and for a long iterator using only what it needs, > but also explicit is better than implicit, and errors should never pass > silently, and other bits of wisdom learned from horrible debugging > experiences. > Aha, yes well you have head, tail, etc. I guess syntax could be added, so that a, b, @c = some sequence would initialize a and b, and leave anything remaining in c. We could then call this @ syntax "teh snek". ? ..I guess I haven't punished myself with enough Perl yet. Regards, Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Nov 30 13:25:03 2018 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 30 Nov 2018 12:25:03 -0600 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On 11/30/18 12:00 PM, Morten W. Petersen wrote: > I guess syntax could be added, so that > > a, b, @c = some sequence > > would initialize a and b, and leave anything remaining in c. We could > then call this @ syntax "teh snek". Close. ;-) Try this: a, b, *c = [4, 5, 6, 7] From morphex at gmail.com Fri Nov 30 13:47:43 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Fri, 30 Nov 2018 19:47:43 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < 2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > I guess syntax could be added, so that > > > > a, b, @c = some sequence > > > > would initialize a and b, and leave anything remaining in c. We could > > then call this @ syntax "teh snek". > > Close. ;-) Try this: > > a, b, *c = [4, 5, 6, 7] > ? I did not know that. Or maybe I read it somewhere and it was in the subconscious. -Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From benjamin at schollnick.net Fri Nov 30 16:42:06 2018 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Fri, 30 Nov 2018 16:42:06 -0500 Subject: RAR functionality In-Reply-To: References: Message-ID: Folks, Can anyone explain to me why RAR support isn?t available natively in python? We have the zipfile and tarfile modules? Yes, there is rarfile and PaTools but they both rely on RAR being available to shell out to? What is it about RAR files that makes it unreasonable to handle in natively in python? Licensing? Bad rar file design? - Benjamin From best_lay at yahoo.com Fri Nov 30 17:10:53 2018 From: best_lay at yahoo.com (Wildman) Date: Fri, 30 Nov 2018 16:10:53 -0600 Subject: RAR functionality References: Message-ID: <7LOdncrNpPbwKJzBnZ2dnUU7-QWdnZ2d@giganews.com> On Fri, 30 Nov 2018 16:42:06 -0500, Benjamin Schollnick wrote: > Folks, > > Can anyone explain to me why RAR support isn?t available natively in python? > > We have the zipfile and tarfile modules? > > Yes, there is rarfile and PaTools but they both rely on RAR being available to shell out to? > What is it about RAR files that makes it unreasonable to handle in natively in python? > Licensing? Bad rar file design? > > - Benjamin RAR is proprietary. -- GNU/Linux user #557453 The cow died so I don't need your bull! From rosuav at gmail.com Fri Nov 30 17:17:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Dec 2018 09:17:02 +1100 Subject: RAR functionality In-Reply-To: References: Message-ID: On Sat, Dec 1, 2018 at 8:43 AM Benjamin Schollnick wrote: > > Folks, > > Can anyone explain to me why RAR support isn?t available natively in python? > > We have the zipfile and tarfile modules? > > Yes, there is rarfile and PaTools but they both rely on RAR being available to shell out to? > What is it about RAR files that makes it unreasonable to handle in natively in python? > Licensing? Bad rar file design? > Licensing, yes. ChrisA From marko at pacujo.net Fri Nov 30 17:40:06 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Dec 2018 00:40:06 +0200 Subject: multiple JSON documents in one file, change proposal References: <87sgzijjjl.fsf@nightsong.com> Message-ID: <87tvjyyyt5.fsf@elektro.pacujo.net> Paul Rubin : > Maybe someone can convince me I'm misusing JSON but I often want to > write out a file containing multiple records, and it's convenient to > use JSON to represent the record data. > > The obvious way to read a JSON doc from a file is with "json.load(f)" > where f is a file handle. Unfortunately, this throws an exception I have this "multi-JSON" need quite often. In particular, I exchange JSON-encoded messages over byte stream connections. There are many ways of doing it. Having rejected different options (), I settled with terminating each JSON value with an ASCII NUL character, which is illegal in JSON proper. > I also recommend the following article to those not aware of how badly > designed JSON is: http://seriot.ch/parsing_json.php JSON is not ideal, but compared with XML, it's a godsend. What would be ideal? I think S-expressions would come close, but people can mess up even them: . Marko From cs at cskk.id.au Fri Nov 30 17:50:12 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 1 Dec 2018 09:50:12 +1100 Subject: multiple JSON documents in one file, change proposal In-Reply-To: <87tvjyyyt5.fsf@elektro.pacujo.net> References: <87tvjyyyt5.fsf@elektro.pacujo.net> Message-ID: <20181130225012.GA92644@cskk.homeip.net> On 01Dec2018 00:40, Marko Rauhamaa wrote: >Paul Rubin : >> Maybe someone can convince me I'm misusing JSON but I often want to >> write out a file containing multiple records, and it's convenient to >> use JSON to represent the record data. >> >> The obvious way to read a JSON doc from a file is with "json.load(f)" >> where f is a file handle. Unfortunately, this throws an exception > >I have this "multi-JSON" need quite often. In particular, I exchange >JSON-encoded messages over byte stream connections. There are many ways >of doing it. Having rejected different options (https://en.wikipedia.org/wiki/JSON_streaming>), I settled with >terminating each JSON value with an ASCII NUL character, which is >illegal in JSON proper. There's a common format called Newline Delimited JSON (NDJSON) for just this need. Just format the outbound records as JSON with no newlines (i.e. make the separator a space or the empty string), put a newline at the end of each. On ingest, read lines of text, and JSON parse each line separately. This is very easy, very partable, and makes for very human readable data files. I strongly recommend it. Cheers, Cameron Simpson From tjol at tjol.eu Fri Nov 30 17:54:28 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 30 Nov 2018 23:54:28 +0100 Subject: multiple JSON documents in one file, change proposal In-Reply-To: <87tvjyyyt5.fsf@elektro.pacujo.net> References: <87sgzijjjl.fsf@nightsong.com> <87tvjyyyt5.fsf@elektro.pacujo.net> Message-ID: <4d875e41-a559-7d03-a3b7-6e66a044e2df@tjol.eu> On 30/11/2018 23:40, Marko Rauhamaa wrote: > Paul Rubin : >> Maybe someone can convince me I'm misusing JSON but I often want to >> write out a file containing multiple records, and it's convenient to >> use JSON to represent the record data. >> >> The obvious way to read a JSON doc from a file is with "json.load(f)" >> where f is a file handle. Unfortunately, this throws an exception > > I have this "multi-JSON" need quite often. In particular, I exchange > JSON-encoded messages over byte stream connections. There are many ways > of doing it. Having rejected different options ( https://en.wikipedia.org/wiki/JSON_streaming>), I settled with > terminating each JSON value with an ASCII NUL character, which is > illegal in JSON proper. FWIW, YAML supports multiple documents in one stream (separated by ---) If you just want multiple JSON objects in a file (without any streaming needs), you can just use a JSON array... > >> I also recommend the following article to those not aware of how badly >> designed JSON is: http://seriot.ch/parsing_json.php > > JSON is not ideal, but compared with XML, it's a godsend. > > What would be ideal? I think S-expressions would come close, but people > can mess up even them: . > > > Marko > From rosuav at gmail.com Fri Nov 30 18:04:20 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Dec 2018 10:04:20 +1100 Subject: multiple JSON documents in one file, change proposal In-Reply-To: <87tvjyyyt5.fsf@elektro.pacujo.net> References: <87sgzijjjl.fsf@nightsong.com> <87tvjyyyt5.fsf@elektro.pacujo.net> Message-ID: On Sat, Dec 1, 2018 at 9:46 AM Marko Rauhamaa wrote: > > Paul Rubin : > > Maybe someone can convince me I'm misusing JSON but I often want to > > write out a file containing multiple records, and it's convenient to > > use JSON to represent the record data. > > > > The obvious way to read a JSON doc from a file is with "json.load(f)" > > where f is a file handle. Unfortunately, this throws an exception > > I have this "multi-JSON" need quite often. In particular, I exchange > JSON-encoded messages over byte stream connections. There are many ways > of doing it. Having rejected different options ( https://en.wikipedia.org/wiki/JSON_streaming>), I settled with > terminating each JSON value with an ASCII NUL character, which is > illegal in JSON proper. There actually is a way to parse concatenated JSON (where you start the next object straight after the previous one, possibly with whitespace). It's not hugely well proclaimed, but it's based on this function: https://docs.python.org/3/library/json.html#json.JSONDecoder.raw_decode Example usage: data = """\ {"foo": 1, "bar": 2} {"foo": 3, "bar": 4} {"foo": 5, "bar": 6} """ from json import JSONDecoder def parse(s, *, decoder=JSONDecoder()): obj, offset = decoder.raw_decode(s) return obj, s[offset:].strip() while data: obj, data = parse(data) print(obj) > > I also recommend the following article to those not aware of how badly > > designed JSON is: http://seriot.ch/parsing_json.php (There's some irony in using a PHP web site to discuss bad design.) > JSON is not ideal, but compared with XML, it's a godsend. > > What would be ideal? I think S-expressions would come close, but people > can mess up even them: . Crockford is opinionated and egotistical. And like all humans, often wrong. JSON is far from a perfect interchange format, and there have been numerous attempts to improve on it (for instance, SUPPORTING TRAILING COMMAS!! ARGH!). See, for instance, JSON5 (https://json5.org/ and https://pypi.org/project/json5/), which is I believe a strict superset of JSON and also a strict subset of JavaScript, keeping it fully compatible both ways. JSON isn't perfect, but for many purposes, it is good enough. Where it isn't, there are often reasonable extensions (such as the use of raw_decode to read multiple objects from a string) that can help. ChrisA From rosuav at gmail.com Fri Nov 30 18:23:05 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Dec 2018 10:23:05 +1100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On Sat, Dec 1, 2018 at 10:18 AM Morten W. Petersen wrote: > > On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < > 2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > > > I guess syntax could be added, so that > > > > > > a, b, @c = some sequence > > > > > > would initialize a and b, and leave anything remaining in c. We could > > > then call this @ syntax "teh snek". > > > > Close. ;-) Try this: > > > > a, b, *c = [4, 5, 6, 7] > > > > > > I did not know that. Or maybe I read it somewhere and it was in the > subconscious. > Be aware that this isn't the same as "leaving" everything in c. It will specifically gather everything in the rest of the iterable and put it all into a list in c. For this example, that wouldn't be a problem, but consider: >>> x = range(10) >>> a, b, *c = x >>> print(x) range(0, 10) >>> print(a, b, c) 0 1 [2, 3, 4, 5, 6, 7, 8, 9] But as long as you never dive into infinite iterators, it's going to be fine. ChrisA From morphex at gmail.com Fri Nov 30 18:55:15 2018 From: morphex at gmail.com (Morten W. Petersen) Date: Sat, 1 Dec 2018 00:55:15 +0100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On Sat, Dec 1, 2018 at 12:25 AM Chris Angelico wrote: > On Sat, Dec 1, 2018 at 10:18 AM Morten W. Petersen > wrote: > > > > On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < > > 2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > > > > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > > > > > I guess syntax could be added, so that > > > > > > > > a, b, @c = some sequence > > > > > > > > would initialize a and b, and leave anything remaining in c. We > could > > > > then call this @ syntax "teh snek". > > > > > > Close. ;-) Try this: > > > > > > a, b, *c = [4, 5, 6, 7] > > > > > > > > > > > I did not know that. Or maybe I read it somewhere and it was in the > > subconscious. > > > > Be aware that this isn't the same as "leaving" everything in c. It > will specifically gather everything in the rest of the iterable and > put it all into a list in c. For this example, that wouldn't be a > problem, but consider: > > >>> x = range(10) > >>> a, b, *c = x > >>> print(x) > range(0, 10) > >>> print(a, b, c) > 0 1 [2, 3, 4, 5, 6, 7, 8, 9] > > But as long as you never dive into infinite iterators, it's going to be > fine. > Mm, yes. This was the intuitive understanding I had of it. The range in Python 3 is what xrange was in Python 2, and if I do x=list(range(100000000)) it takes quite a bit of time, as opposed to x = range(100000000) But this raises the question of how to write Python code, short and sweet, that could handle infinite iterators in such an unpack with multiple variables to assign to. Which I guess is mostly theoretical, as there are other ways of designing code to avoid needing to unpack an infinite iterator using the * prefix. -Morten -- Videos at https://www.youtube.com/user/TheBlogologue Twittering at http://twitter.com/blogologue Blogging at http://blogologue.com Playing music at https://soundcloud.com/morten-w-petersen Also playing music and podcasting here: http://www.mixcloud.com/morten-w-petersen/ On Google+ here https://plus.google.com/107781930037068750156 On Instagram at https://instagram.com/morphexx/ From rosuav at gmail.com Fri Nov 30 19:08:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Dec 2018 11:08:28 +1100 Subject: ValueError vs IndexError, unpacking arguments with string.split In-Reply-To: References: <792be86a-d5bc-c66d-393e-68ef9fbfe4e0@potatochowder.com> Message-ID: On Sat, Dec 1, 2018 at 10:55 AM Morten W. Petersen wrote: > But this raises the question of how to write Python code, > short and sweet, that could handle infinite iterators in > such an unpack with multiple variables to assign to. > > Which I guess is mostly theoretical, as there are other > ways of designing code to avoid needing to unpack > an infinite iterator using the * prefix. It could only be done with the cooperation of the iterable in question. For instance, a range object could implement a "remove first" operation that does this, and several itertools types wouldn't need to change at all. But it can't be done generically other than the way it now is (pump the iterator the rest of the way). ChrisA