Skip to content

Instantly share code, notes, and snippets.

View ychaouche's full-sized avatar

Yassine Chaouche ychaouche

View GitHub Profile
@ychaouche
ychaouche / plot.py
Created January 30, 2014 11:10
How to properly debug this ?
chaouche@karabeela ~/CODE/TEST/PYTHON $ cat plot.py
import numpy
from matplotlib import pyplot
x = numpy.arange(0, 5, 0.1);
y = numpy.sin(x)
pyplot.plot(x, y)
chaouche@karabeela ~/CODE/TEST/PYTHON $ python plot.py
False
<new.Person instance at 0x8ef080c>
Since python is dynamic, list items can have arbitrary values, they don't have to be all of the same type, which is nice. Consider this other example :
characters = [ogre, knight, soldier, artillery]
for character in characters :
character.attack()
character.move()
character.defense()
ogre, knight, soldier and artillery are all objects of different classes, thus they have different types, but they can all be inside one single list. We also suppose that they all have implement an attack method, a move method and a defense method. Since the language is dynamic, you can assign each one to a variable named character and call methods on that variable. You don't have to bind that variable to a type yourself, the language takes care of this at runtime. Each time you assign a value to that variable, its type changes. And if the value you give to it is an object, and as long as that object have the methods and attributes you're asking for, no problem. This is called duck typing and I think this makes th
import openerp
pool = openerp.modules.registry.RegistryManager.get("test")
# get a valid cursor (for browse, search etc.)
cr = pool.db.cursor()
# get the superadmin user ID to have special powers
uid = openerp.SUPERADMIN_ID
# get the module object from the pool
module = pool.get("ir.module.module")
# We want to uninstall the "helloworld" module for instance
uninstall_id = module.search(cr,uid,[("name","=","helloworld")])[0]
import openerp
pool = openerp.modules.registry.RegistryManager.get("test")
# get a valid cursor (for browse, search etc.)
cr = pool.db.cursor()
# get the superadmin user ID to have special powers
uid = openerp.SUPERADMIN_ID
# get the module object from the pool
module = pool.get("ir.module.module")
# We want to uninstall the "helloworld" module for instance
uninstall_id = module.search(cr,uid,[("name","=","helloworld")])[0]
chaouche@karabeela ~/PROG/MERGOU-BZR $ pip search simplegui
SimpleGUICS2Pygame - Primarily a standard Python module reimplementing the SimpleGUI particular module of CodeSkulptor (a browser Python
interpreter).
SimpleGUITk - A wrapper for the CodeSkulptor SimpleGUI API using TkInter
simplegui - simplegui - Simplified GUI generation using Tkinter
chaouche@karabeela ~/PROG/MERGOU-BZR $
chaouche@karabeela ~ $ cat TMP7/CODE/testradiotk.py
import Tkinter
#--------------------------------------------#
root = Tkinter.Tk()
#--------------------------------------------#
# Labels
mlabel = Tkinter.Label(root,text='Open').pack()
mlabel2 = Tkinter.Label(root,text='Save').grid(row=0,column=5,sticky=Tkinter.W)
#--------------------------------------------#
root.mainloop()
...
file_extentions = [('e01', '.e01'),...]
mGui.fileName = filedialog.askopenfilename( filetypes = (file_extension[my_int_var] ,('All Files', '*.*') ) )
...
# Radio Buttons
my_int_var = Tkinter.IntVar()
Radiobutton(mGui,text='.aff',value = 0,variable = my_int_var).grid(row=3,column=0,sticky=W)
Radiobutton(mGui,text='.dd' ,value = 1,variable = my_int_var).grid(row=3,column=1,sticky=W)
Radiobutton(mGui,text='.e01',value = 2,variable = my_int_var).grid(row=3,column=2,sticky=W)
chaouche@karabeela ~/CODE/FB/IMPYTHONIST $ cat seq.py
# gets the list of integers, strips the "\r" special character
L = [int(i.strip()) for i in open("num.txt").read().split("\n")]
seq = [-999999]
tmpseq = [-999999]
for i in L:
if i > tmpseq[-1]:
tmpseq.append(i)
else:
L=[int(num) for num in open('num.txt').readlines()]
greatest = -999999
new_start = new_end = old_start = old_end = 0
for index,item in enumerate(L):
if item > greatest:
new_end = index
else :
if (new_end - new_start) > (old_end - old_start) :
old_start,old_end = new_start,new_end
new_start = new_end = index
chaouche@karabeela ~/TMP7/CODE $ cat > debian.py
my_tuple = ('string1', 'string2')
def my_tuple(string1, string2):
global my_tuple
my_tuple = (string1, string2)
print "These strings has been appended to your tuple:", "%s %s" % (string1, string2)
print
print "my_tuple =", my_tuple