在您的书中第二章3.2小结末尾,有一个添加搜索路径的内容,我跟着做却没有得到和您一样的结果,我不明白在网上也尝试搜索但是没有找到答案,所以请您帮助我一下,感谢您。
import sys
home_dir = 'C:\Users\pylearning'
sys.path.append(home_dir)
sys.path
['C:\Users',
'C:\Users\anaconda3\python39.zip',
'C:\Users\anaconda3\DLLs',
'C:\Users\anaconda3\lib',
'C:\Users\anaconda3',
'',
'C:\Users\anaconda3\lib\site-packages',
'C:\Users\anaconda3\lib\site-packages\locket-0.2.1-py3.9.egg',
'C:\Users\anaconda3\lib\site-packages\win32',
'C:\Users\anaconda3\lib\site-packages\win32\lib',
'C:\Users\anaconda3\lib\site-packages\Pythonwin',
'C:\Users\anaconda3\lib\site-packages\IPython\extensions',
'C:\Users\.ipython',
'C:\Users\pylearning']
%run appap.py
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\magics\execution.py in run(self, parameter_s, runner, file_finder)
702 fpath = arg_lst[0]
--> 703 filename = file_finder(fpath)
704 except IndexError:
~\anaconda3\lib\site-packages\IPython\utils\path.py in get_py_filename(name, force_win32)
108 else:
--> 109 raise IOError('File `%r` not found.' % name)
110
OSError: File `'appap.py'` not found.
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_24776/3108326169.py in <module>
----> 1 get_ipython().run_line_magic('run', 'appap.py')
~\anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2349 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2350 with self.builtin_trap:
-> 2351 result = fn(*args, **kwargs)
2352 return result
2353
~\anaconda3\lib\site-packages\decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.__name__ = func.__name__
234 fun.__doc__ = func.__doc__
~\anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~\anaconda3\lib\site-packages\IPython\core\magics\execution.py in run(self, parameter_s, runner, file_finder)
712 if os.name == 'nt' and re.match(r"^'.*'$",fpath):
713 warn('For Windows, use double quotes to wrap a filename: %run "mypath\\myfile.py"')
--> 714 raise Exception(msg)
715 except TypeError:
716 if fpath in sys.meta_path:
Exception: File `'appap.py'` not found.