473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

python: lexical or dynamic scope?

i cant figure outif python has lexical or general scope.

it seems functions have lexical scope but with some restrictions and
some non-function scopes are dynamic?
Jun 27 '08 #1
3 8758
globalrev <sk*******@yahoo.sewrites:
i cant figure outif python has lexical or general scope.

it seems functions have lexical scope but with some restrictions and
some non-function scopes are dynamic?
I can't think of any instance of dynamic scoping in Python. Can you
give an example of what you are thinking of?

AFAIK, Python has lexical scoping, with the restriction that
non-global non-local names cannot be rebound.

--
Arnaud
Jun 27 '08 #2
On May 13, 3:27 pm, globalrev <skanem...@yahoo.sewrote:
i cant figure outif python has lexical or general scope.

it seems functions have lexical scope but with some restrictions and
Yes. (You can't modify a local variable from an inner scope--this
will change in Python 3.0.)
some non-function scopes are dynamic?
No: I presume you mean the class statement, which is the only thing
other than def that introduces a scope in Python, but it's neither
dynamic nor lexical. In fact it's closed: you can only access
variables in a class scope from that scope, and not from enclosed
scopes (e.g., method defintions) at all.
Carl Banks
Jun 27 '08 #3
Arnaud Delobelle <ar*****@googlemail.comwrote:
AFAIK, Python has lexical scoping, with the restriction that
non-global non-local names cannot be rebound.
I believe so.

It's possible to implement (shallow) dynamic binding as a Python context
manager, though it involves a little unpleasantness with sys._getframe
to get hold of the caller's variables. See

http://www.distorted.org.uk/~mdw/hacks/fluid.py

That Python can do this (and fairly simply) speaks well of its
flexibility and dynamic nature.

I don't know how to make it work properly with multi-threading,
unfortunately.

-- [mdw]
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
25
by: mike420 | last post by:
Ladies and Gentlemen, I present to you the final and ultimate proof of Python's brain-damage: As you may remember, flist = for i in range(3)
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
5
by: paolo veronelli | last post by:
I've a vague idea of the differences,I don't know scheme anyway. I'd like to see an example to show what is missing in python about closures and possibly understand if ruby is better in this...
76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
134
by: Joseph Garvin | last post by:
As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.