Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.python / Re: Python script accessing own source code

SubjectAuthor
* Python script accessing own source codeDino
+* Re: Python script accessing own source codeMichael F. Stemper
|+- Re: Python script accessing own source codeMRAB
|+- Re: Python script accessing own source codeStestagg
|+* Re: Python script accessing own source codeRobin Becker
||`- Re: Python script accessing own source codePaul Rubin
|+- Re: Python script accessing own source codeRobin Becker
|+* Re: Python script accessing own source codeMirko
||`- Re: Python script accessing own source codeDino
|+- Re: Python script accessing own source codeRobin Becker
|+- Re: Python script accessing own source codeChris Angelico
|`- Re: Python script accessing own source codeRobin Becker
`- Re: Python script accessing own source codeDino

1
Python script accessing own source code

<s7gl20$pdt$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13124&group=comp.lang.python#13124

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org.POSTED!not-for-mail
From: din...@nospam.ar (Dino)
Newsgroups: comp.lang.python
Subject: Python script accessing own source code
Date: Wed, 12 May 2021 09:26:22 -0400
Organization: Aioe.org NNTP Server
Lines: 32
Message-ID: <s7gl20$pdt$1@gioia.aioe.org>
NNTP-Posting-Host: TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.7.0
Content-Language: en-US
X-Mozilla-News-Host: news://news.aioe.org:119
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dino - Wed, 12 May 2021 13:26 UTC

Hi, here's my (probably unusual) problem. Can a Python (3.7+) script
access its own source code? Here's a super simple script. How can this
script print() itself?
__________________________________________
def extract_soul(mystring):

if "magic" in mystring.lower():
return "Yes, You got your magic"
else:
return "No, no magic to be found here"

harry = "My name is Potter, Harry Potter, and I'm a magician"
bond = "My name is Bond, James Bond, and I'm a secret agent"

print("- ", harry)
print("- ", extract_soul(harry))
print("- ", bond)
print("- ", extract_soul(bond))
__________________________________________

My final goal is to build my own home-made Python to Javascript custom
"transpiler". As I maintain the "extract_soul()" Python function in the
future, I would like the script to also export a version of the same
function in JavaScript.
The idea is that, if I can capture the Python source code, I should be
able to do the transpiling by running those few lines through a set of
RegEx.subs(). If anyone has other ideas, or can see ways why this
wouldn't work, I would love to hear about it.

Thank you

Re: Python script accessing own source code

<s7gpsv$3g0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13125&group=comp.lang.python#13125

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mstem...@gmail.com (Michael F. Stemper)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 09:48:55 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <s7gpsv$3g0$1@dont-email.me>
References: <s7gl20$pdt$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 12 May 2021 14:49:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3759309e03bdc9e64a1dc3d00685a191";
logging-data="3584"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RALDVNTa8J/tb4qwq5jLxguSn6JATRLo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:EESAGzReSXGCxnWRYDLkDIBf7DY=
In-Reply-To: <s7gl20$pdt$1@gioia.aioe.org>
Content-Language: en-US
 by: Michael F. Stemper - Wed, 12 May 2021 14:48 UTC

On 12/05/2021 08.26, Dino wrote:

> Hi, here's my (probably unusual) problem. Can a Python (3.7+) script
> access its own source code?

Here is a fairly simple python program that reads itself:

================================================
#!/usr/bin/python

import sys

with open( sys.argv[0], "rt" ) as myself:
for line in myself:
junk = sys.stdout.write( "%s" % (line) )

sys.exit(0)
================================================

It's not bullet-proof. If you put it in a directory in your $PATH and
run it from somewhere else, it won't work.

--
Michael F. Stemper
I feel more like I do now than I did when I came in.

Re: Python script accessing own source code

