jeudi 29 octobre 2015

Will this method be ran in my 'if' statement? [duplicate]

This question already has an answer here:

I am wondering what the order of operations is in my if statement.

if not myBool and myFunc():
    # do something
    pass

in the above code, if the myBool variable is true, will the if statement stop there and not run the myFunc() function or will both of them be checked/ran irregardless?

ANSWER: the function will not be ran

xslt performance issue with large if conditions

In my xslt i have code like

 <xsl:param name="acceptType"/>
 <xsl:template match="element-1|element-2............|element-n>
   <xsl:if test=".!=''">           
         <xsl:if test="not(contains($acceptType, 'xml'))">
            <xsl:element name="{local-name()}">
               <xsl:value-of select="$pARRAY"/>
            </xsl:element>
         </xsl:if>
      </xsl:if>
   </xsl:template>

Here i have nearly 1000 elements .Because of this condition checking we are having the performance issue.Is there any alternative way for doing this?.I am thinking to put a global boolean variable and want to check that variable.Is it the right way to increase performance.

Thanks in advance..

For loop with If condition - Iteration when if condition not met

I have this code where i want this for loop to iterate for each row. But this code get do not iterate when the if condition is false. I tried "continue" in else part.But it did not work. Even though if i place a msgbox in else part and click msg box at each time it display then the loop continue. but it is not practical as I have 1000s of rows to check on.

For i = 0 To CustomerDataSet.customer.Rows.count - 1
If i<2 Then
 'Do somethin'
End If
Next

Pleaes help me to make this for loop continue without any user interaction.

Using len with get() function giving incorrect statistics?

I have some code which asks the user to input 26 characters to make their own encryption code and if it's 26 characters long and is not the alphabet or the preset encryption_code, the code will change the encryption_code to whatever they've entered. import tkinter from tkinter import * from tkinter import ttk from tkinter.ttk import *

encryption_code = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'

window = tkinter.Tk()    
window.title("Encryption/Decryption")

change_frame = tkinter.Frame(window)
changed_frame = tkinter.Frame(window)

encrypt_entry = tkinter.Entry(change_frame)

def code_change():
    global changed_frame
    global encrypt_entry
    print(len(encrypt_entry.get()))
    if encrypt_entry.get() == 'LFWOAYUISVKMNXPBDCRJTQEGHZ' or 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
        encrypt_entry.delete(0, tkinter.END)
        changed_incorrect.configure(background=window.cget('bg'))
        changed_incorrect.config(text="Please enter a different code", foreground='red')
        changed_incorrect.pack()
        changed_frame.pack()

    if len(encrypt_entry.get()) == 26:
        encryption_code = encrypt_entry.get()
        encrypt_entry.delete(0, tkinter.END)
        changed_label.configure(background=window.cget('bg'))
        changed_label.config(text="You have successfully changed the encryption code!")
        change_header.config(text=str(encryption_code))
        changed_incorrect.pack_forget()
        changed_label.pack()
        changed_frame.pack()

    elif len(encrypt_entry.get()) < 26 or len(encrypt_entry.get()) > 26:
        changed_incorrect.configure(background=window.cget('bg'))
        changed_incorrect.config(text="Please enter only 26 characters", foreground='red')
        changed_label.pack_forget()
        changed_incorrect.pack()
        changed_frame.pack()

change_label = tkinter.Label(change_frame, text="Please enter your own encryption code in block capitals", font=('Helvetica', 12))
change_header = tkinter.Label(change_frame, text="Make sure it is all 26 letters and do not repeat a letter to prevent errors", font=('Helvetica', 12))
change_confirm = ttk.Button(change_frame, text="Confirm", width=20,  command=code_change)

changed_label = tkinter.Label(changed_frame, text="You have successfully changed the encryption code!", font=('Helvetica', 14))
changed_incorrect = tkinter.Label(changed_frame, text="Please enter your code again", font=('Helvetica', 14))

