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 13:16:20 +0100

slelievre gravatar image

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 07:28:00 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
5

answered 2012-08-21 13:25:54 +0100

DSM gravatar image

updated 2012-08-21 13:28:08 +0100

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 13:37:33 +0100

updated 2012-08-21 13:40:22 +0100

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 13:16:20 +0100

Seen: 947 times

Last updated: Aug 21 '12