[Tutor] enter key

2005-04-04 Thread Diana Hawksworth
I am using the tkinter toolkit.  Just wish to have the button I have formedreplaced by the Enter key - if possible.  Would the raw_input() work, asBernard has suggested, or do I need another piece of code that refers to theEnter key?Thanks. Diana- Original Message - From: "Kent John

Re: [Tutor] one line code

2005-04-04 Thread C Smith
From: "Alan Gauld" <[EMAIL PROTECTED]> With other words I'd like to tell Python: Convert into a float if possible, otherwise append anyway. [ (type(x) == type(5) and float(x) or x) for x in mylist ] This is a perfect opportunity to give the reminder that the conversion functions are also types tha

Re: [Tutor] Operator Overloading

2005-04-04 Thread Kevin Reeder
On Tue, 05 Apr 2005 10:56:40 +1200 (NZST) [EMAIL PROTECTED] wrote: > Fine, but always test the simplified version, unless you're > absolutely certain what you're throwing out! Point taken. > When you do 'A + [4, 5, 6]', python first calls > A.__getattr__('__coerce__'). Everything's working fine

Re: [Tutor] What is the best book to start? - Many Thanks!

2005-04-04 Thread Hoffmann
Hi John, Certainly, I will check it out. Many thanks! Hoffmann --- John Carmona <[EMAIL PROTECTED]> wrote: > Dear Hoffmann, I am also a Newbie and I am currently > going through "A Byte > of Python" tutorial from Swaroop C H. > > http://www.byteofpython.info/download?PHPSESSID=c0d52343d90f69f25

Re: [Tutor] [HELP]how to test properties of a file

2005-04-04 Thread Shidai Liu
On Apr 4, 2005 10:54 PM, Nick Lunt <[EMAIL PROTECTED]> wrote: > I've gotten into the habit of just using the os.?_OK stuff. > > eg > > >>> import os > >>> os.access('/', os.W_OK) > False > >>> os.access('/tmp', os.W_OK) > True > > Thats gotta be simple if I understand it lol :) > > Nick . > I

Re: [Tutor] [HELP]how to test properties of a file

2005-04-04 Thread Shidai Liu
On Apr 4, 2005 10:43 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Its not really the simplest, its not efficient and it might be > dangerous > if the file is not empty. At the very least open using 'a' to avoid > obliterating the file!! > > However the os.stat function and stat module do what yo

Re: [Tutor] Operator Overloading

2005-04-04 Thread jfouhy
Quoting Kevin Reeder <[EMAIL PROTECTED]>: > On Mon, 04 Apr 2005 21:14:21 +1200 > John Fouhy <[EMAIL PROTECTED]> wrote: > > Are you sure you've giving us all the code? > No, I was trying to keep it simple. Anyway, here it is, Fine, but always test the simplified version, unless you're absolutely c

Re: [Tutor] one line code

2005-04-04 Thread Liam Clarke
[(eval(compile('exec """try:t=float("%s")\nexcept:t="%s" """ in globals(),locals()'%(s,s),'','exec')),t)[1] for s in l] Now that's ugly. On Apr 5, 2005 9:51 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > With other words I'd like to tell Python: Convert into a float if > > possible, otherwise ap

Re: [Tutor] Re: building strings of specific length

