简体   繁体   中英

How to skip **forward slash** char in python

Can anyone tell how to skip forward slash char in python?

I want to create a directory abc(17/12/18) so I tried

import os
os.makedirs('abc(17\/12\/18)')

but the folder created was abc(17\\)

Can anyone tell what am I missing? I searched on Internet but was unsuccessful.

You don't need to escape forward slashes in python, only backslashes. The reason you cannot use that filename is that forward slashes are illegal in windows filenames. try this:

import os
os.makedirs('abc(17-12-18)')

You could do this.

import os

os.makedirs('abc(17' + u'\u2215' + '12' + u'\u2215' + '18)')

# This will create a directory named abc(17∕12∕18)

In Windows and Linux, / is not allowed in folder name.

More information here: https://stackoverflow.com/a/31976060/3813027

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM