cannot pass a variable from a function
Kirk Strauser
kirk at strauser.com
Wed Jun 16 19:20:05 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-06-16T22:46:42Z, "Doug Jordan" <djordan8 at houston.rr.com> writes:
> #function suppose to return variable
> def fctn2(c):
> for h in c:
> q=h*80
> return q
>
> def prntfctn(y):
> for j in y:
> print j
>
> fctn2(list)
> prntfctn(q)
The name "q" only exists inside the scope of the fctn2 variable. If you
want it present inside the global scope, assign it there:
q = fctn2(list)
prtnfctn(q)
That should do what you want. Note that I'm unaware of any modern
programming language that would allow a function to assign a value to a
global variable without explicitly requesting it. If such a thing exists,
then I highly recommend you avoid it at all costs.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA0NS95sRg+Y0CpvERAlGRAKCkUJTaBJIckaWCvM2qkEmA8BDSEgCaAgcp
u44PX2uPlSMGYAV4VG5jaC8=
=G3qn
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list