Python: Array v. List [duplicate]

Use lists unless you want some very specific features that are in the C array libraries. python really has three primitive data structures tuple = (‘a’,’b’,’c’) list = [‘a’,’b’,’c’] dict = {‘a’:1, ‘b’: true, ‘c’: “name”} list.append(‘d’) #will add ‘d’ to the list list[0] #will get the first item ‘a’ list.insert(i, x) # Insert an … Read more

Creating random binary files

IMHO – the following is completely redundant: f.write(struct.pack(“=I”,random.randint(0,sys.maxint*2+1))) There’s absolutely no need to use struct.pack, just do something like: import os fileSizeInBytes = 1024 with open(‘output_filename’, ‘wb’) as fout: fout.write(os.urandom(fileSizeInBytes)) # replace 1024 with a size in kilobytes if it is not unreasonably large Then, if you need to re-use the file for reading integers, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)