teleren/devto huggingface dataset:
Convert String to Float in Python
Tags: python, programming, codenewbie, tutorial
Published: 2021-09-17 15:11:20

---
title: Convert String to Float in Python
published: true
date: 2021-09-16 16:38:11 UTC
tags: #python #programming #codenewbie #tutorial
canonical_url: https://itsmycode.com/convert-string-to-float-in-python/
---

ItsMyCode |

In this tutorial, we will take a look at how to convert string to float in Python.

## Convert string to float in Python

Usually, in Python, the user input that we get will be a string when you read the data from the terminal, excel, CSV, or from a web form. We need to convert the string explicitly into the floating-point value before performing any arithmetic operations. Otherwise, Python will throw valueerror.

### `float()` function

The **`float()`** function is a built-in utility method which takes any object as an input parameter and converts into floating point number.Internally **`float() `**function calls specified object` __float__ ()` function.

**Syntax: float(obj)**

The float method accepts only one parameter, which is optional. If you don’t pass any parameter, then the method will return **0.0** as output.

### **Example 1** – Convert string to float

```python 
input= "33.455"
print(input)
print('Before conversion',type(input))

# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))

```

**Output**

```python 
33.455
Before conversion <class 'str'>
33.455
After conversion <class 'float'>
```

### Example 2 – Default float conversion without any input parameter

```python 
output = float()
print(output)

# Output
# 0.0

```

### Example 3 – Convert a String representing integer to a floating-point number

```python 
# string with integer to float 
input= "100"
print(input)
print('Before conversion',type(input))

# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))

```

**Output**

```python 
100
Before conversion <class 'str'>
100.0
After conversion <class 'float'>
```

### Example 4 – Converting string only with a decimal part to float

```python 
# string with integer to float 
input= ".000123"
print(input)
print('Before conversion',type(input))

# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))

```

**Output**

```python 
.000123
Before conversion <class 'str'>
0.000123
After conversion <class 'float'>
```

### Example 5 – Converting a string of exponential to float

```python 
# string with integer to float 
input= "1.23e-4"
print(input)
print('Before conversion',type(input))

# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))

```

**Output**

```python 
1.23e-4
Before conversion <class 'str'>
0.000123
After conversion <class 'float'>
```

The post [Convert String to Float in Python](https://itsmycode.com/convert-string-to-float-in-python/) appeared first on [ItsMyCode](https://itsmycode.com).
Password check PHP
Tags: php, dev, workhard
Published: 2021-09-16 16:33:26

Cette condition permet de ne laisser passer le formulaire
que quand la valeur de password est saisie et au moins 6 caractères.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gd3b28ri6ua836wnyuww.png)
[EKS] Troubleshooting EKS worker node not join to the cluster 
Tags: aws, kubernetes, cloudskills
Published: 2021-09-16 16:24:17

Today, we are talking about EKS cluster and related issue about EKS worker nodes.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azo57jzkb7zpnkx1fu7x.jpeg)

After creating the EKS cluster and worker, we are excited to see our worker nodes status by `kubectl get node`. However, you may see `No resources found` return by the command:
![Screen Shot 2021-09-17 at 12.25.56 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8o9hegr4q1k67wamtme.png)
 

AWS premium support blog has a great article which discuss each part you need to check to see if there is anything wrong:

https://aws.amazon.com/premiumsupport/knowledge-center/eks-worker-nodes-cluster/ 

Instead of issuing a support ticket to AWS Support, we can troubleshoot the issue by ourselves. There is a log collector called `EKS Logs Collector` open sourced in [EKS AMI repo](https://github.com/awslabs/amazon-eks-ami/tree/master/log-collector-script/linux). If you are using EKS optimized Amazon Linux 2 AMI or Windows, we can use this log collector to collect necessary logs from EKS worker nodes to identify the root cause of the issue.

The steps to collect logs :

1. ssh into the worker node
2. Run this project as the root user:
```
$ curl -O https://raw.githubusercontent.com/awslabs/amazon-eks-ami/master/log-collector-script/linux/eks-log-collector.sh
$ sudo bash eks-log-collector.sh 
```
![Screen Shot 2021-09-17 at 12.29.47 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tm1od511nkzs4pq762y.png)

Use `tar zxvf /var/log/eks_i-0670341186c49aa57_2021-09-16_1629-UTC_0.6.2.tar.gz` to uncompress the file
![Screen Shot 2021-09-17 at 1.32.08 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgz3lyrz7a5j356c6dwy.png)

We may find more information when check the `kubelet.log`
```
[ec2-user@ip-192-168-52-78 ~]$ ls
cni  containerd  docker  eks-log-collector.sh  ipamd  kernel  kubelet  networking  sandbox-image  storage  sysctls  system  var_log
[ec2-user@ip-192-168-52-78 ~]$ cd kubelet/
[ec2-user@ip-192-168-52-78 kubelet]$ ls
kubeconfig.yaml  kubelet.log  kubelet_service.txt
```

Next part, I would show you what you would see when encounter each issue in `kubelet.log` 
---




Need more time to finish this article :)
Javascript Meets Ruby
Published: 2021-09-16 15:53:42

##THE BUILD

First and foremost, this was the most challenging project I've worked on to date. From Ruby to Javascript, it is quite the transition but it's been a rewarding journey to complete a fully functional single page application. So let's get into some highlights of the build, shall we?

####Backend

For the past six months or so, I've been fully submerged in the world of Ruby. Learning all the ins and outs, but this was my time to shine. One of the project requirements for this project was using Ruby for our backend portion. Building the backend took me no longer than 20 minutes; setting up the database with necessary data and relationships...BAM, done. Before we move pas this section since we're now pros in Ruby, I wanted to touch on serializers. 

![Screenshot of code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uj77xo5fka39svpxmkt4.png)

As you see here, we have our models and controllers. But wait...where are the views? Well there are no views when utilizing a Javascript frontend and we'll get into how that works right now. 

####Frontend

Whew, now we're to the most challenging part of the build; the frontend. 

To display the application, with a Javascript frontend, we use an html file. Here's what mine looks like. 

![index.html file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3u4637wj4ryo1wgjevcm.png)

Within this file, we include div classes to populate the different sections of our app that we build within their own files. Organizing our files or classes to include functionality related to themselves is called OOP or Object Oriented Programming. This is similar to Object Orientation in Ruby. 

Now, let's dive into a particular part of the build which I found to be pretty cool and a lot different than the Ruby apps I built in the past. With Javascript, we can actually use `.innerHTML` to set or return the HTML content of an element. As you can see below, I used this to return the values of each attribute within it's appropriate element. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yusnlg9vhpsr7w69x22k.png)

In Ruby, we would populate the values of the attributes we wanted displayed, within the actual view or layout. However, in Javascript we can do this within the object file itself and call the div section in our html file. This helps keep our code super clean and easy to follow, especially if we're working on a team with others. 

I've learned a ton and will continue to develop in the world of Javascript. This is only the beginning!
Talk Python To Me Podcast Founder Michael Kennedy Interview
Tags: python, podcast, productivity, writing
Published: 2021-09-16 15:42:17

Michael Kennedy is a successful entrepreneur and software development professional. He created and hosts the weekly podcast, Talk Python To Me, which focuses on Python and related software development topics. He also founded and is the chief author for Talk Python Training, an online Python training program.

We had the opportunity to interview Michael about his programming experiences. [Hope you enjoy the reading!](https://evrone.com/michael-kennedy-interview)
How to fix a partition issue in a bacpac backup
Published: 2021-09-16 15:40:45

<sub>Photo by <a href="https://unsplash.com/@emmages">Emmanuel Ikwuegbu</a> on <a href="https://unsplash.com/s/photos/fix">Unsplash</a></sub>

In order to fix it, we need to perform 6 steps:
- rename the .bacpac file to .zip extension
- extract model.xml and origin.xml
- open model.xml and change the entry
```xml
				<Entry>
					<Element Type="SqlPartitionValue">
						<Property Name="ExpressionScript">
							<Value><![CDATA[NULL]]></Value>
						</Property>
					</Element>
				</Entry>
```
to 
```xml
				<Entry>
					<Element Type="SqlPartitionValue">
						<Property Name="ExpressionScript">
							<Value><![CDATA[CAST(NULL AS DATETIME2)]]></Value>
						</Property>
					</Element>
				</Entry>
```
- Save, and compute the new checksum using Powershell cmdlet [Get-FileHash](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1):
```Powershell
Get-FileHash -Algorithm 256 model.xml
```
- write the checksum in origin.xml to replace previous model.xml checksum
- Put back files model.xml and origin.xml in zip


Hope it helps !
I want to learn programming .
Published: 2021-09-16 15:00:11

I am a student who want to know how to instruct computer and take output as you want to take from it. I am exploring the concept of programming by some courses but I need guidance or a mentor how can teach me how to write programs in a manner .My field of interest is web development I knew the basics of html and advance of css and I am moving towards javascript. If anyone can guide me I am very thankful to you.
Universal configuration for webpack-dev-server
Tags: docker, webpack, open, container
Published: 2021-09-16 14:50:31

---
title: Universal configuration for webpack-dev-server
published: true
description: Configure webpack-dev-server host to 0.0.0.0 to accept requests from any ip address.
tags: Docker, Webpack, open, container
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwbzrt7so6jrighvjhrn.jpg
---
Cover photo by <a href="https://unsplash.com/@alexsiale?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Alex Siale</a> on <a href="https://unsplash.com/s/photos/whale?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>.

I am not a fan of having `webpack-dev-server` configured to open automatically in the browser, in my opinion it comes more handy to configure the browser to open that tab when it is started or to bookmark the dev url. But I think working in a team conventions are very important and if the team feels that it is nice to have it then it is important to configure it so it doesn't get in the way of any developer workflow.

## Accept connections from any ip.

The first part is to configure `webpack-dev-server` to be reachable from outside of the container, often the container can mask the original port the server was running, and to be honest, that is one of the advantages of using containers. That being said, the default configuration is secure by only allowing access on localhost (`127.0.0.1`) but limiting, so you need to manually set [devServer.host](https://webpack.js.org/configuration/dev-server/#devserverhost) to `0.0.0.0` to be externally accessible, you might need to do the same for ws, and that is documented [here](https://webpack.js.org/configuration/dev-server/#websocketurl).

## Configure open to a hardcoded string.

This by itself solves the problem of being able to talk to the server but introduces a little nuisance, open stop working since by default it tries to open `host:port` and host is now `0.0.0.0`, you can always type the address manually in the browser but that defeats the purpose of opening it automatically. So you need to set `devServer.open` to an array containing the string `localhost:port` or whatever ip address you are using. [Open configuration](https://webpack.js.org/configuration/dev-server/#devserveropen) is very flexible and can open more than one page at a time and configure the browser to be used, but you must keep in mind that last thing is OS dependent.

**Note:** if you are using old webpack versions you set this in two variables, `devServer.open` that is a boolean and must be `true` and `devServer.openPage` that will contain the url to be opened.
Outsmarting the C# Compiler - Using Static Types as Type Arguments
Tags: todayilearned, csharp, dotnet, compiler
Published: 2021-09-16 14:48:45

In case you were not aware, the C# compiler prevents you from using static types as type arguments. Trying to use a static type will result in the compiler error [CS0718](https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0718).
```
error CS0718:
  'StaticClass': static types cannot be used as type arguments
```

This can be demonstrated by the following example:
```csharp
static class StaticClass { }
static void Do<T>() => Console.WriteLine(typeof(T).FullName);

Do<StaticClass>();
```

## *Outsmarting* the Compiler
We need to move the `Do<T>` method into a new class and instantiate an instance of that class.
```csharp
class MyClass
{
    public void Do<T>() => Console.WriteLine(typeof(T).FullName);
}

var instance = new MyClass();
```

This alone will not *"fix" the issue*, as calling `instance.Do<StaticClass>()` still results in the same compiler error.

This is where `dynamic` comes into play.
```csharp
((dynamic)instance).Do<StaticClass>();
```

Since `instance` is now of type `dynamic` the compiler will not verify the `Do` call at compile time, but at runtime. Now the code builds. Running it will print `StaticClass` to the console, which indicates that **only the compiler prevents a type argument from being static**, although the runtime can handle static types as type arguments.

The need to *outsmart* the compiler, in most cases, indicates that there is something wrong with your design. Remember, **just because you can, doesn't mean you should.**
How to detect file type in JavaScript without checking its file object type?
Tags: javascript, programming, react, algorithms
Published: 2021-09-16 14:46:42

Usually when we want to check the type for a file that we have to upload we look for its MIME type in the file object.

MIME type is a standard that indicates the nature and format of a file, [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) you can get a list of the most common, there are really [many](https://www.iana.org/assignments/media-types/media-types.xhtml) of them.

###But.. What if the file for some reasons doesn't has an extension or have a wrong extension assigned? 🤔###

Luckily the magic numbers come to our aid.

**Magic numbers** are a byte pattern inside a file that is used to determine which is the type of the file.


Or, more properly, from *Wikipedia*:
> Magic numbers implement strongly typed data and are a form of in-band signaling to the controlling program that reads the data type(s) at program run-time. Many files have such constants that identify the contained data


For have an example of how to implement magic numbers "by hand" with the [FileReader API](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) I strongly recommend reading [this article](https://medium.com/the-everyday-developer/detect-file-mime-type-using-magic-numbers-and-javascript-16bc513d4e1e) by Andreas Kihlberg.

I want instead focus on the [file-type library](https://github.com/sindresorhus/file-type). This library applies the magic numbers approach to the ArrayBuffer of the file for detecting its type. It works with a [large amount](https://github.com/sindresorhus/file-type#supported-file-types) of different file types.

Unfortunately some file types, especially plain-text files, are harder to spot by this method and if you want to check the type you have to use a parser for every kind of file you have to consider.
For example if you want to spot SVG you can use [is-svg] (https://github.com/sindresorhus/is-svg) library from NPM.

I've created a Sandbox using React that show how the file-type library works.
C'mon, try it! 👇

{% codesandbox m7hom %}

👋 See you in the next article!

####Learn more####
* [Wikipedia - Magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming))
* [ArrayBuffer] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
* [Wikipedia - File format] (https://en.wikipedia.org/wiki/File_format)
NodeJs - Static site generator Release 0.1
Tags: opensource, javascript, osd600
Published: 2021-09-16 14:31:32

![mh-ssg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01mwin4xkgghedq8fpat.jpg)
 
# mh-ssg
mh-ssg is a simple static site generator that allows users to convert text files into HTML files. The tool is written in NodeJs with 4 main features. New features will be added on later. Visit the repo [here](https://github.com/minhhang107/mh-ssg).

# Installation
1. Clone the [repo](https://github.com/minhhang107/mh-ssg)
2. Install [Node](https://nodejs.org/en/)
3. Redirect to project directory
4. Install `mh-ssg` globally with `npm i -g .`

# Features
1. Creates HTML files from specified file/directory
2. Allows users to specify an output folder or use folder `dist` as default
3. Allows users to specify a stylesheet
4. Detects and sets the title of the file into the `title` and `h1` of the HTML file (if any)

# Usage
To use the tool, users can specify 3 options
###### -i --input
The tool accepts input as a single text file or or directory. If a directory is specified, the tool will ignore other file types and only process text files.
```
mh-ssg -i <file.txt>
mh-ssg -i <directory>
```
###### -o --output
Users can specify an output directory where they want to save the HTML files to. If the specified directory is not found, the tool will display an error message and will not process the input file. If no directory is given, the tool will use the default `./dist/` 
```
mh-ssg -i <file.txt> -o <directory>
```
###### -s --stylesheet
To use a custom stylesheet, simply pass in the link to the stylesheet to stylesheet option
```
mh-ssg -i <file.txt> -s <link-to-stylesheet>
```

# Example

```
mh-ssg -i file.txt -o folder -s https://cdn.jsdelivr.net/npm/water.css@2/out/water.css
``` 
will convert

##### ./file.txt

```
Silver Blaze


I am afraid, Watson, that I shall have to go,” said Holmes, as we
sat down together to our breakfast one morning.

“Go! Where to?”

“To Dartmoor; to King’s Pyland.”
```

into

##### ./folder/file.html

```
<!doctype html>
<html lang="en" dir="ltr">
<head>
<title>Silver Blaze</title>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">


</head>
<body>
<h1>Silver Blaze</h1>

<p>I am afraid, Watson, that I shall have to go,” said Holmes, as we sat down together to our breakfast one morning.</p>

<p>“Go! Where to?”</p>

<p>“To Dartmoor; to King’s Pyland.”</p>

</body>
</html>
```
How To Enable Real-Time Merge Conflict Detection in WebStorm
Tags: webdev, git, programming, productivity
Published: 2021-09-16 14:30:10

Ah, the dreaded *resolve conflicts* popup. You've finished crafting the perfect code, just a quick merge in of master (ahem, *main*) before you submit your PR, and then... 💥

![img-1-scaled.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631105453895/YWXZ2S8AY.png)


If only there was an early warning system for merge conflicts so you could be better prepared or even avoid the conflicts in the first place I hear you say? Well if you are a WebStorm user today is your lucky day!

Firstly, you'll need to install and set up [GitLive](https://plugins.jetbrains.com/plugin/11955-gitlive). Then if you right click the gutter on WebStorm, you will see the option to “Show Other's Changes”.

![img-2-scaled.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631105494603/8m0GvqeVw.png)


It will be disabled if the file open in the editor is not from git or there are no other changes to it from contributors working on other branches (aka you are safe from conflicts). If it's enabled there will be one or more change indicators in the gutter of the editor.

![img-3.3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631109508311/p5BwXJ3fc.png)

These will show you where your teammates have made changes compared to your version of the file and even update in real-time as you and your teammates are editing.

![key indicators-dark.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631105477371/nVpMNFsi2.png)

If you've made a conflicting change you will see the bright red conflict indicator. These conflicts can be uncommitted local changes you have not pushed yet or existing changes on your branch that conflict with your teammates’ changes.

Click your teammate’s icon in the gutter to see the diff between your version and theirs, the branch the offending changes are from, and the issue connected to that branch if there is one.

![img-5.3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631109501287/HjovOjeE8.png)


From this popup you can also cherry-pick your teammate’s change directly from their local version of the file. For simple conflicts this can be a quick way to resolve them as identical changes on different branches will merge cleanly.

Unfortunately, it's not always possible to resolve a conflict straight away but with the early warning, you'll be better prepared, avoiding any nasty surprises at merge time!

Check out [this blog post](https://blog.git.live/gitlive-11.0-Real-time-merge-conflict-detection) or the [GitLive docs](https://docs.git.live/docs/mergeconflicts/) if you want to learn more.
ForgeRock IPO! 🎉
Tags: career, security, news
Published: 2021-09-16 14:16:39

I am delighted to finally say this **publicly**, See what I did there, ForgeRock is now NYSE listed!

I am not officially posting this for ForgeRock or associated with the social media team, **I just love working here!**

https://bit.ly/3lymvM6