Re: [Tutor] Graphics with Python: wxPython vs. tkinter vs., PyCairo vs. PyX vs...
There is also PyQt4 which is my favorite. I'm a beginner in programming I tryed first PyQt and I gave up because it seemed so complicated. Then I've played a litle with tkinter which I think is very poor. I moved to wxpython which as a learning curve similar to that of tkinter, but a wider set of widgets available. Then o tryed again PyQt and it wasn't complicated anymore! PyQt as a even wider set of wigets than wxpy but the BIG advantage is QtDesigner which you can use to design your interfaces and then you only have to code the methods to the actions you want the widgets to perform. Good luck Paulino > Date: Wed, 17 Jan 2007 14:09:57 -0600 > From: "Vijay Pattisapu" <[EMAIL PROTECTED]> > Subject: [Tutor] Graphics with Python: wxPython vs. tkinter vs. > PyCairo vs. PyX vs... > To: tutor@python.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Hey friends-- > > I've been looking through the archives and haven't found any > comparative evaluation of Python graphics libraries... > > Which is the best (or your favorite), and for what tasks? > > Thanks a lot! > Vijay > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Division doesn't work
Hi all, In my script I want to convert 14105 bytes to kilobytes and and this is what I do: >>> s = 14105 >>> print '%0.2f' % (s/1024) 13.00 This not correct and I don't know why. The answer is 13.77. Any pointers please that would help my in the right direction? Thanks Johan -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16 04:36 PM ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Division doesn't work
You assign s as an integer... it should be a float to get the right result... So either define s as s = 14105.0 or as s = float(14105) it'll then result in the right answer : In [17]: s=14105.0 In [18]: s/1024 Out[18]: 13.7744140625 In [19]: s = float(14105) In [20]: s/1024 Out[20]: 13.7744140625 HTH - Geofram On 1/18/07, Johan Geldenhuys <[EMAIL PROTECTED]> wrote: Hi all, In my script I want to convert 14105 bytes to kilobytes and and this is what I do: >>> s = 14105 >>> print '%0.2f' % (s/1024) 13.00 This not correct and I don't know why. The answer is 13.77. Any pointers please that would help my in the right direction? Thanks Johan -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16 04:36 PM ___ 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] Division doesn't work
Or actually an even easier way is to just to divide bij a float and the end result will also be a float. So in your case divide bij 1024.0 ;-) In [21]: s=14105 In [22]: s/1024.0 Out[22]: 13.7744140625 HTH - Geofram On 1/18/07, Geoframer <[EMAIL PROTECTED]> wrote: You assign s as an integer... it should be a float to get the right result... So either define s as s = 14105.0 or as s = float(14105) it'll then result in the right answer : In [17]: s=14105.0 In [18]: s/1024 Out[18]: 13.7744140625 In [19]: s = float(14105) In [20]: s/1024 Out[20]: 13.7744140625 HTH - Geofram On 1/18/07, Johan Geldenhuys <[EMAIL PROTECTED]> wrote: > Hi all, > > In my script I want to convert 14105 bytes to kilobytes and and this is > what I do: > > >>> s = 14105 > >>> print '%0.2f' % (s/1024) > 13.00 > > This not correct and I don't know why. The answer is 13.77. > > Any pointers please that would help my in the right direction? > > Thanks > > Johan > > -- > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: > 2007/01/16 04:36 PM > > ___ > 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] Division doesn't work
Thanks at lot. Something as simple as that... J _ From: Geoframer [mailto:[EMAIL PROTECTED] Sent: 18 January 2007 02:10 PM To: Johan Geldenhuys Cc: tutor@python.org Subject: Re: [Tutor] Division doesn't work You assign s as an integer... it should be a float to get the right result... So either define s as s = 14105.0 or as s = float(14105) it'll then result in the right answer : In [17]: s=14105.0 In [18]: s/1024 Out[18]: 13.7744140625 In [19]: s = float(14105) In [20]: s/1024 Out[20]: 13.7744140625 HTH - Geofram On 1/18/07, Johan Geldenhuys mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]> wrote: Hi all, In my script I want to convert 14105 bytes to kilobytes and and this is what I do: >>> s = 14105 >>> print '%0.2f' % (s/1024) 13.00 This not correct and I don't know why. The answer is 13.77. Any pointers please that would help my in the right direction? Thanks Johan -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16 04:36 PM ___ Tutor maillist - HYPERLINK "mailto:Tutor@python.org"Tutor@python.org HYPERLINK "http://mail.python.org/mailman/listinfo/tutor"; \nhttp://mail.python.org/mailman/listinfo/tutor -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16 04:36 PM -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16 04:36 PM ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Redirect from a CGI script
How can i redirect to another URL from a python CGI script. Is's suposed to be as simply as: print "Location : http://newurl " It's not working. this simple code does't work - 'print "Content-Type:text/html\n\n" 'print "Location : /cgi-bin/ecodiv.pyw " 'print I use CGIHTTPServer, the server script is as follows: 'from BaseHTTPServer import HTTPServer 'from CGIHTTPServer import CGIHTTPRequestHandler 'HTTPServer(("localhost", 80), CGIHTTPRequestHandler).serve_forever() instead of redirecting, it only prints 'Location : /cgi-bin/ecodiv.pyw' inthe browser Paulino ___ O SAPO já está livre de vírus com a Panda Software, fique você também! Clique em: http://antivirus.sapo.pt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Redirect from a CGI script
2007/1/18, Paulino <[EMAIL PROTECTED]>: How can i redirect to another URL from a python CGI script. Is's suposed to be as simply as: print "Location : http://newurl " It's not working. this simple code does't work - 'print "Content-Type:text/html\n\n" 'print "Location : /cgi-bin/ecodiv.pyw " 'print I use CGIHTTPServer, the server script is as follows: 'from BaseHTTPServer import HTTPServer 'from CGIHTTPServer import CGIHTTPRequestHandler 'HTTPServer(("localhost", 80), CGIHTTPRequestHandler).serve_forever() instead of redirecting, it only prints 'Location : /cgi-bin/ecodiv.pyw' inthe browser I haven't tested it, but I think I had a similar error recently, and that was solved by removing the \n\n at the end of the Content-Type line. You could try that. -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Division doesn't work
Johan Geldenhuys wrote: > Hi all, > > In my script I want to convert 14105 bytes to kilobytes and and this is > what I do: > >> >> s = 14105 >> >> print '%0.2f' % (s/1024) > 13.00 > > This not correct and I don't know why. The answer is 13.77. > > Any pointers please that would help my in the right direction? As well as the solutions Geofram has given, you can change the behaviour of addition like this: In [2]: from __future__ import division In [3]: 14105/1024 Out[3]: 13.7744140625 Then the old-style integer division is done with //: In [4]: 14105//1024 Out[4]: 13 More info here: http://www.python.org/doc/2.2.3/whatsnew/node7.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Redirect from a CGI script
Paulino wrote: > How can i redirect to another URL from a python CGI script. > > Is's suposed to be as simply as: > > print "Location : http://newurl " > It's not working. > > this simple code does't work - > 'print "Content-Type:text/html\n\n" Try it without the two extra newlines. A blank line in the output signals the end of the HTTP headers and the start of the content, so the following line is considered part of the content and is displayed by the browser. Kent > 'print "Location : /cgi-bin/ecodiv.pyw " > 'print > > I use CGIHTTPServer, the server script is as follows: > > 'from BaseHTTPServer import HTTPServer > 'from CGIHTTPServer import CGIHTTPRequestHandler > 'HTTPServer(("localhost", 80), CGIHTTPRequestHandler).serve_forever() > > instead of redirecting, it only prints 'Location : /cgi-bin/ecodiv.pyw' inthe > browser > > Paulino > > > ___ > > O SAPO já está livre de vírus com a Panda Software, fique você também! > Clique em: http://antivirus.sapo.pt > > ___ > 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] Division doesn't work
On Thu, 18 Jan 2007 13:09:48 +0100, Geoframer <[EMAIL PROTECTED]> wrote: >You assign s as an integer... it should be a float to get the right >result... <...> Yes, that is the wordt defect of Python: its inability to read programmer mind and detect the rteal programmer intentions. Zara ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Division doesn't work
On Thu, 18 Jan 2007, Johan Geldenhuys wrote: > Thanks at lot. Something as simple as that... No, don't feel bad about it: integer division is a bad "gotcha!" in Python. Integer division is known to be suprising, and it'll eventually be replaced by true division in Python 3: http://www.python.org/dev/peps/pep-0238/ Till then, just tread more careful when using division. (But you knew division was wacky anyway... *grin*) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginners
> I dont have any programming background, i know only c language. you say you don't have any programming experience but that you know C... i'm not sure what you mean by that. how many years have you been using C? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Perfect Python web stack?
Hi, Check the thread in the archive. This has been discussed recently. I have been exploring Django, and since I don't want to go into SQL now, I like it. It generates DB code from your model and you don't have to do SQL. It helps to do your app FAST! But that's just my opinion. Hugo OkaMthembo wrote: > Please help me to decide. I might have asked some of you before, so > please bear with me. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Correct Way to Start a Python Program Under Linux
Hi, Please help I'm at my wits end... My program comprises of 2 modules and runs a gui written in pygtk2, I have at the beginning of each: #!/bin/env python I made it executable (chmod a+x) I can run them from a terminal window like $ /path/to/file.py this works fine and dandy no probs at all but ultimately I want to share this program and I want people to launch the program directly from a menu and not a shell. now if I create a file launcher on the task bar that points directly to the same file it runs and seems to be ok except.. my program uses subprocess.Popen({command string}, etc) and these calls to Popen do not work, only if I run the program from a shell window. So am I doing something wrong please tell me? I have spent hours and hours debugging and changing the code in different ways and always the same, I cannot get a subprocess to spawn into another process unless I run the program from a shell window ,please help! Wayne. ___ What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship. http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Variables of Variables
Hi Everybody, Is there a way to do variables of variables in python. For example in perl: $foo = 'bar' $$foo = '5' and $bar will have a value of 5. I have been search high and low for a simple way to do this in python? -Thanks, Tino ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variables of Variables
On 19/01/07, Tino Dai <[EMAIL PROTECTED]> wrote: > Hi Everybody, > > Is there a way to do variables of variables in python. For example in > perl: > > $foo = 'bar' > $$foo = '5' > > and $bar will have a value of 5. I have been search high and low for a > simple way to do this in python? In the context of objects, you can do this with setattr() and getattr(). eg: >>> class MyClass(object): ... pass ... >>> m = MyClass() >>> m.a = 3 >>> getattr(m, 'a') 3 >>> m.b Traceback (most recent call last): File "", line 1, in ? AttributeError: 'MyClass' object has no attribute 'b' >>> setattr(m, 'b', 7) >>> m.b 7 >>> delattr(m, 'b') >>> m.b Traceback (most recent call last): File "", line 1, in ? AttributeError: 'MyClass' object has no attribute 'b' Obviously, anywhere you see a string in that example, you could substitute a variable with a string value. You can't do this if you aren't working with objects. (well, maybe you could if you used some black magic.. but you should generally avoid that) However, the other question you should ask yourself is: should you be using a dictionary instead? Rather than storing your data as variables, you could store it in a dictionary. Then you can dynamically access data however you like.. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variables of Variables
> Rather than storing your data as variables, you could store it in a > dictionary. Then you can dynamically access data however you like.. Suggesting a dictionary here is right. The technique in the original poster's question is deprecated and widely known to be a Bad Idea in Perl. See Mark Jason Dominus's "Why it's stupid to use a variable as a variable name': http://perl.plover.com/varvarname.html So trying to simulate soft references in Python is damaging: we should do what we can to keep the idea from propagating. *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Perfect Python web stack?
"OkaMthembo" <[EMAIL PROTECTED]> wrote > Please help me to decide. I might have asked some > of you before, so please bear with me. > > I want to build a database driven python web app > and i need to decide, so please vote on the best > components "Best" will depend on many things. For the database itself that would be including things like: 1) How busy the site will be - transaction volumes 2) Your past experience 3) Your development environment 4) The sophistication of your queries 5) The variety of your data types 6) Your need for other access to the database - eg MIS reporting packages, backup facilities, client-server access etc > 1) MySQL vs PostGRES Postgres gets better write ups from database afficianados but MySql has a big following. Personally I use either sqlite for small jobs or Interbase (aka FireBird as freeware) for more complex jobs. > 2) Lighttpd + FastCGI vs Apache + mod_python No experience of any of these. Lighttpd looks interesting though. > 3) Pylons + Cheetah + Kid/Mochikit/Dojo vs Django/Turbogears Don't know Pylons but Cheetah/Kid/Mochikit are all part of TurboGears which i am using and so far finding quite easy and intuitive. I chose TurboGears over Django primarily because I like its modular "best of breed" approach and on my initial look I preferred the style of the Kid templates to the Django ones... No expert, but HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Perfect Python web stack?
"Dave Kuhlman" <[EMAIL PROTECTED]> wrote > I'm currently learning Pylons. The tutorials for Pylons discuss > two object-relational mappers for Python: SQLObject and SQLAlchemy. > If you want to view your database from a higher, more abstract > level, you might want to look at them, too. FWIW. Both of these are standard in TurboGears too. SQL Alchemy seems to get the expert users vote. SQLObjects seems to be older and works OK for the simple stuff I've been playing with so far. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Telepathic Python (was: Division doesn't work)
> -Original Message- > Date: Thu, 18 Jan 2007 14:16:07 +0100 > From: Zara <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Division doesn't work > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=us-ascii > > On Thu, 18 Jan 2007 13:09:48 +0100, Geoframer <[EMAIL PROTECTED]> > wrote: > > >You assign s as an integer... it should be a float to get the right > >result... > <...> > > > Yes, that is the wordt defect of Python: its inability to read > programmer mind and detect the rteal programmer intentions. > > > Zara Hi, Zara. All programming languages seem to share that drawback, as do all computing machines. They always do exactly what we tell them to do, instead of what we want to do. Drat! Regards, Barry [EMAIL PROTECTED] 541-302-1107 We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is a mixin class?
"Don Taylor" <[EMAIL PROTECTED]> wrote >I have a vague idea what a mixin class is, I would like to get a >better > handle on it. The mixin style of OOP comes from the old (1970's vintage) Flavors version of Lisp. In Flavors the metaphor was to start with the Vanilla flavor and mix-in other flavours as you needed. In Flavors it was common to define lots of small abstract classes (mixins) and then the application xclass would inherit from as many mixins as needed. I have seen classes with as many as 30 or more mixins and absolutely no methods of their own, they were all inherited. For this style to work well requires that mixins are type neutral. Or more specifically they use "Duck Typing", or are protocol based. That makes languages like Python natural homes for mixins. Although mixins can inherit from other base classes it is traditional that they stand alone so that thee is no risk of double inheritance of a base class and subsequent confusion in the class dispatch table. Mixins are particularly uiseful as a way to add common functionality to groups of classes that are otherwise not related in a type heirarchy. Error or Security logging is a common application where you can simply create logging versions of non logging classes by defining the logging version to inherit from the original class and the logging mixin. Once that is done you can use the new class exactly like the old one and get logging without having to write any new code. The downside is that the heavy use of mixins can be confusing to debug, introduce unexpected side effects, introduce unexpected dependency loops and spread bugs across lots of classes - making them hard to pin down... > I guess that because of multiple inheritance Python does not need a > formal way of specifying mixin classes so I presume that there is > some > conventional interpretation/coding that is followed for mixin > classes. The original mixins were simply abstract classes in Lisp. Modern languages wishing to use the concept sometimes add explicit support for mixin type classes, or more usually just rely on conventions - such as expecting them to be pure abstract classes. > So, what constitutes a mixin class and what are the conventional > ways to > denote them in code? Normally I just mention that its intended as a mixin in the doc string. Mixin programming is really more a style of OO programming using multiple inheritance rather than anything special about the classes themselves. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Correct Way to Start a Python Program Under Linux
<[EMAIL PROTECTED]> wrote > I can run them from a terminal window like > > $ /path/to/file.py > > this works fine and dandy no probs at all but ultimately I want to > share this program and I want people to launch the program directly > from a menu and not a shell. That should be straightforward too. > now if I create a file launcher on the task bar that points directly > to > the same file it runs and seems to be ok except.. I'm not sure what you mean by a filelauncher. In my window manager I just add the file path to my menu by editing a dialog box or config file. which environment are you using? > my program uses subprocess.Popen({command string}, etc) > and these calls to Popen do not work, only if I run the program from > a > shell window. How do you know it doesn't work? Do you get an error or just silence? If you launch a program that writes to stdout then you had better be sure it has a stdout to write to! Are you sure its not just dumping its output to /dev/null? OTOH it could also be that the import path is not set correctly(try checking your PYTHONPATH environment variable) Can you give us a bit more info about what you mean by the statement that it doesn't work? > So am I doing something wrong please tell me? It sounds like it should be OK, but we need a bit more info as above... As a check try writing a very simple program with no external dependencies and see if it works... -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor