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.
http://www.mired.org/home/mwm/
Independe
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
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
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.pyt
> 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
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
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
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 i