我已成功导入单个文件,但该文件调用其他文件,我收到错误。所以我正在尝试导入整个文件夹。我不想逐个导入每个文件,因为我知道必须可以导入整个文件夹。以下是我用于导入文件的语法:
import importlib.machinery
import os
temp_directory2 = '/Users/me/PycharmProjects/inference_engine2/inference2/ancient/temp.py'
temp_directory = '/Users/me/PycharmProjects/inference_engine2/inference2/Proofs/main_loop.py'
main_directory = '/Users/me/PycharmProjects/inference_engine2/inference2/Proofs/'
b = os.path.exists(temp_directory)
loader = importlib.machinery.SourceFileLoader('temp', temp_directory)
handle = loader.load_module('temp')
答案 0 :(得分:1)
使用__init__.py
将其转换为包。更多信息:https://docs.python.org/2/tutorial/modules.html
答案 1 :(得分:1)
您可以在文件开头添加列表<?php
require_once "connection.php";
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$username= $_POST['username'];
$password= sha1($_POST['password']);
$sql = "SELECT * FROM information WHERE username = '$username' AND password
='$password'";
$result = mysqli_query($connection, $sql);
if($result){
echo "Yippii";
} else {
echo "Error";
}
$rowcount = mysqli_num_rows($result);
if($rowcount > 0){
echo "Uspw ok";
$row = mysqli_fetch_assoc($result);
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
$_SESSION['id'] = $row['id'];
$_SESSION['status'] = $row['status'];
$_SESSION['username'] = $username;
$_SESSION['login'] = true;
echo $_SESSION['username'];
echo $_SESSION['id'];
if($_SESSION['status'] == "1"){
header('Location: red_form.php');
} else {
header('Location: yellow_form.php');
}
}
}
?>
</body>
</html>
的路径,如下所示:
sys.path
注意,因为你是在列表的开头插入路径,所以这是python寻找模块的第一个地方。