Fog Creek Software
Discussion Board




Your thoughts on Python

Joel,
I have been a regular reader of your articles and have admired your points of view on many things because of their practicality.  I am curious to know your thoughts on the Python language.  As a programmer and system designer, what aspects do you look for in a programming language?

Hemanth
Monday, March 15, 2004

I know practically nothing about Python. When I looked at it, it appeared to be "yet another late-bound slow interpreted scripting language" of which I already have more than I need, so I didn't look much closer.

I do, however, agree wholeheartedly with Dave Winer's admiration of the way Python gives indenting semantic meaning.

http://archive.scripting.com/2002/04/16#l9187a7a9c639f12a6eb37f9d56568861

I'm sure most programmers consider this to be frighteningly annoying, but most programmers are wrong. Giving indentation semantic meaning is a stroke of genius. In one fell swoop, it forces code to be indented neatly and correctly, while avoiding an entire class of bugs caused by code that looks like it's doing X when it's really doing Y and averting a whole class of worthless flamewars.

That said, I just don't have any use for another scripting language so I haven't been able to justify the time to learn Python.

Joel Spolsky
Fog Creek Software
Monday, March 15, 2004

And for a somewhat faster .net version of python:

http://www.python.org/~jeremy/weblog/031209a.html

if you prefer the jvm to the clr, the same guy gave us jython:

http://www.jython.org/

Then again, I'm severely biased ;-)

fool for python
Tuesday, March 16, 2004

Joel, Python might interest you because most people who use it considers it one of the most usable programming languages there is.  It is just an absolute pleasure to work with -- everything is so intuitive and clean.  The clean language design seems to have seeped through to most the API designs as well.

I think it is an interesting question to see if there is any way to quantify these benefits, but they are very real nonetheless.  I feel like python is so flexible and fast that I am less likely to write code with bugs, to let cases go untested.  Its short iteration cycles let me mold the structure of my programs quickly and exactly how I want them.

It does have a few warts -- in my opinion the import statement is one -- but overall it is fantastically usable.  I can imagine that right now it's not the best language for business purposes, but it definitely is worth learning for anyone with a general interest in programming.  Not to be too effusive, but for an experienced programmer it is not so much a question of learning python, but rather finding it within yourself.  : )

And people can always pick on scripting languages for being slow (I know fast, I program almost exclusively in C for my job), but Python has the defense that there is the Python/C API.  It is DESIGNED to be extended with C for performance critical applications.  It can interface with existing C code with a wrapper.  There are tons of C libraries that are available to python programmers, including the whole Win32 library, I believe MFC, OpenGL, TeX libraries, expat (XML), HTML, HTTP, encryption, compression, math, you name it...

Though one thing I have a problem with is that, recently, it seems the development efforts going a little too far in the theoretical abstract direction, instead of focusing on developing professional development tools, polishing warts, and consolidating/maturing the already excellent libraries.  I think it could easily be a lot more popular than it is now, given its benefits.  And popularity is always a big plus when deciding to use any programming language.

Roose
Tuesday, March 16, 2004

Are there examples of succesfull commercail apps done with python?

drazen
Tuesday, March 16, 2004

