Ask Your Question
0

how to create directory named s where s is a string ('mkdir s' will create directory 's')

asked 2012-08-21 06:16:20 -0600

How does one create directory named s where s is a string ('mkdir s' will create directory 's'), I want to turn the preparser off in this.

edit retag flag offensive close merge delete

Comments

What about the command cd? How can I change directory to s, where s is a string representing a path?

slelievre gravatar imageslelievre ( 2012-08-22 00:28:00 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
5

answered 2012-08-21 06:25:54 -0600

DSM gravatar image

updated 2012-08-21 06:28:08 -0600

You can use os.mkdir (see docs here):

sage: !ls -a 
.  ..
sage: s = "somedirectoryname"
sage: os.mkdir(s)            
sage: !ls -a                 
.  ..  somedirectoryname
edit flag offensive delete link more
4

answered 2012-08-21 06:37:33 -0600

updated 2012-08-21 06:40:22 -0600

DSM's answer is good. Another option: from within Sage, you can also do

sage: from sage.misc.misc import sage_makedirs
sage: sage_makedirs('/tmp/new/directory/here')

This will create any intermediate directories as necessary. (This function runs os.makedirs(...), along with a little error-checking.)

Re the preparser: to turn it off, just do preparser(False), then execute the command, then turn it back on with preparser(True).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-21 06:16:20 -0600

Seen: 197 times

Last updated: Aug 21 '12