<mailman.224.1620838345.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13126&group=comp.lang.python#13126

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 17:49:15 +0100
Lines: 27
Message-ID: <mailman.224.1620838345.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de QFJrjR+hhyVDamA5Zo46HANl0/dleUXDv5j9QCg3cg6w==
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=jb1koM3r;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'fairly':
0.05; 'code?': 0.09; 'from:addr:python': 0.09;
'received:192.168.1.64': 0.09; 'subject:script': 0.09;
'subject:source': 0.09; 'subject:Python': 0.12; 'import': 0.14;
'problem.': 0.14; 'from:addr:mrabarnett.plus.com': 0.16;
'from:name:mrab': 0.16; 'junk': 0.16; 'message-
id:@mrabarnett.plus.com': 0.16; 'received:plus.net': 0.16;
'subject:code': 0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr
:python-list': 0.23; 'run': 0.24; 'header:User-Agent:1': 0.31;
'received:192.168.1': 0.31; 'script': 0.32; 'else,': 0.32;
'program': 0.33; 'work.': 0.33; 'header:In-Reply-To:1': 0.33;
'received:192.168': 0.37; "it's": 0.38; 'source': 0.38; 'put':
0.39; 'hi,': 0.39; 'simple': 0.40; 'directory': 0.40; 'here':
0.62; 'skip:o 10': 0.62; 'skip:b 10': 0.62; 'skip:# 10': 0.64;
'your': 0.64; 'received:212': 0.68; 'michael': 0.69
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1620838156; bh=sUHxcGU9ElY9wGNlj82yO/9gjZZRkNHed8oRkZGbiYU=;
h=Subject:To:References:From:Date:In-Reply-To;
b=jb1koM3r7bDUB81nM8ErVVsjW/VxfF4KBSez6HrCPHuLd9AW0dwlRJJRHMr9Pll2I
m59qbdR2F6GQhgf+7RDtfooWkMTMG0IeRuU15Lylen+2eGeGc9sP2PqN6h/jYTE6Nf
9SO9savtz0T62UUYjckV9fP8ZcrxJUomiYA/Mr1fcdkmTBYB1slfX6yQ6VcceL5a0o
5vBLJwecCN4RNWELf1rmxiDvag3C28pKDxJh5/hg/QDhkip1PTh7wiiw8hovIWU6DQ
10DAfEkKthW7G76BeJAEJpLMboUG+3s6mkx2g1xTKEO9kU8VeWMcltdtF0LIlO1C+2
81gmGqRnlDtPA==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.3 cv=fI+iIaSe c=1 sm=1 tr=0
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=NMRJotDB8T8Y-Znvka4A:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
In-Reply-To: <s7gpsv$3g0$1@dont-email.me>
Content-Language: en-GB
X-CMAE-Envelope: MS4wfDsMHDLoWbeaAoP5+9qWpo3KSIqdS5e/BBmTwI3KbP9h6sVzBN72cv18hJKsZQBNZfGMMOOAe1Lu/bfSBYcIO8jjKlrTiuNFooGAArEBIVd83pKK90EE
89ZPpGCAzKUfnUuxFkSy2ikanLs/92cK1mkJL1+3Yz3rPskXkEORRBXPfKreunQeJXz4yckfVywJzg==
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
 by: MRAB - Wed, 12 May 2021 16:49 UTC

On 2021-05-12 15:48, Michael F. Stemper wrote:
> On 12/05/2021 08.26, Dino wrote:
>
>> Hi, here's my (probably unusual) problem. Can a Python (3.7+) script
>> access its own source code?
>
> Here is a fairly simple python program that reads itself:
>
> ================================================
> #!/usr/bin/python
>
> import sys
>
> with open( sys.argv[0], "rt" ) as myself:
> for line in myself:
> junk = sys.stdout.write( "%s" % (line) )
>
> sys.exit(0)
> ================================================
>
> It's not bullet-proof. If you put it in a directory in your $PATH and
> run it from somewhere else, it won't work.
>
How about this:

with open(__file__) as myself:
print(myself.read(), end='')

Re: Python script accessing own source code

<mailman.225.1620840930.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13127&group=comp.lang.python#13127

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: stest...@gmail.com (Stestagg)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 18:35:16 +0100
Lines: 34
Message-ID: <mailman.225.1620840930.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<CACFDE8ZM31x-B3ibUyygxo0oR65gEtq5qM-qPfUWnBPd-9zxPg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de GSi2rF4lZwNCreNOSrGgWAP2UDGQSqOVSCCrfa1ZHbUA==
Return-Path: <stestagg@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=gsahWTWu;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'fairly': 0.05; 'code?':
0.09; 'subject:script': 0.09; 'subject:source': 0.09;
'subject:Python': 0.12; 'import': 0.14; '&gt;': 0.14; 'problem.':
0.14; '==========': 0.16; 'inspect': 0.16; 'junk': 0.16;
'subject:code': 0.16; '\xc2\xa0for': 0.16; 'wrote:': 0.16;
'python': 0.16; 'to:addr:python-list': 0.23; 'run': 0.24;
'script': 0.32; 'else,': 0.32; 'to:name:python': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'program': 0.33; 'work.': 0.33; 'header
:In-Reply-To:1': 0.33; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; "it's": 0.38; 'source': 0.38; 'put':
0.39; 'hi,': 0.39; 'simple': 0.40; 'directory': 0.40; 'here':
0.62; 'skip:b 10': 0.62; 'skip:# 10': 0.64; 'your': 0.64;
'michael': 0.69; 'skip:p 50': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=djQXXUHj3KdY7qNwAoMHkBT/yuZbE3xe3KEZbeYqhdM=;
b=gsahWTWuN8YOorLFJKeIgUjeZTNhGRgOofbyiRmKYb9I/HKf03Ur4teVTikGTF29mi
++fQ9fbZlE2kfeL6GrnZNzFm57TxeFybO9J74t0wybytuqWNoHxemzdoScnQQf40EvpX
TXu0cS+XwNYJyYJZMOa+LpLhmpffmbqQA/fF0m14/OkPUjXiAxOxomRxdF7HFEEo1Av6
8IYsC/hGDzT4tovHZ3yqM9iYGXGjnZ+ofxbV+AE6ZGriV5gUyZSf4NoxVYy2Bn6ozZ5M
P1rhMMf2IKYmyvS2agGJqFnT67PJy7Vb+gnxtLsIVVyv9RAd2Kbd9Xg6CKBAxRTbF5ua
SCZw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=djQXXUHj3KdY7qNwAoMHkBT/yuZbE3xe3KEZbeYqhdM=;
b=oKnjBaVsnzJLyS5dCQ12p/+DYtBulcKnnWiqS5YRH9A7D+s+6f9YCGsCOM+7iDc8ua
9SpplMc8A5OlmRFZBdYJncZ8KSWN8CucFB8WvUDSdzZ/UoDRTZoBrHe4Uw9O+RTTKQTl
MI4f0rBSMIyTTs9nMBFWi6nsVGX1I7j3bFX4i2Rl6J6G2lrVvElvKo+sMFnjiwXi6yVH
kR3xM3QGGFOtu3TL/UY0QihSlwwt+BeMzSxPY6x1FGsDbDtkIAkwzQzCFd1Cs0BYLnTW
xazK4G1MWsYzozhK8E0grJKoMOb8tStFz5tjDqvsGpdF5pY+2uDrUFFz3z6174O8/Ioh
awYA==
X-Gm-Message-State: AOAM533XCln69zpvnrt7Ya9VRDKGgcJ8Mzy76tIJEfTC3yZzzji5WBvC
EyLAme0vyZmqJ4rxTzqBSBL9LDoMnR73VBsXQCHT5o/3Ae9hEg==
X-Google-Smtp-Source: ABdhPJxtsZ2hdD/yFrganXj3mX8VzPs09tmy+DOp8ObT4V0OsYQtvzT79dcCCjFE+owo5qNOV+OK2fE0qzVmslNIPYM=
X-Received: by 2002:aa7:990f:0:b029:2a0:ce4f:c4e8 with SMTP id
z15-20020aa7990f0000b02902a0ce4fc4e8mr33440627pff.15.1620840927284; Wed, 12
May 2021 10:35:27 -0700 (PDT)
In-Reply-To: <cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CACFDE8ZM31x-B3ibUyygxo0oR65gEtq5qM-qPfUWnBPd-9zxPg@mail.gmail.com>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
 by: Stestagg - Wed, 12 May 2021 17:35 UTC

