This is python 3.5 under Lubuntu. I'm creating a two-dimensional list of 0's (8 x 64) and then I assign a value to each position (dirty and fast way to store a cryptographic transformation, I'm just prototyping). When I try to retrieve the value stored in any position I get a different value than the one I stored (see doctest at the end of the code).  I'd like to know what's happening and why I'm not getting the results I'm expecting (if I can't find a solution I'm going to change it to a huge if-elif block).  _taulesS = 8 * [64 * [0]]  _taulesS[0][0] = 14 _taulesS[0][1] = 0 _taulesS[0][2] = 4 _taulesS[0][3] = 15 ... _taulesS[0][13] = 13 _taulesS[0][14] = 8 _taulesS[0][15] = 1 _taulesS[0][16] = 3 _taulesS[0][17] = 10 _taulesS[0][18] = 10 _taulesS[0][19] = 6 ... _taulesS[0][62] = 0 _taulesS[0][63] = 13 _taulesS[1][0] = 15 _taulesS[1][1] = 3 _taulesS[1][2] = 1 _taulesS[1][3] = 13 ...  _taulesS[1][62] = 15 _taulesS[1][63] = 9 _taulesS[2][0] = 10 _taulesS[2][1] = 13 ... _taulesS[7][59] = 5 _taulesS[7][60] = 5 _taulesS[7][61] = 6 _taulesS[7][62] = 8 _taulesS[7][63] = 11   def taulesS(s, value):     """     &gt;&gt;&gt; taulesS(0, 17)     10      Doctest fails, taulesS(0, 17) returns 12     """     return _taulesS[s][value]
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
64500
Currently, I'm trying to get a method in Python to return a list of zero, one, or two strings to plug into a string formatter, and then pass them to the string method. My code looks something like this:  class PairEvaluator(HandEvaluator):   def returnArbitrary(self):     return ('ace', 'king')  pe = PairEvaluator() cards = pe.returnArbitrary() print('Two pair, {0}s and {1}s'.format(cards))   When I try to run this code, the compiler gives an IndexError: tuple index out of range. How should I structure my return value to pass it as an argument to .format()?
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
59865
I'm trying to make a game where the damage you deal is rolled by a dice. It all works. However, it keeps on giving the same values in a row so it isn't entirely random  ini_open("Health.ini"); attack = ini_read_real( "Attacks", "Felix", 0); ini_close(); global.damage=0 repeat(attack){ global.damage=irandom(6) }   if (global.damage ==0){instance_create_depth(300, 400, 0, obj_numbers0)} if (global.damage ==1){instance_create_depth(400, 400, 0, obj_numbers1)} if (global.damage ==2){instance_create_depth(500, 400, 0, obj_numbers2)} if (global.damage ==3){instance_create_depth(600, 400, 0, obj_numbers3)} if (global.damage ==4){instance_create_depth(700, 400, 0, obj_numbers4)} if (global.damage ==5){instance_create_depth(800, 400, 0, obj_numbers5)} if (global.damage ==6){instance_create_depth(900, 400, 0, obj_numbers6)}   The attack value is 1 because it is only one dice that is used for damage for now. The software I am using is Game Maker Studio 2
12905
How do you get the  of two variables in Python?  For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):  str1 = raw_input("Enter string one:") str2 = raw_input("Enter string two:") if logical_xor(str1, str2):     print "ok" else:     print "bad"   The ^ operator seems to be bitwise, and not defined on all objects:  &gt;&gt;&gt; 1 ^ 1 0 &gt;&gt;&gt; 2 ^ 1 3 &gt;&gt;&gt; "abc" ^ "" Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: unsupported operand type(s) for ^: 'str' and 'str'
2525
My  has failed me.  In Python, are the following two tests for equality equivalent?  n = 5 # Test one. if n == 5:     print 'Yay!'  # Test two. if n is 5:     print 'Yay!'   Does this hold true for objects where you would be comparing instances (a list say)?  Okay, so this kind of answers my question:  L = [] L.append(1) if L == [1]:     print 'Yay!' # Holds true, but...  if L is [1]:     print 'Yay!' # Doesn't.   So == tests value where is tests to see if they are the same object?
69570
I'm testing an implementation of Bitcoin, which uses the curve Secp256k1 for ECDSA, and I want to see how it handles the point at infinity ($0$) if present in a signature. For example, r could be the x coordinate of the encoding of the point at infinity.   How is the $0$ encoded? Can it be encoded?  I found that bouncycastle prefixes the encoding of 0 with 0x00, and has some other defined prefixes (ECCurve.decodePoint()) but I don't known how this information applies (or even if it does apply to) to the encoding of $(r,s)$. This info seems to be in the X9.62 standard.
49176
Why does python 2.5.2 have the following behavior  &gt;&gt;&gt;[2].extend([]) == [2] False  &gt;&gt;&gt; [2].extend([]) == None True  $ python --version Python 2.5.2   I assume I'm not understanding something here, but intuitively I'd think that [2].extend([]) should yield [2]
4991
Using SQLite3 with Python 2.5, I'm trying to iterate through a list and pull the weight of an item from the database based on the item's name.  I tried using the "?" parameter substitution suggested to prevent SQL injections but it doesn't work. For example, when I use:  for item in self.inventory_names:     self.cursor.execute("SELECT weight FROM Equipment WHERE name = ?", item)     self.cursor.close()   I get the error:     sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 8 supplied.   I believe this is somehow caused by the initial creation of the database; the module I made that actually creates the DB does have 8 bindings.  cursor.execute("""CREATE TABLE Equipment      (id INTEGER PRIMARY KEY,      name TEXT,     price INTEGER,      weight REAL,      info TEXT,      ammo_cap INTEGER,      availability_west TEXT,     availability_east TEXT)""")   However, when I use the less-secure "%s" substitution for each item name, it works just fine. Like so:  for item in self.inventory_names:     self.cursor.execute("SELECT weight FROM Equipment WHERE name = '%s'" % item)     self.cursor.close()   I can't figure out why it thinks I have 8 bindins when I'm only calling one. How can I fix it?
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
76150
byte x = -1; for(int i = 0; i &lt; 8; i++) {     x = (byte) (x &gt;&gt;&gt; 1);     System.out.println("X: " + x); }   As I understand it, java stores data in two's-complement, meaning -1 = 11111111 (according to wikipedia).    Also, from the java docs: "The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension. "  Which means that >>> would shift a 0 to the left most bit every time.  So I expect this code to be  iteration: bit representation of x  0: 11111111  1: 01111111  2: 00111111  3: 00011111  ...so on  However, my output is always X: -1, meaning (I guess) that >>> is putting the sign bit in the left most position.  So I then try >>, and same result.  What's going on?  I would expect my output to be: X: -1, x: 127, x: 63, etc.
60990
I am attempting to create a plane and set the color; the following code throws an error at this line:    bpy.data.materials['RSgreen'].diffuse_color=(0,0,0)   the error is:  ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 3  which makes no sense to me; diffuse_color calls for 3 parameters in the .  bpy.ops.mesh.primitive_plane_add(size=4,enter_editmode=False,location=(-2,-2,0.01)) bpy.context.active_object.name='Plane2' bpy.ops.material.new() bpy.data.materials[1].name='RSgreen' bpy.data.materials['RSgreen'].diffuse_color=(0,0,0) bpy.context.object.data.materials.append(bpy.data.materials['RSgreen'])
90370
What is wrong with this command? It says it has a problem with value separators, but i can't find it  /summon ArmorStand ~ ~ ~10 {ShowArms:1,NoBasePlate:1,Pose:{LeftArm:[0f,0f0f],RightArm:[0f,0f,0f],Body:[0f,0f,0f],LeftLeg:[0f,0f,0f],RightLeg:[0f,0f,0f],Head:[0f,0f,0f]},ArmorItems:{id:diamond_boots,ench:[{id:protection,lvl:1000},{id:blast_protection,lvl:1000},{id:thorns,lvl:1000},{id:unbreaking,lvl:1000}]},{id:diamond_leggings,ench:[{id:protection,lvl:1000},{id:blast_protection,lvl:1000}, {id:thorns,lvl:1000},{id:unbreaking,lvl:1000}]}, {id:diamond_chestplate,ench:[{id:protection,lvl:1000},{id:blast_protection,lvl:1000},{id:thorns,lvl:1000},{id:unbreaking,lvl:1000}]},{id:diamond_helmet,ench:[{id:protection,lvl:1000},{id:blast_protection,lvl:1000},{id:thorns,lvl:1000},{id:unbreaking,lvl:1000}]}}
104224
I have been scratching my head about this one for the last day or so - I just can't see why a procedure works in one environment, but then fails in another due to a conversion error (same data, same code).  The plan for (a heavily cut down version of) the working server is here:   (This doesn't seem to be working, so I've uploaded the plan XML to pastebin here: )  A bit of background for the relevant columns causing the problem:  The propertyInst table holds a column called ValueStr, which is an nvarchar data type. The GeneralLedgerCode table has a column id of data type int. Our developers are attempting to join between the two tables. The ValueStr column holds text data, XML data, int data, decimal data etc. As a matter of course we decided to add a function to ensure only integers are parsed (ISNUMERIC(ValueStr) = 1). What we didn't realise is that this would then also try to convert any decimal values - this is causing a conversion error in production of the nature:  Conversion failed when converting the nvarchar value '0.1' to data type int.  My question here is, given that the Table Scan of the propertyInst table will be picking up all numeric values including decimals, why is the implicit conversion in the scalar operator then not failing with the same conversion error? The output of the ISNUMERIC query returns some of these decimals. I can't see how the attached plan is working at all.  Does an implicit conversion operator never fail outright, and is the conversion error coming from the probe residual in the hash match operator? Then again, how could the value even make it to the operator when it would fail the implicit conversion?  As a small assistance, the plan image is here, with the Compute Scalar I'm asking about circled.    In addition, I can see that there are no actual rows logged against the scalar operator - does this mean the engine decided not to use that particular operator at runtime due to the conversion error?    Any help would be appreciated.
61612
I'm looking for a  way to convert numbers to string format, dropping any redundant '.0'   The input data is a mix of floats and strings. Desired output:  0   --> '0'  0.0 --> '0'  0.1 --> '0.1'  1.0 --> '1'  I've come up with the following generator expression, but I wonder if there's a faster way:  (str(i).rstrip('.0') if i else '0' for i in lst)   The truth check is there to prevent 0 from becoming an empty string.  EDIT: The more or less acceptable solution I have for now is this:  ('%d'%i if i == int(i) else '%s'%i for i in lst)   It just seems strange that there is no elegant way to handle this (fairly straightforward) case in python.
79695
I am trying to calculate a field that marks duplicates and sequentially numbers them.  I am using the code below that I found here: .  It works, but I get a duplicate starting value before it begins sequentially numbering unless I only run the field calculator on the selected values.  When I calculate after manually selecting the duplicate rows and running it on only those values, it works fine.  Here's the code:  prevFieldValue = '' counter = 0 def GetDuplicateCounter(myFieldValue):   global prevFieldValue   global counter   if myFieldValue == prevFieldValue:     counter += 1   else:     counter = 1     prevFieldValue = myFieldValue   return counter   Results running it on all roads (nothing selected):    Results running it after manually selecting the duplicated fields (not too efficient!).
48764
Does anyone know how the built in dictionary type for python is implemented?  My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer.