Re: is it a bug in exec?
Of cause your code runs well. But if you remove the "global foo" in main(), it will fail. And it will succeed again if you call exec(t1) directly. I think this behavior is strange. Even I pass a shadow copy of globals and locals to exec, it still fails. So perhaps there is a basic difference between exec(t1,dg,dl) and exec(t1,globals(),locals()). What do you think about it? Thanks. On Jan 21, 2:14 am, Steven D'Aprano wrote: > On Thu, 20 Jan 2011 20:52:15 -0800, [email protected] wrote: > > In pyhton 3.1, I found the following code will succeed with argument 1 > > to 4 and fail with argument 5 to 9. It is really strange to me. I > > suspect it may be a buy in exec() function. Does anyone have some idea > > about it? Thanks. > > What makes you think it's a bug? Is there anything in the documentation > of exec that suggests to you that some other behaviour should occur? What > version of Python are you using? > > Without knowing what behaviour you expect and what behaviour you see, how > are we supposed to know if you've found a bug or not? > > I suggest you fire up the interactive interpreter and try this: > > t1 = """ > class foo: > def fun(): > print('foo') > > def main(): > global foo > foo.fun() > > main() > """ > > dg = {} > dl = {} > > exec(t1, dg, dl) > > then inspect the values of dg and dl and see if it helps. If not, write > back with what you expect to happen, and what you see instead. > > -- > Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: is it a bug in exec?
I see now. Thank you so much.
I think namespace is really a confusing part in Python.
On Friday, January 21, 2011 11:00:32 AM UTC-6, Peter Otten wrote:
> There are only two cases that matter: identical local/global namespaces and
> distinct local/global namespaces:
>
> >>> code = """\
> ... x = 42 # put x into the local namespace
> ... def f():
> ... print(x) # look up x in the global namespace
> ... f()
> ... """
> >>> exec(code, {}, {})
> Traceback (most recent call last):
> File "", line 1, in
> File "", line 4, in
> File "", line 3, in f
> NameError: global name 'x' is not defined
> >>> ns = {}
> >>> exec(code, ns, ns)
> 42
>
> Also note that
>
> >>> globals() is locals()
> True
>
> on the module level.
>
> Peter
--
http://mail.python.org/mailman/listinfo/python-list
Conversion: execfile --> exec
The python 2.x command is as following:
---
info = {}
execfile(join('chaco', '__init__.py'), info)
--
But execfile has been removed in python 3.x.
So my problem is how to convert the above to a 3.x based command?
thanks very much
--
https://mail.python.org/mailman/listinfo/python-list
Fwd: Re: How to upgrade python from 2.4.3 to 2.4.4 ?
> Okay if one builds such from sources... but us poor > Windows flunkies > without a build environment have to wait for some > kindly soul to build > the installer compatible with the new Python > version. > especially since I havent got MS visual studio... and mingw is not supported... :-( hello __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Re: How to upgrade python from 2.4.3 to 2.4.4 ?
> > mingw32 is supported and can compile many > extensions. See the following > post: > > http://groups.google.com/group/comp.lang.python/msg/8e2260fe4d4b7de9 > > If you meant something else with your comment, > please explain. > thanks for the reference.. I just got the latest source for python and reading contents in PC, PCbuild, PCbuild8 directories. It would be nice if the windows build was as simple as running ./configure and make... The link for pexports-0.42h.zip is broken so I cant test it on an extension. hello __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: 3d programming without opengl
you might find this interesting... www.ogre3d.org/ and its python wrapper http://www.ogre3d.org/wiki/index.php/PyOgre With /without Hardware acceleration... with /without OpenGL or DirectX... hello Get your email and see which of your friends are online - Right on the New Yahoo.com (http://www.yahoo.com/preview) -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: wxPython 2.7.2.0
Is there a new version of Demo Docs released also? I get this error from Sourceforge after clicking on the link at wxPython page. Could not read file. Go back. /home/ftp/pub/sourceforge//w/wx/wxpython/wxPython2.7-win32-docs-demos-2.7.2.0.exe Nov 08, 2006 07:10 --- Robin Dunn <[EMAIL PROTECTED]> wrote: > Announcing > -- > > The 2.7.2.0 release of wxPython is now available for > download at > http://wxpython.org/download.php. This is expected > to be the last > stepping stone in the path to the next stable > release series, > 2.8.x. We're pushing full speed ahead in order to > get 2.8.0 included > with OSX 10.5, and so far we are very close to being > on schedule. This > release has some house-keeping style changes, as > well as some > user-contributed patches and also the usual crop of > bug fixes. Source > and binaries are available for both Python 2.4 and > 2.5 for Windows and > Mac, as well some pacakges for varous Linux > distributions. A summary > of changes is listed below and also at > http://wxpython.org/recentchanges.php. > > > What is wxPython? > - > > wxPython is a GUI toolkit for the Python programming > language. It > allows Python programmers to create programs with a > robust, highly > functional graphical user interface, simply and > easily. It is > implemented as a Python extension module that wraps > the GUI components > of the popular wxWidgets cross platform library, > which is written in > C++. > > wxPython is a cross-platform toolkit. This means > that the same program > will usually run on multiple platforms without > modifications. > Currently supported platforms are 32-bit Microsoft > Windows, most Linux > or other Unix-like systems using GTK2, and Mac OS X > 10.3+, in most > cases the native widgets are used on each platform. > > > Changes in 2.7.2.0 > -- > > Patch [ 1583183 ] Fixes printing/print preview > inconsistencies > > Add events API to wxHtmlWindow (patch #1504493 by > Francesco Montorsi) > > Added wxTB_RIGHT style for right-aligned toolbars > (Igor Korot) > > Added New Zealand NZST and NZDT timezone support to > wx.DateTime. > > wx.Window.GetAdjustedBestSize is deprecated. In > every conceivable > scenario GetEffectiveMinSize is probably what you > want to use instead. > > wx.Image: Gained support for TGA image file format. > > wx.aui: The classes in the wx.aui module have been > renamed to be more > consistent with each other, and make it easier to > recognize in the > docs and etc. that they belong together. > > FrameManager --> AuiManager > FrameManagerEvent --> AuiManagerEvent > PaneInfo --> AuiPaneInfo > FloatingPane --> AuiFloatingPane > DockArt -->AuiDockArt > TabArt --> AuiTabArt > AuiMultiNotebook --> AuiNotebook > AuiNotebookEvent --> AuiNotebookEvent > > wx.lib.customtreectrl: A patch from Frame Niessink > which adds an > additional style (TR_AUTO_CHECK_PARENT) that > (un)checks a parent when > all children are (un)checked. > > wx.animate.AnimationCtrl fixed to display inactive > bitmap at start > (patch 1590192) > > Patch from Dj Gilcrease adding the > FNB_HIDE_ON_SINGLE_TAB style flag > for wx.lib.flatnotebook. > > wx.Window.GetBestFittingSize has been renamed to > GetEffectiveMinSize. > SetBestFittingSize has been renamed to > SetInitialSize, since it is > most often used only to set the initial (and > minimal) size of a > widget. > > The QuickTime backend for wx.media.MediaCtrl on MS > Windows works > again. Just pass > szBackend=wx.media.MEDIABACKEND_QUICKTIME to the > constructor to use it instead of the default > ActiveMovie backend, > (assuming the quicktime DLLs are available on the > system.) > > -- > Robin Dunn > Software Craftsman > http://wxPython.org Java give you jitters? Relax > with wxPython! > > -- > http://mail.python.org/mailman/listinfo/python-list > hello Sponsored Link Degrees online in as fast as 1 Yr - MBA, Bachelor's, Master's, Associate Click now to apply http://yahoo.degrees.info -- http://mail.python.org/mailman/listinfo/python-list
Need array help
I am switching from microsoft visual basic programming to python programming. In microsoft visual basic you can Dim a variable so that you can add variables by changing the number on the end of the variable as in the following example; Dim acct(100) numoffiles=4 data=10 ct=1 while ct <> numoffiles acctfile(ct) = data ct= ct + 1 data= data + ct Wend The results are; acctfile(1)=10 acctfile(2)=12 acctfile(3)=15 And you can compare the values of the new variables; if acctfile(1) > acctfile(2) then print "yes" if acctfile(2) > acctfile(1) then print "yes" when I try to create acctfile(ct) = data I get the following error; ***can't assign to function call. Then it gives the program line of the problem Here is the progam in python; numoffiles=4 data=10 ct=1 while ct != numoffiles: acctfile(ct) =data ct += 1 data= data + ct print acctfile(ct) Does anybody know how this is done in Python? -- http://mail.python.org/mailman/listinfo/python-list
