discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: The nature of Python in OpenSCAD and future plans/features

GS
Guenther Sohler
Wed, Sep 6, 2023 6:36 AM

Hi William,

I am trying to understand what you are doing.
Interfering means that either one of the cube or the file does not work ?
what's your seen behaviour ?
I am not used to path or file but I believe it should be the
current name of the script, but this does not exist.
The used python script in openscad is just a string and does not have a
filename(python does not know the path of your editor console)
Did you intend to write new content to the script file while you execute it
?

Cheers

On Wed, Sep 6, 2023 at 4:28 AM William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: "William F. Adams" willadams@aol.com
To: OpenSCAD General Discussion discuss@lists.openscad.org
Cc:
Bcc:
Date: Wed, 6 Sep 2023 02:28:18 +0000 (UTC)
Subject: [OpenSCAD] Re: The nature of Python in OpenSCAD and future
plans/features
Experimenting a bit more, the following sort of worked:

import os

h = 1
w = 2
d = 3

fn = os.path.basename(name)

string = ("cube" + str(w) + str(d) + str(h))

f = open(fn, "a")
f.write(string)

cube([w,d,h]).output()

f.close()

but I'm still mystified as to why:

fn = os.path.basename(file)

didn't work.

---------- Forwarded message ----------
From: "William F. Adams via Discuss" discuss@lists.openscad.org
To: OpenSCAD General Discussion discuss@lists.openscad.org
Cc: "William F. Adams" willadams@aol.com
Bcc:
Date: Wed, 6 Sep 2023 02:28:18 +0000 (UTC)
Subject: [OpenSCAD] Re: The nature of Python in OpenSCAD and future
plans/features


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Hi William, I am trying to understand what you are doing. Interfering means that either one of the cube or the file does not work ? what's your seen behaviour ? I am not used to __path__ or __file__ but I believe it should be the current name of the script, but this does not exist. The used python script in openscad is just a string and does not have a filename(python does not know the path of your editor console) Did you intend to write new content to the script file while you execute it ? Cheers On Wed, Sep 6, 2023 at 4:28 AM William F. Adams via Discuss < discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: "William F. Adams" <willadams@aol.com> > To: OpenSCAD General Discussion <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Wed, 6 Sep 2023 02:28:18 +0000 (UTC) > Subject: [OpenSCAD] Re: The nature of Python in OpenSCAD and future > plans/features > Experimenting a bit more, the following sort of worked: > > import os > > h = 1 > w = 2 > d = 3 > > fn = os.path.basename(__name__) > > string = ("cube" + str(w) + str(d) + str(h)) > > f = open(fn, "a") > f.write(string) > > cube([w,d,h]).output() > > f.close() > > > > but I'm still mystified as to why: > > fn = os.path.basename(__file__) > > didn't work. > > > > ---------- Forwarded message ---------- > From: "William F. Adams via Discuss" <discuss@lists.openscad.org> > To: OpenSCAD General Discussion <discuss@lists.openscad.org> > Cc: "William F. Adams" <willadams@aol.com> > Bcc: > Date: Wed, 6 Sep 2023 02:28:18 +0000 (UTC) > Subject: [OpenSCAD] Re: The nature of Python in OpenSCAD and future > plans/features > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
WF
William F. Adams
Wed, Sep 6, 2023 12:45 PM

Guenther Sohler guenther.sohler@gmail.com wrote:

Interfering means that either one of the cube or the file does not work ? >what's your seen behaviour ?

Execution en toto was blocked by the error.

I am not used to path or file but I believe it should >be the current name of the script, but this does not exist.

Correct, OIC.

The used python script in openscad is just a string and >does not have a filename(python does not know the path of your editor console)

Oh.

Did you intend to write new content to the script file while you execute it ?

Yes. I wanted to write out a file which has the same name, but a different file extension.
I'm looking at your other mail and will see what I can puzzle out.
William

Guenther Sohler <guenther.sohler@gmail.com> wrote: >Interfering means that either one of the cube or the file does not work ? >what's your seen behaviour ? Execution en toto was blocked by the error. >I am not used to __path__ or __file__ but I believe it should >be the current name of the script, but this does not exist. Correct, OIC. >The used python script in openscad is just a string and >does not have a filename(python does not know the path of your editor console) Oh. >Did you intend to write new content to the script file while you execute it ? Yes. I wanted to write out a file which has the same name, but a different file extension. I'm looking at your other mail and will see what I can puzzle out. William