On 2021-05-12 15:48, Michael F. Stemper wrote:

> > On 12/05/2021 08.26, Dino wrote:
> >
> >> Hi, here's my (probably unusual) problem. Can a Python (3.7+) script
> >> access its own source code?
> >
> > Here is a fairly simple python program that reads itself:
> >
> > ================================================
> > #!/usr/bin/python
> >
> > import sys
> >
> > with open( sys.argv[0], "rt" ) as myself:
> > for line in myself:
> > junk = sys.stdout.write( "%s" % (line) )
> >
> > sys.exit(0)
> > ================================================
> >
> > It's not bullet-proof. If you put it in a directory in your $PATH and
> > run it from somewhere else, it won't work.
> >
>
>
Here's a fairly simple option:

==========
import inspect
import sys

print(inspect.getsource(sys.modules[__name__]))
========

Re: Python script accessing own source code

<mailman.226.1620844882.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13128&group=comp.lang.python#13128

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob...@reportlab.com (Robin Becker)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 19:41:19 +0100
Lines: 14
Message-ID: <mailman.226.1620844882.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de K0jIJ0OpnRZiJMvwyzdwmw/4mMnnesOVX3gpV8ZuKmGA==
Return-Path: <robin@reportlab.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=reportlab-com.20150623.gappssmtp.com
header.i=@reportlab-com.20150623.gappssmtp.com
header.b=UOh+C4pB; dkim-adsp=none (unprotected policy);
dkim-atps=neutral
X-Spam-Status: OK 0.018
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:script': 0.09;
'subject:source': 0.09; 'traveling': 0.09; 'subject:Python': 0.12;
'problem': 0.15; 'becker': 0.16; 'received:192.168.0.16': 0.16;
'robin': 0.16; 'subject:code': 0.16; 'writes': 0.16; 'python':
0.16; 'creates': 0.23; 'to:addr:python-list': 0.23; 'code': 0.24;
'seems': 0.26; 'header:User-Agent:1': 0.31; 'think': 0.31; 'but':
0.31; 'script': 0.32; 'header:In-Reply-To:1': 0.33;
'received:192.168.0': 0.34; 'received:google.com': 0.34;
'received:192.168': 0.37; "that's": 0.37; 'could': 0.40; 'skip:o
10': 0.62; 'accessing': 0.65; 'skip:f 30': 0.71; 'easy.': 0.84;
'itself.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=reportlab-com.20150623.gappssmtp.com; s=20150623;
h=subject:to:newsgroups:references:from:message-id:date:user-agent
:mime-version:in-reply-to:content-language:content-transfer-encoding;
bh=xtDcoZdhAhKbtWHTik31LORfFudSkfW1Be4xvm6z0Bs=;
b=UOh+C4pBzndbOCDiCOAtAkuaDQF4cMk8g+wJsF3Gope1lvjgF3W5iVC8WxVMbREmGz
M6ffRx4X2P/0XyLeP1BNMbepxRyVbkE0Hkcp9aYQQmvlaR8HeYZhTtUsFtdExRzm9mgw
ljCqa8lSAfw0nffbrJbuw7QfhSd3ei0JqK0je5CTF8jBYYdJh7WdjBaf6syEzZc3N2fB
qDnKx5WWkZEViU2wf7wUzpY0L7L1Jk9Y0a7Ii4ZCyk8K2BnE1XHndxR0KN1bO6ZBsssA
zNaay9sPo3iBdv4vDqH5fqO7bVguXXLPQCmv/5fDcI5zau6dKQLYgeFh1bLIR3Vu1ugi
x/vg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:subject:to:newsgroups:references:from:message-id
:date:user-agent:mime-version:in-reply-to:content-language
:content-transfer-encoding;
bh=xtDcoZdhAhKbtWHTik31LORfFudSkfW1Be4xvm6z0Bs=;
b=oeUsrfPGUnJwl7R+zsn69bcF2si/jiByplnF+glebqukjhXqLMUlH8FK/1+2IXr2xZ
c+T/oApHvZqMJHKQBg+eoUO8lGbPY6rNtyvHOFoT/cErs1GXM1hknPgPKlJy8kSVAAsT
c/veDIfD/p1OFhxfgItOlTSfyOuVbPpTW1mv3Lyy9KvELPPTNWwRsyud3gK0kkphFf0L
7srtozLJFysmFk2VtLAvzPlwoJBdUhsnZQpE+CqA/7oFMr9k2nzHL80FCzYc2NBfkDfq
QO/eTRVRXHMvaK+WKceMXWNaorOpXq3RmlnR/ss6BHZsrskZqly/owFrmKWT5MXB+lWz
OyZg==
X-Gm-Message-State: AOAM532sGx3oTDESZ5p0Wi78J9J+CeD/xAEv+7QRsWVEpHxxm2aeeAhR
A0KSa/zgKRHnzjD05sC+RDimyYGMZCc5RS4i
X-Google-Smtp-Source: ABdhPJyMCaSnOYJYQwuiciPkZn8ZDh2GoOWeEd+1fdFXdiZVpdxK0sy9YaqYJFZ/4u7djh0Qftboww==
X-Received: by 2002:a5d:608a:: with SMTP id w10mr45948523wrt.371.1620844880729;
Wed, 12 May 2021 11:41:20 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
In-Reply-To: <cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
Content-Language: en-US-large
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
 by: Robin Becker - Wed, 12 May 2021 18:41 UTC

