小编Roy*_*ish的帖子

Python:使Pickle文件更安全吗?

在我的Python程序中,我使用了Pickle模块来保存用户定义,然后在下次运行程序时将它们加载回来.现在我从Python Wiki网站上的UsingPickle文章中了解到,Pickle文件很可能被黑客攻击等等,使其变得不安全.

我注意到Pickle文件通常只留在Python脚本所在的目录中.有没有办法让这些文件更安全,远离视线?如果是这样,当在安装脚本中包含Pickle文件时,这会如何影响我在脚本上使用cx_Freeze?

import pickle

terms = pickle.load(open("save.p", "rb"))

def print_menu():
    print('Computing Terms')
    print()
    print('0. Quit')
    print('1. Look Up a Term')
    print('2. Add a Term')
    print('3. Redefine a Term')
    print('4. Delete a Term')
    print('5. Display All Terms')

while True:
    print_menu()
    print()
    choice = input('Choice: ')
    if choice == '0':
        break
    elif choice == '1':
        print('\n')
        term = input('Type in a term you wish to see: ')
        if term in terms:
            definition = terms[term]
            print('\n')
            print(term, '-', definition, '\n')
            print()
            print('----------------------------------------------------------------') …
Run Code Online (Sandbox Code Playgroud)

python pickle

1
推荐指数
1
解决办法
3179
查看次数

Python - tkinter'AttributeError:'NoneType'对象没有属性'xview''

我正在尝试在DISABLED Entry窗口小部件上放置滚动条.然而,它不断出现错误AttributeError: 'NoneType' object has no attribute 'xview'.是因为没有返回任何值,或者无论是否返回值,小部件都应该出现?

以下是我的程序的代码; 我已经注释掉了滚动条的代码:

from tkinter import *
from tkinter import ttk

def calculate(*args):
    try:
        value = int(binary.get(), 2)
    except ValueError:
        pass

    decimal.set(value)

root = Tk()
root.title("Binary to Decimal Converter")
root.wm_iconbitmap("python-xxl.ico")

mainframe = ttk.Frame(root, padding = "3 3 12 12")
mainframe.grid(column = 0, row = 0, sticky = (N, W, E, S))
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)

binary = StringVar()
decimal = StringVar()

