\06 is converted to a character that looks like a spade

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • curious000cat
    New Member
    • Dec 2014
    • 2

    \06 is converted to a character that looks like a spade

    Code:
    saveInPath = "C:\Users\User\Documents\AV_FILES\06_School\Python205\ProjectNov2014\CODE_CLEAN\NotQuiteBackUP"		
    lccSysProcCons = SystemProcessControls()
    dateTimeNow = lccSysProcCons.getDateTimeNow()
    name = "RejectedTracksList %s" % str(dateTimeNow)
    saveAsName = saveInPath + "\\" + name + ".txt"
    print saveAsName
    The code above is from a python script currently being developed. The script errors out due to an invalid filename.
    The invalid value was due to the saveAsName which when printed out shows up as:

    C:\Users\User\D ocuments\AV_FIL ES♠_School\Pyth on205\ProjectNo v2014\CODE_CLEA N\NotQuiteBackU P\RejectedTrack sList 2014-12-27 15:31:07.txt

    NOTICE the spade character [♠] in place of [\06].

    Why is this? This will probably be resolved by changing the folder name. I just want to know why this happens.
    Last edited by bvdet; Dec 27 '14, 03:09 PM. Reason: Please use code tags when posting code
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    From the Python docs:
    "The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. String literals may optionally be prefixed with a letter "r" or "R"; such strings are called raw strings and use different rules for backslash escape sequences."

    In your case, precede the open quote with an "r" so it will be treated as a raw string or use double backslashes "\\".
    Code:
    >>> print r"C:\Users\User\Documents\AV_FILES\06_School\Python205\ProjectNov2014\CODE_CLEAN\NotQuiteBackUP"
    C:\Users\User\Documents\AV_FILES\06_School\Python205\ProjectNov2014\CODE_CLEAN\NotQuiteBackUP
    >>> print "C:\\Users\\User\Documents\\AV_FILES\\06_School\\Python205\\ProjectNov2014\\CODE_CLEAN\\NotQuiteBackUP"
    C:\Users\User\Documents\AV_FILES\06_School\Python205\ProjectNov2014\CODE_CLEAN\NotQuiteBackUP
    >>>

    Comment

    • curious000cat
      New Member
      • Dec 2014
      • 2

      #3
      Hi! Somebody told me that the phenomenon was due to it being converted to a unicode character, well anyway, I also did as you suggested. Thanks!

      Comment

      Working...