........
>
> with open(__file__) as myself:
>     print(myself.read(), end='')

very nice, but accessing code that's already seems quite easy. I think the real problem is to get a python script name
that creates and writes itself. So I would ask if any one has the solution to the self writing script

python find-tomorrows-lotto-numbers.py

since GvR has been shown to have time traveling abilities such a script could paradoxically appear acausally.
--
yrs-not-too-seriously
Robin Becker

Re: Python script accessing own source code

<mailman.227.1620845334.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13129&group=comp.lang.python#13129

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob...@reportlab.com (Robin Becker)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 19:41:19 +0100
Lines: 15
Message-ID: <mailman.227.1620845334.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de XdkN9JuVYYsA5ubZ7sNd7gLyarRiedYJV0XAg9YZT5Rw==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:ciao.gmane.io':
0.09; 'received:gmane.io': 0.09; 'received:list': 0.09;
'subject:script': 0.09; 'subject:source': 0.09; 'traveling': 0.09;
'subject:Python': 0.12; 'problem': 0.15; 'becker': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'robin': 0.16; 'subject:code':
0.16; 'writes': 0.16; 'python': 0.16; 'creates': 0.23; 'to:addr
:python-list': 0.23; 'code': 0.24; 'seems': 0.26; 'header:User-
Agent:1': 0.31; 'think': 0.31; 'but': 0.31; 'script': 0.32;
'header:In-Reply-To:1': 0.33; "that's": 0.37; 'could': 0.40;
'skip:o 10': 0.62; 'accessing': 0.65; 'received:116': 0.71;
'skip:f 30': 0.71; 'easy.': 0.84; 'itself.': 0.84
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
In-Reply-To: <cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
Content-Language: en-US-large
X-Mailman-Approved-At: Wed, 12 May 2021 14:48:53 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
 by: Robin Becker - Wed, 12 May 2021 18:41 UTC

........
>
> with open(__file__) as myself:
>     print(myself.read(), end='')

very nice, but accessing code that's already seems quite easy. I think the real problem is to get a python script name
that creates and writes itself. So I would ask if any one has the solution to the self writing script

python find-tomorrows-lotto-numbers.py

since GvR has been shown to have time traveling abilities such a script could paradoxically appear acausally.
--
yrs-not-too-seriously
Robin Becker

Re: Python script accessing own source code

