[Tutor] Fwd: iterating

2007-04-30 Thread Cecilia Alm
to adding or deleting keys (rather than changing the value associated with the key). -- E. Cecilia Alm Graduate student, Dept. of Linguistics, UIUC Office: 2013 Beckman Institute -- E. Cecilia Alm Graduate student, Dept. of Linguistics, UIUC Office: 2013 Beckm

[Tutor] iterating

2007-04-30 Thread Cecilia Alm
1) Unordered maps/collections like sets and dictionaries also seem to support iterating over set members or dictionary keys with "for x in y" syntax. As far as I can tell, the following three ways generally behave the same way, or is there a difference in behavior between: a) for key in dictionary

Re: [Tutor] No return statement

2007-04-24 Thread Cecilia Alm
ep it. > > 2007/4/24, Cecilia Alm <[EMAIL PROTECTED]>: > > My apologies for asking a trivial question about programming practice. > > > > As mentioned in the online tutorial > > (http://docs.python.org/tut/node6.html#SECTION00670), > > function

[Tutor] No return statement

2007-04-24 Thread Cecilia Alm
My apologies for asking a trivial question about programming practice. As mentioned in the online tutorial (http://docs.python.org/tut/node6.html#SECTION00670), functions which lack a return statement ('procedures') actually return "None". For such functions, I assume it's preferre

Re: [Tutor] An identity question

2007-04-22 Thread Cecilia Alm
foo3() >>> b = foo3() >>> a is b False >>> a[0] is b[0] True >>> a[0] = 100 >>> a[0] is b[0] False >>> a [100, 321321, 432432] >>> b [232131, 321321, 432432] 2007/4/22, Kent Johnson <[EMAIL PROTECTED]>: > Cecilia Alm wrote: >

[Tutor] An identity question

2007-04-22 Thread Cecilia Alm
The differences in cases 1 and 3 vs. 2 is due to 'common values' of name assignments being treated a bit differently, right? Also, it's clear why case 5 evaluates to false. But, why does the case 4 equality check evaluate to True, whereas case 1 and 3 don't? case 1: >>> a = 1 >>> b = 1 >>

Re: [Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
? However, for example for a global integer counter, the name would need to be defined in the local name space, as shown by Andreas' previous example. 2007/4/15, Alan Gauld <[EMAIL PROTECTED]>: > "Cecilia Alm" <[EMAIL PROTECTED]> wrote > > > Hm, I'm confu

Re: [Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
> difficult to understand, but sometimes it is useful. For example you > might have a shared configuration module, or a module might have > configuration parameters that can be changed. Yes, this is exactly the case I got. (Otherwise, I'd rather avoid "globals" all together.) Thanks for your resp

Re: [Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
x27;global' in this context which causes misunderstanding?) 2007/4/15, Andreas Kostyrka <[EMAIL PROTECTED]>: > * Cecilia Alm <[EMAIL PROTECTED]> [070415 23:19]: > > 2007/4/15, Andreas Kostyrka <[EMAIL PROTECTED]>: > > >* Cecilia Alm <[EMAIL PROTECTED]> [07

Re: [Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
> attributes of the module object. When you import the module in another > module, you gain access to the imported module's attributes using the > normal dot notation for attribute access. By " attribute access", you also mean modifying/assigning to, right?

Re: [Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
2007/4/15, Andreas Kostyrka <[EMAIL PROTECTED]>: > * Cecilia Alm <[EMAIL PROTECTED]> [070415 18:21]: > > If a module "x" imports module "y" with a global variable "z", then > > this global can be referred or assigned to in "x" wi

[Tutor] imported module/global

2007-04-15 Thread Cecilia Alm
If a module "x" imports module "y" with a global variable "z", then this global can be referred or assigned to in "x" with the syntax "y.z" (no "global" keyword preceding) and changes are accessible to class methods in "y" referring to "global z". I assume this is related to namespace/scope? Than

[Tutor] No need to seed random?

2007-03-24 Thread Cecilia Alm
After importing random, there is no need to call random.seed() in a python program, is there? (unless one wishes to specifically control what the seed is.) Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] executing a string representing python code

2007-03-06 Thread Cecilia Alm
.rd.yahoo.com/mail/uk/taglines/default/nowyoucan/spamguard/*http://us.rd.yahoo.com/evt=40565/*http://uk.docs.yahoo.com/nowyoucan.html>– Tired of unwanted email come-ons? Let our SpamGuard protect you. -- E. Cecilia Alm Graduate student, Dept.

Re: [Tutor] executing a string representing python code

2007-03-06 Thread Cecilia Alm
oo.com/evt=40565/*http://uk.docs.yahoo.com/nowyoucan.html>goes wherever you go - free your email address from your Internet provider. -- E. Cecilia Alm Graduate student, Dept. of Linguistics, UIUC Office: 2013 Beckman Institute ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] executing a string representing python code

2007-03-05 Thread Cecilia Alm
>> f = locals()["some_func"] >> print f("wasn't that cool!") There should be no need for this trickery. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld

[Tutor] Fwd: executing a string representing python code

2007-03-05 Thread Cecilia Alm
ou exec the str, it will create a function object, and then you can obtain the object by accessing the object by kwd in the locals() dictionary. Guess it's not really magic, but I think it is still pretty cool ;) There also several variations to this method, but this is the most readable IM

[Tutor] executing a string representing python code

2007-03-02 Thread Cecilia Alm
I know that there are several ways to execute a string which represents a piece of python code. Out of curiosity, is it only eval which returns a value? (as below, where the string corresponds to a defined function). def addone(val): ... return val + 1 ... res = eval('addone(10)') Thanks

[Tutor] Two sys.exit questions

2007-02-28 Thread Cecilia Alm
I have two quick questions: 1) Why does sys.exit() not work in a try clause (but it does in the except clause)? try: ...print 1 ...sys.exit(0) ... except: ...print 2 ...sys.exit(0) ... 1 2 # python exited 2) If opening a file fails in the below 2 cases, sys.exit(message) print

[Tutor] Follow-up Qs: Re: Identity operator (basic types)

2007-02-11 Thread Cecilia Alm
Thanks for the respones. A few follow-up questions: For these basic types (float, integer, string, char, bool) does python always figure out the identity change when assigning a 'new value', as it seems to do below? i = "hi" j = i print i, j, id(i), id(j) hi hi 12235136 12235136 j += i print

[Tutor] Identity operator (basic types)

2007-02-09 Thread Cecilia Alm
Why does the identity operator return "True" in the below cases, that is when assigning the same value to basic variable types (float, integer, string, bool..)? Are these rcopied by reference (shallow)? If so why? i = 10 j = 10 i is j True a = 10 b = a a is b True Thanks!

[Tutor] IDLE: configuration

2006-05-22 Thread Cecilia Alm
Hi, How can I set tab as default indendation for the file editor window in IDLE? I tried to change this in "Configuration Window" and "Apply", but still get 4 spaces. What does work is setting indentation to "8" and then enabling toggle tabs when I open a new window. Thanks, Cecilia ___