Easy questions from a python beginner

wheres pythonmonks wherespythonmonks at gmail.com
Sun Jul 11 13:48:05 EDT 2010


I'm an old Perl-hacker, and am trying to Dive in Python.  I have some
easy issues (Python 2.6)
which probably can be answered in two seconds:

1.  Why is it that I cannot use print in booleans??  e.g.:
>>> True and print "It is true!"

I found a nice work-around using eval(compile(.....,"<string>","exec"))...
Seems ugly to this Perl Programmer -- certainly Python has something better?

2.  How can I write a function, "def swap(x,y):..." so that "x = 3; y
= 7; swap(x,y);" given x=7,y=3??
(I want to use Perl's Ref "\" operator, or C's &).
(And if I cannot do this [other than creating an Int class], is this
behavior limited to strings,
 tuples, and numbers)

3.  Why might one want to store "strings" as "objects" in numpy
arrays?  (Maybe they wouldn't)?

4.  Is there a way for me to make some function-definitions explicitly
module-local?
(Actually related to Q3 below: Is there a way to create an anonymous scope?)

5. Is there a way for me to introduce a indention-scoped variables in python?
See for example: http://evanjones.ca/python-pitfall-scope.html

6.  Is there a Python Checker that enforces Strunk and White and is
bad English grammar anti-python?  (Only half joking)
http://www.python.org/dev/peps/pep-0008/

Thanks,
W



More information about the Python-list mailing list