I'm learning python, wrote an example from a book on creating backup, only instead of using gnu32win I used winRAR for archiving the code:

import os import time # files and directories to add to the list sourse = ['c:\\backup\\'] print('Create ', len(sourse), ' backup') # backup storage directory target_dir = ('D:\\backup') print('backup storage directory') # archiv name format target = target_dir + os.sep + time.strftime('%Y.%m.%d_') + '.rar' print('archiv name format') rar = "'C:\Program_Files\WinRAR\WinRAR.exe u -as -dh {0} {1}'".format(target, "".join(sourse)) if os.system(rar) == 0: print('backup ok') else: print('backup error') 

I use IDE PyCharm, in the console I get the following error:

 'Create 1 backup backup storage directory archiv name format    ⥬     㤠          㪠          . backup error' 

In pycharm is the utf-8 encoding, tell me what could be the problem?

  • Perhaps a problem with slashes. In the line, single slashes need to be duplicated ("escape"): C:\Program_Files\WinRAR\WinRAR.exe -> C:\\Program_Files\\WinRAR\\WinRAR.exe . Also, are you sure that your folder is called Program_Files and not Program Files (space instead of underscore)? - ankhzet
  • I tried with two slashes, replaced the underscore with a space, the error was modified: ⠪ ᪠ 訡 䠩 , ⪥ ⮬ . - Anatoly

1 answer 1

  1. To work with a space to work, you need to wrap it in quotes. You can simplify the task by making the path to the program part of the format of the backup command:

     archiver = "C:\\Program Files\\WinRAR\\WinRAR.exe" rar = "'{0}' u -as -dh {1} {2}".format(archiver, target, "".join(sourse)) 
  2. Cyrillic encodings in the console during development - that is also a hemorrhoid. Perhaps WinRAR.exe and / or os.system use encodings from the list of cp866 / win-1251 / win-1252 and you'd better set one of them (or use the tips from here: Support Cyrillic in PyCharm )

  3. Perhaps it will be easier for you to start learning from online tutorials? (google search on python online tutorial )
  • The change of encodings only changes some characters for others. In general, as I understand it, the problem is not with the code, but when the Python is accessed by WinRAR, something happens ... In any case, thanks, I will try something else. - Anatoly