<mailman.228.1620847027.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13130&group=comp.lang.python#13130

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mirkok.l...@googlemail.com (Mirko)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 21:17:04 +0200
Lines: 33
Message-ID: <mailman.228.1620847027.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de xizXOa85hyI7TQpNOFlaDgxicSI5UPVS9EZrAGjDN/Lw==
Return-Path: <mirkok.lists@googlemail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=googlemail.com header.i=@googlemail.com header.b=KSjYbxii;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'command-
line': 0.07; 'from:addr:googlemail.com': 0.09; 'message-
id:@googlemail.com': 0.09; 'schrieb': 0.09; 'subject:script':
0.09; 'subject:source': 0.09; 'traveling': 0.09; 'subject:Python':
0.12; 'import': 0.14; 'problem': 0.15; 'becker': 0.16; 'filename':
0.16; 'mean,': 0.16; 'robin': 0.16; 'subject:code': 0.16;
'writes': 0.16; 'python': 0.16; 'creates': 0.23; 'to:addr:python-
list': 0.23; 'code': 0.24; 'seems': 0.26; 'think': 0.31; 'but':
0.31; 'script': 0.32; 'received:google.com': 0.34; 'skip:o 30':
0.35; "that's": 0.37; 'could': 0.40; 'skip:o 10': 0.62;
'accessing': 0.65; 'skip:f 30': 0.71; 'easy': 0.75; 'received:37':
0.78; 'easy.': 0.84; 'itself.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20161025;
h=subject:to:references:from:message-id:date:user-agent:mime-version
:in-reply-to:content-transfer-encoding;
bh=6+t+CIE9xZkkNKeXuMQF3b6SUKj6QCg/596bHTC/xvM=;
b=KSjYbxiimGRBzl0UgSNOzuPO7KM55ryuALEUBdeI0ZdeLZ7lKDo87fQ/YQq3Utr1QW
IXUH9iAHYZV/7B3YI3yfkje+HI6MH/zrX9BvKqCBA2vJ+OoTDAe2ExYxD1D1dDx9QVv7
YOHU3TFcB5cIr6oT2cQtXTu1MEBhDlWUUX16YoC+z9atJhoMJ+1cfhaUtgAYd2M/CwIQ
yV/1GaX8BgdKjQum7FzPEFwKQh7ey6arNbDoXZPZ9hk+/Xs6OtZVWTOvZata/kcG0ESh
IPDLjD159SKV+Y5M+YA4nXYslwVd1gtSW5tuY9Yr71AIiQ9NZILQjPBbrpiS906sizEI
+ljw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:subject:to:references:from:message-id:date
:user-agent:mime-version:in-reply-to:content-transfer-encoding;
bh=6+t+CIE9xZkkNKeXuMQF3b6SUKj6QCg/596bHTC/xvM=;
b=JFHH1WTdTTpKXIKi11TCBK1QhVvw3l1vUcK3Tf2sAPKrFM8gPrTxQFhfmbhjPNKxnE
xPlrVV37Af+kzcodpSnvXcTra8dAKBOHvxJ1CKtnzO3PTgVEeN1j4GuZlQePm/+ttUaE
wuPY/ZFKgRKpKQpnkJrbqPdC+mP55nlau1m5l1tHZwbWcEzTA8jZ8bRzCDZp6+bK7KHV
SRFgbqkZzQjUfEroSqmHyIXaEELD3NhAidERmlmCEogI6tInBlNS3uq7OsJqESLzuDY7
KRp9KzbPnh7xkWf4NP5Xwakpw+ReeY/OGZ1hqm9v/im8m5PLX1dtMysv7tJbZLCGe9ar
qJqg==
X-Gm-Message-State: AOAM533HiTHiJOV96ZkG5kiKIBa+t+V9bSdGrjrCp+YgqVMU5gc2CSp8
BEh2gICEVbDDjkyoLTbur4csKafPWBo=
X-Google-Smtp-Source: ABdhPJy5uAKjweFFSC92C3nIA/OOsnAZq15ALBjCB+Nve5izQJNgC1EAbeP07/KC+FNBbJ+PHfznTw==
X-Received: by 2002:a5d:400f:: with SMTP id n15mr43133792wrp.274.1620847026148;
Wed, 12 May 2021 12:17:06 -0700 (PDT)
x-enigmail-draft-status: N1110
user-agent: Mozilla/5.0 (X11; Linux x86_64;
rv:37.0) Gecko/20100101 Thunderbird/37.0
in-reply-to: <5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <609C29B0.6020800@googlemail.com>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
 by: Mirko - Wed, 12 May 2021 19:17 UTC

Am 12.05.2021 um 20:41 schrieb Robin Becker:
> .......
>>
>> with open(__file__) as myself:
>> print(myself.read(), end='')
>
> very nice, but accessing code that's already seems quite easy. I
> think the real problem is to get a python script name that creates
> and writes itself. So I would ask if any one has the solution to the
> self writing script
>
> python find-tomorrows-lotto-numbers.py
>
> since GvR has been shown to have time traveling abilities such a
> script could paradoxically appear acausally.
> --
> yrs-not-too-seriously
> Robin Becker

Not sure, if that's what you mean, but writing a self-replicating
script is easy too:

import os
import sys

with open(os.path.abspath(__file__)) as myself:
with open(sys.argv[1], "w") as yourself:
yourself.write(myself.read())

Give it a filename as a command-line argument and it will write
itself to that file.

Re: Python script accessing own source code

<s7hag0$15g3$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13131&group=comp.lang.python#13131

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!news.uzoreto.com!aioe.org!TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org.POSTED!not-for-mail
From: din...@nospam.ar (Dino)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 15:32:15 -0400
Organization: Aioe.org NNTP Server
Lines: 9
Message-ID: <s7hag0$15g3$1@gioia.aioe.org>
References: <s7gl20$pdt$1@gioia.aioe.org>
NNTP-Posting-Host: TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.7.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dino - Wed, 12 May 2021 19:32 UTC

On 5/12/2021 9:26 AM, Dino wrote:
>
> Hi, here's my (probably unusual) problem. Can a Python (3.7+) script
> access its own source code? Here's a super simple script. How can this
> script print() itself?

To everyone who responded, thank you. Very helpful.

Re: Python script accessing own source code

<s7hak2$15g3$2@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13132&group=comp.lang.python#13132

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!feeder5.feed.usenet.farm!feeder1.feed.usenet.farm!feed.usenet.farm!aioe.org!TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org.POSTED!not-for-mail
From: din...@nospam.ar (Dino)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 15:34:25 -0400
Organization: Aioe.org NNTP Server
Lines: 10
Message-ID: <s7hak2$15g3$2@gioia.aioe.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
<mailman.228.1620847027.3087.python-list@python.org>
NNTP-Posting-Host: TmE/PbLrEEa11yKGF/NPKQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.7.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dino - Wed, 12 May 2021 19:34 UTC

On 5/12/2021 3:17 PM, Mirko wrote:
>
> Give it a filename as a command-line argument and it will write
> itself to that file.

Thank you. My problem is that the function I produce will need to be
JavaScript. I'll figure it out

Thanks

Re: Python script accessing own source code

<87fsyrzfpe.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13135&group=comp.lang.python#13135

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Wed, 12 May 2021 16:37:33 -0700
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <87fsyrzfpe.fsf@nightsong.com>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<mailman.226.1620844882.3087.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="cca5e7733e88bf3401ac390bd9e2c4c0";
logging-data="29310"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xSUkbVxFEdsjG6348qdFA"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:0kqwLRMlGhbs2i/XW8E2zqmHrzQ=
sha1:xg7p9ri1XbgEN/eSfMS93VoEUYk=
 by: Paul Rubin - Wed, 12 May 2021 23:37 UTC

Robin Becker <robin@reportlab.com> writes:
> I think the real problem is to get a python script name that creates
> and writes itself.

Hint: that type of script is sometimes called a "quine".

Re: Python script accessing own source code

<mailman.229.1620890744.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13137&group=comp.lang.python#13137

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob...@reportlab.com (Robin Becker)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Thu, 13 May 2021 08:25:41 +0100
Lines: 33
Message-ID: <mailman.229.1620890744.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
<eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 2wmxdbtfk4Uw5oAqIhfuMAppPfYf2IG1wJYcxKWzrWfQ==
Return-Path: <robin@reportlab.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=reportlab-com.20150623.gappssmtp.com
header.i=@reportlab-com.20150623.gappssmtp.com
header.b=NkwZN0ye; dkim-adsp=none (unprotected policy);
dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'command-
line': 0.07; 'programmer': 0.07; 'schrieb': 0.09;
'subject:script': 0.09; 'subject:source': 0.09; 'traveling': 0.09;
'subject:Python': 0.12; 'import': 0.14; 'becker': 0.16;
'filename': 0.16; 'mean,': 0.16; 'received:192.168.0.16': 0.16;
'robin': 0.16; 'subject:code': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.23; '>>>': 0.26; 'creating': 0.27; 'header:User-
Agent:1': 0.31; 'but': 0.31; 'script': 0.32; 'python-list': 0.32;
'header:In-Reply-To:1': 0.33; 'received:192.168.0': 0.34;
'received:google.com': 0.34; 'skip:o 30': 0.35;
'received:192.168': 0.37; 'way': 0.37; "that's": 0.37; 'really':
0.37; 'something': 0.38; 'to:2**1': 0.38; 'could': 0.40; 'skip:o
10': 0.62; 'future': 0.67; 'easy': 0.75
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=reportlab-com.20150623.gappssmtp.com; s=20150623;
h=subject:to:newsgroups:references:from:message-id:date:user-agent
:mime-version:in-reply-to:content-language:content-transfer-encoding;
bh=Xvo6o+rBV8HKbGVRxMkRYT0ugE6trhW6sQTPIfjjfng=;
b=NkwZN0yeYonRe0cEILchQBs4W4YMSgDCaTFfOgj8Zh7+65eZd2M9Y/pYjMqV2VUjkq
Cz/iLwr+MOxt/Nts7HFfbAcBDZRJrQM9v5LfuaZTvUKuaSSq35D1VmnVMDSCf4A+Xebj
RfuP62Mz+nzuhKzPJ6D/peQcyUOTGD//o27JWjRLl55QsNsKk/WuZLtuEdS8rqz7f9xt
8CathmisOwqUAt16aa4I4vdoS5xSAbffLE9Ry0ljmJya/+MCb6myxIu7vW2u/oXmkOrd
FCez6kkLQ9ee/Q5sHEDH7JERLesrnjS6HliQmqQ9fHfWvRNJTB/qaNBXl512QGs0u4ft
WZgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:subject:to:newsgroups:references:from:message-id
:date:user-agent:mime-version:in-reply-to:content-language
:content-transfer-encoding;
bh=Xvo6o+rBV8HKbGVRxMkRYT0ugE6trhW6sQTPIfjjfng=;
b=hjVUrn5T85B1g68Vicx03vDKZWR+twut0aItsO3bG5mWUNTsG/fgYy2DN0xIkmizMy
JwrCMi+U20kFp5glfkvpxSvbhKXsYrHOx5dL1ZSeEcjbKQEf4LVA0sryuYvCm3Itsi/Q
4fi4LSc/FfBF89P75ciOegMv/vy/rXP7kGJX+b5X4oR/H8kSkKG5qbO7GZtPLYmHfX8p
P8pgoS/idTXfrCgtVf2FRI/rZ97iAwtbOOuNVwos/r22FAraxNMokUDeagyD6Wh2HLfB
4+dWqV6C/e2rleDMG43n5GbP1mPMYtOhyISJU33STJX2PVBlwIP0Ca9gFZJOHhpcx9V7
BErw==
X-Gm-Message-State: AOAM531+hNbCIB+5XqN8yvnEMDRlw8O3qsRDuSCIg3XNCMPqcSKQ+mcB
5O+fRQZKUOf5/03hvOuX2Hn98KDrvIUuPHqv
X-Google-Smtp-Source: ABdhPJz36zVTiobZe1tm4fYVQ7Oxvh237g9HtO1lhKRZu6Eef1jOJM+4JzWmWUdMk8QbId3JkyfFlw==
X-Received: by 2002:adf:e4c4:: with SMTP id v4mr7614430wrm.346.1620890742760;
Thu, 13 May 2021 00:25:42 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
In-Reply-To: <609C29B0.6020800@googlemail.com>
Content-Language: en-US-large
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
 by: Robin Becker - Thu, 13 May 2021 07:25 UTC

On 12/05/2021 20:17, Mirko via Python-list wrote:
> Am 12.05.2021 um 20:41 schrieb Robin Becker:
>> .......
>>>
>...........
>> since GvR has been shown to have time traveling abilities such a
>> script could paradoxically appear acausally.
>> --
>> yrs-not-too-seriously
>> Robin Becker
>
>
> Not sure, if that's what you mean, but writing a self-replicating
> script is easy too:

actually I was really joking about self creating scripts that do something useful like finding future lotto numbers.

the artificial programmer servant is some way off

>
> import os
> import sys
>
> with open(os.path.abspath(__file__)) as myself:
> with open(sys.argv[1], "w") as yourself:
> yourself.write(myself.read())
>
>
> Give it a filename as a command-line argument and it will write
> itself to that file.
>
--
Robin Becker

Re: Python script accessing own source code

<mailman.230.1620891011.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13138&group=comp.lang.python#13138

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Thu, 13 May 2021 17:29:57 +1000
Lines: 30
Message-ID: <mailman.230.1620891011.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
<eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
<CAPTjJmpVp-uR=qbWWz0yNnv6=XFWeO2RAr=oTFREyoU-b=iNKQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de UAcMBq88VP+dygQV38VO5gjiPdNE7wXfJOGx/EeA+fCA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=SSbukGN1;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'programmer': 0.07;
'schrieb': 0.09; 'subject:script': 0.09; 'subject:source': 0.09;
'traveling': 0.09; 'subject:Python': 0.12; 'import': 0.14;
'becker': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'mean,': 0.16; 'received:mail-
il1-x135.google.com': 0.16; 'robin': 0.16; 'subject:code': 0.16;
'think.': 0.16; 'variant': 0.16; 'wrote:': 0.16; 'thu,': 0.20;
'language': 0.22; 'creates': 0.23; 'to:addr:python-list': 0.23;
'code': 0.24; '>>>': 0.26; 'creating': 0.27; 'but': 0.31;
'script': 0.32; '13,': 0.32; 'python-list': 0.32;
'to:name:python': 0.32; 'message-id:@mail.gmail.com': 0.33;
'program': 0.33; 'header:In-Reply-To:1': 0.33;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'trying': 0.36; 'way': 0.37; "that's": 0.37; 'really': 0.37;
"it's": 0.38; 'something': 0.38; 'called': 0.40; 'could': 0.40;
'your': 0.64; 'future': 0.67; 'demand': 0.68; 'easy': 0.75;
'2021': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=p937ZAXEDiBFd0Fbsn+j8Pwp2JDKIn6feExV6BFcFOk=;
b=SSbukGN1DUKN0BnsOjT2BUVBUBYBBnzd76mbSqlREIssy8kMLzEJcHUlQG7ptJMYHz
dwkjO12OU10kaTrLao2M9eTQV+jgxTdHEZy4LjzOTP0Ff5u68dum2a0RBFDkBFn8MnUF
tiOAweHoQIbGhOYAGFtADoQMUqn0RCxxi9rIUMqJiHQKw/ZhPFaN0c/5DLXJ0wwpU1Da
4sjGbjP0AY5b2w67NxCck1m6utASeWlLiANZCHTFMTVD4JdhQtt/Bx4XKXVbxoPgLnJ2
zeWsMEMTW5UU5lkyEWuGA9wFwnU3D0Lbi7k+GwpAeY5VbD6WB2Y2mz4ERjDSowPSNeAX
COww==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=p937ZAXEDiBFd0Fbsn+j8Pwp2JDKIn6feExV6BFcFOk=;
b=FswK6MAnsJVpGniO8bYj6XFvGuIpgSIkWD4to0HCx5HhwSvco0T7tzEwoR0K0HP7AJ
ZSoqRii0flOb+e1/g7Jcny4z5r/y0DhjgkHLT1BvmxilZMR+udJvk7TRlxwV5+XlPVN4
7TbnqLkWVvrqyJVPb0d/BWzqWzeKjZAmd6A+RNPfD8qSZVamUkJds2wQyWmOnCscSest
4SIzxikzy6f0cUba7/STt2c7myuhzFv7O6QlimNYeqgYU0oO9H2ItPiaUup+f5DilJaI
x/MeN7KRwuXhhFDd1zuh3YNEzub1a/SodSlYwWeOdSbMib1QhTts7mPJ7Wo5Yu+2fjj/
9LCA==
X-Gm-Message-State: AOAM531MUfZfaYXW2g/gsFAm1El7DePOwIbKEXHxkfV9np1T75X+4p0E
BKYyYZBH5RDaMKZ0m0ucgFn+G0qSvDW10XgnqNE4iIrMxjI=
X-Google-Smtp-Source: ABdhPJyRs6dEgryya+7WzxoyNF/J/krbY1QiI45xSXaMqLa1ppmuKkTqZUSoen3Rf0K+8/nbn4pypBZiSvOll9QLxoI=
X-Received: by 2002:a92:d7c2:: with SMTP id g2mr35688013ilq.265.1620891008981;
Thu, 13 May 2021 00:30:08 -0700 (PDT)
In-Reply-To: <eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpVp-uR=qbWWz0yNnv6=XFWeO2RAr=oTFREyoU-b=iNKQ@mail.gmail.com>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
<eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
 by: Chris Angelico - Thu, 13 May 2021 07:29 UTC