Take a look at zope (http://www.zope.org)

There exist several commercial web-applications on top of this application server, e.g. a service desk / docflow system by Naumen (http://www.naumen.ru).

There exist a bunch of scientific libraries / applications using python, it is very popular in bioinformatics (http://biopython.org).

tws
Tuesday, March 16, 2004

I laughed at the indentation feature when I first heard about it, but got addicted within 5 minutes of actually using Python. It's a great too that one does not have to type semicolons at the end of each line of code.

Now if only Python would dump this useless required colon at the end of each "if" and "def" line, it would definitely bring home the Oscar in the "Cleanest language that looks like plain English and does not require weird syntax" category.

Jan Derk
Tuesday, March 16, 2004

Heretic! And to think I bought FogBugz to manage a Python project :-)

In all seriousness, Python isn't that slow, but then again, it's not for all apps. My current project (http://jaeger.blogmatrix.com) is put together with Python and wxWindows and has a fairly significant amount of code in it -- but none of that code is algorithmically complex.

At my "real" job, I was using Java but we're speed freaks here (we use very complex finance/risk management model) so I've switched over to C++ (actually C++ written using mainly C functions and using Fortran-style memory layouts). Python would definitely not be appropriate for this environment!

Anyway, in conclusion (as they say): Python is god -- for the right apps. 15 minutes can get one hooked for life. It did for me.

David Janes
Tuesday, March 16, 2004

The redundant colon comes from a usability study.  Apparently complete newbies had a hard time realizing indentation was significant without it, in a Python precedessor.
http://www.python.org/tim_one/000573.html

Of course, one can critique the applicability of the study, and it occasionally bites certain Pythonistas.  (Then again, it might have bitten more people without colons.)  But Guido likely didn't have the funds to commission more studies with Python, so I think it was understandable.

Tayssir John Gabbour
Tuesday, March 16, 2004

"Giving indentation semantic meaning is a stroke of genius."

Python is *full* of strokes of genius; this is merely the most obvious, in-your-face example.

Simon Brunning
Tuesday, March 16, 2004

I've written lots of code in Python and I came away with three impressions:

1.  The indentation thing is okay.  I wouldn't call it a stroke of genius, but I didn't mind it.

2.  Tuples are way cool.

3.  The % operator for strings is great.  C# should have this as a syntactic shortcut for String.Format().

Eric Sink
Tuesday, March 16, 2004

If complete newbies have a hard time realizing that indentation is significant, then why not add parentheses or begin/end around each block?

In your link van Rossum mentions that he likes uniformity in a language. This colon, however, is the dissonant in the otherwise brilliant Python symphony. The other clean language, Ruby, does not use it either. But then again Ruby suffers from its "end" statement. I guess nothing is perfect and I should not rant so much about a colon. Oh well, I just go back browsing the web for good scuba operators on Koh Tao, Thailand.

Jan Derk
Tuesday, March 16, 2004

BTW, BitTorrent is written in Python + wxWindows.

Fred
Tuesday, March 16, 2004

"Of course, one can critique the applicability of the study, and it occasionally bites certain Pythonistas.  (Then again, it might have bitten more people without colons.)"

People without colons are rare. I see no reason to compromise a language's design just to cater to such a small demographic.

Karl von L.
Tuesday, March 16, 2004

I am sure that one of the functional programming languages uses indentation, I think it was HUGS which is essentially Haskell. The only people who found indentation a problem were programming newbies who hadn't learned about writing clean and understandable code. Old timers like me didm't have those sort of problems, there was enough in Haskell to trip me up elsewhere.

WhatTimeIsItEccles
Tuesday, March 16, 2004

Ensim Webppliance, one of the more popular comercial hosting platform solutions, is written in Python.

Guillermo Bertossi
Tuesday, March 16, 2004

google uses python

 
Tuesday, March 16, 2004

I wish Python had PHP's ease of implementation as a web development language. Two or three times now I've tried to get mod_python going without success. It's curiously hard to write the first "hello world" page in response to a GET. Requiring the twisted library and hence another whole web server seems a little excessive when I've got a perfectly good Apache installation. Similarly with Zope.

julian Bond
Tuesday, March 16, 2004

Julian, if it's been a while since you've used mod_python, you might take a look at the latest version (released last month). They've added a way of including Python code in HTML, like you do with PHP. If you're interested, there's an article about it at http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html

(I'm not crazy about the PHP way of doing things myself, but it certainly can be convenient sometimes.)

Moss Collum
Tuesday, March 16, 2004

The most popular daily use of Python are probably the parts of Google written in Python, but of course that isn't a typical app. As far as I know, the most popular pure Python app in use today is BitTorrent, which is getting between 1.3 - 1.5 million downloads a month from SourceForge. Those numbers also qualify BitTorrent as one of the most popular Open Source apps. Here's a direct link to the monthly download stats...

http://sourceforge.net/project/stats/index.php?report=months&group_id=33044

When I first started using Python one of the first things I did was translate many of my VBScripts I used regularly to Python. Mark Hammond's pywin32 (win32all) makes this very easy as it gives you simple access to COM components and the Python code is very similar to the VBScript code for a given task like automating Outlook, so it is easy to understand and debug. In many cases, you can remove or isolate the Windows dependencies imposed by WSH or VBScript and you'll end up with a useful cross-platform script that will work on Mac OS X and Linux instead of just working on Windows.

Organizations using Python

http://www.python.org/community/users.html

I just started a page to track apps written in C/C++ that support Python for scripting the app and components. This is analogous to what many MS apps do with VBScript, but Python is much better at it and cross-platform. This use of Python is really catching on especially in the commercial game sector.

http://www.python.org/cgi-bin/moinmoin/AppsWithPythonScripting

And finally, if you're still wondering what all this Python hoopla is about, you should check out the following...

http://altis.pycs.net/stories/2003/04/16/whatIsPythonAndWhyPython.html

http://pythonology.org/

ka

Kevin Altis
Tuesday, March 16, 2004

Anyone who once used Perl or PHP and now prefer Python for web apps? I started with Perl but now use PHP exclusively for the web (easier and much easier to deploy) but I still use Perl for cron jobs and command line stuff. Before I did PHP I would have said "use Perl" ... I wonder if someone can say the same for Python or maybe most of the people posting are coming down for C,C++,Java etc. I think they have a different perspective. I find Perl and PHP extremely easy to use to get things done ...  why write 500 more lines ... if the speed doesn't make any difference? So I kind of fee like Joel, I've already got 2 scripting langauges, why bother with Python?

Me
Tuesday, March 16, 2004

>>>
I find Perl and PHP extremely easy to use to get things done ...  why write 500 more lines ... if the speed doesn't make any difference? So I kind of fee like Joel, I've already got 2 scripting langauges, why bother with Python?
>>>


(In Perl's case) because you might want to re read your code 6 months from now. Python favors cleanliness.

Adriano Varoli Piazza
Tuesday, March 16, 2004

I used perl for several years for some quite large scale projects (~30Kloc).
A couple of years ago I discovered python.  I won't use perl again unless I'm
forced to.  Python is not "just another scripting language" - it has
lots of seriously good design.  You'll find lots of people that have moved
from python to perl - very few (any?) that have moved in the other direction.

Mark Russell
Tuesday, March 16, 2004

I have a Python story which I'm a little bit shocked by.

I've always liked scripting languages. I like Perl a lot. Then last year I thought I'd get into Python, and was converted within an afternoon. There's no doubt this is a beautiful, easy and stress-free language. I've written several smallish  programs in it over the last year.

However, in the last couple of months I've been writing a desktop app. in Windows. When I started, I looked at Python and Visual Basic. I started playing about in both environments. But somehow VB took off and suddenly, a couple of months later, I've found I've been happily writing the code in VB. I have days when I think about switching and re-writing, but basically I'm locked in.

I still think Python is a better language. It has far more good features than VB. My VB code is undoubtedly longer than the equivalent Python. The string processing is clunkier. And the lack of inheritance a big drawback.

And yet, somehow, in practice, it hasn't mattered. The code flows easily enough. The language's failings don't hold me up. I get round lack of inheritence using helpers and strategies. The string processing works out OK.

But I think the best explanation I ended up in VB is this : A good IDE counts for a *hell* of a lot. And the VB IDE has stuff I don't have in the Python IDEs I've tried.

Particularly, auto-completion of function names, and the prompting of the required arguments is a *huge* productivity boost. (Maybe because I have lousy short-term memory for such things.) The integration of the form-editor and the code behind the controls is still a lot better than, say, PythonCard. And, generally, it does feel more integrated.

I'm sure decent Python IDEs exist, or are around the corner. And I hope I will be switching one day. But right now I'm kind of surprised I've been so happy in VB. 

Another interesting point. I'm generally against strong-typing. And I love Python's lack of typing. But I realize that I appreciate the *write-time* support that types give me in the VB IDE. Not sure how to transport that to Python.

Also the reason I don't find the typing a pain in VB is because it's interpretted, so you still don't have the compile stage interupting the flow,

phil jones
Tuesday, March 16, 2004

I believe that in learning Python you are not learning any old scripting language.  You are learning what it is to produce a truely elegant design; code that is beauty and art as much as it is function.

I can only hope that this same beauty begins to seep into the other diciplines of software design and becomes the norm.  The BitTorrent client GUI is a good example.

But then, you really have to try it to grok it.

Mars
Tuesday, March 16, 2004

I've used both PHP and Python for professional web development -- started with home-grown Python system, moved to doing more PHP for professional reasons, then moved back to Python and Zope.

It's definitely true that Python is a harder web environment to set up, and support for it is mixed.  It's harder still that there's a lot of different environments, like Zope, Webware, mod_python, cgi, SkunkWeb, and the list goes on with about 20 other frameworks.  It's a mess.

But the language is great, and when you look past the lack of a canonical easy-to-administer environment I think you'll see that Python is much better suited for web programming than PHP.  PHP is just a crazy bad language -- it's a really expedient environment, but it's a lousy language.  At least Perl and Python differ by intention -- PHP is just way underdesigned.

The web situation is a real shame, because Python is actually quite expedient in other domains.  Anyway, I still use Python exclusively for my web programming, and quite happily, you just have to get over a certain hump to become productive.

Ian Bicking
Tuesday, March 16, 2004

You think Python has lots of web frameworks?

Check this out:

http://www.manageability.org/blog/stuff/how-many-java-web-frameworks

Phillip J. Eby
Wednesday, March 17, 2004

Mars: "But then, you really have to try it to grok it."

That's true of any language, isn't it? For instance, it's easy to slam Perl because it "looks ugly" to people who aren't used to sigils, but when you've used it for a while and think in it you don't read or understand the code the same way and the sigils aren't noise any longer.

Personally, i think it will be a very interesting world when (if?) Python and other scripting languages have access to CPAN through Parrot...

http://www.parrotcode.org/

Chris Winters
Wednesday, March 17, 2004

In my younger days, I was very interested in different programming languages and different ways of doing the same thing.

I have learned well and used several programming languages a lot, including C++, Java, LISP, ObjectPascal, BASIC, Oberon, etc.


Python is a fantastic language.

When learning Python, I had this experience many times: I started working on a project, finished it, and was astonished at how little time it took to complete the project.

The productivity gain is significant.


However, most of the apps I write require a GUI, and I create the user interface using Delphi or VS .NET.

Developing a GUI in Python is a lot slower than developing the same GUI in Delphi or VS .NET.


So - when developing in Python, I save development time when writing the algorithms of the program, and then waste the savings on doing the GUI part.

Because of this, developing a program in Python takes the same amount of time as developing the program in Delphi.

And so I prefer to write in Delphi because I get a compiled .EXE which runs lightning-fast.


Now, if there was a good, mature GUI builder for Python, I would immediately switch to Python because the combination of Python + good/fast GUI builder would enable me to develop applications a lot faster.

I think that for such an environment, a 20% development time saving could realistically be obtained.

This is VERY attractive and VERY significant.

There is a Python GUI builder called BOA Constructor. Unfortunately, it's very beta :), and crashes a lot.

MX
Wednesday, March 17, 2004

BOA Constructor is an open-source GUI builder for Python.

Project page:
http://boa-constructor.sourceforge.net/

Screenshots:
http://boa-constructor.sourceforge.net/Screenshots/

MX
Wednesday, March 17, 2004

I'm curious, has anyone tried out Ruby?

In the elegant languages department, Ruby is well worth a look. Highly recommended if you have some free time on your hands, and don't mind getting addicted.

Download the windows installer, which comes with a basic IDE as well, at http://tinyurl.com/2hvnd

The best resource for starting is, IMO, The Pragmatic Programmer's Guide, by David and Andy. Link: http://www.rubycentral.com/book/

SB
Thursday, March 18, 2004

I'm curious, has anyone tried out Ruby?

In the elegant languages department, Ruby is well worth a look. Highly recommended if you have some free time on your hands, and don't mind getting addicted.

Download the windows installer, which comes with a basic IDE as well, at http://tinyurl.com/2hvnd

The best resource for starting is, IMO, The Pragmatic Programmer's Guide, by David and Andy. Link: http://www.rubycentral.com/book/

SB
Thursday, March 18, 2004

I have tried Ruby a while ago - so long ago, that I don't remember a lot.

It is indeed elegant, however, I remember that it is the kind of language where lots of things are implicit and not spelled out in the code.

I didn't get more into it because of the lack of mainstream acceptance.

You can find lots of libraries for VB, Delphi, C++, etc.

You will find a lot less libraries for Python.

And even less libraries for Ruby.

So this is why I avoided it.

And I ended up avoiding Python for the lack of a good GUI builder, too.

MX
Thursday, March 18, 2004

In the 80s I was working for a governmental science lab and we did a lot of our data processing in a language called IDL(c) from rsi. This language had very many features that python or other scripting languages have now. It was a very strong boost in the productivity for the programmers (which were mostly scientists) and the whole lab was switching to this language (only time critical applications were written in fortran or c). When I left the lab and worked for a university I could not afford the high price of the software anymore and I was looking for alternatives. The requirements were ease of use and platform neutrality. After a while I found python and later on jython. I think the combination of jython (as a glue and scripting language) and java (for the low level parts) is the best that you can get. Using this on a large memory machine with a decent jvm like the one from bea gives you a strong advantage over programming in c++. The benchmarks that I were running on my machine were showing that the jython/java combination was faster than the python/c++ version.

p.s. there is a decent python/jython mode for jedit which gives you a great jython/java ide with features like code completion, class browsing, in-process compilation, debugger support, built-in jython interpreter, javadoc generation and many many more. http://www.jedit.org

Ferdinand Jamitzky
Thursday, March 18, 2004

"""Personally, i think it will be a very interesting world when (if?) Python and other scripting languages have access to CPAN"""

It's been possible for quite a while now.  See:

http://www.python.org/cgi-bin/moinmoin/PyPerl

It allows you to embed a Perl interpreter in Python (via 'import perl') or a Python interpreter in Perl (via the 'Python::Object' package).

Phillip J. Eby
Thursday, March 18, 2004

In this day and age of automatic code formatters, I would find Python's indentation-is-significant to be very annoying.  Forcing programmers to manually indent as part of the language makes automatic code formatting impossible, and is a waste of a million keystrokes per year.

NoName
Friday, March 19, 2004

Please tell me that's a joke. In this age of automatic indenting, your text editor should do all that work for you; no extra keypresses. NoName, is this a troll?

Gareth McCaughan
Friday, March 19, 2004

I am not trolling.  Text editors can't read my mind.  They can't predict what the next line should be, frequently forcing me to use backspace or spaces to put it where I really want.  It's even worse when the indentation itself is used to designate the beginning and end of a logical block, thereby stopping the auto-indent from knowing when to back-dent.

With braces to designate the end of logical blocks I can just type however I want and run it thru the auto-format when I'm ready.

Still, I am looking into learning Python and the indentation issue won't stop me.  It will be annoying but other languages have their own annoying characteristics.

NoName
Friday, March 19, 2004

Most text editors I've used (and I am but a wee child of 29) indent or deindent with a single chord:  shift-tab (or shift-alt-tab) on Windows and command-] and command-[ on Mac... and if you're really concerned about it, you can write all your code on a single line and then block-indent the whole thing later.

So I hope you'll forgive my saying that citing that as a reason not to use a language seems... well... perhaps a bit trollish.  "No, dammit, I can't drive this car -- it doesn't have a variable-speed rear window wiper control, and I *can't live without it!*"

Sam Livingston-Gray
Saturday, March 20, 2004

...which should be continued, "No, that's fine -- I'll just walk.  See you there next week."

Sam Livingston-Gray
Saturday, March 20, 2004

"""Text editors can't read my mind. """

No, but they can read your keystrokes.  In any editor with a proper Python mode, typing ':' and ENTER indents the next line, and all following ones.  Outdent is then typically backspace, shift+TAB, or some such.

So, compare with braces...  open brace+ENTER, close brace...  Hm, same number of keystrokes, including uses of the shift key, unless your Python outdent is backspace (in which case it's better) or your non-Python editor adds the closing brace for you (in which case it's better).

Either way, not a lot to fuss about, and so automatic that it will probably disappear into the background during your very first coding session.  Just like an editor indenting automatically after an open brace, it just "does what you mean".  It may not be reading your mind, but it's close enough.

Phillip J. Eby
Saturday, March 20, 2004

Speaking of Python IDEs: has anyone tried Visual Python (VS.NET plug-in) from ActiveState:

http://www.activestate.com/Products/Visual_Python/

I used Visual XSLT from the same guys and it was a great experience for a XSLT newbie.

Cristian Cheran
Sunday, March 21, 2004

AFAIK, all the editors and IDEs listed on the wiki understand Python source enough to do smart indenting.

http://www.python.org/cgi-bin/moinmoin/PythonEditors

ka

Kevin Altis
Sunday, March 21, 2004

A year ago I was of the same mind as Joel; when I needed to use a scripting language for text processing some years back, I thought Perl/Python?, Perl had the mind share, so I went Perl.
Then last year I had the ask of extending a significant real time application, originally developed in Ada, that translates telephony switch control protocols on the fly. Various difficulties with continuing with the Ada led me to contemplate adopting Python, because mainly of relevant praise for the language from a colleague.
(A few remarks about Ada for this purpose; experience translating other Ada programs to C++ suggests that at least for programs of 10-50KLOC 1 Ada Loc approximately equals 1 C++ LOC. If this had been Ada 95 instead of 83 then probably it would be much more economical in LOC than C++, but it was '83 vintage. The idea of implementing a real-time system such as this in C++ which has no semantic support for multi-tasking is a nightmare; I know that people do it, I just wouldn't pay for such a project myself).
Now on closer examination one discovers that Python has threading and some very handy modules for common synchronisation semantics. Indeed this a feature of climbing the Python learning curve, everything you encounter has been done really well.
What astonished me is that after two weeks I had written 2k lines in this unfamiliar language that reproduced the funtionality of the 20k lines of Ada (and the hypothetical 20k lines of C++). What' more, it worked. Bottom-up implementation of the Ada package architecture with its Python equivalent, with test programs for each component on the way, was a completely smooth process. No nasty surprises, obscure bugs, memory leaks, stress test collapses. An order of magnitude improvement in productivity for a particularly difficult application.
In the intervening months I have used Python for several diverse projects: XML applications, exploratory data analysis with neural networks, etc. For anything algorithmic or data structure intensive it is fantastically useful. For most compute-intensive situations you can hand off to C modules (the numeric module is particularly convenient for this), and there are tools like psyco providing acceleratioin through JIT-style compilation to machine code. Don't be too worried about speed; write in 1month the app that takes a year in C++, and spend another month tu ning it if you really need to. Also scalability; I've absolutely no fear of developing large programs in Python, the source code is wonderfully readable and maintainable, especially compared with Perl or C++ which are very often write-only exercises.
Two areas I have not tackled with Python: web applications and GUI applications.
I note an earlier contributors remarks about IDEs; I too have recently been using VB and VBA where the client wouldn't allow Python. Despite the handy benefits of the IDE programming in VB compared to Python seems like swimming in treacle.
If you enter the Python community you will discover it is populated by some very smart people who have done remarkable things with it. Don't worry about lack of library support; you can find everything you need and the benefit is it will be extraordinarily accessible when you use it.

Pythonista
Wednesday, March 24, 2004

    "... Two areas I have not tackled with Python: web    applications and GUI applications. ..."

for me this cuts to reasons I use python. I use python as a systems tool doing all the boring scripting stuff I need to do ...

for example
*admin
-backup of data
-mirroring of data
-status tools

or as business logic in apps ....
*code
-scripting business logic
-code boilerplate generation
-testing

or misc other things ....
*misc
-spider aggregators
-munging
-email

python is the ideal cross platform system language for win,*nix (inc mac).  python also can be embedded in applications for windows etc (try that with perl). but perl kills python (for me) server side because of CPAN (and mature Apache, mod_perl, DBI)

so my mantra is " ... python on the desktop,  perl on the server ..."

peter renshaw
Wednesday, March 24, 2004

"""Text editors can't read my mind. """

if condition:
    pass
else:
    if condition2:
        pass
    # 
#

By putting single comment characters at the ends of blocks, Visual Slickedit can do all of it's smart-indet-on-paste and my eye can follow complex blocks more easily.  Totally optional, but it should quiet anyone who complains that there are no end-of-block delimiters.

Jim Carroll
Tuesday, March 30, 2004

The phrase "'Scripting Language' My Arse" springs to mind: http://www.python.org/pycon/dc2004/papers/6/paper.txt

Michael Hudson
Wednesday, March 31, 2004

Python is a nice language, Python with braces (I call it "braython") is even nicer. (I wrote a little processor to allow braces and then strip them out.)

Contrary to Joel, using indentation to convey meaning give my tired brain cells conniptions.

Gary Cornell
Friday, April 02, 2004

""" (I wrote a little processor to allow braces and then strip them out.) """

I'm curious whether you find yourself indenting the code within the braces.

sfb
Wednesday, April 07, 2004

It's funny how no one mentions the relative genious of pyGTK and libglade here. I've written a fairly complex commercial application (http://www.immunitysec.com/CANVAS) entirely in Python, and used libglade to huge advantage. Having your GUI as an xml file separate from your codebase is a fantastic way to let you do rapid application development - and it's completely cross platform.

Dave Aitel
Saturday, April 17, 2004

I need help corecting this concrete calc.




# Tk Gui
from Tkinter import *

# Messages
import tkMessageBox

# function definition for use in an event
# ALL functionality must be in the def statement
def doit(event):
    if tkMessageBox.askyesno("Alert...","Do you really want to compute?"):
       
        l = float(text1.get())
        w = float(text2.get())
        t = float(text3.get())
        concrete = (l * w) * t / 27
        c = 77.50 * concrete
        rock = (l * w) * 220 / 9 / 2000
        cr = rock * 12
 
        cl = l * w
        total = cl * 7
        labor = total - (cr + c)
        text4.insert("end", answer)

        if total < 2500:
            peggy = 100
            total = total + peggy
           
        elif total >= 2501 <= 5000:
            peggy = 200
            total = total + peggy
           
        else:
            peggy = 300
            total = total + peggy
     
            self.result_var.set('Waiting for a number...')

     


     
# Put entries on text box   
    answer = "the amount of concrete needed is " ,concrete, "cubic yards" + text4.get() + "\n"
    answer = "the cost of concrete is " ,c, + text4.get() + "\n"
    answer = "the rock needed is " ,rock, 'tons, based on the 2" standard' + text4.get() + "\n"
    answer = "the cost of rock is" , cr,  + text4.get() + "\n"
    answer = "the cost of labor is " ,labor, "dollars" + text4.get() + "\n"
    answer = "the total cost of job is " , total, "dollars" + text4.get() + "\n"
    text.insert("end",answer)   
    if s > 1000:
            text4.config(bg = "red")
    else:
            text4.config(bg = "blue")
       
def clearit(event):
    text1.delete(0,"end")
    text2.delete(0,"end")
    text3.delete(0,"end")
    text3.config(bg = "white")   
    text1.focus_set()
   
root = Tk()
root.title("Concrete Calculator")

root.geometry("600x400")
root.geometry("+100+100")
# change background color
root.config(bg = "pink")
# create a frame
frame = Frame(root,bg = "purple")
# Text fields for Data Entry
# pady puts space between the fields
# Change cursor too, just for fun gumby etc
Label(text='Enter the length of concrete job in feet').pack(side="top")
text1 = Entry(root,width = 20)
text1.pack(side = "top", pady = 10)

Label(text='Enter the width of concrete job in feet').pack(side="top")
text2 = Entry(root,width = 20)
text2.pack(side = "top", pady = 10)

Label(text='Enter the thickness of concrete in tenths').pack(side="top")
text3 = Entry(root,width = 20)
text3.pack(side = "top", pady = 10)

# Add a button and change color of the button
# Change cursor too, just for fun gumby etc
click = Button(frame,text = "Enter",bg = "darkgreen",fg = "white")
click.pack(side = "left", pady = 10,padx = 20)
#click.bind("<ButtonRelease>",doit)
# To release the button use this line
click.bind("<ButtonRelease>",doit)

clear = Button(frame,text = "Clear")
clear.pack(side = "left",padx = 20)
clear.bind("<ButtonRelease>",clearit)

frame.pack(side = "top")

# pack the buttons in an invisible frame




# text box
text = Text(root)
text.pack(side = "top")
# Use this code to make box expand with maximize
#text.pack(side = "top",fill = "both",expand = 1)

text1.focus_set()
root.mainloop()

peggy walker
Monday, June 14, 2004

*  Recent Topics

*  Fog Creek Home