473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Python C API Question.

This is my first crack at using Python from a C level, and also a long time
since I have even used C, so my wording might be off, when creating a new
list utilizing the PyList_New(...) function, instead of creating a list of a
fixed length, is there a way to create a variabled length instead?

Any help is greatly apprecited.

Adonis
Jul 18 '05 #1
2 1216
Adonis wrote:
This is my first crack at using Python from a C level, and also a long
time since I have even used C, so my wording might be off, when creating a
new list utilizing the PyList_New(...) function, instead of creating a
list of a fixed length, is there a way to create a variabled length
instead?


AFAIK they are always variable length - they always support appending to
them. The argument is just about the initial capacity, so if you know that
beforehand, you can optimize allocation of list entries.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Please see
http://docs.python.org/api/listObjects.html

C's PyList_Append() is roughly equivalent to Python's list.append().
If you want to construct a list without knowing how many items will
eventually be in it, use PyList_New(0), then PyList_Append for each
item you want to add. This will be as efficient as the similar
Python code
l = [f(x) for x in s]
in terms of the number of resizes the internal array-of-pointers
undergoes.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBenQpJd01MZaTXX0RAqfMAKCUzOhSLjNezjDW71GQwQ dWWgmgoQCgq3lT
27if6lFdJCQ6yLp8b6/UYQg=
=XAeP
-----END PGP SIGNATURE-----

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
158
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends...
4
by: Martitza | last post by:
Hi. I work for a small company (actually in process of forming) interested in embedding or extending python as part of our commercial non-open-source product. We have legal counsel, but are...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.