On Thu, May 13, 2021 at 5:27 PM Robin Becker <robin@reportlab.com> wrote:
>
> On 12/05/2021 20:17, Mirko via Python-list wrote:
> > Am 12.05.2021 um 20:41 schrieb Robin Becker:
> >> .......
> >>>
> >...........
> >> since GvR has been shown to have time traveling abilities such a
> >> script could paradoxically appear acausally.
> >> --
> >> yrs-not-too-seriously
> >> Robin Becker
> >
> >
> > Not sure, if that's what you mean, but writing a self-replicating
> > script is easy too:
>
> actually I was really joking about self creating scripts that do something useful like finding future lotto numbers.
>
> the artificial programmer servant is some way off
>

Perhaps not so far off as you might think. With import hooks, it's
entirely possible to have a program that creates itself on demand -
for instance, you might transpile your script from some variant form
of the language (maybe you're trying out a proposed new syntax). It
won't help you with the lotto, but it certainly is an AI assistant for
a programmer that creates runnable code when called upon.

ChrisA

Re: Python script accessing own source code

<mailman.231.1620926933.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13141&group=comp.lang.python#13141

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob...@reportlab.com (Robin Becker)
Newsgroups: comp.lang.python
Subject: Re: Python script accessing own source code
Date: Thu, 13 May 2021 08:25:41 +0100
Lines: 34
Message-ID: <mailman.231.1620926933.3087.python-list@python.org>
References: <s7gl20$pdt$1@gioia.aioe.org> <s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
<eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de bzZqde0/BlbME2Jh+jks+AbYGeGJsANDJ7Jzpf9kDt4Q==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'command-
line': 0.07; 'programmer': 0.07; 'received:ciao.gmane.io': 0.09;
'received:gmane.io': 0.09; 'received:list': 0.09; 'schrieb': 0.09;
'subject:script': 0.09; 'subject:source': 0.09; 'traveling': 0.09;
'subject:Python': 0.12; 'import': 0.14; 'becker': 0.16;
'filename': 0.16; 'mean,': 0.16; 'received:116.202': 0.16;
'received:116.202.254': 0.16; 'received:116.202.254.214': 0.16;
'robin': 0.16; 'subject:code': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.23; '>>>': 0.26; 'creating': 0.27; 'header:User-
Agent:1': 0.31; 'but': 0.31; 'script': 0.32; 'python-list': 0.32;
'header:In-Reply-To:1': 0.33; 'skip:o 30': 0.35; 'way': 0.37;
"that's": 0.37; 'really': 0.37; 'something': 0.38; 'could': 0.40;
'skip:o 10': 0.62; 'future': 0.67; 'received:116': 0.71; 'easy':
0.75
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
In-Reply-To: <609C29B0.6020800@googlemail.com>
Content-Language: en-US-large
X-Mailman-Approved-At: Thu, 13 May 2021 13:28:52 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <eab3330b-ed0f-3b4b-aa52-5b07e7a19a4a@everest.reportlab.co.uk>
X-Mailman-Original-References: <s7gl20$pdt$1@gioia.aioe.org>
<s7gpsv$3g0$1@dont-email.me>
<cc8ea2d1-a03c-acbe-3127-7d555d3f61de@mrabarnett.plus.com>
<5ee47805-3e06-5f57-d829-d1c35420c999@everest.reportlab.co.uk>
<609C29B0.6020800@googlemail.com>
 by: Robin Becker - Thu, 13 May 2021 07:25 UTC

On 12/05/2021 20:17, Mirko via Python-list wrote:
> Am 12.05.2021 um 20:41 schrieb Robin Becker:
>> .......
>>>
>...........
>> since GvR has been shown to have time traveling abilities such a
>> script could paradoxically appear acausally.
>> --
>> yrs-not-too-seriously
>> Robin Becker
>
>
> Not sure, if that's what you mean, but writing a self-replicating
> script is easy too:

actually I was really joking about self creating scripts that do something useful like finding future lotto numbers.

the artificial programmer servant is some way off

>
> import os
> import sys
>
> with open(os.path.abspath(__file__)) as myself:
> with open(sys.argv[1], "w") as yourself:
> yourself.write(myself.read())
>
>
> Give it a filename as a command-line argument and it will write
> itself to that file.
>
--
Robin Becker

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor