Re: How to create a script that list itself ?
Duncan Booth [EMAIL PROTECTED] wrote: Dave Hansen wrote: Stealing from the old C chestnut: s=s=%c%s%c;print s%%(34,s,34);print s%(34,s,34) Or a bit shorter: s='s=%s;print s%%`s`';print s%`s` It was pointed out to me that the shortest Python program which produces itself on stdout is: -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
Tim Roberts [EMAIL PROTECTED] writes: It was pointed out to me that the shortest Python program which produces itself on stdout is: -- Which, oddly enough, is also the shortest shell program that produces itself on stdout. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
Dave Hansen wrote: Stealing from the old C chestnut: s=s=%c%s%c;print s%%(34,s,34);print s%(34,s,34) Or a bit shorter: s='s=%s;print s%%`s`';print s%`s` -- http://mail.python.org/mailman/listinfo/python-list
How to create a script that list itself ?
How to create a script that list itself ? I would like to know, where is the script's code is stored once we start it. I know I can achieve that, using files : print file('myscript.py','rb').read() But is there a way / a variable that contains the current file in memory ? Thanks. Xaqc -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
On 9 Jan 2006 10:09:19 -0800 in comp.lang.python, Patrick Allaire [EMAIL PROTECTED] wrote: How to create a script that list itself ? Stealing from the old C chestnut: s=s=%c%s%c;print s%%(34,s,34);print s%(34,s,34) I would like to know, where is the script's code is stored once we start it. I know I can achieve that, using files : Well, in the above, the script (or rather, the information necessary to print the script) is actually stored in a string that is part of the script... Regards, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
On 2006-01-09, Patrick Allaire [EMAIL PROTECTED] wrote: How to create a script that list itself ? This is probably about as close as you're going to get: import sys pring open(sys.argv[0],'r').read() And that isn't 100% reliable. I would like to know, where is the script's code is stored once we start it. It isn't. At least none of the implimentations I know of have the script's source code in memory. The PVM or JVM bytecodes to which the program has been compiled are in memory somewhere, and there _may_ be some trick you can use to get at those. I know I can achieve that, using files : print file('myscript.py','rb').read() But is there a way / a variable that contains the current file in memory ? I don't believe so. -- Grant Edwards grante Yow! RHAPSODY in Glue! at visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
But is there a way / a variable that contains the current file in memory ? yes: import __main__ you can do: import inspect import __main__ print inspect.getsource(__main__) or simply: print open(__file__).read() nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
import sys path = os.path.dirname(sys.argv[0]) print Path:%s % (path) ## If you ran this as a script, This would print the location of where the script itself is running. Hope it helps! Rob -- http://mail.python.org/mailman/listinfo/python-list