Python论坛  - 讨论区

标题:[python-chinese] 怎么把字符串变为raw string

2007年12月20日 星期四 09:59

Youhong Han python.han在gmail.com
星期四 十二月 20 09:59:17 HKT 2007

ÎÒÓÃdjangoÉÏ´«Í¼Æ¬ºó£¨windowsÏÂÃæ)£¬µÃµ½µÄ·¾¶ÈçÏ£º
'/media/upload\images\2007\12\19\DSC_3050stand.JPG'
ÏÖÔÚÒª¸üÕýΪ£º
'/media/upload/images/2007/12/19/DSC_3050stand.JPG'
ÔÚ¿ØÖÆ̨ÀïÃæ¿ÉÒÔ
r'/media/upload\images\2007\12\19\DSC_3050stand.JPG'.replace('\\','/')
µ«ÊÇÏÖÔÚ
path = '/media/upload\images\2007\12\19\DSC_3050stand.JPG'
Ôõô±í´ïʽµÄ·½Ê½±ä³Éraw string ?

¸½£ºÄ£ÐÍÀïÃ棺
IMG_ROOT = "upload/images/%Y/%m/%d",
photo_path = models.ImageField(_('photo'), upload_to=IMG_ROOT)
ΪʲôÎÒ»á»ñµÃÕâ¸ö´íÎóµÄ·¾¶£¿
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071220/79ca94b6/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年12月20日 星期四 10:15

xxmplus xxmplus在gmail.com
星期四 十二月 20 10:15:17 HKT 2007

http://www.python.org/doc/2.4/lib/os-path.html

On Dec 20, 2007 12:59 PM, Youhong Han <python.han at gmail.com> wrote:
> 我用django上传图片后(windows下面),得到的路径如下:
> '/media/upload\images\2007\12\19\DSC_3050stand.JPG'
> 现在要更正为:
> '/media/upload/images/2007/12/19/DSC_3050stand.JPG'
> 在控制台里面可以
> r'/media/upload\images\2007\12\19\DSC_3050stand.JPG'.replace('\\','/')
> 但是现在
> path = '/media/upload\images\2007\12\19\DSC_3050stand.JPG'
> 怎么表达式的方式变成raw string ?
>
> 附:模型里面:
> IMG_ROOT = "upload/images/%Y/%m/%d",
> photo_path = models.ImageField(_('photo'), upload_to=IMG_ROOT)
> 为什么我会获得这个错误的路径?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
Any complex technology which doesn't come with documentation must be the best
available.

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年12月20日 星期四 11:11

Youhong Han python.han在gmail.com
星期四 十二月 20 11:11:31 HKT 2007

ÄãûÓÐÃ÷°×ÎÒµÄÎÊÌâ¡£ÎÒÖªµÀwindowsϵķ¾¶·Ö¸î·ûºÏËÑ"\"

On Dec 20, 2007 10:15 AM, xxmplus <xxmplus在gmail.com> wrote:

> http://www.python.org/doc/2.4/lib/os-path.html
>
> On Dec 20, 2007 12:59 PM, Youhong Han <python.han在gmail.com> wrote:
> > ÎÒÓÃdjangoÉÏ´«Í¼Æ¬ºó£¨windowsÏÂÃæ)£¬µÃµ½µÄ·¾¶ÈçÏ£º
> > '/media/upload\images\2007\12\19\DSC_3050stand.JPG'
> > ÏÖÔÚÒª¸üÕýΪ£º
> > '/media/upload/images/2007/12/19/DSC_3050stand.JPG'
> > ÔÚ¿ØÖÆ̨ÀïÃæ¿ÉÒÔ
> > r'/media/upload\images\2007\12\19\DSC_3050stand.JPG'.replace('\\','/')
> > µ«ÊÇÏÖÔÚ
> > path = '/media/upload\images\2007\12\19\DSC_3050stand.JPG'
> > Ôõô±í´ïʽµÄ·½Ê½±ä³Éraw string ?
> >
> > ¸½£ºÄ£ÐÍÀïÃ棺
> > IMG_ROOT = "upload/images/%Y/%m/%d",
> > photo_path = models.ImageField(_('photo'), upload_to=IMG_ROOT)
> > ΪʲôÎÒ»á»ñµÃÕâ¸ö´íÎóµÄ·¾¶£¿
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
>
> --
> Any complex technology which doesn't come with documentation must be the
> best
> available.
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071220/02be2a75/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号