constructor overwrite

2010-02-15 Thread Mug
hi ,i had a problem on constructor overwrite:
i have something like:

class obj:
def __init__(self, x=100, y=None):
if y is None:
  self.x=x
else:
  self.y=y
so i can call :
objet = obj()  # x=100 y=None
or
objet = obj(40) # x= 40 y=None

but if i do :
objet = obj('not cool') #x='not cool' y=None
since x is not typed .

i am waiting for a result:
objet = obj('not cool') #x=100 y='not cool'
as they do in C++ or java.
is there a way to do it?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


initilize a memory zone in python

2009-08-30 Thread Mug
hello, i'm new in python, i used to program in C,
i have a small problem, i tryed to do some serial port things
manipulation
with python.
i have something like:

import sys,termios

fd = sys.stdin.fileno()
term_conf=termios.tcgetattr(fd);

now i want to modify the actuall values in term_conf  zone to zero
i don't see how to do it,
in C we can do : bzero(term_conf,sizeof(struct termios));
i want to know if it exist a similar function in python, thanks
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: initilize a memory zone in python

2009-08-30 Thread Mug
On Aug 30, 8:58 pm, Diez B. Roggisch de...@nospam.web.de wrote:
 Mug schrieb:

  hello, i'm new in python, i used to program in C,
  i have a small problem, i tryed to do some serial port things
  manipulation
  with python.
  i have something like:

  import sys,termios

  fd = sys.stdin.fileno()
  term_conf=termios.tcgetattr(fd);

  now i want to modify the actuall values in term_conf  zone to zero
  i don't see how to do it,
  in C we can do : bzero(term_conf,sizeof(struct termios));
  i want to know if it exist a similar function in python, thanks

 In python you don't modify memory like that.

 For the above function, you pass a value as the one you got to
 tcgetattr, with values modified as you desire them.
i tryed
print term_conf
and i saw that the term_conf is actually represent with an array in
python:

zsh/3 4201 [1] % python test.py
[27906, 5, 1215, 35387, 15, 15, ['\x03', '\x1c', '\x7f', '\x15',
'\x04', '\x00', '\x01', '\xff', '\x11', '\x13', '\x1a', '\xff',
'\x12', '\x0f', '\x17', '\x16', '\xff', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00']]

it's a array of 7 elements, with the seventh element it self a array,
so in order to initialize them to zero, there's no other way than
modify them
one by one in a loop? is there a fonction like memset or bzero in
python?


 Diez

-- 
http://mail.python.org/mailman/listinfo/python-list