Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread ALAN GAULD
> Doesn't short-circuit evaluation refer specifically to the behavior > where arguments are only evaluated if they need to be? It's a very > useful feature, but not technically required for the "val = val or 1" > behavior to work. Its essential. If Python always evaluated all parts of a boole

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread Steven D'Aprano
ALAN GAULD wrote: Doesn't short-circuit evaluation refer specifically to the behavior where arguments are only evaluated if they need to be? It's a very useful feature, but not technically required for the "val = val or 1" behavior to work. Its essential. If Python always evaluated all par

[Tutor] Meaning of -1 in Python

2010-12-10 Thread Ben Ganzfried
I'm currently working through the Google Python tutorial exercises and had questions about the following function: def not_bad(s): # +++your code here+++ # LAB(begin solution) n = s.find('not') b = s.find('bad') if n != -1 and b != -1 and b > n: s = s[:n] + 'good' + s[b+3:] return

Re: [Tutor] Calling Program within Program

2010-12-10 Thread patty
Hello Modulok: The code below is very simple, so I don't think you would have needed to read it. I will review the subprocess doc and look this up in my books and class notes. If I have more questions, I will email the group. I also realized that I wasn't clear in asking a secondary question w

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread Alan Gauld
"Steven D'Aprano" wrote Python knows that if val is true then it doesn't need to evaluate the second term that causes it to return val rather than 1. That's what makes it short circuiting, but that's not why it returns the first argument. `or` in standard Pascal doesn't short-circuit. But

Re: [Tutor] Meaning of -1 in Python

2010-12-10 Thread Alan Gauld
"Ben Ganzfried" wrote n = s.find('not') b = s.find('bad') if n != -1 and b != -1 and b > n: s = s[:n] + 'good' + s[b+3:] return s It's clear that n!=-1 and b!=-1 means something like : "if in the string 's' we find the word "not" and in string 's' we find the word "bad." Exactly the o

[Tutor] the "**" operator?

2010-12-10 Thread Alex Hall
Hi all, I was googling a way to do something like mydict=mydict.extend(additionaldict) and someone on a forum recommends this: mydict=dict(mydict, **additionaldict) What is the ** doing here? I tried to look it up, but Google seems to ignore it since it is punctuation. The poster on the forum says

Re: [Tutor] the "**" operator?

2010-12-10 Thread Joel Goldstick
The value you provide as the second argument must be a dictionary. Google kwargs python for lots of more in depth info On Fri, Dec 10, 2010 at 2:14 PM, Alex Hall wrote: > Hi all, > I was googling a way to do something like > mydict=mydict.extend(additionaldict) > > and someone on a forum recomm

Re: [Tutor] the "**" operator?

2010-12-10 Thread Piotr Kamiński
Dnia 10-12-2010 o 20:14:30 Alex Hall napisał(a): Hi all, I was googling a way to do something like mydict=mydict.extend(additionaldict) and someone on a forum recommends this: mydict=dict(mydict, **additionaldict) What is the ** doing here? As far as I know the ** indicates that the argumen

Re: [Tutor] the "**" operator?

2010-12-10 Thread Hugo Arts
On Fri, Dec 10, 2010 at 8:14 PM, Alex Hall wrote: > Hi all, > I was googling a way to do something like > mydict=mydict.extend(additionaldict) > mydict.update(additionaldict) see also: http://docs.python.org/library/stdtypes.html#dict.update > and someone on a forum recommends this: > mydict=di

[Tutor] Writing to the terminal?

2010-12-10 Thread Modulok
List, Forgive me if I don't describe this well, I'm new to it: Assume I'm working in a command shell on a terminal. Something like tcsh on xterm, for example. I have a program which does *something*. Let's say it counts down from 10. How do I print a value, and then erase that value, replacing it

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Wayne Werner
If you just want a single line you can use chr(13) which is a carriage return. If you want a more complex program you'll need a curses type library hth, wayne On 12/10/10, Modulok wrote: > List, > > Forgive me if I don't describe this well, I'm new to it: > > Assume I'm working in a command shell

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Corey Richardson
On 12/10/2010 3:14 PM, Modulok wrote: List, Forgive me if I don't describe this well, I'm new to it: Assume I'm working in a command shell on a terminal. Something like tcsh on xterm, for example. I have a program which does *something*. Let's say it counts down from 10. How do I print a valu

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Corey Richardson
On 12/10/2010 3:34 PM, Wayne Werner wrote: If you just want a single line you can use chr(13) which is a carriage return. If you want a more complex program you'll need a curses type library hth, wayne On 12/10/10, Modulok wrote: List, Forgive me if I don't describe this well, I'm new to it

[Tutor] 'ascii' codec can't decode byte

