I think as a general rule with os.chdir()/os.getcwd() in Python apps. you can't 
assume its value, it's a single piece of state shared across the entire app. 
and all libraries, so really the best thing to do is not use it or rely on it.
Your result is not surprising, Leo is setting it between script calls.  
Possibly Leo is doing this intentionally in a constructive way, setting the cwd 
to the path implied by the node you're in (taking into account the location of 
the .leo file and all parent @path directives.  If you think about it a truly 
Leonine shell representation might use the tree to represent directories.
For your application I'm not sure what the best approach might be.  You could 
sandwich your shell work between calls to some get_last_cwd() / save_last_cwd() 
that stores a cwd in a uA per node or something.
Or perhaps a custom cd() function that does both get_last_cwd() and 
save_last_cwd() at once, saves having to remember to use the other functions.
Cheers -Terry

      From: john lunzer <[email protected]>
 To: leo-editor <[email protected]> 
Cc: [email protected]
 Sent: Wednesday, February 15, 2017 7:58 AM
 Subject: Re: Leo's HOME directory
   
I'll use this thread because it seems relevant. I'm trying to do some 
experiments using Leo as a shell. Amongst other things I'm trying to change 
this current working directory. I have a small node script:
@language python

import os
os.chdir("..")
g.es(os.getcwd(), color="green")
Perhaps naively I expected the log to show that I keeping dropping down a 
level, as it would in a interactive python session. Unfortunately the output is 
the same each time.
Any suggestions on changing the working directory? Or suggestions on 
alternatives to keeping track of working directory in scripts.
On Thursday, April 21, 2016 at 7:20:52 PM UTC-4, Edward K. Ream wrote:
On Thu, Apr 21, 2016 at 1:44 PM, Largo84 <[email protected]> wrote:

Sorry I don't know the whole back story on this, but why was this plugin 
disabled?

​I have no recollection of 2008 :-)
​ 
What's the alternative way to explicitly specify a different HOME directory 
than the OS default?

​According to lm.computeHomeDir, ​ ​the home directory is

    os.path.expanduser("~")

​There is a comment in Leo's code that Windows searches the HOME, HOMEPATH and 
HOMEDRIVE environment vars. Full details here. (Search for expanduser on this 
page).

Edward
-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


   

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to