Re: [Tutor] program spontaneously closes...
Alan Gilfoy wrote: > Hello All. > I've been concocting some simple programs based on an online tutorial, > and I, of course, save a program as a .py file. > > When running my program via IDLE, once I've cleaned out the bugs, it > works as I expect it to. > > But I noticed something else: > > Clicking directly on the file's icon has the program open in the > Windows command line program as a .exe file. > > The command line program seems to work through my program OK, but the > command line program shuts down immediately after the program has run > through, as opposed to staying open in order to display the result. This is true of any executable on almost any system. If there is no deliberate pause-before-terminating, then the program will terminate and the window will close. This has been asked so many times on these lists I am almost weary of reading & responding. Putting raw_input() at the end is not a workaround. It is the solution. Unless you want to redesign the operating system. [I > noticed that if the command line program is not waiting for a resposne > to a prompt, it stays open.] > > Relevant code block: > > #rectangle stuff > length = int(raw_input("Please enter the length of your rectangle, as > a whole number : ")) #lets user input a number > width = int(raw_input("Please enter the width of your rectangle, as a > whole number : ")) #lets user input a number > area = length * width > print " " > print " " > print " " > print "the length is" > print length > print " " > print "the width is" > print width > print " " > print "So the area is" > print area > print " " > > end = (raw_input("Type something, and press Enter, and the program > should shut down.")) > #workaround > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a python book
Sorry, it is www.diveintopython.org , not .com On Sat, 25 Nov 2006, =?ISO-8859-1?Q? Arild_B._N=E6ss ?= wrote: Den 25. nov. 2006 kl. 13.32 skrev Dick Moores: At 08:40 PM 11/24/2006, Jalil wrote: If you already know C you should be fine with python ref book. Python Essential Reference (2nd Edition) The 3rd ed. came out Feb 2006. http://tinyurl.com/yjvn6o I have also been wondering about a second book to get. I've already got "Beginning Python" from Apress, which is good, but very basic. I'm weighing "Python in a Nutshell" against "Python Essential Reference". In one of the customer reviews on the amazon-page (linked to above), someone claims: "The Nutshell book documents each function of a module with an explanation of how to use it and what to watch out for. It often provides a useful example. Beazley, on the other hand, has mostly restated the web docs, which are free." Any opinions on this? (BTW: When I try to visit diveintopython.com, that someone just mentioned in this thread, I get up a web page that has little if anything to do with python.) Arild N?ss___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] shebang question
>From what I can tell/remember, the first works in the *nix environment if python is in your $PATH, the latter will find python "somehere" on your system by looking at wher the executables should be. On 26/11/06, shawn bright <[EMAIL PROTECTED]> wrote: > Hey there all, > what is the difference between > #!/usr/bin/python > and > #!/usr/bin/env python > ? > > thanks > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > -- John Maclean - 07739 171 531 MSc (DIC) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with Tkinter, please
At 01:37 PM 11/23/2006, Alan Gauld wrote: >"Dick Moores" <[EMAIL PROTECTED]> wrote > > > def compute_fact(): > > value = int(entry_get()) > > > File "factTk1-a.py", line 22, in compute_fact > > value = int(entry_get()) > > NameError: global name 'entry_get' is not defined > > > > I'm so dumb I don't see how to define it. > >get is a method of the Entry widget. >So the syntax is entry.get() not entry_get. > >HTH, Sure did, Alan. Some time has passed and I've made some progress. My question now is about the placement of buttons. Here's part of my code: = root = Tk() fram = Frame(root, bg = "black").pack() Label(fram, text = "Enter a positive integer, n",).pack() entry = Entry(fram, fg = "red", width = 30) entry.focus_set() entry.pack(side='top') Button(fram, text="Compute n!", command=compute_fact).pack(side='top') Button(fram, text="Compute n-cubed", command=compute_cube).pack(side="top") Button(fram, text="Compute factors of n", command=compute_factors).pack(side="top") Button(fram, text="Exit", command=sys.exit).pack(side="top") #text = ScrolledText(fram) text = ScrolledText(fram, bg = "cyan", fg = "red") text.insert(END, "n-factorial or n-cubed will appear here.\n\n") text.insert(END, 'And again, with commas inserted.\n\n') text.insert(END, "And yet again, in scientific notation.") text.pack(side="top", expand = 1, fill = "both") mainloop() = I've done a lot of fiddling around with setting "side=left", and trying to put all the buttons inside a second Frame inside the first one, but I can't get the layout I want, which is the Label on top of the Entry, then a row of the first 3 buttons (which respectively trigger 3 different computations on the integer the user enters). Then below that, the Exit button, with the Text widget at the bottom. How to do this? Is it impossible with the pack() method? Thanks, Dick Moores >Alan G. > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] shebang question
Hey there all, what is the difference between #!/usr/bin/python and #!/usr/bin/env python ? thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] program spontaneously closes...
Hello All. I've been concocting some simple programs based on an online tutorial, and I, of course, save a program as a .py file. When running my program via IDLE, once I've cleaned out the bugs, it works as I expect it to. But I noticed something else: Clicking directly on the file's icon has the program open in the Windows command line program as a .exe file. The command line program seems to work through my program OK, but the command line program shuts down immediately after the program has run through, as opposed to staying open in order to display the result. [I noticed that if the command line program is not waiting for a resposne to a prompt, it stays open.] Relevant code block: #rectangle stuff length = int(raw_input("Please enter the length of your rectangle, as a whole number : ")) #lets user input a number width = int(raw_input("Please enter the width of your rectangle, as a whole number : ")) #lets user input a number area = length * width print " " print " " print " " print "the length is" print length print " " print "the width is" print width print " " print "So the area is" print area print " " end = (raw_input("Type something, and press Enter, and the program should shut down.")) #workaround ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a Python Book
"Python Programming for the absolute beginner" auth: Michael Dawson Although touted as, and directed toward, a new programmer, the book is an excellent 'sing along' tome that illustrates good examples with a good structure of creating small working scripts, and gets very well into some heavy subjects, including OOP, GUI programming. A well written, well thought out effort. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
* Python <[EMAIL PROTECTED]> [061125 14:47]: > On Sat, 2006-11-25 at 00:10 -0600, Luke Paireepinart wrote: > > Although I'm prettty sure most modern linux distros come with Python > > already installed, so you don't need to be concerned about those linux > > folk. > > I think Windows is the only major OS distribution that still omits > Python. > > > Except, I find that it's more trouble for linuxers to get packages > > for > > their python scripts, because they have to make-install etc. whereas > > windows people have a nice friendly, > > fuzzy little GUI installer for the majority of python packages. > > The belief that all Linux software must be compiled and installed > manually is a common misconception. The major Linux distributions all Even worse is the common misconception that this is even a problem. One big benefit of this is, that package authors are forced to consider the built and install environment. As a cynic, and this is only a rule of thumb, the following points usually means force built/install automation: a) commercial software => usually smaller user population (and well, Windows does usually come preinstalled, so the population that does Windows installations is extremly small). b) closed source software => it does not matter how ugly it is, as nobody sees it. And providing a sensible environment is often not considered relevant by management. (E.g. I once did revamp the build system of a commercial closed source application, but I had to hide the work hours in a "paid-for" project) c) Windows => Windows has no systematic filesystem layout, is still having problems with filesystem permissions, and lacks a standard compilation environment. These are additative, IMHO ;) Yeah, I know there are exceptions, but over a decade these points have been validated in many, many cases. > have servers with thousands of packages that install easily, either from > a command line or a GUI interface. For my Fedora laptop: > yum install python-kid > checks for any dependencies (e.g. python-elementtree) and installs all > needed packages. (There is no need for the package to have been written > in Python. I just used a Python example since this is a Python list.) > Most Linux packages have available source code and you *can* install > from source, but that is not forced on you. Basically software installation on Linux (and to a lesser degree on commercial Unixes) is way less flashy than on Windows, but at the same time more advanced. Automatic fetching and dependency resolution have been standard features for Linux distribution for years now. E.g. Installing package B that breaks package A is considered a bug on Debian. Installing package B on Windows that replaces common DLLs and breaks half of the system is "state of the art". > > If a Python package is not available through yum, installation from the > Cheese Shop is still quite simple, and certainly no more difficult than > on Windows. As noted above if there a no distribution specific packages, we can fallback on a number of Python specific ways to build packages: a) easyinstall. Autofetching, building and installing, including dependencies. b) eggs. binary and system-independant prepackaged Python packages. Including version management of a given package. c) distutils setup.py => no autofetching of dependencies. automatic build + install. Btw, these are also available ob Windows, as these are Python specific ways to handle packages. OTOH they are hindered on Windows by the fact that there is no standard compiler environment (see above) that is always available. Getting a VS NET 7.1 license in the office (a big international company *g*) takes days. It's a pain, but it's easier to patch the installed python config to compile via mingw. And if I think about that one, yes, the private closed source packages that are Windows specific have the worst buildsystem. Aka a README where one can copy & paste CL.EXE invocation from. Cool, not. Andreas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about HORIZONTAL BAR CHART.....
As far as I understand, I need to design an algorithm which computes the padding between each bar (space between each bar) and the length of each bar ( remember that this is a HORIZONTAL BAR CHART). I am trying to understand your email. ( Please bear with my slow comprehension ) Regards, Asrarahmed Kadri On 11/24/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote: Asrarahmed Kadri wrote: > > > Hi Folks, > > I am constructing a bar-chart using Tkinter. The function takes a list > 'data' and draws horizontal bar for each value. > Now what I want is the the canvas widget should be able to handle > variable number of data-items. I cannot figure out how to do that, > because I have hard coded the lengths of X and Y axes. I want to make > the entire function a lot more flexible so that it determines the > length of both the axes on the basis of data supplied to it. #disclaimer Note: I didn't realize you said horizontal bar charts. This does vertical bar charts. It should be trivial to change this. Sorry for not reading your post more carefully to begin with. #for width >>> data = [1,5,6,7,8,3,2,9] >>>target_width = 600 >>>padding = 10 >>>num_of_data_items = len(data) >>>individual_width =( target_width-(padding*(num_of_data_items-1)))/num_of_data_items >>>individual_width 66 >>>individual_width*num_of_data_items 528 >>>padding* (len(data)-1) 70 >>>528 + 70 598 #for height >>>target_height = 600 >>> maxval = max(yvals) >>> for item in yvals: print int((float(item)/maxval) * target_height) 66 333 400 466 533 200 133 600 Did you honestly try to think this through before posting? It's a very simple concept. Not trying to be mean, just frank. I think you could've done this on your own if you had tried. Good luck with your bar charts. :) When you ask a question such as this "I cannot figure out how to do that, because I have hard coded the lengths of X and Y axes. I want to make the entire function a lot more flexible so that it determines the length of both the axes on the basis of data supplied to it." The way you should be reasoning is this: I have hardcoded the lengths of the x and y axes. I need to change this for my function to operate how I want it to. How do I change it? 1) I have the data set already, so how do i figure out the width? (or height, if you're doing horizontal bar graphs) Well, I can make the following distinctions: - I have a target width (the width of the canvas) that they must all fit within. - all bars will be the same width - there should be some distance between each bar. - this distance should be the same no matter how many data elements there are, IE fixed. - so if I have a fixed width between variable amounts of data, how would I design an algorithm to perform this for me on any arbitrary data set? 2) How do I figure out the height of the data sets? (or width, if you're doing horizontal bar graphs) The following distinctions can be made: - I have a target height that they all must fit within (the height of the canvas) - Only the maximum value should be the full height of the canvas. - the others should be less than this height, depending NOT on their ratio to the height of the maximum bar, but on their ratio to the data that generated this. -- what do we use for ratios? Fractions! HTH, -Luke -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] PLEASE assign a (meaningful) subject to your posts
Pretty please. Posts without subject headers irritate the hell out of Eudora. Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a python book
Narasimha wrote: > Hi! Friends, > > I am new to python. I have a vacation of 15 days. Please suggest me a > python book (or a website). > > I already know C language. I have heard much about Python. I think Learning Python is a good book if you already have some programming experience. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a python book
Arild B. Næss wrote: > > Den 25. nov. 2006 kl. 13.32 skrev Dick Moores: > >> At 08:40 PM 11/24/2006, Jalil wrote: >>> If you already know C you should be fine with python ref book. >>> >>> *Python Essential Reference (2nd Edition)* >> >> The 3rd ed. came out Feb 2006. >> http://tinyurl.com/yjvn6o >> > > I have also been wondering about a second book to get. I've already got > "Beginning Python" from Apress, which is good, but very basic. > > I'm weighing "Python in a Nutshell" against "Python Essential > Reference". In one of the customer reviews on the amazon-page (linked to > above), someone claims: "The Nutshell book documents each function of a > module with an explanation of how to use it and what to watch out for. > It often provides a useful example. Beazley, on the other hand, has > mostly restated the web docs, which are free." > > Any opinions on this? Python in a Nutshell does give good concise explanations of the modules. The version of Beazley that I have, which is pretty old (2000), doesn't seem to add much to the docs. But personally I prefer the online docs to either. I think a good intermediate Python book is the Python Cookbook. This gives a lot of examples of using Python and the standard library in ways you might not have thought of. It is a good collection of idiomatic Python. > > (BTW: When I try to visit diveintopython.com, that someone just > mentioned in this thread, I get up a web page that has little if > anything to do with python.) Try diveintopython.org Kent > > Arild Næss > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On Sat, 2006-11-25 at 00:10 -0600, Luke Paireepinart wrote: > Although I'm prettty sure most modern linux distros come with Python > already installed, so you don't need to be concerned about those linux > folk. I think Windows is the only major OS distribution that still omits Python. > Except, I find that it's more trouble for linuxers to get packages > for > their python scripts, because they have to make-install etc. whereas > windows people have a nice friendly, > fuzzy little GUI installer for the majority of python packages. The belief that all Linux software must be compiled and installed manually is a common misconception. The major Linux distributions all have servers with thousands of packages that install easily, either from a command line or a GUI interface. For my Fedora laptop: yum install python-kid checks for any dependencies (e.g. python-elementtree) and installs all needed packages. (There is no need for the package to have been written in Python. I just used a Python example since this is a Python list.) Most Linux packages have available source code and you *can* install from source, but that is not forced on you. If a Python package is not available through yum, installation from the Cheese Shop is still quite simple, and certainly no more difficult than on Windows. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a python book
Den 25. nov. 2006 kl. 13.32 skrev Dick Moores: At 08:40 PM 11/24/2006, Jalil wrote: If you already know C you should be fine with python ref book. Python Essential Reference (2nd Edition) The 3rd ed. came out Feb 2006. http://tinyurl.com/yjvn6o I have also been wondering about a second book to get. I've already got "Beginning Python" from Apress, which is good, but very basic. I'm weighing "Python in a Nutshell" against "Python Essential Reference". In one of the customer reviews on the amazon-page (linked to above), someone claims: "The Nutshell book documents each function of a module with an explanation of how to use it and what to watch out for. It often provides a useful example. Beazley, on the other hand, has mostly restated the web docs, which are free." Any opinions on this? (BTW: When I try to visit diveintopython.com, that someone just mentioned in this thread, I get up a web page that has little if anything to do with python.) Arild Næss___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please suggest a python book
At 08:40 PM 11/24/2006, Jalil wrote: If you already know C you should be fine with python ref book. Python Essential Reference (2nd Edition) The 3rd ed. came out Feb 2006. http://tinyurl.com/yjvn6o Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
* Luke Paireepinart <[EMAIL PROTECTED]> [061125 07:11]: > Not the batch script, obviously, but the rest of your program. > Although I'm prettty sure most modern linux distros come with Python > already installed, so you don't need to be concerned about those linux folk. > Except, I find that it's more trouble for linuxers to get packages for I beg to differ here. Most Python packages (well, there are some Windows-only packages that are a mess, but wonder why that is so), are trivial to build and install: python setup.py install For most packages, even fetching the package is automated via ez_install. Even further, with eggs you probably could automatically fetch (and potentially build and install) a package from inside an app, but that is considered bad tone (security wise, and automatism might break). And to make it even funnier all of this is trival scriptable, while all these nice GUI installers take my time. The point is easy: Building a custom Python with a set of crazy dependencies takes some hours on my Linux laptop. Setting up the same crazy dependencies with GUI dependencies on Windows XP took me almost a week. I admit, my sympathies lie with the "type a command, go to lunch, come back and have dozens servers installed and configured" crowd, and not the "uhh, no time for lunch today, I have to wait when the GUI installer will prompt me some stupid question" crowd :) > their python scripts, because they have to make-install etc. whereas > windows people have a nice friendly, > fuzzy little GUI installer for the majority of python packages. > So including an interpreter on the CD With your program that has all of > the dependencies built in may not be a bad idea. > Oh, and to address your original question: > I don't think it's possible to have a single .exe with all your > program's functionality contained within. It is. But it is usually not worth the pain. Hints: * one can build almost all modules statically into the binary. * one can zip all Python code into one zip file. * and to make it even funnier, zip files are "appendable" onto almost all binaries. * there are a number of tools that google will show you that automate this process more or less painfully. Andreas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor