Re: How can a module know the module that imported it?
so: # moduleA.py import moduleB # moduleB.py import sys stuff = sys._getframe(1).f_locals print stuff Prints: {'__builtins__': module '__builtin__' (built-in), '__file__': 'C:\\Documents and Settings\\userName\\My Documents\ \python\\moduleA.py', '__name__': '__main__', '__doc__': None} Looks like you could query stuff['__file__'] to pull what you're after. ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can a module know the module that imported it?
On Nov 12, 10:10 am, Ethan Furman et...@stoneleaf.us wrote: AK Eric wrote: so: # moduleA.py import moduleB # moduleB.py import sys stuff = sys._getframe(1).f_locals print stuff Prints: {'__builtins__': module '__builtin__' (built-in), '__file__': 'C:\\Documents and Settings\\userName\\My Documents\ \python\\moduleA.py', '__name__': '__main__', '__doc__': None} Looks like you could query stuff['__file__'] to pull what you're after. ? The leading _ in _getframe indicates a private function to sys (aka implementation detail); in other words, something that could easily change between one Python version and the next. I'm using the inspect module (for the moment, at least), and my question boils down to: Will it work correctly on all versions of Python in the 2.x range? 3.x range? Good point, I totally missed that. Someone had passed that solution to me at one point and I was so excited I kind of looked that over :P -- http://mail.python.org/mailman/listinfo/python-list
Re: Does turtle graphics have the wrong associations?
On Nov 12, 11:31 am, Terry Reedy tjre...@udel.edu wrote: Alf P. Steinbach wrote: One reaction to url: url: http://preview.tinyurl.com/ProgrammingBookP3 has been that turtle graphics may be off-putting to some readers because it is associated with children's learning. What do you think? I just started using the module for simple plots. I am not a child. You cannot please everyone. I used Turtle back on the Apple in the early 80's... so I personally have very positive feelings towards it ;) To each their own eh? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 Global Variables
It isn't a neat trick anymore once you realize the name '__main__' isn't special. Replace __main__ with foo, or config, or whatever, and you get the same results. Ok, there is a catch: a file with that name must exist, at least an empty one... True. I do feel a bit less special now :-P And again, I think there is a difference from saying you *can* work a certain way, and you *should* work a certain way. Making a 'global module' you import and muck with = good. Other ways discussed = bad (for the most part). But I think it's important to understand the underlying system especially when one is first learning: I hand a heck of a time having someone explain this stuff to me when I was learning the basics (and I'm still figuring it out, even from this thread) and now that I get how it works (I uh... think) it makes me a stronger scripter. The common thought seemed to be you shouldn't do it that way, so I'm not going to explain it to you which I've always found quite frustrating. And along those lines... Should we start talking about how you can add stuff to __builtin__ and then it really is exposed to everything? (right, unless I'm missing some other Python idiom?) Again, *not advocating* in standard practice, but I think it's important to understand how it works. (ducks incoming flak) #- # moduleA.py import __builtin__ __builtin__.spam = 42 __builtins__[ham] = 24 #- # moduleB.py # This will fail if moduleA isn't executed first print spam, ham import moduleA import moduleB 42 24 -- http://mail.python.org/mailman/listinfo/python-list
Re: How can module determine its own path?
How can a module determine the path of the file that defines it? (Note that this is, in the general case, different from sys.argv[0].) __file__ Also: import inspect print inspect.getsourcefile(lambda:None) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 Global Variables
2/ in Python, global really means module-level - there's nothing like a true global namespace. Isn't that __main__? import __main__ __main__.foo = asdfasdf print foo # asdfasdf Not advocating, but it does serve the purpose. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 Global Variables
Good that you're not advocating it, because IMHO it's bad practice to have circular import dependencies. By using the __main__ alias, you avoid the worst problems, but that just means the others are more subtle. I figured I'd get that kind of response, not that it's incorrect ;) Great power\great responsibility\etc. As I understand it, when you enter Python statements at the interactive prompt, it's adding the result directly to ___main___ (which for lack of a better term I like to call 'universal' scope... rolls off the tongue better than 'doubleunderscore main doubleunderscore'): foo = 23 import __main__ print __main__.foo 23 While this might not be the most common way of working for most people (I'm guessing most folks are in a nice cozy IDE), people working this way are mucking about in the 'universal' scope without (possibly) even knowing it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple audio
Yep, you can run it without any kind of GUI to my knowledge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Skeletal animation
Building on what others have said and giving a +1 to Carl: I work daily in Maya doing character setup and rigging. As far as doing it straight in Python, again, like others, take a look at PyGame or Blender. I think the main question is: Do you want skeletal animation, or do you want skeletal animation specifically in Python? While Python is heavily used in Blender, I'm not sure how much of the foundation it actually makes. Take a look ta this PyGame: http://www.pygame.org/project-StickyPy-1248-2254.html Of course PyGame is just a wrapper for SDL Joints and skeletons are abstract concepts that sure, you could do with Python. The question is how you want to render that to the screen, and that's where the other apps come in. -- http://mail.python.org/mailman/listinfo/python-list
Query screen resolution?
Thought this would be easy, maybe I'm missing something :) Trying to query the x,y resolution of my screen. I've seen this available through http://python.net/crew/mhammond/win32/ : from win32api import GetSystemMetrics print width =, GetSystemMetrics (0) print height =,GetSystemMetrics (1) But I was hoping for something built-in, and something non-OS specific. Is that available? Would be nice to detect for multiple monitors as well, but I'm probably asking too much :) Thanks! -- http://mail.python.org/mailman/listinfo/python-list