[Tutor] pointers
Kent Johnson
kent37 at tds.net
Wed Jan 11 17:30:21 CET 2006
Burge Kurt wrote:
> Sorry for the previous message I did it by mistake..
> the function was like below:
>
> void get_args(int argc, char* argv[], Argument* args)
> {
> //check the amount of the arguments
> if(argc%2 == 0)
> {
> printf("Error, incorrect argument numbers : %d\n",argc);
> print_help();
> exit(1);
> }
>
> .....
> .........
> }
>
> My first question about the pointers here; how can I convert them to
> Python?
Python doesn't have pointers in the sense of direct references to
memory. Python has very good built in support for higher-level
structures than C has. Strings and lists are both built in.
As Bernard has pointed out, where a C function might have a count (argc)
and a pointer to an array of pointers to strings (char* argv[]), Python
uses just a list of strings.
I'll guess that Argument* args is a pointer to an array of Argument
objects. In Python this would be represented by a list of Argument objects.
Use of lists and strings should be covered in any introductory Python
tutorial or book; you might find one you like here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
http://wiki.python.org/moin/IntroductoryBooks
Kent
>
> And second and may be a little stupid; do I need to define argc how can
> I get arguments in python ?
>
> Thanks in advance,
>
> Burge
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list