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
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
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
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
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:
>
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
>>
? 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
> 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
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
> 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?
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
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
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
.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.
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
>> 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
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
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
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
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
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!
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
___
22 matches
Mail list logo