除了通过pip从/ site-data文件夹加载已安装的python模块的负载之外,我猜那是设置PYTHONPATH的地方
它是从其他地方加载的吗?例如,当我调用python app.py时的当前路径?
答案 0 :(得分:0)
它使用safe_import,它最终使用Python内置函数中的static void Main(string[] args)
{
string fileDirectory;
string printServer;
string printerQueue;
string sftpServer;
string sftpUsername;
string sftpPassword;
Get_AppSettings(out fileDirectory, out printServer, out printerQueue, out sftpServer, out sftpUsername, out sftpPassword);
//DirectoryInfo dir = new DirectoryInfo(fileDirectory);
using (SftpClient sftp = new SftpClient(sftpServer, sftpUsername, sftpPassword))
{
try
{
sftp.Connect();
using (PrintServer printer = new PrintServer(printServer))
{
using (PrintQueue queue = new PrintQueue(printer, printerQueue))
{
var files = sftp.ListDirectory(fileDirectory);/*
foreach (SftpFile file in files)
{
string fileName = file.Name;
string filePath = file.FullName;
using (Stream fs = File.OpenWrite(".\\workfiles\\" + fileName))
{
sftp.DownloadFile(filePath, fs);
}
} */
foreach (SftpFile file in files)
{
string fileName = file.Name;
string filePath = file.FullName;
Stream fr = File.OpenRead(".\\workfiles\\" + fileName);
long length = fr.Length;
PrintSystemJobInfo printJob = queue.AddJob(fileName);
byte[] bytes = new byte[length];
int len = fr.Read(bytes, 0, Convert.ToInt32(length));
printJob.JobStream.Write(bytes, 0, len);
printJob.Pause();
fr.Close();
//sftp.DeleteFile(".\\workfiles\\" + fileName);
printJob.JobStream.Close();
}
}
}
sftp.Disconnect();
}
catch (Exception except)
{
}
}
}
。这意味着您的组件必须可以通过普通的Python导入路径导入。