投稿時間:2023-01-08 16:12:47 RSSフィード2023-01-08 16:00 分まとめ(17件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… iOS/iPadOS向け「One Drive」アプリのカメラアップロード機能がRAW形式に対応 − 「iOS/iPadOS 14」のサポートも終了 https://taisy0.com/2023/01/08/166825.html iosipados 2023-01-08 06:21:05
AWS lambdaタグが付けられた新着投稿 - Qiita 【AWS】基本的なウェブアプリケーションをクイック開発する https://qiita.com/grapefruit_0514/items/1d53045fc14c90165dd7 公式サイト 2023-01-08 15:18:52
python Pythonタグが付けられた新着投稿 - Qiita 【Python】PandasのDataFrameで、毎日・毎時間などの時系列のindexを作る方法(pandas.date_range) https://qiita.com/takuma-1234/items/2bb734ec4d562149b4b9 dataframe 2023-01-08 15:42:36
python Pythonタグが付けられた新着投稿 - Qiita WindowsによるPython入門 #02: 変数 https://qiita.com/PythonMan/items/c031254ecb5b4349000b windows 2023-01-08 15:17:46
Ruby Rubyタグが付けられた新着投稿 - Qiita [初学者向け] Ruby 論理演算子を理解しよう https://qiita.com/shin_h/items/f86aa53eaa72561f1d2b 論理演算子 2023-01-08 15:38:30
Linux Ubuntuタグが付けられた新着投稿 - Qiita Ubuntu20.04で右クリックで新しいドキュメント https://qiita.com/nacanaca/items/c1b0f259ce8ca26b7338 ctrlaltt 2023-01-08 15:20:12
AWS AWSタグが付けられた新着投稿 - Qiita 【AWS】基本的なウェブアプリケーションをクイック開発する https://qiita.com/grapefruit_0514/items/1d53045fc14c90165dd7 公式サイト 2023-01-08 15:18:52
海外TECH DEV Community OOP in Python: A Practical Guide https://dev.to/anurag629/oop-in-python-a-practical-guide-10mj OOP in Python A Practical Guide Day of Days Data Science Bootcamp from noob to expert GitHub link Complete Data Science Bootcamp Main Post Complete Data Science Bootcamp Recap Day Yesterday we have studied in detail about python buit it data struccture Object Oriented Programming OOP is a programming paradigm that is based on the concept of objects which can contain data and code that manipulate that data In OOP a class is a template for creating objects It defines the properties data and methods functions that an object can have An object is an instance of a class created from the class template Here is an example of a simple class in Python Major Python OOPs concept In this section we will deep dive into the basic concepts of OOP We will cover the following topics ClassObjectMethodInheritanceEncapsulationPolymorphismData Abstraction ClassA straight forward answer to this question is A class is a collection of objects Unlike the primitive data structures classes are data structures that the user defines They make the code more manageable class Car class body pass ObjectWhen we define a class only the description or a blueprint of the object is created There is no memory allocation until we create its object The objector instance contains real data or information Instantiation is nothing but creating a new object instance of a class Let s create the object of the above class we defined obj Car print obj lt main Car object at xfdfc gt Since our class was empty it returns the address where the object is stored i e xfcebdYou also need to understand the class constructor before moving forward Class constructorUntil now we have an empty class Car time to fill up our class with the properties of the car The job of the class constructor is to assign the values to the data members of the class when an object of the class is created There can be various properties of a car such as its name color model brand name engine power weight price etc We ll choose only a few for understanding purposes class Car def init self name color self name name self color colorSo the properties of the car or any other object must be inside a method that we call init This init method is also known as the constructor method We call a constructor method whenever an object of the class is constructed Now let s talk about the parameter of the init method So the first parameter of this method has to be self Then only will the rest of the parameters come The two statements inside the constructor method are self name nameself color color This will create new attributes namely name and color and then assign the value of the respective parameters to them The “self keyword represents the instance of the class By using the “self keyword we can access the attributes and methods of the class It is useful in method definitions and in variable initialization The “self is explicitly used every time we define a method Note You can create attributes outside of this init method also But those attributes will be universal to the whole class and you will have to assign the value to them Suppose all the cars in your showroom are Sedan and instead of specifying it again and again you can fix the value of car type as Sedan by creating an attribute outside the init class Car car type Sedan class attribute def init self name color self name name instance attribute self color color instance attributeHere Instance attributes refer to the attributes inside the constructor method i e self name and self color And Class attributes refer to the attributes outside the constructor method i e car type MethodsSo far we ve added the properties of the car Now it s time to add some behavior Methods are the functions that we use to describe the behavior of the objects They are also defined inside a class Look at the following code class Car car type Sedan def init self name mileage self name name self mileage mileage def description self return f The self name car gives the mileage of self mileage km l def max speed self speed return f The self name runs at the maximum speed of speed km hr obj Car Honda City print obj description print obj max speed The Honda City car gives the mileage of km l The Honda City runs at the maximum speed of km hrThe methods defined inside a class other than the constructor method are known as the instance methods Furthermore we have two instance methods here description and max speed Let s talk about them individually description This method is returning a string with the description of the car such as the name and its mileage This method has no additional parameter This method is using the instance attributes max speed This method has one additional parameter and returning a string displaying the car name and its speed Notice that the additional parameter speed is not using the “self keyword Since speed is not an instance variable we don t use the self keyword as its prefix Let s create an object for the class described above obj Car Honda City print obj description print obj max speed The Honda City car gives the mileage of km l The Honda City runs at the maximum speed of km hrWhat we did is we created an object of class car and passed the required arguments In order to access the instance methods we use object name method name The method description didn t have any additional parameter so we did not pass any argument while calling it The method max speed has one additional parameter so we passed one argument while calling it Note Three important things to remember are You can create any number of objects of a class If the method requires n parameters and you do not pass the same number of arguments then an error will occur Order of the arguments matters Let s look at this one by one Creating more than one object of a classclass Car def init self name mileage self name name self mileage mileage def max speed self speed return f The self name runs at the maximum speed of speed km hr Honda Car Honda City print Honda max speed Skoda Car Skoda Octavia print Skoda max speed The Honda City runs at the maximum speed of km hr The Skoda Octavia runs at the maximum speed of km hr Passing the wrong number of arguments class Car def init self name mileage self name name self mileage mileageHonda Car Honda City print Honda TypeError Traceback most recent call last Cell In line self name name self mileage mileage gt Honda Car Honda City print Honda TypeError init missing required positional argument mileage Since we did not provide the second argument we got this error Order of the argumentsclass Car def init self name mileage self name name self mileage mileage def description self return f The self name car gives the mileage of self mileage km l Honda Car Honda City print Honda description The car gives the mileage of Honda Citykm lObject Oriented Programming Argument OrderMessed up Notice we changed the order of arguments Now there are four fundamental concepts of Object oriented programming Inheritance Encapsulation Polymorphism and Data abstraction It is very important to know about all of these in order to understand OOPs Till now we ve covered the basics of OOPs let s dive in further Inheritance in Python ClassInheritance is the procedure in which one class inherits the attributes and methods of another class The class whose properties and methods are inherited is known as Parent class And the class that inherits the properties from the parent class is the Child class The interesting thing is along with the inherited properties and methods a child class can have its own properties and methods How to inherit a parent class Use the following syntax class parent class body of parent class passclass child class parent class body of child class passLet s see the implementation class Car parent class def init self name mileage self name name self mileage mileage def description self return f The self name car gives the mileage of self mileage km l class BMW Car child class passclass Audi Car child class def audi desc self return This is the description method of class Audi obj BMW BMW series print obj description obj Audi Audi A L print obj description print obj audi desc The BMW series car gives the mileage of km l The Audi A L car gives the mileage of km l This is the description method of class Audi We have created two child classes namely “BMW and “Audi who have inherited the methods and properties of the parent class “Car We have provided no additional features and methods in the class BMW Whereas one additional method inside the class Audi Notice how the instance method description of the parent class is accessible by the objects of child classes with the help of obj description and obj description And also the separate method of class Audi is also accessible using obj audi desc EncapsulationEncapsulation as I mentioned in the initial part of the article is a way to ensure security Basically it hides the data from the access of outsiders Such as if an organization wants to protect an object information from unwanted access by clients or any unauthorized person then encapsulation is the way to ensure this You can declare the methods or the attributes protected by using a single underscore before their names Such as self name or def method Both of these lines tell that the attribute and method are protected and should not be used outside the access of the class and sub classes but can be accessed by class methods and objects Though Python uses just as a coding convention it tells that you should use these attributes methods within the scope of the class But you can still access the variables and methods which are defined as protected as usual Now for actually preventing the access of attributes methods from outside the scope of a class you can use “private members“ In order to declare the attributes method as private members use double underscore in the prefix Such as self name or def method Both of these lines tell that the attribute and method are private and access is not possible from outside the class class car def init self name mileage self name name protected variable self mileage mileage def description self return f The self name car gives the mileage of self mileage km l obj car BMW series accessing protected variable via class method print obj description accessing protected variable directly from outsideprint obj name print obj mileage The BMW series car gives the mileage of km l BMW series Notice how we accessed the protected variable without any error It is clear that access to the variable is still public Let us see how encapsulation works class Car def init self name mileage self name name private variable self mileage mileage def description self return f The self name car gives the mileage of self mileage km l obj Car BMW series accessing private variable via class method print obj description accessing private variable directly from outsideprint obj mileage print obj name EncapsulationWhen we tried accessing the private variable using the description method we encountered no error But when we tried accessing the private variable directly outside the class then Python gave us an error stating car object has no attribute name You can still access this attribute directly using its mangled name Name mangling is a mechanism we use for accessing the class members from outside The Python interpreter rewrites any identifier with “ var as “ ClassName var And using this you can access the class member from outside as well class Car def init self name mileage self name name private variable self mileage mileage def description self return f The self name car gives the mileage of self mileage km l obj Car BMW series accessing private variable via class method print obj description accessing private variable directly from outsideprint obj mileage print obj Car name mangled nameThe BMW series car gives the mileage of km l BMW seriesNote that the mangling rule s design mostly avoids accidents But it is still possible to access or modify a variable that is considered private This can even be useful in special circumstances such as in the debugger PolymorphismThis is a Greek word If we break the term Polymorphism we get “poly many and “morph forms So Polymorphism means having many forms In OOP it refers to the functions having the same names but carrying different functionalities class Audi def description self print This the description function of class AUDI class BMW def description self print This the description function of class BMW audi Audi bmw BMW for car in audi bmw car description This the description function of class AUDI This the description function of class BMW When the function is called using the object audi then the function of class Audi is called and when it is called using the object bmw then the function of class BMW is called Data abstractionWe use Abstraction for hiding the internal details or implementations of a function and showing its functionalities only This is similar to the way you know how to drive a car without knowing the background mechanism Or you know how to turn on or off a light using a switch but you don t know what is happening behind the socket Any class with at least one abstract function is an abstract class In order to create an abstraction class first you need to import ABC class from abc module This lets you create abstract methods inside it ABC stands for Abstract Base Class from abc import ABCclass abs class ABC Body of the class passImportant thing is you cannot create an object for the abstract class with the abstract method For example from abc import ABC abstractmethodclass Car ABC def init self name self name name abstractmethoddef price self x passobj Car Honda City Now the question is how do we use this abstraction exactly The answer is by using inheritance from abc import ABC abstractmethodclass Car ABC def init self name self name name def description self print This the description function of class car abstractmethod def price self x passclass new Car def price self x print f The self name s price is x lakhs obj new Honda City obj description obj price This the description function of class car The Honda City s price is lakhs Car is the abstract class that inherits from the ABC class from the abc module Notice how I have an abstract method price and a concrete method description in the abstract class This is because the abstract class can include both of these kinds of functions but a normal class cannot The other class inheriting from this abstract class is new This method is giving definition to the abstract method price which is how we use abstract functions After the user creates objects from new class and invokes the price method the definitions for the price method inside the new class comes into play These definitions are hidden from the user The Abstract method is just providing a declaration The child classes need to provide the definition But when the description method is called for the object of new class i e obj the Car s description method is invoked since it is not an abstract method Taken most of content from Exercise Question you will find in the exercise notebook of Day on GitHub If you liked it then 2023-01-08 06:05:25
海外TECH DEV Community Build a custom MySQL Docker Container https://dev.to/sumana2001/build-a-custom-mysql-docker-container-404f Build a custom MySQL Docker ContainerTired of going through endless documentation for setting up your database in any computer apart from your local computer Setting up a database every time you want to do some API testing Well Docker is here to help you out and spin up a local database This will make it super easy for you to test their code and write data without installing and configuring a lot of tools In the beginning stages of development of course you wouldn t want to spend hours configuring the database so a custom MySQL container can change your life What is dockerDocker is an application build and deployment tool to help you create run and deploy applications It uses the concept of container i e you create a package of your code with dependencies that can be deployed as one single unit Although the concept of containers has been around for a long time docker makes the tasks of setting up and handling the containers very easy Let s start creating We will be creating and deploying a custom docker image What can this docker image do It can Create a database marvel Create a table superheroes Set the superhero id to auto incrementInsert records into the tableBefore starting make sure you have Docker installed If not you can install it from here Create a project folder let s call it marvel db Here s what the project structure would look like We ll go through each of the files one by one Create the SQL scripts Create a folder called scripts to store both your SQL files one for creating the database and table and the second one for inserting the new records Pro tip Be careful with what you name these files because docker will go through them in alphabetical order So if the name of the file inserting the records is alphabetically before the file creating the table you might face a lot of errors Let s name our first file create table sqlCREATE DATABASE IF NOT EXISTS marvel DEFAULT CHARACTER SET utf COLLATE utf general ci GOUSE marvel GOCREATE TABLE superheroes superhero id int NOT NULL name varchar NOT NULL DEFAULT color varchar NOT NULL noOfMovies int NOT NULL ENGINE InnoDB DEFAULT CHARSET utf GOALTER TABLE superheroes ADD PRIMARY KEY superhero id GOALTER TABLE superheroes MODIFY superhero id int NOT NULL AUTO INCREMENT So here s what we have done in the above code We create a database marvel if it already doesn t exist Then we go inside that database and create a new table superheroes Next we set superhero id as the primary key of the table and set it to auto increment The GO command used after every query is a batch separator in SQL that tells SQL that there are more statements to be executed in the SQL file Now we ll create the second file let s call it insert table sql for inserting new records INSERT INTO superheroes name color noOfMovies VALUES Iron Man Gold Captain America Blue Thor Dark Grey Hulk Green Black Widow Red Hawkeye Grey Wanda Maximoff Dark Red Black Panther Purple War Machine Black Spider Man Blue Create Dockerfile Now that our sample database is complete we will create a Dockerfile to actually run these scripts FROM mysql latest ENV MYSQL DATABASE marvelCOPY scripts docker entrypoint initdb d Confused about the above code Here s what it means In this tutorial we re creating a custom MySQL image which means we are taking MySQL s own docker image as a starting point for ours So the first line is calling the latest version of the MySQL docker image Next the second line means that we are creating a MySQL database called marvel as soon as the Dockerfile is run Lastly the third line copies all the scripts in the script folder to docker entrypoint initdb d which will be automatically executed during container setup See it in action Guess what We have created our custom MySQL Docker container Let s build it and check if it works Run the command in your terminal to build the docker image with the name marveldb docker build t marveldb Pro tip Docker images built with an ARM based architecture like the Apple Silicon chip can create issues when deploying images to a Linux or Windows based AMD environment like AWS EC ECS etc So you need a way to build AMD based images on the ARM architecture which you can build by using the flag platform linux x as used above Windows and Linux users don t need to use this flag You can check if your new image is running with the command docker images Now run the docker container with the following command docker run d p name marvelDB e MYSQL ROOT PASSWORD Marvel platform linux x marveldb Again you can leave out the platform flag if you are using Windows or Linux You check if your container is running with the command docker container ls Execute the container to run SQL queries docker exec it marvelDB bash Go inside the MySQL terminal mysql uroot pYou ll be prompted to enter the password Write the root password you used while running the container in our case Marvel Now you can run whatever SQL queries you want you will notice you have the marvel database and superheroes table already created with records in it Take it one step further 🪜In industries or big organizations there is usually not just one docker container They have many services or containers that they have to manage together So instead of running and building each container we can use a docker compose file It stores all the essential information about all the services and now you can run countless containers with one single command Let s start by creating a docker compose yml file version services marvelDB image marveldb platform linux x environment MYSQL ROOT PASSWORD Marvel ports That s it Run the docker compose docker compose up It will create a service called marvel db name of our project folder inside which there is a container with the name marvel db marvelDB You can confirm the name of your container using docker container ls Now you can again run the exec command and get the exact same result This process might not seem that fruitful in this example but when things get more complex the docker compose file makes a huge difference Push to docker hub ️Wow We re in the endgame now The last thing to do is to push your custom MySQL container to the cloud so that anyone from anywhere can access it First create an account on Docker Hub Create a repository and give it a name and description Then from the terminal run docker login and enter your credentials Now tag your image docker tag local image tagname username new repo tagnameIn my case docker tag marveldb sumana marvel Next push your image to the new repositorydocker push username new repo tagnameIn my case docker push sumana marvel When the process is complete you will be able to pull your image from anywhere using the command docker pull username new repo tagnameIn my case docker pull sumana marvel Outro We have successfully created a custom MySQL container From here the sky is the limit We can add endless functionalities on top of different prebuilt images and that s the beauty of docker If you got stuck anywhere you can check out the entire source code on Github and view the live repository on Docker Hub In case you have some questions regarding the article or want to discuss something under the sun feel free to connect with me on LinkedIn If you run an organisation and want me to write for you please do connect with me 2023-01-08 06:01:50
北海道 北海道新聞 帝京大、大勝で2連覇 ラグビー全国大学選手権 https://www.hokkaido-np.co.jp/article/784755/ 選手権 2023-01-08 15:38:00
北海道 北海道新聞 北海道内3363人感染6人死亡 新型コロナ https://www.hokkaido-np.co.jp/article/784753/ 北海道内 2023-01-08 15:26:00
北海道 北海道新聞 弟子の若隆景、若元春に期待 荒汐親方がトークイベント https://www.hokkaido-np.co.jp/article/784752/ 隆景 2023-01-08 15:21:00
北海道 北海道新聞 小型釣り船衝突、男性死亡 広島・呉市の沖 https://www.hokkaido-np.co.jp/article/784751/ 広島県呉市 2023-01-08 15:19:00
北海道 北海道新聞 揺れる英王室、不和深刻 ヘンリー王子、父や兄に批判展開 https://www.hokkaido-np.co.jp/article/784750/ 近刊 2023-01-08 15:16:00
北海道 北海道新聞 後志管内101人感染 小樽市72人 新型コロナ https://www.hokkaido-np.co.jp/article/784749/ 新型コロナウイルス 2023-01-08 15:13:00
北海道 北海道新聞 駿台学園が6大会ぶり優勝 全日本高校バレー最終日 https://www.hokkaido-np.co.jp/article/784748/ 東京体育館 2023-01-08 15:09:00
北海道 北海道新聞 兵庫で住宅火災、男性死亡 居住者3人と連絡取れず https://www.hokkaido-np.co.jp/article/784747/ 兵庫県伊丹市桜ケ丘 2023-01-08 15:09:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)