2005-04-04 Thread jfouhy
Quoting Andrei <[EMAIL PROTECTED]>: > You could do (I'll use 20 instead of 72 to keep it readable): > > >>> s = "%20s" % "xyz" > >>> len(s), s > (20, ' xyz') > > or: > > >>> s = "xyz" > >>> s = s + (20 - len(s)) * ' ' > >>> s, len(s) > ('xyz ', 20) Just a comment --- You can do the second exa

Re: [Tutor] [HELP]how to test properties of a file

2005-04-04 Thread Nick Lunt
I've gotten into the habit of just using the os.?_OK stuff. eg >>> import os >>> os.access('/', os.W_OK) False >>> os.access('/tmp', os.W_OK) True Thats gotta be simple if I understand it lol :) Nick . Alan Gauld wrote: The simplest, IMHO, is : try: f = file(filename, "w") [...] except IOError:

Re: [Tutor] one line code

2005-04-04 Thread Alan Gauld
> With other words I'd like to tell Python: Convert into a float if > possible, otherwise append anyway. [ (type(x) == type(5) and float(x) or x) for x in mylist ] Should do it... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org

Re: [Tutor] [HELP]how to test properties of a file

2005-04-04 Thread Alan Gauld
> The simplest, IMHO, is : > > try: >f = file(filename, "w") >[...] > except IOError: >print "The file is not writable" > > Of course, not that this method empty the file if it is writable ! The > best is to just put your IO code in such a try block ... That way, > you're sure the file

Re: [Tutor] using the enter key

2005-04-04 Thread Kent Johnson
Diana Hawksworth wrote: > At the moment I have some user input tied to a button that allows the input to be "submitted" and then an answer is supplied. How can I get rid of this submit button, and have the user just press the "enter" key and have the same result happen? How is the user interfac

Re: [Tutor] Re: If elif not working in comparison

2005-04-04 Thread Kent Johnson
gerardo arnaez wrote: Hi all. I would like to post the very small py files I have written while doing this. Would anyone object. I think at most there be 20 lines of code all the files put together. I woul dlike to hear some crituqe on them That's no problem, for 20 lines just put it in the body o

[Tutor] using the enter key

2005-04-04 Thread Diana Hawksworth
Hello list!   At the moment I have some user input tied to a button that allows the input to be "submitted" and then an answer is supplied.  How can I get rid of this submit button, and have the user just press the "enter" key and have the same result happen?   TIA.  Diana ___

Re: [Tutor] Re: If elif not working in comparison

2005-04-04 Thread gerardo arnaez
Hi all. I would like to post the very small py files I have written while doing this. Would anyone object. I think at most there be 20 lines of code all the files put together. I woul dlike to hear some crituqe on them Thanks On Apr 4, 2005 11:08 AM, Christopher Smith <[EMAIL PROTECTED]> wrote: >

Re: [Tutor] building strings of specific length

2005-04-04 Thread Mike Hall
You can chop off anything past 72 characters with: s2 = s[:72] On Apr 4, 2005, at 7:04 AM, Vines, John (Civ, ARL/CISD) wrote: Hello. I have a question regarding strings. How do I format a string to be a specific length? For example I need 'string1' to be 72 characters long. Thanks for your time,

Re: [Tutor] building strings of specific length

2005-04-04 Thread Max Noel
On Apr 4, 2005, at 16:04, Vines, John (Civ, ARL/CISD) wrote: Hello. I have a question regarding strings. How do I format a string to be a specific length? For example I need 'string1' to be 72 characters long. Thanks for your time, John You can use the string methods ljust, rjust and zfill:

Re: [Tutor] Launching a file browser

2005-04-04 Thread Mike Hall
On Apr 1, 2005, at 4:12 PM, Jeff Shannon wrote: At the OS level, these two actions are *completely* different. The webbrowser module launches an entirely separate program in its own independent process, where the "file browser" is opening a standard dialog inside of the current process and depende

[Tutor] Re: building strings of specific length

2005-04-04 Thread Andrei
Vines, John (Civ, ARL/CISD) wrote on Mon, 4 Apr 2005 10:04:59 -0400: > Hello. I have a question regarding strings. How do I format a string to be a > specific length? > For example I need 'string1' to be 72 characters long. You could do (I'll use 20 instead of 72 to keep it readable): >>> s =

[Tutor] building strings of specific length

2005-04-04 Thread Vines, John (Civ, ARL/CISD)
Hello. I have a question regarding strings. How do I format a string to be a specific length? For example I need 'string1' to be 72 characters long. Thanks for your time, John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/li

Re: [Tutor] Re: If elif not working in comparison

2005-04-04 Thread Christopher Smith
On Monday, Apr 4, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: Would I used an if else: construction to determine where the INR value lay and decide what precentage to increase it by? Yes, that seems to be the right way to do that. The caveat is that when you are using boolean tests

[Tutor] Re: one line code

2005-04-04 Thread Andrei
Christian Meesters wrote on Mon, 4 Apr 2005 14:49:28 +0200: > Could it be that a C-like solution with > '?' and ':' is more straightforward than a solution with Python or am I > just too blind to see a real pythonic solution here? Pierre did the Python equivalent of the ternary operator in his

Re: [Tutor] Operator Overloading

2005-04-04 Thread Kevin Reeder
On Mon, 04 Apr 2005 21:14:21 +1200 John Fouhy <[EMAIL PROTECTED]> wrote: > Are you sure you've giving us all the code? No, I was trying to keep it simple. Anyway, here it is, class MyList: def __init__(self, start): self.wrapped = [ ] for x in start: self.wrapped.append(x)

Re: [Tutor] one line code

2005-04-04 Thread Pierre Barbier de Reuille
Mmmhhh ... not strictly one line but ... import re float_str = re.compile(r"^\s*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$") val = [ ( (float_str.match(s) and [float(s)]) or [s])[0] for s in l2 ] It's not really "readable" but well ... it works ^_^ Pierre Christian Meesters a écrit : Hi Yesterday

[Tutor] Re: one line code

2005-04-04 Thread Wolfram Kraus
Christian Meesters wrote: Hi Yesterday night I was thinking about the following problem: I do have a list like l = ['1','2','3','abc','','4'] - for instance like a list one could get from a file import with the csv module (which is where my 'problem' comes from). Now I would like to generate the fo

[Tutor] one line code

2005-04-04 Thread Christian Meesters
Hi Yesterday night I was thinking about the following problem: I do have a list like l = ['1','2','3','abc','','4'] - for instance like a list one could get from a file import with the csv module (which is where my 'problem' comes from). Now I would like to generate the following list, preferabl

Re: [Tutor] Operator Overloading

2005-04-04 Thread John Fouhy
Kevin Reeder wrote: This is not my code but is taken from the book I'm working with. My problem is that whenever I call to the __add__ method the counters increase by 2 while calls the __len__ method increase the counters by 1 as expected. Well, I can't duplicate your results.. I get the behaviou