Re: Python homework
Hi, On 05/12/17 06:33, nick martinez2 via Python-list wrote: I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. For this kind of problem I think the collections module [1] can be very useful. In this case in particular have a look at the Counter package ;) Lorenzo. [1] https://docs.python.org/3.6/library/collections.html I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. This is what I have so far: import random def rollDie(number): rolls = [0] * 6 for i in range(0, number): roll=int(random.randint(1,6)) rolls[roll - 1] += 1 return rolls if __name__ == "__main__": result = rollDie(50) print (result) print(max(result)) -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited)
On 2017-12-13, Lawrence D’Oliveiro wrote: > On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >> Try `pip install certifi` > > It really is preferable to install standard distro packages where available, > rather than resort to pip: > > sudo apt-get install python3-certifi No, it really really isn't. -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (_ss
On 2017-12-11, F Massion wrote: > Am Dienstag, 12. Dezember 2017 14:33:42 UTC+1 schrieb Jon Ribbens: >> On 2017-12-11, F Massion wrote: >> > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed > (_ssl.c:748) >> >> Try `pip install certifi` > > certifi was installed. > If I make the following changes I do not have the error message. I don't > understand why, but this makes a difference: > > #import requests --> import urllib.request > > url = 'https://en.wikipedia.org/wiki/Stethoscope' > #res = requests.get(url) --> res = urllib.request.urlopen(url).read() That's because that won't even try to verify the SSL certificate. -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited)
On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens wrote: > On 2017-12-13, Lawrence D’Oliveiro wrote: >> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >>> Try `pip install certifi` >> >> It really is preferable to install standard distro packages where available, >> rather than resort to pip: >> >> sudo apt-get install python3-certifi > > No, it really really isn't. This isn't a connected series of statements intended to establish a proposition. This is just contradiction. Not very useful here. Care to elaborate as to why apt-get is such a bad thing? Generally, if you're using a system-provided Python (either Py2 or Py3) and not using a virtual environment, it's easier and safer to use your system-provided package manager to install additional components. If you want to argue otherwise, argue it, don't just assert it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited)
Op 13-12-17 om 13:01 schreef Chris Angelico: > On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens > wrote: >> On 2017-12-13, Lawrence D’Oliveiro wrote: >>> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: Try `pip install certifi` >>> It really is preferable to install standard distro packages where >>> available, rather than resort to pip: >>> >>> sudo apt-get install python3-certifi >> No, it really really isn't. > This isn't a connected series of statements intended to establish a > proposition. This is just contradiction. Not very useful here. Care to > elaborate as to why apt-get is such a bad thing? > > Generally, if you're using a system-provided Python (either Py2 or > Py3) and not using a virtual environment, it's easier and safer to use > your system-provided package manager to install additional components. > If you want to argue otherwise, argue it, don't just assert it. Why do you ask this of Jon Ribbens? As far as I can see, Laurence D'Oliveiro, just stated something as fact, without argument. Why do you give him a pass but expect Jon Ribbens to argue his position? -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited)
On Wed, Dec 13, 2017 at 11:26 PM, Antoon Pardon wrote: > Op 13-12-17 om 13:01 schreef Chris Angelico: >> On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens >> wrote: >>> On 2017-12-13, Lawrence D’Oliveiro wrote: On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: > Try `pip install certifi` It really is preferable to install standard distro packages where available, rather than resort to pip: sudo apt-get install python3-certifi >>> No, it really really isn't. >> This isn't a connected series of statements intended to establish a >> proposition. This is just contradiction. Not very useful here. Care to >> elaborate as to why apt-get is such a bad thing? >> >> Generally, if you're using a system-provided Python (either Py2 or >> Py3) and not using a virtual environment, it's easier and safer to use >> your system-provided package manager to install additional components. >> If you want to argue otherwise, argue it, don't just assert it. > > Why do you ask this of Jon Ribbens? As far as I can see, Laurence D'Oliveiro, > just stated something as fact, without argument. Why do you give him a pass > but expect Jon Ribbens to argue his position? > Because Lawrence's post didn't come through to me, probably because he's put something in the headers to say that he doesn't want to talk to people on the mailing list, so I'm not going to (not really able to) do him the courtesy of replying. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
nick.martin...@aol.com (nick martinez2) writes: > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls def rollDie(number): from random import choices return choices((1,2,3,4,5,6), k=number) ps: sorry for the noise if someone else in this thread has already highlighted the usefulness of `random.choices` -- https://mail.python.org/mailman/listinfo/python-list
Re: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited)
On 2017-12-13, Chris Angelico wrote: > On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens > wrote: >> On 2017-12-13, Lawrence D’Oliveiro wrote: >>> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: Try `pip install certifi` >>> >>> It really is preferable to install standard distro packages where >>> available, rather than resort to pip: >>> >>> sudo apt-get install python3-certifi >> >> No, it really really isn't. > > This isn't a connected series of statements intended to establish a > proposition. This is just contradiction. Not very useful here. Care to > elaborate as to why apt-get is such a bad thing? > > Generally, if you're using a system-provided Python (either Py2 or > Py3) and not using a virtual environment, it's easier and safer to use > your system-provided package manager to install additional components. > If you want to argue otherwise, argue it, don't just assert it. I'll make assertions if I feel like it, especially in response to bare assertions. System-provided Python has tended to be a disaster and best kept at bargepole-distance. But regardless, in this specific case you'll note that the OP is clearly using Windows and therefore any advice to use 'sudo apt-get' will be less than entirely helpful. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
from random import randint rolls = [randint(1, 6) for x in range(50)] print("Average: %s" % (sum(rolls) / len(rolls))) print("Most Common: %s" % max(rolls, key=rolls.count)) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
On Thu, Dec 14, 2017 at 3:23 AM, wrote: > from random import randint > > rolls = [randint(1, 6) for x in range(50)] > print("Average: %s" % (sum(rolls) / len(rolls))) > print("Most Common: %s" % max(rolls, key=rolls.count)) Great demo of a bad algorithm. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: > > A Windows equivalent would be to have a .py file associated normally > with the regular console, but some individual ones associated with > pythonw.exe - without renaming them to .pyw. AFAIK there is no way to > do this on Windows short of renaming the files. If using another file is ok, then a shell shortcut or hard link would work.A symbolic link doesn't work because it seems the shell resolves the link before querying the file association. -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Thu, Dec 14, 2017 at 7:56 AM, eryk sun wrote: > On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: >> >> A Windows equivalent would be to have a .py file associated normally >> with the regular console, but some individual ones associated with >> pythonw.exe - without renaming them to .pyw. AFAIK there is no way to >> do this on Windows short of renaming the files. > > If using another file is ok, then a shell shortcut or hard link would > work.A symbolic link doesn't work because it seems the shell resolves > the link before querying the file association. As workarounds go, a hardlink isn't too bad. (A shell shortcut has its own problems and limitations.) But you still need to be able to define a filename pattern, usually by specifying an extension, that catches the alternates. So it's definitely a workaround, not a true feature. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Wed, Dec 13, 2017 at 9:04 PM, Chris Angelico wrote: > On Thu, Dec 14, 2017 at 7:56 AM, eryk sun wrote: >> On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: >>> >>> A Windows equivalent would be to have a .py file associated normally >>> with the regular console, but some individual ones associated with >>> pythonw.exe - without renaming them to .pyw. AFAIK there is no way to >>> do this on Windows short of renaming the files. >> >> If using another file is ok, then a shell shortcut or hard link would >> work.A symbolic link doesn't work because it seems the shell resolves >> the link before querying the file association. > > As workarounds go, a hardlink isn't too bad. (A shell shortcut has its > own problems and limitations.) But you still need to be able to define > a filename pattern, usually by specifying an extension, that catches > the alternates. So it's definitely a workaround, not a true feature. I think a shell shortcut is a good workaround. It's less obtrusive than a hard link since the script still has the same name. The command line would be something like `"C:\Windows\pyw.exe" "path\to\script.py"`. Clear the shortcut's "start in" field to make pyw.exe inherit the working directory of the parent process. Add .LNK to the PATHEXT environment variable to support executing "script.lnk" as "script". -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > On 05/12/17 06:33, nick martinez2 via Python-list wrote: >> I have a question on my homework. My homework is to write a program in >which >> the computer simulates the rolling of a die 50 times and then prints >> (i). the most frequent side of the die (ii). the >average die value of all >> rolls. > >For this kind of problem I think the collections module [1] can be very >useful. In this case in particular have a look at the Counter package ;) > >Lorenzo. > >[1] https://docs.python.org/3.6/library/collections.html > > A nice answer at face value, and for general questions, but perhaps not the best given the subject line and the first sentence in the OP's note. Counting is such a fundamental programming skill, that I expect whoever teaches this course expects students to know how to count, without appealing to a third-party object to do all their work for them. When I teach my course, I have no desire to have all my students turn into cargo cultists. At least this particular student did post his intended solution, instead of outright begging for code. And most of the responses I see did attempt to work within the perceived constraints regarding what language tools the student was expected to use. Roger Christman Pennsylvania State University -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
On 12/13/2017 8:28 AM, bo...@choices.random.py wrote: nick.martin...@aol.com (nick martinez2) writes: def rollDie(number): rolls = [0] * 6 for i in range(0, number): roll=int(random.randint(1,6)) One could just as well use randint(0, 5) and skip the -1 below. rolls[roll - 1] += 1 return rolls This returns a list with a count of how many times each of 1 to 6 is chosen in *number* rolls. def rollDie(number): from random import choices return choices((1,2,3,4,5,6), k=number) This returns a list with all *number* rolls. Assuming the the first function is the one wanted, one could feed choices into a counter. (The import should be outside of the function.) def rollDie(number): rolls = [0] * 6 for i in random.choices((0,1,2,3,4,5), k=number): rolls[i] += 1 return rolls -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
ANN: Wing Python IDE v. 6.0.9 released
Hi, We've just released Wing 6.0.9, which adds support for Vagrant, improves support for Django and Plone, further improves remote development, fixes startup problems seen on some OS X systems, and makes about 35 other improvements. For details, see https://wingware.com/pub/wingide/6.0.9/CHANGELOG.txt Download now: http://wingware.com/downloads About Wing Wing is a family of cross-platform Python IDEs 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, embedded scripting, and other applications. Wing 101 and Wing Personal omit some features and are free to download and use without a license. Wing Pro requires purchasing or upgrading a license, or obtaining a 30-day trial at startup. 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, support for Python 3.6, Vagrant, Jupyter, and Django 1.10+, easier Raspberry Pi development, optimized debugger, OS X full screen mode, One Dark color palette, expanded free product line, and much more. For details, see http://wingware.com/wingide/whatsnew. Wing 6 works with Python versions 2.5 through 2.7 and 3.2 through 3.6, including also Anaconda, ActivePython, EPD, Stackless, and others derived from the CPython implementation. 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 https://wingware.com/doc/install/migrating Links Release notice: https://wingware.com/news/2017-12-13 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 supp...@wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python homework
On Thursday, December 7, 2017 at 7:11:18 AM UTC-8, Rhodri James wrote: > Sigh. Please don't do people's homework for them. It doesn't teach > them anything. Now Nick had got 90% of the way there and shown his > working, which is truly excellent, but what he needed was for someone to > hint at how to search through the array, not to be handed a working > example with no explanation. I teach Python programming from time to time. I've noticed that a few people post quite esoteric solutions to students' homework problems. The unstated intent seems to be to get the student's teacher to quiz the student on their solution. When the student can't explain what the code does, a hard lesson will be learned. Mario Osorio's solution to the homework problem uses a list comprehension, formatted printing, and even a lambda function. If my students are new to Python and I see them using lambdas, you bet I'll be asking questions. All that being said: since Nick Martinez actually showed working code and explained where he was stuck, he doesn't strike me as the kind of student that needs a stealth lesson in the hazards of plagiarism. -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: [...] > That said, I don't see this feature as being very useful > compared to just using "open with" when I occasionally need > to open a file with a non-default program. That's the point i was trying to make, but i think it may have whoooshed over Chris's head. ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson wrote: > On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: > [...] >> That said, I don't see this feature as being very useful >> compared to just using "open with" when I occasionally need >> to open a file with a non-default program. > > That's the point i was trying to make, but i think it may > have whoooshed over Chris's head. ;-) No, it didn't. I just happen to have about twelve years' experience with a GUI system that has this as a feature, and I found it extremely helpful. It's funny how our experience colours our expectations, isn't it? We just won't settle for trash once we've tasted quality. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python GUI application embedding a web browser - Options?
On Wednesday, October 19, 2016 at 3:08:15 AM UTC-7, Paul Moore wrote: > I'm looking to write a GUI application in Python (to run on Windows, using > Python 3.5). The application is just a relatively thin wrapper around a > browser - it's presenting an existing web application, just in its own window > rather than in a standard browser window. I'm looking for advice on a good > GUI toolkit to use. > > I've not done much GUI programming in Python, so I don't have a "preferred > toolkit" as such. A bit of Google searching found an embedded browser widget > in PyQt, but the examples I tried didn't work - it looks like the QWebView > class is deprecated and has been removed in the current version of PyQt. I > haven't really found any other examples (there's a "embedding a web page in > Tkinter" example I found, but it looks like it's just doing rendering, not > embedding a full browser - which I need as the site I want to access uses > CSS/JavaScript). > > Is there any good option for this, or would I be better looking elsewhere for > a solution? I could probably work out how to knock something up using .NET, > or a HTA file, for example, I'm just more comfortable coding in Python. > > Thanks, > Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
Am 14.12.17 um 02:55 schrieb Chris Angelico: On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson wrote: On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: [...] That said, I don't see this feature as being very useful compared to just using "open with" when I occasionally need to open a file with a non-default program. That's the point i was trying to make, but i think it may have whoooshed over Chris's head. ;-) No, it didn't. I just happen to have about twelve years' experience with a GUI system that has this as a feature, and I found it extremely helpful. It's funny how our experience colours our expectations, isn't it? We just won't settle for trash once we've tasted quality. I'm still unconvinced that this is much different from the Windows way (though I haven't used OS/2, so I'm probably missing something): Suppose, you have a file "Letter.txt" in your Documents folder on Windows. With standard settings, the "dumb" user (non IT expert) does not see the ".txt". It shows up as "Letter" with an icon for "written text". If you double click on it, Notepad will come up. If you right click, you'll see a list of programs which can open text files: Notepad, Wordpad, MS Word, any other editor you might have installed. How is the file extension different (to the regular user!) than a file type information stored in an alternate stream? Both are normally invisible and determine a default application as well as a number of programs which can open/edit the file. The only thing I can see from your description, apparently it was possible to change the default for an individual file ("Open this file always with Wordpad instead of Notepad") without changing th eglobal default. Is this the missing feature? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Please tell me how to execute python file in Ubuntu by double
On Thu, Dec 14, 2017 at 5:44 PM, Christian Gollwitzer wrote: > Am 14.12.17 um 02:55 schrieb Chris Angelico: >> >> On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson >> wrote: >>> >>> On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: >>> [...] That said, I don't see this feature as being very useful compared to just using "open with" when I occasionally need to open a file with a non-default program. >>> >>> >>> That's the point i was trying to make, but i think it may >>> have whoooshed over Chris's head. ;-) >> >> >> No, it didn't. I just happen to have about twelve years' experience >> with a GUI system that has this as a feature, and I found it extremely >> helpful. It's funny how our experience colours our expectations, isn't >> it? We just won't settle for trash once we've tasted quality. >> > > I'm still unconvinced that this is much different from the Windows way > (though I haven't used OS/2, so I'm probably missing something): > > Suppose, you have a file "Letter.txt" in your Documents folder on Windows. > With standard settings, the "dumb" user (non IT expert) does not see the > ".txt". It shows up as "Letter" with an icon for "written text". If you > double click on it, Notepad will come up. If you right click, you'll see a > list of programs which can open text files: Notepad, Wordpad, MS Word, any > other editor you might have installed. > > How is the file extension different (to the regular user!) than a file type > information stored in an alternate stream? Both are normally invisible and > determine a default application as well as a number of programs which can > open/edit the file. If you accept that a file's name consists of the "visible part" and the "part that affects file associations", then I suppose you could say that Windows allows you to customize a file's associations. However: 1) You can use this to select a file's category, but a file has to be in precisely one category. A file cannot be both a "text file" (associated with your editor of choice) and a "program file" (associated with "run this program") unless you create a "text program file" hybrid type and manually control your associations. Want to install a new text editor? Sure. Go associate it with all of your text types. With OS/2's type system, a program can choose on installation to associate itself with "Plain Text", and then all text-y files will see that program in their "Open With" sets, even if they're another type as well (maybe "Makefile", associated with make). 2) The sort of user who would consider the file extension to be out-of-band information is NOT going to be inventing new file extensions and crafting associations for them. So you're basically limited to those categories that have been set up by someone else. > The only thing I can see from your description, apparently it was possible > to change the default for an individual file ("Open this file always with > Wordpad instead of Notepad") without changing th eglobal default. Is this > the missing feature? 3) This. It's impossible to have one file in a category have a different default; you have to change the whole category's configuration. 4) A file's "category" also controls other things than its program association(s), such as its icon. So if you want to invent a new file category, you have to replicate all those other settings. 5) And the big one: you have to accept that the file name is no longer in your control. So this fundamentally won't work with any file that is looked for by another program, other than in the specific way of "this is the file you clicked on". So you can't choose the editor for an ancillary config file, you can't subcategorize your Python scripts and still import them successfully, and you basically can't categorize dotfiles (because ".bashrc" is of the type "bashrc", whereas ".zshrc" is of the completely different type "zshrc"). So it's an imperfect solution even as far as it goes, and a highly limiting way to do things. I'm sure it made good sense back when MS-DOS file systems ruled the Windows world, and 8.3 was just the way of things. ChrisA -- https://mail.python.org/mailman/listinfo/python-list