2010-12-10 Thread Susana Iraiis Delgado Rodriguez
Hello members: I need your help, I'm developing a python script to make an excel file... I've been working in this for a long time. The module will write some data from a .shp file. Unfortuanely that information has some characters unrecorgnized by ascii. I tried to fix this adding an unicode sent

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Steven D'Aprano
Modulok wrote: List, Forgive me if I don't describe this well, I'm new to it: [snip description of a progress bar] Here's one way: import time, sys f = sys.stdout for i in range(20): time.sleep(1) # do some work f.write('=') f.flush() # make the change visible immediately else:

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Hugo Arts
On Fri, Dec 10, 2010 at 9:38 PM, Corey Richardson wrote: > > Try that in the interactive interpreter, it doesn't work. print "a" + chr(13) > a You forgot to print something after the carriage return. It works for me: Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Typ

[Tutor] Globals as variables in a tkinter widget

2010-12-10 Thread echowit
This code produces a good run. from tkinter import * root = Tk() class Application(Frame): global sv, Ptype, PtypeI, sel_rate_label, label label = Label(root) Ptype = 999 PtypeI = IntVar() W = 5 Y = 4 def sel(self): global W global Y Ptype = P

Re: [Tutor] role playing game - help needed

2010-12-10 Thread ALAN GAULD
Thanks again Alan. Much clearer now. One final part I don't understand. > "%d is the result of %d + %d" % (6+7,6,7) > >I understand (I think) the 6+7 part but why the ,6,7 after that. I could >see how either '6+7' or '6,7' would be the correct format but not both. The format string ha

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Alan Gauld
"Modulok" wrote Assume I'm working in a command shell on a terminal. Something like tcsh on xterm, for example. I have a program which does *something*. Let's say it counts down from 10. How do I print a value, and then erase that value, replacing it with another value? This is one of those

Re: [Tutor] Globals as variables in a tkinter widget

2010-12-10 Thread Alan Gauld
wrote This code produces a good run. Not sure what you mean by that. What is "a good run"? from tkinter import * root = Tk() class Application(Frame): global sv, Ptype, PtypeI, sel_rate_label, label This is bizarre. Globals are generally considered evil and to be avoided if possible.

Re: [Tutor] the "**" operator?

2010-12-10 Thread Alex Hall
Thanks all! I thought update() would add an item even if it would be a duplicate, but apparently not. I also now better understand why I am always passing around *args and **kwargs when calling super(). Very interesting... On 12/10/10, Hugo Arts wrote: > On Fri, Dec 10, 2010 at 8:14 PM, Alex Hall

[Tutor] Code evaluation inside of string fails with __get_item

2010-12-10 Thread Tim Johnson
I'm using Python 2.6.5. The following problem is coming from inside of a complex code base and involves an implementation that I have used for years, and is now failing to execute in certain conditions. This problem occurs with either of the follow two classes, which are 'lifted' from 'Python Cookb

Re: [Tutor] Writing to the terminal?

2010-12-10 Thread Emile van Sebille
On 12/10/2010 12:14 PM Modulok said... List, Forgive me if I don't describe this well, I'm new to it: Assume I'm working in a command shell on a terminal. Something like tcsh on xterm, for example. I have a program which does *something*. Let's say it counts down from 10. How do I print a value

Re: [Tutor] the "**" operator?

2010-12-10 Thread Hugo Arts
On Sat, Dec 11, 2010 at 1:26 AM, Alex Hall wrote: > Thanks all! I thought update() would add an item even if it would be a > duplicate, but apparently not. I also now better understand why I am > always passing around *args and **kwargs when calling super(). Very > interesting... > Actually, it d

Re: [Tutor] Meaning of -1 in Python

2010-12-10 Thread Terry Carroll
On Fri, 10 Dec 2010, Alan Gauld wrote: "Ben Ganzfried" wrote n = s.find('not') b = s.find('bad') if n != -1 and b != -1 and b > n: s = s[:n] + 'good' + s[b+3:] return s It's clear that n!=-1 and b!=-1 means something like : "if in the string 's' we find the word "not" and in string 's

Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread Walter Prins
Hi Steven On 10 December 2010 03:50, Steven D'Aprano wrote: > Some languages (Pascal comes to mind) doesn't have short-circuit behaviour > at all. > Don't mean to nit pick, but in my experience it really depends on the compiler implementation and which version of Pascal you're talking about. Ce

[Tutor] using a networked data file

2010-12-10 Thread Bill Allen
This is somewhat non-Python specific I have an idea for a Python application that I want to write at work. The application needs to have a data file be available to multiple users for access, read and write. I know that a typical database, such as mysql, would work ok. However, I am trying t

[Tutor] Code evaluation inside of string fails with __get_item

2010-12-10 Thread Tim Johnson
This is a resend. I note that the original had an incorrect `reply-to' ID attached to it. (sorry) -- I'm using Python 2.6.5. The following problem is coming from inside of a complex code base and involves an implementation that I have

Re: [Tutor] Tutor Digest, Vol 82, Issue 45, Topic 3, Globals

2010-12-10 Thread echowit
my tutorial. t uses variables in the same way rather than literal values, hat might make it more obvious. Maybe :-) HTH, Alan G. - next part -- n HTML attachment was scrubbed... RL: <http://mail.python.org/pipermail/tutor/attachments/20101210/a7647551/attachment-0001.html