error while importing a module

Cameron Simpson cs at cskk.id.au
Tue Mar 19 00:16:50 EDT 2019


On 18Mar2019 20:11, Sharan Basappa <sharan.basappa at gmail.com> wrote:
>On Tuesday, 19 March 2019 08:34:25 UTC+5:30, Sharan Basappa  wrote:
>> I have a design file that I am importing in a test file to run some tests.
[...]
>> The design file compiles fine when I run it standalone but when I import it in the test file, I see error on the very first line where I am importing the design file.
>The following 2 lines were missing before the import
>
>import sys
>sys.path.append('D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion')

I suggest you make that string a "raw" string:

  sys.path.append(r'D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion')

Unlike a normal Python string 'foo', a raw string r'foo' does not 
interpret slosh escapes (\n, \r etc).  In any string which is supposed 
to include sloshes (backslashes) you should write these as raw string to 
avoid unfortunate slosh escapes being interpreted as special characters.  

In your string above the sequence \a indicates an ASCII BEL character, 
which rings the terminal bell (in modern terminal emulators this often 
means to emit a beep or to flash the window to attract attention). So it 
isn't the path string you thought it was.

There are several slosh escapes recognised by Python strings; see the 
documentation for details. But when you _don't_ want the sequences 
interpreted, use a raw string.

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list