0% found this document useful (0 votes)
2 views7 pages

Python

The document explains object-oriented programming (OOP) concepts, focusing on objects, attributes, and methods, using a human as an example. It discusses the creation of classes and subclasses, the importance of functions for code efficiency, and various commands in DesignScript for handling lists and user inputs. Additionally, it touches on the Argparse library for creating interactive interfaces and handling input validation.

Uploaded by

carrilck3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Python

The document explains object-oriented programming (OOP) concepts, focusing on objects, attributes, and methods, using a human as an example. It discusses the creation of classes and subclasses, the importance of functions for code efficiency, and various commands in DesignScript for handling lists and user inputs. Additionally, it touches on the Argparse library for creating interactive interfaces and handling input validation.

Uploaded by

carrilck3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Python, what´s a object orient programming?

An object is something which has one or more attributes and methods. In this
case, the attributes are like the properties; for example, if we think about a
human as an object the height, name, hair color, age and others, those human
properties are object attributes. In the other hand, the methods are the type of
things that the human can do, and those actions can change his own
attributes, for example, a person can change his name, hair color, age, and
others. However, the person can run, read, and others, and those actions are
methods too.
Person.ChangeName
Person.GainWeight
Person.LoseHeight
Those´re methods ´examples
However, if we want to create an object with need first a create a class. A class
´s like a mold which allows create objects.

Note: When we´re talking about an instance that refers to something


created in the model
On the other hand, we can create a subclass with a class

And the objects of that subclass are instance too


This is an example of class and subclasses created with that class

If we make a comparative, the result we will get a Boolean

The creation of function it´s a good practical in programming, because if we


need to repeat an action a lot of times, the code´s easier to understand.

In this case the function only give a result which, it´s not in a variable
With this command we well see if an instance belong to a specific class or
subclass

In designscript to split

The command set helps to create list without repeated elements

The command enumerates allow create a loop and get the list index and the
element

To get access to the last elements in list, this´s useful when we don’t know the
amount of elements
El comando Continue sirve para saltarnos el código del bucle en una de las
iteraciones e ir a la siguiente

Y break sirve para romper el loop tant si es while o for


To DesignScript, that´s useful to a line and arc

Argparse
It allows us create interactive interfaces, but the difference between that
functions and the input ones, it´s about the possibility of create validations of
the information, covert the data in the correct type, generate help messages,
and others…
When we´re talking about create validation we refer to these actions

In the previous example we can see that the input have to be an Float type, so
if we put an incorrect type the program create an error
We can also limit the options

And a lot of options…


So, the first step to use this functions it creates a “parser”, that object which
interpreted the program’s inputs. This is the way to create it

To add inputs to the parser, and we can see all the actions we can take

This is a more practical example, in that case the arguments are as the
attributes of the parser (Object), but that´s like a template, and with the
function parse_args we create the object with specific attributes.
The strip command´s used to delete the space in an input, that´s to avoid
some possible mistake in the moment to put some information in the input

The function “lower” convert all the words in lowercase, and endswith to verify
the lasts words

When we´re working in legacy projects of IA, it´s common get problems related
with compatibility of some libraries, the error looks like:

Ezdxf library
This a library to manipulate DXF files, so we can edit them, create new files,
etc…

You might also like