请查看以下代码。
class AddParams
{
public int a, b;
public AddParams(int numb1, int numb2)
{
a = numb1;
b = numb2;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ID of thread in 1: {0}",
Thread.CurrentThread.ManagedThreadId);
AddAsync();
Console.ReadLine();
}
private static async Task AddAsync()
{
Console.WriteLine("***** Adding with Thread objects *****");
Console.WriteLine("ID of thread in Main(): {0}",
Thread.CurrentThread.ManagedThreadId);
AddParams ap = new AddParams(10, 10);
await Sum(ap);
Console.WriteLine("Other thread is done!");
}
static async Task Sum(object data)
{
await Task.Run(() …Run Code Online (Sandbox Code Playgroud) 当我通过 Visual Studio Code 加载文件时,VScode 找不到目录。
我可以在没有终端问题的情况下运行代码,结果是:
young@young-desktop:/media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials/10_RNN/ChatBot$ python text_load_text.py
['fij\n', 'feijfaef\n', 'ef\n', 'awef\n', 'awe\n', 'g\n', 'aweg\n', 'ae\n', 'wg\n', 'awe\n', 'h\n', 'aw\n', 'h\n', 'aw\n', 'ef\n', 'aweg\n', 'wea\n', 'gaw\n', 'eg\n', '\n']
Run Code Online (Sandbox Code Playgroud)
但是使用 VScode:
young@young-desktop:/media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials$ cd /media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /home/young/anaconda3/bin/python /home/young/.vscode/extensions/ms-python.python-2018.6.0/pythonFiles/PythonTools/visualstudio_py_launcher.py /media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials 39707 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput /media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials/10_RNN/ChatBot/text_load_text.py
Traceback (most recent call last):
File "/media/young/5e7be152-8ed5-483d-a8e8-b3fecfa221dc/text/mycodehtml/pracdl/golbin/TensorFlow-Tutorials/10_RNN/ChatBot/text_load_text.py", line 8, in <module>
with open('test.txt', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
Run Code Online (Sandbox Code Playgroud)
什么原因导致这个问题?
test.txt 文件原本打算位于 ./data/test.txt
所以我测试了
with open('./data/test.txt', 'r') as …Run Code Online (Sandbox Code Playgroud)