[Tutor] Program won't print out in Windows 10
While the following program prints out fine using Python 2.7.6 in Ubuntu 14.04.4 as developed using Geany 1.23.1, same program won't print out to printer under Windows 10 Pro (64 bit). Geany uses there is version 1.28 using Python 2.7.12. I can use CTRL-P to print out the listing. = # hello2.py import os print print "Hello World!" print pr = os.popen("lpr", "w") for i in range(1,8): pr.write("\n") pr.write("\n") pr.write("\t\t01 02 03 04 05") pr.write("\n") pr.close print print("\tPlease wait several moments for printer to catch up.") print === Thanking you readers in advance in resolving this non Windows printing issue. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Program won't print out in Windows 10
On Sun, Jul 24, 2016 at 11:38:06AM -0400, Ken G. wrote: > While the following program prints out fine using > Python 2.7.6 in Ubuntu 14.04.4 as developed using > Geany 1.23.1, same program won't print out to printer > under Windows 10 Pro (64 bit). Geany uses there is > version 1.28 using Python 2.7.12. I can use CTRL-P > to print out the listing. The critical piece of code that does the printing is the external function "lpr". This is not part of Python: it is a Unix/Linux command that controls the "line printer". On some machines lpr doesn't exist and it may be called "lp" instead. Does lpr or lp exist on Windows 10? I can see it exists in Windows 7. If you open up a Windows shell, the command.com or cmd.exe or whatever it is called, and enter "lpr", what happens? Perhaps you are getting a permissions error. Perhaps lpr simply isn't installed, or isn't configured properly, or can't find your printer. Once you get lpr working from the Windows 10 command line, then and only then can you hope to get it working from Python. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable in tkinter?
On Sat, Jul 23, 2016 at 01:55:03PM -0400, R. Alan Monroe wrote: > > button = tkinter.Button(frame, text='Up', command=click_up) > > button = tkinter.Button(frame, text='Down', command=click_down) > > > > when I first looked at it I thought it would not work, thinking that the > > second reference to button = would over write the first one. > > It DOES overwrite it, in this sense: > > The first button is a thing that exists because Button() generates it. > "button" is a word you can now use to refer to that thing. > > Later on, the second call to Button() generates a new, separate thing. > "button" is now a word you can use to refer to the second thing, > but *the first thing doesn't cease to exist*. Why not? Why isn't the first button not garbage collected? -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable in tkinter?
Steven D'Aprano wrote: > On Sat, Jul 23, 2016 at 01:55:03PM -0400, R. Alan Monroe wrote: >> > button = tkinter.Button(frame, text='Up', command=click_up) >> > button = tkinter.Button(frame, text='Down', command=click_down) >> >> >> > when I first looked at it I thought it would not work, thinking that >> > the second reference to button = would over write the first one. >> >> It DOES overwrite it, in this sense: >> >> The first button is a thing that exists because Button() generates it. >> "button" is a word you can now use to refer to that thing. >> >> Later on, the second call to Button() generates a new, separate thing. >> "button" is now a word you can use to refer to the second thing, >> but *the first thing doesn't cease to exist*. > > Why not? Why isn't the first button not garbage collected? The answer is of course always the same: because there is another reference. The hard part is also always the same: how can that reference be found? Here's a way to do it in this case: $ cat tksnippet.py import tkinter window = tkinter.Tk() def click_up(): pass def click_down(): pass counter = tkinter.StringVar() frame = tkinter.Frame(window) frame.pack() button = tkinter.Button(frame, text='Up', command=click_up) button.pack() print("button whose reference we are going to overwrite:") print(repr(button), button) button = tkinter.Button(frame, text='Down', command=click_down) button.pack() label = tkinter.Label(frame, textvariable=counter) label.pack() $ python3 -i tksnippet.py button whose reference we are going to overwrite: .13066974024.13067097744 >>> forgotten_button = frame.nametowidget(".13066974024.13067097744") >>> forgotten_button >>> forgotten_button["text"] 'Up' So it is indeed the up-button rather than a reused memory address. The above snippet is only for demonstration purposes; if you plan to access a widget later-on you should always use the straightforward approach and keep a reference around in your own code. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable in tkinter?
On 23/07/16 16:38, Jim Byrnes wrote: > # the views > frame = tkinter.Frame(window) > frame.pack() > button = tkinter.Button(frame, text='Up', command=click_up) > button.pack() > button = tkinter.Button(frame, text='Down', command=click_down) > button.pack() > that is wrong because the program does work. Could someone explain to > me why it works? Others have pointed out that a hidden reference to the buttons exists. In fact Tkinter, in common with most GUIIs, works by building a tree of objects starting at the top level window and then working down thru' each lower level. Usuially in Tkinter we start with a line like top = tkinter.Tk() # create the topmost widget Then when we create subwidgets, like your frame we pass the outer widget as the parent: frame = tkinter.Frame(top) Then when you create the buttons you pass frame as the first argument which makes frame the parent of the buttons. What happens is that when you create the widget the parent object adds your new instance to its list of child widgets. And that's the hidden reference that keeps your button alive even after you overwrite the button variable. You can access the widget tree of any widget using its 'children' attribute: >>> import tkinter as tk >>> top = tk.Tk() >>> f = tk.Frame(top) >>> f.pack() >>> tk.Label(f,text="Hello there!").pack() >>> f.children {'140411123026128': } >>> But it's not very user friendly so if you need to access a widget after creating it its better to use a unique variable to store a reference. -- 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@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
I am using Python 2.7.12 on Windows 10 filename = "මේක තියෙන්නේ සිංහලෙන්.txt" Why can't I get Python to print the name out? filename = "මේක තියෙන්නේ සිංහලෙන්.txt" Unsupported characters in input filename = u"මේක තියෙන්නේ සිංහලෙන්.txt" Unsupported characters in input above is the python ide output Even from within a program I cant get this to print. any help? Please dont ask me to use python 3. :) -- Kalasuri Diliup Gabadamudalige http://www.diliupg.com http://soft.diliupg.com/ ** This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. ** ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python programmin problem
IM sorry I do not understand: For array A of length N, and for an integer k < N: -- By k do you mean value of k or position of k in the list? L(A, k) is the length of the longest increasing subsequence of the prefix of A with length k, where that subsequence needs to include the k'th element too. What is L? This L function tries to capture the idea of having a *partial* solution that involves a portion of the array A. Why is it helpful? Because of two crucial things: 1. If we know L(A, 1), L(A, 2), ... all the way to L(A, N), then we can just look at the maximum value of those pieces. That's going to be a solution to the general problem. -- By maximum value do you mean I have to sum up the values in the list? Why? 2. For a subproblem L(A, k), if we know the values for L(A, 1), L(A, 2), ... , L(A, k-1), then we can compute L(A, k) by looking at those other subproblems: the result of L(A, k) is related to them. -- How do we find those subproblems? And then how do you relate them to the main problem? Can you please explain more in details? Thank you so much Monika -- Original Message -- From: Danny Yoo To: Alan Gauld Cc: "monik...@netzero.net" , tutor Subject: Re: [Tutor] python programmin problem Date: Sat, 23 Jul 2016 00:13:36 -0700 On Thu, Jul 21, 2016 at 11:30 PM, Alan Gauld via Tutor wrote: > > Forwarding to list. Please use reply-all when responding to tutor messages. > > As Danny suggested this is quite a complex problem. I wasn't sure whether > it was just the programming or the bigger algorithm issue you were stuck on. [warning: large message ahead.] This problem is unfortunately not something you can just code by trying to hack it till it works. At this level of difficulty, these kinds of problems are *not* easy: they require some understanding of fundamentals in algorithms, not Python. That is, the actual coding of this is not the hard part. A direct solution to this problem is a couple of lines and involves nothing more loops and arrays. The difficulty is understanding how to use solutions of sub-problems toward the general large problem. I should state this more strongly: trying to hack the solution is not going to work. I have to ignore the code presented in this thread because there's very little to preserve. The approach of trying to look at only the very previous element is simply not viable. The most direct approach I know to do this is by talking about this in terms of subproblems. Here is a sketch of the idea: Let's put on our magical thinking cap, and say that we'd like to design a function L(A, m) with the following funny property: For array A of length N, and for an integer k < N: L(A, k) is the length of the longest increasing subsequence of the prefix of A with length k, where that subsequence needs to include the k'th element too. What is L? This L function tries to capture the idea of having a *partial* solution that involves a portion of the array A. Why is it helpful? Because of two crucial things: 1. If we know L(A, 1), L(A, 2), ... all the way to L(A, N), then we can just look at the maximum value of those pieces. That's going to be a solution to the general problem. 2. For a subproblem L(A, k), if we know the values for L(A, 1), L(A, 2), ... , L(A, k-1), then we can compute L(A, k) by looking at those other subproblems: the result of L(A, k) is related to them. How so? --- As a concrete example, consider a list A = [5, 8, 6, 7]. * What is L(A, 1)? We want the length of the longest subsequence of the prefix [5] that includes the 5. And that's just 1. L(A, 1) = 1. That is, we're starting from scratch: we can't do better than just pick the 5 as the start of our subsequence. Since our subsequence just has [5], that's a subsequence of length 1. * What is L(A, 2)? We want the length of the longest subsequence of the prefix [5, 8] that includes the 8. Why does knowing L(A, 1) help us? Because we know L(A, 1) is 1. What does that mean? We look at L(A, 1) to see if maybe we can pick the subsequence that it is measuring, and augment it. We know L(A, 1) is the length of the longest sequence that ends up including the first element of A, so we know that subsequence ends with a [... 5]. And we can extend that subsequence so it look like [..., 5, 8]. And we know that such an extension will be of length 2. Can we do any better? There are no other subproblems, so no. That is, L(A, 2) = 2. * What is L(A, 3)? We want the length of the longest subsequence of the prefix [5, 8, 6] that includes the 6. We look at L(A, 1): can we just extend [..., 5] with a 6? Yes, and that gives us 2 as a possible answer for L(A, 3). Why 2? Because L(A, 1) = 1, and if we extend the subsequence measured by L(A, 1), we make it one element longer, so 1 + 1 = 2. Can we do better? We look at L(A, 2): can we just extend [..., 8]
[Tutor] Help with error in paramiko
Hello. I have a problem because when I connect to the remote server via SSH gives me an error with paramiko library, but I connect to the same server with programs like putty, ssh and another there is no error. Here the screenshot: *Script.* [image: Imágenes integradas 1] *the result of run* [image: Imágenes integradas 7] *the result of log.* The problem is when the ZAHO command with the library in the logs can see the error highlighted runs. *[image: Imágenes integradas 6]* *PD: *The feature of the remote server unknown but the script work on the Linux server. Feature the computer client. Windows 7 64bits. Python3.4 Library paramiko, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] installing openpyxl
Dear Experts, following instructions in a youtube video I thought I finally succeded to install openpyxl. However I got the traceback below: >>> import openpyxl Traceback (most recent call last): File "", line 1, in import openpyxl File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\__init__.py", line 29, in from openpyxl.workbook import Workbook File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\workbook\__init__.py", line 5, in from .workbook import Workbook File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\workbook\workbook.py", line 8, in from openpyxl.worksheet import Worksheet File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\worksheet\__init__.py", line 4, in from .worksheet import Worksheet File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\worksheet\worksheet.py", line 34, in from openpyxl.cell import Cell File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\cell\__init__.py", line 4, in from .cell import Cell, WriteOnlyCell File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\cell\cell.py", line 30, in from openpyxl.utils.datetime import ( File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\utils\datetime.py", line 13, in from jdcal import ( ImportError: No module named 'jdcal' How do I get jdcal ? Tanks everybody for help, Marcus. .. dear Experts, could someone please tell me what exactly I have to type in my a) Python 35 command line or b) desktopcomputer ( W10, 64bit)-command line in ordert to install openpyxl which I downloaded in C:\Users\marcus\Downloads on my computer. I have used all kinds of commands with pip install at the end, all unsuccessful. Thanks for help. Marcus. --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft. https://www.avast.com/antivirus ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] installing openpyxl, problem solved
Dear Experts, problem solved, dont bother, Marcus. . Dear Experts, following instructions in a youtube video I thought I finally succeded to install openpyxl. However I got the traceback below: >>> import openpyxl Traceback (most recent call last): File "", line 1, in import openpyxl File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\__init__.py", line 29, in from openpyxl.workbook import Workbook File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\workbook\__init__.py", line 5, in from .workbook import Workbook File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\workbook\workbook.py", line 8, in from openpyxl.worksheet import Worksheet File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\worksheet\__init__.py", line 4, in from .worksheet import Worksheet File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\worksheet\worksheet.py", line 34, in from openpyxl.cell import Cell File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\cell\__init__.py", line 4, in from .cell import Cell, WriteOnlyCell File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\cell\cell.py", line 30, in from openpyxl.utils.datetime import ( File "C:\Users\marcus\AppData\Local\Programs\Python\Python35\lib\site-packages\op enpyxl\utils\datetime.py", line 13, in from jdcal import ( ImportError: No module named 'jdcal' How do I get jdcal ? Tanks everybody for help, Marcus. .. dear Experts, could someone please tell me what exactly I have to type in my a) Python 35 command line or b) desktopcomputer ( W10, 64bit)-command line in ordert to install openpyxl which I downloaded in C:\Users\marcus\Downloads on my computer. I have used all kinds of commands with pip install at the end, all unsuccessful. Thanks for help. Marcus. --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft. https://www.avast.com/antivirus ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable in tkinter?
On 07/24/2016 02:08 PM, Alan Gauld via Tutor wrote: On 23/07/16 16:38, Jim Byrnes wrote: # the views frame = tkinter.Frame(window) frame.pack() button = tkinter.Button(frame, text='Up', command=click_up) button.pack() button = tkinter.Button(frame, text='Down', command=click_down) button.pack() that is wrong because the program does work. Could someone explain to me why it works? Others have pointed out that a hidden reference to the buttons exists. In fact Tkinter, in common with most GUIIs, works by building a tree of objects starting at the top level window and then working down thru' each lower level. Usuially in Tkinter we start with a line like top = tkinter.Tk() # create the topmost widget Then when we create subwidgets, like your frame we pass the outer widget as the parent: frame = tkinter.Frame(top) Then when you create the buttons you pass frame as the first argument which makes frame the parent of the buttons. What happens is that when you create the widget the parent object adds your new instance to its list of child widgets. And that's the hidden reference that keeps your button alive even after you overwrite the button variable. You can access the widget tree of any widget using its 'children' attribute: import tkinter as tk top = tk.Tk() f = tk.Frame(top) f.pack() tk.Label(f,text="Hello there!").pack() f.children {'140411123026128': } But it's not very user friendly so if you need to access a widget after creating it its better to use a unique variable to store a reference. Thanks Peter and Alan, After I proved to myself that it worked and I thought about it, I suspected it had to do with a reference. It's nice to have it confirmed is such a clear manner. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Program won't print out in Windows 10
On 24/07/2016 16:38, Ken G. wrote: While the following program prints out fine using Python 2.7.6 in Ubuntu 14.04.4 as developed using Geany 1.23.1, same program won't print out to printer under Windows 10 Pro (64 bit). Geany uses there is version 1.28 using Python 2.7.12. I can use CTRL-P to print out the listing. Thanking you readers in advance in resolving this non Windows printing issue. Rather: user believing that what works under Linux will work under Windows issue :) You might find this page helpful: http://timgolden.me.uk/python/win32_how_do_i/print.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python programmin problem
On Jul 23, 2016 9:27 AM, "monik...@netzero.net" wrote: > > IM sorry I do not understand: > > For array A of length N, and for an integer k < N: > -- By k do you mean value of k or position of k in the list? > The letter 'k' is typically intended to be used as an index, a position into a list. I'm trying to say that k had to be pointed somewhere in the list by constraining it to be less than the size of the list. > > 1. If we know L(A, 1), L(A, 2), ... all the way to L(A, N), then > we can just look at the maximum value of those pieces. That's going > to be a solution to the general problem. > -- By maximum value do you mean I have to sum up the values in the list? Why? "Maximum" is a notion of comparing and picking out the biggest thing we see. It doesn't have to do with addition. If we have a bunch of numbers, we can do a lot more than just add then together. Numbers are more interesting than that. Both summation and maximum-finding are operations that are intended to take a bunch of bits of information in order to discover something new. So, conceptually speaking, there *is* a deep, underlying connection. But I don't think that's what you're intending to talk about. > 2. For a subproblem L(A, k), if we know the values for L(A, 1), > L(A, 2), ... , L(A, k-1), then we can compute L(A, k) by looking at > those other subproblems: the result of L(A, k) is related to them. > -- How do we find those subproblems? And then how do you relate them to the main problem? > > Can you please explain more in details? Unfortunately, no. This is the wrong venue. Please: I strongly encourage you to talk with your professor or study group: it really does sound like this is the first time you've seen these kinds of concepts. Longest common subsequence is not the ideal problem to use to introduce these concepts: it is meant to help you *master* them. I would not dare trying to use it as a first example into learning dynamic programming. You probably want to use a problem that has fewer moving parts. Your instructor likely has a much nicer introductory problem so that you can learn the patterns of thinking through these problems. Anyway, hope that makes sense. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python programmin problem
> You probably want to use a problem that has fewer moving parts. Your instructor likely has a much nicer introductory problem so that you can learn the patterns of thinking through these problems. Just to add: there are online resources you can use for this. Khan Academy, for example: https://www.khanacademy.org/computing/computer-science/algorithms. For self study, i can also recommend Introduction to Algorithms. https://mitpress.mit.edu/books/introduction-algorithms. When I'm using the term "subproblem", I'm mentally recalling the training I received from learning about recursion. Recursion is much more than about functions calling themselves. That is, if we've learned about recursion and thought: "why use recursion when you have loops?", then we've missed a key point, which is this: it's intended to teach how to think about subproblems and synthesizing from them. That's the answer I should have given to your question about thinking about subproblems. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python programmin problem
On 24/07/16 20:58, Danny Yoo wrote: > Please: I strongly encourage you to talk with your professor or study > group: it really does sound like this is the first time you've seen these > kinds of concepts. I agree with Danny, you should talk to your teacher. I suspect the teacher may have set the problem without appreciating the full extent of the complexity involved. It certainly doesn't seem like you are properly equipped to solve it. Maybe he/she can provide a simpler subset of problem. Of course this assumes you have a teacher to ask? Your original post doesn't state where you found the problem, it may be you just picked it up on a web site or book and have unwittingly bitten off more than you are ready to chew just now? It also depends a bit on whether the intent is to learn about Python programming or about algorithms. If its the latter then you might just want to ask on a different (math based) forum. But if its Python you are interested in then find an easier problem for now. Otherwise you will lose sight of the Python problem in trying to solve the math one. -- 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@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with error in paramiko
On 23/07/16 09:12, José de Jesus Marquez Rangel wrote: > Hello. > > I have a problem because when I connect to the remote server via SSH gives > me an error with paramiko library, but I connect to the same server with > programs like putty, ssh and another there is no error. > > Here the screenshot: > > *Script.* > [image: Imágenes integradas 1] > > *the result of run* > [image: Imágenes integradas 7] > This is a text based forum and as such your images didn't make it through the server. If possible just copy/paste the text into a mail message. Also paramiko is really outside the scope of this group (core language and standard library) so you might do better on a paramiko forum such as their mailing list: param...@librelist.com -- 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@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] installing openpyxl, problem solved
On 24/07/16 20:04, marcus lütolf wrote: > Dear Experts, problem solved, don’t bother, Marcus. For the sake of the archive can you post a short mail stating what the solution was? -- 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@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor