... | @@ -147,7 +147,7 @@ We can **decompress** this file as usual to have access to all the files and fol |
... | @@ -147,7 +147,7 @@ We can **decompress** this file as usual to have access to all the files and fol |
|
|
|
|
|
### Creating our working repo
|
|
### Creating our working repo
|
|
|
|
|
|
In this subject, all your work will be stored in a **public Gitlab repo**. You will fork from this repo, In other words, you will have your own branch. Just click on the 'fork' button on the top right and complete the requested information (select your username for the namespace and set a project slug you are happy with -as you can see I inherited a slug that is not adequate right now-).
|
|
In this subject, all your work will be stored in a **public Gitlab repo**. You will fork from [this repo,](https://gitlab.etsit.urjc.es/rperez/pne-studentslab) In other words, you will have your own branch. Just click on the 'fork' button on the top right and complete the requested information (select your username for the namespace and set a project slug you are happy with -as you can see I inherited a slug that is not adequate right now-).
|
|
|
|
|
|
After some seconds **your repository will be ready**. You can have a look at your main gitlab page to check that it is there.
|
|
After some seconds **your repository will be ready**. You can have a look at your main gitlab page to check that it is there.
|
|
|
|
|
... | @@ -155,33 +155,25 @@ Your repo is ready for start working working! |
... | @@ -155,33 +155,25 @@ Your repo is ready for start working working! |
|
|
|
|
|
## Working with Pycharm and Gitlab
|
|
## Working with Pycharm and Gitlab
|
|
|
|
|
|
For developing in python we are going to use the [PyCharm IDE](https://www.jetbrains.com/pycharm/download/?gclid=Cj0KCQiA-JXiBRCpARIsAGqF8wU4k1AvuaMc2tQ7gsbn23gdFIMNlczsnPDi-WyXa-cKkdUgxcbW7hYaAn2uEALw_wcB&gclsrc=aw.ds#section=linux) (Community edition 2019.3.2) It is already installed in the Linux machines of the Lab
|
|
For developing in python we are going to use the [PyCharm IDE](https://www.jetbrains.com/pycharm/download/?gclid=Cj0KCQiA-JXiBRCpARIsAGqF8wU4k1AvuaMc2tQ7gsbn23gdFIMNlczsnPDi-WyXa-cKkdUgxcbW7hYaAn2uEALw_wcB&gclsrc=aw.ds#section=linux) (Community edition 2022.2). It is already installed in the lab environment.
|
|
|
|
|
|
### Opening PyCharm
|
|
### Opening PyCharm
|
|
|
|
|
|
Go to the **activities menu** in the top left corner and write pycharm. Click on the PyCharm icon. **CAUTION!** In the lab there are two version of PC. We will use the **Community Edition** (which is OpenSource). Make sure the icon looks like this one:
|
|
Go to the **activities menu** in the top left corner and write pycharm. Click on the PyCharm icon. **CAUTION!** In the lab there are two version of the program. We will use the **Community Edition** (which is OpenSource). Make sure the icon looks like this one (squared):
|
|
|
|
|
|

|
|

|
|
|
|
|
|
If this is **the first time** it is opened, some configuration windows will appear
|
|
If this is **the first time** it is opened, some configuration windows will appear.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Select **Do not import setting** and click on **OK**. Another window will apper asking you to select the Pycharm color theme
|
|
IThe initial window will show up (maybe the program requests some other information, but that would be easy to handle):
|
|
|
|
|
|

|
|
|
|
|
|
|
|
I will use the default theme: **Darcula**. Click on **Next:Featured plugins**
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
In this windows just click on **Start using PyCharm**. The initial window will show up:
|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|
### Cloning our working repo
|
|
### Cloning our working repo
|
|
|
|
|
|
We are going to work on our **working repository** that is in Github. The first step is called c**loning the repo**. It will **copy the repository** from github and creates a **local copy** in **our computer**.This operation is executed only **one time per computer**. If you are working in two computers, one in this Lab and the other at home, you will have to **clone twice**: one per computer
|
|
We are going to work on our own **working repository** that is in gitlab (you just forked it!). The first step is called **cloning the repo**. It will **copy the repository** from gitlab and create a **local copy** in **your computer**.This operation is executed just **once per computer**, so, if you are working in two computers, you will have to **clone the repository twice**.
|
|
|
|
|
|
From the main Pycharm windows we select the option **Get from version Control**
|
|
From the main Pycharm windows we select the option **Get from version Control**
|
|
|
|
|
... | @@ -191,53 +183,53 @@ This window shows up. It is asking us for the location of our project in the rep |
... | @@ -191,53 +183,53 @@ This window shows up. It is asking us for the location of our project in the rep |
|
|
|
|
|

|
|

|
|
|
|
|
|
We change to the Browser and go to our **working repo** main page at Github and click on the **Clone or download** button
|
|
We just go to the browser and go to our **working repo** main page and click on the **Clone or download** button.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Click on the **copy button** on the right side
|
|
Click on the **copy button** on the right side.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Then move to the Pycharm Windows and paste the URL by pressing Ctrl-V on the keyboard:
|
|
Then move to the Pycharm Windows and paste the URL.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Then select below the **local folder** were you want to store your project. By default it is located in the **PycharmProjects** folder in your home. I will use the default folder. Click on the **Clone** button
|
|
Then select below the **local folder** were you want to store your project. By default it is located in the **PycharmProjects** folder in your home. I will use the default folder. Click on the **Clone** button.
|
|
|
|
|
|
Now you will be asked if you want to **open** the new project
|
|
Now you will be asked if you want to **open** the new project.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Click on **YES**. The main window appears along with a welcome message
|
|
Click on **YES**. The main window appears along with a welcome message (as you can see, the images are from other repo, but it does not matter, right?).
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Click on the **Close** button. **We are ready to work on our projects!**
|
|
Click on the **Close** button. **We are ready to work!**
|
|
|
|
|
|

|
|

|
|
|
|
|
|
In this **animation** the whole process is shown
|
|
In this **animation** the whole process is shown.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
### Our first commit to the repo
|
|
### Our first commit to the repo
|
|
|
|
|
|
If you click on the top left **2019-2020-PNE folder**, you will see all the **contents** of your working project, with all the folder for the practices
|
|
If you click on the top left folder, you will see all the **contents** of your working project, with the structure I have designed.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Before doing our first python program, let's make some **changes** to the **README file** and upload into our remote repository in Github. Click on the **small button** in the README file for viewing it as text
|
|
Before doing our first python program, let's make some **changes** to the **README file** and upload into our remote repository in Gitlab. Click on the README file to edit it.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Add some text. Notice how the color of the README file has changed. It is indicating that a change has been made: The **current README** file is **different** than the file stored in the **repository**
|
|
Add some text. Notice how the color of the README file has changed. It is indicating that a change has been made: the **current README** file is **different** than the one stored in the **repository**.
|
|
|
|
|
|
Let's **commit** that change. Click on the **green tick** in the upper right corner
|
|
Let's **commit** that change. Click on the **green tick** in the upper right corner.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Everytime you commit a change, you should write a comment. In this case we can write _my first change_. Then click on the **commit** button
|
|
Every time you commit a change, you should write a comment. In this case we can write _my first change_. Then click on the **commit** button.
|
|
|
|
|
|

|
|

|
|
|
|
|
... | @@ -245,25 +237,25 @@ Congrats! You've done your first commit! |
... | @@ -245,25 +237,25 @@ Congrats! You've done your first commit! |
|
|
|
|
|

|
|

|
|
|
|
|
|
But you have committed your change to the **local repository** in your computer. It is not yet in github. You have to execute a **push command**. Click on the option at **VCS/Git/Push**
|
|
But you have committed your change to the **local repository** in your computer. It is not yet in gitlab. You have to execute a **push command**. Click on the option at **VCS/Git/Push**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
In the next screen click on the **Push** button
|
|
In the next screen click on the **Push** button.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Enter your Github **username** and **password**. Then click on **Log In**
|
|
Enter your Gitlab **username** and **password**. Then click on **Log In**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
After some seconds your changes will be pushed
|
|
After some seconds your changes will be pushed.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
**Congrats!** You've made your first contribution to your remote github repository!
|
|
**Congrats!** You've made your first contribution to your remote gitlab repository!
|
|
|
|
|
|
If you go to your github repo page you will see your changes
|
|
If you go to your gitlab repo page, you will see the changes you just did.
|
|
|
|
|
|

|
|

|
|
|
|
|
... | @@ -273,15 +265,15 @@ Let's write our first python program in Pycharm. The first step is to configure |
... | @@ -273,15 +265,15 @@ Let's write our first python program in Pycharm. The first step is to configure |
|
|
|
|
|
### Configuring the python environment
|
|
### Configuring the python environment
|
|
|
|
|
|
We have to chose which python interpreter to use. Go to **File/Setting** and click on the **Project:2019-2020-PNE-Practices/Project Interpreter** option
|
|
We have to chose which python interpreter to use. Go to **File/Setting** and click to select the project interpreter as shown in the image below.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Click on the **configure** button on the right:
|
|
Click on the **configure** button on the right.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
And then on the **ADD** option
|
|
And then on the **Add** option.
|
|
|
|
|
|

|
|

|
|
|
|
|
... | @@ -293,176 +285,144 @@ And click again on **OK** for closing the Settings Windows |
... | @@ -293,176 +285,144 @@ And click again on **OK** for closing the Settings Windows |
|
|
|
|
|

|
|

|
|
|
|
|
|
The **python interpreter** is ready! You will see the new folder called **venv**. It contains the python interpreter and all the related files needed
|
|
The **python interpreter** is ready! You will see the new folder called **venv**. It contains the python interpreter and all the related files needed.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
### Writing the Hello world program
|
|
### Writing the Hello world program
|
|
|
|
|
|
Let's write our first Hello world program in Pycharm. First we create a **new folder** called Hello for working there
|
|
Let's write our first Hello world program in PyCharm. You could create a specific folder to store this first script, but as you forked from a repo I designed myself, I did it for you. I named it "Hello".
|
|
|
|
|
|
#### Creating the Hello Folder
|
|
|
|
|
|
|
|
In the the Pycharm project windows select the **2019-2020-PNE-Practices** project
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
and click on the **File/New** Menu
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
Then select the **Directory** option
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
and type in the new directory file: **Hello**. Press the **Enter** Key
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
In our **project view**, on the right we can see now the new empty folder: **Hello**
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
In **animation** the process of creating a **new folder** is shown:
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
#### Creating a python file
|
|
#### Creating a python file
|
|
|
|
|
|
Let's create our first python file. Make sure the **Hello folder is selected**, as we want to create our new file in that directory. Then click on **File/new/python file**
|
|
Let's create our first python file. Make sure the **Hello folder is selected**, as we want to create our new file in that directory. Then click on **File/new/python file**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
**Type in** the **filename**. For example **hello**. It is not necessary to introduce the extesion (.py)
|
|
**Type in** the **filename**. For example **hello**. It is not necessary to introduce the extension (.py) since we already indicated we were creating a Python script.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
As we are working with the **Github repo**, Pycharm ask us if we want this new file to be **added** to our **local repository**. Click on **ADD**. Sometimes you just want to make a quick test on a temporary file. In that case you do not want it to be included in the repo. But in this case, we want to include our **hello.py** file into the repo for learning
|
|
As we are working with the **Gitlab repo**, PyCharm asks us if we want this new file to be **added** to our **local repository**. Click on **Add**. Sometimes you just want to make a quick test on a temporary file. In that case you may not want it to be included in the repo. But in this case, we want to include our **hello.py** file into the repo.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
We can see now the **new hello.py file** in the **project view** on the right side
|
|
We can see now the **new hello.py file** in the **project view** on the right side.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Also, the file is opened on a new tap. **We are now ready for typing python code!**. Look at the **green tick** in the upper right corner. It tells us that the hello.py is **ok**, with **no errors**
|
|
Also, the file is opened on a new tab. **We are now ready for typing python code!**. Look at the **green tick** in the upper right corner. It tells us that the hello.py is **ok**, with **no errors**.
|
|
|
|
|
|
Notice the color of the new file: green. It means that is a new file, added to the project, but it is not already in the repository, because we still have **not committed** the file
|
|
Notice the color of the new file: green. It means that is a new file, added to the project, but it is not already in the repository, because we still have **not committed** the file.
|
|
|
|
|
|
In this **animation** the process of creating a **new python file** is shown
|
|
In this **animation** the process of creating a **new python file** is shown.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
#### Writing the code
|
|
#### Writing the code
|
|
|
|
|
|
It is time to write the **hello world program**. It consist of two print stataments:
|
|
It is time to write the **hello world program**.
|
|
|
|
|
|
```python
|
|
```python
|
|
print("This is my first python program in the Pycharm IDE")
|
|
print("This is my first python program in the Pycharm IDE")
|
|
print("Hello world!!")
|
|
print("Hello world!!")
|
|
```
|
|
```
|
|
|
|
|
|
In the **hello.py tab** type start typing in the **code**
|
|
When the editor detects you have written the first letters, _pr_, it shows below some of the functions that matches. You can continue typing or pressing the **TAB key** for accepting the first choice,
|
|
|
|
|
|
When the editor detects you have written the first letters, _pr_, it shows below some of the functions that matches. You can continue typing or pressing the **TAB key** for accepting the first choice
|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Once the **print()** function is typed, the editor will show us all the possible **parameters** that the print function has. The first one (values) are variables or strings we want to print
|
|
Once the **print()** function is typed, the editor will show us all the possible **parameters** that the print function has. The first one (values) are variables or strings we want to print.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
We continue writing the string we want to print. Finish pressing the **enter** key. You should see something like this, with the **green tick** on the right
|
|
We continue writing the string we want to print. Finish pressing the **ENTER** key. You should see something like this, with the **green tick** on the right.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Imagine that you make a mistake typing the print. You delete accidentaly the final bracket. In that case you will see a **red exclamation** and a **red mark** on the location where the error is detected
|
|
Imagine that you make a mistake typing the print. In that case you will see a **red exclamation marl** and a **red sign** on the location where the error is detected.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
If you place the **mouse pointer** on the **red line** below the red exclamation, you will get **more information** about the error
|
|
If you place the **mouse pointer** on the **red line** below the red icon, you will get **more information** about the error.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Let's finish our program. Write the second line
|
|
A typical error is to add a **blank new line** after the last line. The **python style guide** recommends not to do that. Therefore, you will see a **warning** in that case.
|
|
|
|
|
|

|
|
|
|
|
|
|
|
A typical error is to add a **blank new line** after the last line. The **python style guide** recommends not to do that. Therefore, you will see a **warning** in that case:
|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|
If you place the pointer in the **upper mark**, you will read that there is **1 week error**
|
|
If you place the pointer in the **upper mark**, you will read that there is **1 weak error**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
If you place the pointer in the **second mark** on the right, you will see the **error message**
|
|
If you place the pointer in the **second mark** on the right, you will see the **error message**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
In this **animation** the process of **writing the hello world** is shown
|
|
In this **animation** the process of **writing the hello world** is shown.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
In this **animation** some **errors** are forced and corrected
|
|
In this **animation** some **errors** are forced and corrected.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
### Running the program
|
|
### Running the program
|
|
|
|
|
|
The first time a file is created, cannot be executed directly. The buttons for running and debugging cannot be pressed. Also there is an option that says: **add configuration**
|
|
The first time a file is created, cannot be executed directly. The buttons for running and debugging cannot be pressed. Also there is an option that says: **add configuration**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Instead of creating a custom configuration, we will let Pycharm to create one for us. Click on **Run/Run**
|
|
Instead of creating a custom configuration, we will let PyCharm to create one for us. Click on **Run/Run**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Click on the **hello** option
|
|
Click on the **hello** option.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
The program will **run**. A **new run** tab is open in the bottom. There you will see the **messages** we have printed. Also notice that now there is a **new configuration**, called **hello** and the run and debug **green buttons** are activated
|
|
The program will **run**. A **new run** tab is open in the bottom. There you will see the **messages** we have printed. Also notice that now there is a **new configuration**, called **hello** and the run and debug **green buttons** are activated.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Once the configuration has been created, **running the program is straightforward**. Just click on the green run button in the toolbar
|
|
Once the configuration has been created, **running the program is straightforward**. Just click on the green run button in the toolbar.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
### Adding the program to the github repo
|
|
### Adding the program to the gitlab repo
|
|
|
|
|
|
Now that the program is working, it is time to **add** it to our **repo**. First we have lo add it to our **local repo** (commit) and then **pushing** it to the **remote repo** at Github
|
|
Now that the program is working, it is time to **add** it to our **repo**. First we have lo add it to our **local repo** (commit) and then **pushing** it to the **remote repo** at Gitlab.
|
|
|
|
|
|
* Click on the **commit button**
|
|
* Click on the **commit button**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
* Add a **comment** to the commit and press the commit button
|
|
* Add a **comment** to the commit and press the commit button.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Notice that now the hello.py file is **NOT green anymore**. It has the same color than the other files in the local repo
|
|
Notice that now the hello.py file is **NOT green anymore**. It has the same color than the other files in the local repo.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
* Now go to **VCS/Git/Push** and click on **Push**
|
|
* Now go to **VCS/Git/Push** and click on **Push**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
After some seconds, you will see the **confirmation message**. Our local repo has been pushed to Github!
|
|
After some seconds, you will see the **confirmation message**. Our local repo has been pushed to Gitlab!
|
|
|
|
|
|

|
|

|
|
|
|
|
|
* Go to the browser and **check** that the changes are in **Github**
|
|
* Go to the browser and **check** that the changes are in **Gitlab**.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
If you enter into the Hello folder, the **hello.py** file will be there
|
|
If you enter into the Hello folder, the **hello.py** file will be there.
|
|
|
|
|
|

|
|

|
|
|
|
|
|
Congrats! You have created, running and committed to the Github repo your first python program
|
|
Congrats! You have created, running and committed to the Gitlab repo your first python program.
|
|
|
|
|
|
## Exercises
|
|
## Exercises
|
|
|
|
|
... | @@ -470,22 +430,22 @@ The only way of **mastering** something is practicing, practicing and practicing |
... | @@ -470,22 +430,22 @@ The only way of **mastering** something is practicing, practicing and practicing |
|
|
|
|
|
### Ex-1: hello.py
|
|
### Ex-1: hello.py
|
|
|
|
|
|
* Add another **print()** statement to the _hello.py_ program
|
|
* Add another **print()** statement to the _hello.py_ program.
|
|
* Add some **comments**
|
|
* Add some **comments**.
|
|
* Make sure you get a **green tick**
|
|
* Make sure you get a **green tick**.
|
|
* **Run** the program
|
|
* **Run** the program.
|
|
* **Upload** the changes to your github repo
|
|
* **Upload** the changes to your gitlab repo.
|
|
|
|
|
|
### Ex-2: count.py
|
|
### Ex-2: count.py
|
|
|
|
|
|
* In the **2019-2020-PNE-Practice** project create a **new folder** called: **Session-01**
|
|
* In your project create a **new folder** called: **S01**.
|
|
* Inside the **Session-01 folder**, write a python the **count.py** program that prints the number from 1 to 20 in the console
|
|
* Inside this new folder, code a python script called **count.py** that prints the number from 1 to 20.
|
|
* **Upload** that new file in your github repo
|
|
* **Upload** that new file in your gitlab repo.
|
|
|
|
|
|
### Ex-3: sum20.py
|
|
### Ex-3: sum20.py
|
|
|
|
|
|
* Inside the **Session-01** folder, write the python **sum20.py** program for calculating the sum of the first 20 integer numbers (1+2+3+...+20). The result should be printed on the console
|
|
* Within the same folder, code a script called **sum20.py** for calculating the sum of the first 20 integer numbers (1+2+3+...+20). The result should be printed out.
|
|
* Upload that file in your github repo
|
|
* Upload that file in your gitlab repo.
|
|
|
|
|
|
# END of the session
|
|
# END of the session
|
|
|
|
|
... | | ... | |