binary_entry = ttk.Entry(mainframe, width …
Run Code Online (Sandbox Code Playgroud)

python tkinter scrollbar

1
推荐指数
1
解决办法
3980
查看次数

JavaScript - 验证日期输入,因此它只是当前或未来

我正在尝试验证日期输入框,以便它只接受当前或未来的日期.到目前为止,我一直在努力寻找最终确实如此的答案.

这是输入框的HTML,不包括<form>标签:

<p>
   <label>Date:</label>
   <br>
   <input type="number" name="date" placeholder="DD/MM/YYYY" onchange="checkDate()">
</p>
<div id="datewarn"></div> 
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的JavaScript代码,它验证输入的格式是DD/MM/YYYY,输入的数字是有效的日历编号,但这仍然接受过去的日期.

function checkDate() {
    var valid = true;
    var redate = /(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d/;

    if (!redate.test(document.bookingsform.date.value)) {
        document.bookingsform.date.style.border = "1px solid red";
        document.getElementById("datewarn").innerHTML = "Enter a date in the format DD/MM/YYYY.";
        document.bookingsform.date.title = "Please enter a date in the format DD/MM/YYYY.";
        document.getElementById("datewarn").style.display = "block";
        valid = false;
    } else {
        document.bookingsform.date.style.border = "1px inset #EBE9ED";
        document.bookingsform.date.style.borderRadius = "2px";
        document.getElementById("datewarn").style.display = "none";
    }
}
Run Code Online (Sandbox Code Playgroud)

我做过的研究建议使用date.js库?这是一个内置的库还是我必须得到的东西?

这只能是JavaScript,没有jQuery.

编辑:对不起,忘了添加RegEx变量.

javascript validation date

1
推荐指数
1
解决办法
4万
查看次数

SQL Server - 与where子句相反

我有一个数据集,我想过滤掉满足特定条件的行,但是它比我想象的要复杂得多.

基本上我想做的事情是这样一种WHERE (column1 NOT LIKE 'Z%' and column2 != '2')观点,即查询只会返回一行,其中某一特定行没有像column1中的'Z%'那样的值,并且在column2 中没有值'2' .

例如:

完整的数据集

column1 | column2
-----------------
ACAL    | 2
-----------------
ZVBBU3  | 2
-----------------
FSKE2   | X
Run Code Online (Sandbox Code Playgroud)

我想要的数据集

column1 | column2
-----------------
ACAL    | 2
-----------------
FSKE2   | X
Run Code Online (Sandbox Code Playgroud)

但是,它没有这样做.所以,我想有可能是一个编程方法类似WHERE (!(column1 LIKE 'Z% and column2 = '2')),其中!将返回指定标准的对面,但是,这将引发一个语法错误.有没有办法做我想做的事情?

sql sql-server-2005

1
推荐指数
1
解决办法
1342
查看次数

JavaScript - 检查单选按钮是否被选中

在我的表单中,我有两个单选按钮,页面有一个脚本来验证表单本身,直到单选按钮。因此,如果您在单选按钮之前满足所有条件,您将能够提交表单,因此我自然要确保用户在提交表单之前选择一个选项。

我在这里找到了一个函数:Radio button validation in javascript

我已经改编了顶部答案中的脚本以适合我当前的脚本,但它不起作用。它要么崩溃,要么显示错误,但仍会转到提交页面。

自从答案使用var formValid = false;和我使用valid = true;.

我已经注释掉了函数的单选按钮检查部分并将其返回到默认参数(并清除了答案对大括号的错误使用)。

function checkForm() {
    var valid = true;
    var radios = document.getElementsByName("smoking");

    if (!retext.test(document.myform.textfield.value)) {
            document.myform.textfield.style.border = "3.5px solid red";
            document.getElementById("text").innerHTML = "Invalid text.";
            document.getElementById("text").style.display = "block";
            valid = false;
    }

    if (!re.test(document.myform.email.value)) {
        document.myform.email.style.border = "3.5px solid red";
        document.getElementById("emailwarn").innerHTML = "Invalid email.";
        document.getElementById("emailwarn").style.display = "block";
        valid = false;
    }

    if (!retel.test(document.myform.tel.value)) {
        document.myform.tel.style.border = "3.5px solid red";
        document.getElementById("telwarn").innerHTML = "Invalid telephone …
Run Code Online (Sandbox Code Playgroud)

html javascript forms

0
推荐指数
1
解决办法
1万
查看次数

WPF - 如何根据不同类的方法的进度更新ProgressBar?

在我的 WPF 应用程序中,我有一个 ProgressBar,我想Value根据另一个类的方法中取得的进度动态设置其属性。但是我不确定如何做到这一点。

执行该工作的类和方法类似于:

public class WorkerClass
{
    public void doSomething(string filePath)
    {
        using (var package = new Package(filePath)) 
        {
            foreach (var item in package) 
            {
                updateMethod(item); //once this method call is complete I want the ProgressBar to update its Value
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在 MainWindow.xaml.cs 类中,关注的方法是一个button_Click()方法:

private void btnUpload_Click(object sender, RoutedEventArgs e)
{
    progressBar.Value = 10;

    WorkerClass worker = new WorkerClass();
    worker.doSomething(txtFilePath.Text); //I want the ProgressBar value to update during this method execution …
Run Code Online (Sandbox Code Playgroud)

c# wpf .net-4.5

0
推荐指数
1
解决办法
3836
查看次数

标签 统计

javascript ×2

python ×2

.net-4.5 ×1

c# ×1

date ×1

forms ×1

html ×1

pickle ×1

scrollbar ×1

sql ×1

sql-server-2005 ×1

tkinter ×1

validation ×1

wpf ×1