why function got dictionary
Hi,
I am seeking an explanation for following:
Python 2.5.2 (r252:60911, Apr 8 2008, 21:49:41)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def g(): return
...
>>> g.__dict__
{}
Q: why function got dictionary? What it is used for?
Thx, Andy
--
http://mail.python.org/mailman/listinfo/python-list
Re: why function got dictionary
Diez B. Roggisch wrote: >> >> Q: why function got dictionary? What it is used for? > > because it is an object, and you can do e.g. > you mean an object in the following sense? >>> isinstance(g,object) True where could I read more about that? Andy -- http://mail.python.org/mailman/listinfo/python-list
why objects of old style classes are instances of 'object'
Hi, Q: from the subject, why objects of old style classes are instances of 'object'? >>> class a():pass >>> A=a() >>> isinstance(A,object) True I would expect False Thx, Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: why objects of old style classes are instances of 'object'
Diez B. Roggisch wrote: But not everything is a newstyle-class: class Foo: pass ... isinstance(Foo, object) True isinstance(Foo, type) False class Bar(object): pass ... isinstance(Bar, type) True thx for explanation. but more I look at it less and less I like the notation of new-style-class definition. what is an added value of adding "(object)" since it is already an object. Any insight? Note: I am not a language purist, more a pragmatic who like a good style. Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Success stories
Cristina Yenyxe González García wrote: 2008/4/23, Reedick, Andrew <[EMAIL PROTECTED]>: IIRC, Python is used in games like Eve Online (SciFi MMO) and Vampire: Bloodlines (RPG.) Years later, a dedicated fan is still fixing/updating the Bloodlines python scripts that control the dialogue and scripted events. Now that you mention it, Python was also used in the Star Wars: Knights of the Old Republic (KotOR) saga. You can even search the scripts across the disc and take a look at hilarious code comments like "this works but I don't know why" :D and Shrek 3 http://www.linuxjournal.com/article/9653 -- a. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Success stories
Bob Woodham wrote: x = x++; has unspecified behaviour in C. what about C++ -- http://mail.python.org/mailman/listinfo/python-list
is +=1 thread safe
Hi,
I have a piece of software which uses threads in very massive way - like
hundreds of them generated every second.
there is also a piece of code which maintains the number of outstanding
threads, simply
counter+=1 is executed when before starting the thread and counter-=1
after it finishes.
all is very simple and by the end of the program life I expect the
counter to zero out.
however I am getting values -1, -2, 1 ,2 ,3 and quite often 0 as expected.
I guarded those statement with Lock.{acquire,release} and now it always
returns 0.
But I still can not believe that +=1 is not a thread safe operation.
Any clue?
--
Andy
--
http://mail.python.org/mailman/listinfo/python-list
Re: is +=1 thread safe
Duncan Booth wrote: [...] is equivalent to: x = x.__iadd__(1) thx all for answers and hints ... Generating hundreds of threads is, BTW, a very good way to get poor performance on any system. Don't do that. Create a few threads and put the actions for those threads into a Queue. If you want the threads to execute in parallel investigate using sub-processes. I know that limitation. However I am bridging to existing software which is hard to be changed. and on powerful machine I have at hand it works quite fast. The threading module already has a function to return the number of Thread objects currently alive. I have threads within threads - so it does not suit me :-(. -- Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: is +=1 thread safe
Alexander Schmolck wrote: AlFire <[EMAIL PROTECTED]> writes: The threading module already has a function to return the number of Thread objects currently alive. I have threads within threads - so it does not suit me :-(. How about using a scalar numpy array? They are mutable, so I assume that x += 1 should be atomic. I ended up with following: counter=[] counter=0 counter.append(None)counter+=1 counter.pop() counter-=1 len(counter)counter A. -- http://mail.python.org/mailman/listinfo/python-list
