New job, hu dis? Python crash course and using POSTMAN for web development. Today I learned: Monday 13 June, 2022
Photo by Bence Balla-Schottner on Unsplash
I start a new job soon where I'll be using python to create APIs, so I'm going to divert my learning focus away from GO for now.
API building features requests such as POST, PUT, GET and DELETE.
You use these to define 'routes'.
In python, 'jsonify()' seems to be some sort of method to convert a value into a json object.
Also in python, instead of using 'else' in conditional statements, it used 'elif'.
There is a concept called 'resources' in API building.
From the Flask tutorial, which is creating a todo app, it creates two resources;
A todo list
A single todo item.
There is a variable named 'self' that is some times passes in as an argument to python methods.
'def' is a keyword. I'm not sure if it used to create a method, or to define a new API route.
POSTMAN is a desktop browser that is used to test API's.
- I just finished this video tutorial: Postman API tutorial for beginners
Django is a framework for python, and within it is a library called GEODJANGO. This is used for mapping and GIS purposes.
EOL is a error message, meaning 'end of line'.
- It happens if you type a mismatched quotation marks when writing a print command.
NameError is another error in py. It happens if you don't use quotation marks at all.
A string with """ triple quotes can span multiple lines.
- When not assigned to a variable, it can be used as a multi-line comment.
If you want to print both a string and a float or integer, you need to wrap the float or integer in this:
str()
print "This is the number: " + str(number)
You can define a specific letter within a string by using this:
fifth_letter = "MONTY"[4]
The above will assign the letter "Y" to the variable fifth_letter.
Methods that use dot notation only work with strings.
- lion = "roar"
- len(lion)
- lion.upper()
You can use % to make printing strings easier:
name = "Mike"
print "Hello %s" % (name)
The above code will replace the %s with what comes after the second %
If there are multiple %s in a string, you need to input the same about of strings after it.
- print "The %s who %s %s!" % ("Knights", "say", "Ni")
Theses are called placeholders.
- There was actually something similar to this in the Flask RESTful tutorial from today that I was confused about. I'll go back and inspect it again now with fresh eyes.
For boolean operators:
'Not' is evaluated first
'And' is evaluated second
'Or' is evaluated third
'raw_input()' is used to accept user's input into the console.