我是Mac的新手,我正在尝试在MAC上安装MySQLdb for Python但是在按照http://www.tutorialspoint.com/python/python_database_access.htm上提到的步骤操作后,我在运行后收到错误
$ python setup.py build
Run Code Online (Sandbox Code Playgroud)
错误:
clang: warning: argument unused during compilation: '-mno-fused-madd'
_mysql.c:44:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
注意:我的"mysql_config"路径是/ Applications/MAMP/Library/bin/mysql_config我该怎么办?
有没有办法在Python中为数组中的键赋值?
PHP中的示例:
$inputArr = array(
'vertex'=>values[0],
'visited'=>values[1],
'letter' => $values[2]
)
Run Code Online (Sandbox Code Playgroud)
这是我在Python中尝试的方式:
file_name = input('Enter a file name: ')
f = open(file_name, 'r')
data = f.readlines() //Read the lines
for line in data:
values = line.split(' ') Split line following the spaces
inputArr = array(
'vertex'=>values[0], //Pass each value to a key in that array
'visited'=>values[1],
'letter' => $values[2]
)
print (inputArr)
Run Code Online (Sandbox Code Playgroud) 我试图使用pop与列表,但它给了我以下错误
AttributeError: 'str' object has no attribute 'pop'
Run Code Online (Sandbox Code Playgroud)
我使用pop的方式是:
vertex = my_queue.pop()
Run Code Online (Sandbox Code Playgroud)
令人困惑的是,当我使用print(顶点)时,它打印出数据,这意味着它工作正常,但同时显示错误令人困惑.
我的代码:
def bfs(my_data):
my_queue = [] #array to store vertices
#print(my_data[0])
my_queue.insert(0, my_data[0]);
my_data[0]['visited'] = '1';
int_vertex = []
while my_queue:
vertex = my_queue.pop()
for n_vertex in vertex['neighbors']:
#print(type(n_vertex))
int_vertex = int(n_vertex)
if my_data[int_vertex]['visited'] == '0':
my_data[int_vertex]['visited'] = '1'
test.insert(0, my_data[int_vertex])
my_queue = str(test)
Run Code Online (Sandbox Code Playgroud)
my_queue和my_data是列表,顶点是dict
我正在尝试使用验证方法验证Signin()和Signup()的用户名和密码字段.现在,当我输入正确的用户名时,它会继续显示错误,我不知道为什么.
验证方法:
void signup_username_validation(String username) //Username validation for signup
{
String user_name = "";
if(user_name.length() < 6 || user_name.length() > 15)
{
System.out.println("Username cannot be less then 6 and greater then 15 characters");
Signup();
}
}
void signup_password_validation(String password) //Password validation for signup
{
String pass = "";
if(pass.length() < 6)
{
System.out.println("Password cannot be less then 6 characters");
Signup();
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我打电话给他们的方式
System.out.println("Enter Username: ");
username = keyboard.next();
signup_username_validation(username);
System.out.println("Enter Password: ");
password = keyboard.next();
signup_password_validation(password);
Run Code Online (Sandbox Code Playgroud)