Global variables in a C extension for Python

2011-12-28 Thread Lorenzo Di Gregorio
Hello, I've written a C extension for Python which works so far, but now I've stumbled onto a simple problem for which I just can't find any example on the web, so here I am crying for help ;-) I'll trying to reduce the problem to a minimal example. Let's say I need to call from Python

How to print zero-padded floating point numbers in python 2.6.1

2009-11-04 Thread Lorenzo Di Gregorio
Hello, I thought that I could zero-pad a floating point number in 'print' by inserting a zero after '%', but this does not work. I get: print '%2.2F' % 3.5 3.50 print '%02.2F' % 3.5 3.50 How can I get print (in a simple way) to print 03.50? Best Regards, Lorenzo --

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Lorenzo Di Gregorio
On 21 Jun., 22:51, Scott David Daniels scott.dani...@acm.org wrote: LorenzoDiGregoriowrote: On 21 Jun., 01:54, Dave Angel da...@ieee.org wrote: ... class B(object):     def __init__(self,test=None):         if test==None:             test = A()         self.obj =()         return

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Lorenzo Di Gregorio
On 21 Jun., 01:54, Dave Angel da...@ieee.org wrote: LorenzoDiGregoriowrote: On Jun 20, 8:43 pm, Dave Angel da...@ieee.org wrote: LorenzoDiGregoriowrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem:

Inheritance and forward references (prototypes)

2009-06-20 Thread Lorenzo Di Gregorio
Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here I would have a prototype of

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Lorenzo Di Gregorio
On Jun 20, 8:43 pm, Dave Angel da...@ieee.org wrote: Lorenzo Di Gregorio wrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object):     def __init__(self):         return

Re: once assigment in Python

2007-09-17 Thread Lorenzo Di Gregorio
On 17 Sep., 16:54, Larry Bates [EMAIL PROTECTED] wrote: IMHO variables like what you describe are really data not program variables. You might consider putting variables like these in a dictionary and then check to see if the keys exist before assignment: var_dict={} # # See if 'varname'

once assigment in Python

2007-09-14 Thread Lorenzo Di Gregorio
Hello, I've been using Python for some DES simulations because we don't need full C speed and it's so much faster for writing models. During coding I find it handy to assign a variable *unless it has been already assigned*: I've found that this is often referred to as once assigment. The best I

Re: once assigment in Python

2007-09-14 Thread Lorenzo Di Gregorio
Thank you very much for your suggestions! I'll try in the next days to elaborate a bit on the last two ones. By the way, the once assignment is not that evil if you use it for hardware modeling. Most hardware models look like: wire1 = function() instance component(input=wire1,output=wire2)