Hi all,
I need to initialize an array iteratively. For example array my_arryay needs to initialized with 512 characters and next with 1024 characters and next with 2048 characters etc etc, which can only be iteratively.
Something as in C:
for( i = 0; i<100:i++)
{
my_array = 'a';
}
Finally i will need to use the my_array as a buffer. For example the way buffer is provided as an argument in a TCP send operation:
send(socket,buffer,no_of-bytes)
Could any one please tell me how to do this?

Thanks,
Prashanth

Hi all,
I found out the answer:
my_array = 'a'
for i in range(480)
my_array = my_array + 'b'

and then my_array can be used as a buffer the way we do in C.

Hi all,
I need to initialize an array iteratively. For example array my_arryay needs to initialized with 512 characters and next with 1024 characters and next with 2048 characters etc etc, which can only be iteratively.
Something as in C:
for( i = 0; i<100:i++)
{
my_array = 'a';
}
Finally i will need to use the my_array as a buffer. For example the way buffer is provided as an argument in a TCP send operation:
send(socket,buffer,no_of-bytes)
Could any one please tell me how to do this?

Thanks,
Prashanth

You can say also

my_array='a'+479*'b'

What you are creating is not an array, but an object called a string ...

my_array = 'a'
for i in range(10):
    my_array = my_array + 'b'

print my_array        # abbbbbbbbbb
print type(my_array)  # <type 'str'>

Hi all,
I need to initialize an array iteratively. For example array my_arryay needs to initialized with 512 characters and next with 1024 characters and next with 2048 characters etc etc, which can only be iteratively.
Something as in C:
for( i = 0; i<100:i++)
{
my_array = 'a';
}
Finally i will need to use the my_array as a buffer. For example the way buffer is provided as an argument in a TCP send operation:
send(socket,buffer,no_of-bytes)
Could any one please tell me how to do this?

Thanks,
Prashanth

Maybe you must check
http://docs.python.org/c-api/buffer.html

hi all thanks for the reply. your solutions have made me to solve the array problem effectively.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.