change_label.pack()
change_header.pack()
encrypt_entry.pack()
change_confirm.pack()
change_frame.pack()

window.mainloop()

My problem is whenever I try and input 26 characters e.g. QWERTYUIOPASDFGHJKLZXCVBNM, it tells me I haven't entered 26 characters when it clearly is 26 characters and the message is only meant to pop up if the user hasn't entered 26 characters.

UPDATE: using print(len(encrypt_entry.get())) has shown me that my entry is 26 but my code is saying it's not 26 characters.

If condition in python in a loop

I am facing difficulty with the correct syntax of the if condition. I want to apply the condition to check the equality of a string. But the way i am trying to do it, is giving me an error:

AttributeError: 'str' object has no attribute 'any'
for :
for a in prod_comm:
    if prod_comm['label']==('label":"neg"}').any():
        prod_pos.append(a)

or :

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
for :
for a in prod_comm:
    if prod_comm.label==('label":"neg"}'):
        prod_neg.append(a)

What I am trying to do is: have a dataframe with 2 columns- c and label. I want to divide this dataframe into different files based on the type of label, which is either:

label":"neg"}    or     label":"pos"}

How may i go forward with the classification? I guess there is an issue with the syntax i am using, but can't find the correct syntax on the net.

Example dataset:
        comment                                  label
    0   need 3 bhk house                         "label": "neg"}
    2   tried to list my property                "label": "neg"}
    22  i have issue with the map                "label": "neg"}
    24  also help with the rental agreements     "label": "pos"}
    37  sort option should be available.         "label": "pos"}

expected output:
two datasets:
prod_pos - with the comments corresponding to label: "label": "pos"}
prod_neg - with the comments corresponding to label: "label": "neg"}
i.e. 

prod_pos:
    comment                                  label
24  also help with the rental agreements     "label": "pos"}
37  sort option should be available.         "label": "pos"}

prod_neg:
        comment                                  label
    0   need 3 bhk house                         "label": "neg"}
    2   tried to list my property                "label": "neg"}
    22  i have issue with the map                "label": "neg"}

Thanks for your help!

Break for loop if variable is false

Trying to break a for loop if the variable $DEVP doesn't exist.

nme=(Y6T1 Y6-T1 Y6.T1 Yr6T1 Yr6-T1 Yr6.T1 Yr6Term1)
DEVP=(/dev/disk2 /dev/disk3 /dev/disk4 /dev/disk5 /dev/disk6 /dev/disk7 /dev/disk8)

for ((i = 0; i < 7; i++)) ; do 
    if [ ${nme[i]} ${DEVP[i]} = 0 ] ; then
        diskutil eraseDisk FAT32 ${nme[i]} ${DEVP[i]}
    else
        echo “Formatted USBs” ; break
    fi
done

Why am I getting this error? How can I fix?

I am getting the error "mysql_fetch_assoc() expects parameter 1 to be resource" I believe I am missing something, but I don't know what it could be. If I remove the "mysql_fetch_assoc" I get a similar error. I am new to PHP.

if ($username) {
    if ($_POST['submit']) {
        $oldpassword = $_POST['oldpassword'];
        $newpassword = $_POST['newpassword'];
        $repeatnewpassword = $_POST['repeatnewpassword'];

        $connect = mysqli_connect("localhost", "root", "Nflfan40", "phplogin"); 
        mysqli_select_db($connect, "phplogin");

        $queryget = ("SELECT password FROM users WHERE username = '$username'") or die("Error: Unregistered user.");
        $row = mysql_fetch_assoc($queryget);

        $oldpassworddb = $row['password'];

        if ($oldpassword==$oldpassworddb)
        {
            if ($newpassword==$repeatnewpassword) {
                echo "yay!";
            }
            else
                die("Error: New passwords don't match.");
        }
        else
            die("Error: Wrong initial password.");
    }
}
else
    die("Error: Must be logged in.");

What does this mean and how can this be resolved?