Re: initilize a memory zone in python

2009-08-31 Thread Diez B. Roggisch

Mug schrieb:

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?


Again: no, there is no such function. But for the above, you'd easily write:

foo = [0] * 7 # only do this with immutables
foo[-1] = ['\x00'] * 16

alternatively, you modify the result you got from tcgetattr in the 
places you want.




Diez
--
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 Diez B. Roggisch

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.


Diez
--
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


Re: initilize a memory zone in python

2009-08-30 Thread Grant Edwards
On 2009-08-30, Mug exallion.l...@gmail.com wrote:

 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

You're probably better off just using pyserial:

  http://pyserial.sourceforge.net/

If you really want to muck about with termios stuff, you can
look at the posix serial module in pyserial to see how it's
done.

 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

Have you looked at the documentation for termios.tcgettattr()?

It returns a list of integers.  If you want set them to zero,
then just set them to zero.

If you want a configuration that's all zeros, why bother
calling tcgetattr() at all?  Just set the configuration to
zeros:

term_conf = [0,0,0,0,0,0]

-- 
Grant

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


Re: initilize a memory zone in python

2009-08-30 Thread Grant Edwards
On 2009-08-31, Grant Edwards gra...@visi.com wrote:

 If you want a configuration that's all zeros, why bother
 calling tcgetattr() at all?  Just set the configuration to
 zeros:

 term_conf = [0,0,0,0,0,0]

Oops, I forgot about cc.  That should be:

  term_conf = [0,0,0,0,0,0,['\x00']*32]

That's why it's easier to just use pyserial ;)
  
-- 
Grant


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


Re: initilize a memory zone in python

2009-08-30 Thread r
On Aug 30, 4:59 pm, Mug exallion.l...@gmail.com wrote:
(snip)
 is there a fonction like memset or bzero in python?

Not that i know of ;). Try this link for a coverage of the Python
built-in functions. You cannot write quality Python code without
them.
http://docs.python.org/3.1/library/functions.html

What you refer to as an array is called a list round here, see this
informative read
http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range

And be sure to check out list comprehentions too, just icing on the
cake ;)

python 3000 docs
http://docs.python.org/3.1/


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