teleren/devto huggingface dataset:
How to get file extension in Python?
Tags: python, programming, codenewbie, tutorial
Published: 2021-09-12 08:05:17

---
title: How to get file extension in Python?
published: true
date: 2021-09-11 18:13:43 UTC
tags: #python #programming #codenewbie #tutorial
canonical_url: https://itsmycode.com/how-to-get-file-extension-in-python/
---

ItsMyCode |

In Python, we can extract the file extension using two approaches. Let’s take a look at each of these with examples.

## Python get file extension using os module `splitext()` function

The os module has extensive functions for interacting with the operating system. The OS module can be used to easily create, modify, delete, and fetch file contents or directories.

**_Syntax:_ os.path.splitext(path)**

The function` splitext()` will take the path as an argument and return the tuple with filename and extension.

```python 
import os

# returns tuple wit filename and extension
file_details = os.path.splitext('/home/usr/sample.txt')
print("File Details ",file_details)

# extract the file name and extension
file_name = file_details[0]
file_extension = file_details[1]

print("File Name: ", file_name)
print("File Extension: ", file_extension)

```

**Output**

```python 
File Details ('/home/usr/sample', '.txt')
File Name: /home/usr/sample
File Extension: .txt
```

## Python get file extension using pathlib module 

pathlib module comes as a standard utility module in Python and offers classes representing filesystem paths with semantics appropriate for different operating systems.

**`pathlib.path().suffix`** method can be used to extract the extension of the given file path.  

```python 
import pathlib
  
# pathlib function which returns the file extension
file_extension = pathlib.Path('/home/usr/sample.txt').suffix
print("The given File Extension is : ", file_extension)
```

**Output**

```python 
The given File Extension is : .txt
```

What if your extension is like  **`sample.tar.gz` ** with multiple dots, and if you use the above methods, you will only get the last part of the extension, not the full extension.

You can use the **`pathlib `** module with **`suffixes `** property which returns all the extensions as a list. Using that, we can join into a single string, as shown below.

```python 
import pathlib
  
# pathlib function which returns the file extension
file_extension = pathlib.Path('/home/usr/sample.tar.gz').suffixes
print("File extension ", file_extension)
print("The given File Extension is : ", ''.join(file_extension))
```

**Output**

```python 
File extension ['.tar', '.gz']
The given File Extension is : .tar.gz
```

The post [How to get file extension in Python?](https://itsmycode.com/how-to-get-file-extension-in-python/) appeared first on [ItsMyCode](https://itsmycode.com).
CSS-Typography
Tags: html, css, javascript, react
Published: 2021-09-11 17:06:23

Typography is a main thing when it comes to front-end designing.
Here, we can look more into typography tips.👇

## Font-family 😊
    1.In font-family, mostly we can use serif and sans-serif.sans- 
     serif is widely used in modern-websites and we can use serif 
     in luxury websites.
    2.In sans-serif , we can use Inter, Opensas, roboto, 
       Montserrat , worksans , lato etc
    3.In serif , we can use Merriweather, aleso, playfair-display, 
       cormorant , cardo, lora etc

## font-size😒
    1.Normal text 16px-32px
    2.font-size of Long text can be more than 20px.
    3.Headlines 50px and font-weight:600
    4.For any text don't go more than font-weight:400 expect 
      headlines

##  paragraphs🤦‍♂️
    1.Don't make paragraph so long and Use less than 75 characters 
     per line.
    2.if paragraphs are long , user's will find it difficult to 
     read the information that you are trying to convey through 
     it.

##  line-height😢
    1.For Normal text, line-height should be in between 1.5 and 2
    2.For big Text go for less than 2

##  Letter-spacing👌
    1.Decrease letter spacing in headlines
    2.For small headlines , make every letter in uppercase With 
      low letterspacing
##  Don't do🤞
    1.Don't justify text
    2.Small blocks are fine
    3.Don't center long text blocks

##Thanks so much for your awesome time. Let's get together again soon.

<a href="https://www.buymeacoffee.com/rohitbrk" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="38" width="124"></a>
Week 2 in Task force at awesomity and Code of Africa
Tags: codeofafrica, taskforce3, awesomitylab, codinglifestyle
Published: 2021-09-11 18:11:44

Tough, puissant, influential, dominant, long, energizing week, that is all I can say on this second week in Task force 3.0 at Awesomity and code of Africa.


How?, on Monday we had a course with Yannick CTO @awesomity of git workflow, which was different from my poor practices. I learned many things to improve. In the afternoon we learned more about  virtual meeting etiquette which was about how to prepare yourself before, in, after meeting.

Wait … no game ? Yeah, we had a game of lifting a stick with one finger which was tough at first, but easy after knowing the method to use.

Ok, continue, We had a soft skills session with Axel about CoA values. I learned that before joining a company it is better to understand their values because you should know how the company lives day by day. We also learned intercultural communication with Anja which made me realise that I know the audience before using gestures and how cultures can affect someone in the workspace.

No coding? Oooh, we did some tough but easy codewars, with Yannick we learned about containerizing, dockerization, documentation which was good to know because When I was a scrum master of 30 people at school it was hard to manage them, but today it can be easy because of what I learned with Yannick.


In conclusion, This week was tough because we had to deliver a presentation on Friday, I had many things to say which made me not realize about time, I used 14min...Ooh instead of 4 min. Anyway I wish to become best in both soft and coding skills at the end of this 6 weeks program.
What is JavaScript? How did It Come Out?
Tags: javascript, programming
Published: 2021-09-11 17:54:50

JavaScript is a dynamic programming language widely used in web browsers. Client-side scripts written in JS manage the behavior of websites such as browser-user interactions and especially asynchronous interaction, displaying and changing content. In addition to the client side, it is also widely used on the server side, thanks to environments such as NodeJS.

*A programming language like a Swiss army knife* that allows you to develop with ReactJS, AngularJS, VueJS on the frontend, NodeJS on the backend, React-Native as cross-platform on the mobile side

JavaScript was written by Brendan Eich in May 1995 in just 10 days, yes 10 days. Of course, the whole language did not become like this in 10 days. Eich wrote this programming language for Netscape Navigator, and it was called Mocha, then changed to LiveScript in September 1995.
So why did LiveScript suddenly become JavaScript? Confusing some people even now;

**Of course it has nothing to do with the Java language, so JavaScript is not a scripted version of Java :)**
It was used as a “marketing tactic” that would increase its popularity because it evoked the Java language, which was very popular at that time, and this naming has survived to the present day.

In 1996, Microsoft announced VBScript languages with JScript and VisualBasic infrastructure, which are similar to JavaScript, and then provided CSS support for JScript, but it did not work correct. This is how Netscape and Internet Explorer’s browser war started, at that time logos such as the one below were featured at the bottom of the websites.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3nrxngthex0xcsaivd9.png)
 ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucbqxzsw9nnk7jy397ub.png)

In November 1996, Netscape applied to Ecma International for the standardization of JavaScript and was named ECMAScript after its acceptance. Afterwards, it continued to grow by getting continuous updates. Currently, the last version released continues to evolve as ES2021 or ES12.

*Source; *
https://tr.wikipedia.org/wiki/JavaScript#Standartla%C5%9Fma
VS Code keyboard shortcuts for Windows
Tags: vscode, programming, ui, webdev
Published: 2021-09-11 17:49:00

15 VS Code keyboard shortcuts for Windows to speed up your programming. I have listed down a few keyboard shortcuts that will make your life easier as a coder. These shortcuts help in saving a lot of time and once you get the hang of it, you will be using them every time you code.
**1. Quick open:** `Ctrl`+`P`
**2. Copy line:** `Shift`+`Alt`+`↑`/`Shift`+`Alt`+`↓`
**3. Move line:** `Alt`+`↑`/`Alt`+`↓`
**4. Code formatting:** `Shift`+`Alt`+`F`
**5. Navigate to a specific line:** `Ctrl`+`G`
**6. Go to the beginning of the file:** `Ctrl`+`Home`
**7. Go to the end of the file:** `Ctrl`+`End`
**8. Insert cursor above/below:** `Ctrl`+`Alt`+`↑`/`↓`
**9. Select all occurrences of current selection:** `Shift`+`Ctrl`+`L`
**10. Open terminal:** `Ctrl`+`` ` ``
**11. Create new terminal:** `Ctrl`+`Shift`+`` ` ``
**12. Split screen:** `Ctrl`+`\`
**13. Fold (collapse) region:** `Ctrl`+`Shift`+`[`
**14. Go back/forward:** `Alt`+`←`/`→`
**15. Jump to matching bracket:** `Ctrl`+`Shift`+`\`

###Basic Shortcuts
**1. Delete line:** `Ctrl`+`X` (You don’t have to select the entire line)
**2. Copy line:** `Ctrl`+`C` (You don’t have to select the entire line)
**3. Find:** `Ctrl`+`F`
**4. Replace:** `Ctrl`+`H`
**5. Save:** `Ctrl`+`S`

**Happy Coding! 😊**

[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqmyq1twcon9ndguelyd.png)](https://www.buymeacoffee.com/hardiquedasore)

Follow us on [Instagram ](https://www.instagram.com/commitandpush/)
Private chat application using Django and Ajax
Tags: django, github, python, javascript
Published: 2021-09-11 17:43:49

I was going through tutorials online, to find web chat application projects. But the most of them were room chat apps with no sort of security. So thought of building a chat application having features like chat, file sharing one to one with security verification, etc.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0aw02qjiw26uflmzxi5o.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9y3pckjmw16a6wpydnr2.png)
 Here is the the link to github repo:https://github.com/krishna-vasudev/ChitChat.
Here is the link to deployed application:https://chitprivatechatapp.herokuapp.com/
Please give your honest feedbacks.
CRYPTOHACK Challenges
Tags: cryptographychallenges
Published: 2021-09-11 17:42:54

CRYPTOHACK is a free platform to learn and practice cryptography. The challenges are grouped into 9 sections, from introduction to misc.I enjoyed solving the problems.
Link to the Website : https://cryptohack.org/

Here's how I solve the Introduction section:

1. Finding Flags
Each challenge is designed to help introduce you to a new piece of cryptography. Solving a challenge will require you to find a "flag".

These flags will usually be in the format crypto{y0ur_f1rst_fl4g}. The flag format helps you verify that you found the correct solution.

Try submitting this into the form below to solve your first challenge. 

Ans : The flag is available in the description  

2. Great Snakes
Modern cryptography involves code, and code involves coding. CryptoHack provides a good opportunity to sharpen your skills.

Of all modern programming languages, Python 3 stands out as ideal for quickly writing cryptographic scripts and attacks. For more information about why we think Python is so great for this, please see the FAQ.

Run the attached Python script and it will output your flag.

great_snakes.py

Ans : Download the file and run it using python3 python-file.py

3. Network Attacks
Several of the challenges are dynamic and require you to talk to our challenge servers over the network. This allows you to perform man-in-the-middle attacks on people trying to communicate, or directly attack a vulnerable service. To keep things consistent, our interactive servers always send and receive JSON objects.

Python makes such network communication easy with the telnetlib module. Conveniently, it's part of Python's standard library, so let's use it for now.

For this challenge, connect to socket.cryptohack.org on port 11112. Send a JSON object with the key buy and value flag.

The example script below contains the beginnings of a solution for you to modify, and you can reuse it for later challenges.

Connect at nc socket.cryptohack.org 11112

telnetlib_example.py

Ans : In this challenge we need to replace the {"buy" : "clothes"} with {"buy" : "flag"} . Then run the python script using python3 python-file.py
Feedback and improvements for my mini project
Tags: webdev, react, webapp
Published: 2021-09-11 17:39:16

I created a mini web app it will convert time and date from one time zone to other time zone.

Here is the link: 
https://time-zone-converter.vercel.app/

For Source code or API docs please visit https://github.com/saketh-kowtha/time-zone-converter

Please visit and give your feedback or any improvements and suggestions if any 

Cheers!
Tips for computer science students
Published: 2021-09-11 17:28:28

Here are some tips that I would like computer science/software engineering graduates to consider once they graduate:

💡 **Choose experience over salary**: I understand that when you graduate you dream about earning big money because you’ve been grinding throughout the university, and now you want to earn better money. However, first, you work for experience, and then the experience will work for you in the future.

💡 **Attend networking events**: networking is a great way to meet people who can help you get your first job. Try to attend face-to-face meetups, webinars, conferences, and employability events. Network with the intention of making friends, because friends are the ones who are actually going to help you.

💡 **Stick with one language and framework**: pick whatever language you like and stick with it for some time. You will learn more languages, tools, and frameworks as time goes by, but my point is that there is no point in learning multiple languages and frameworks just to make your CV look fuller (or “experienced”).

I hope this helps! 😊
Development, Deployment and Monitoring notes 
Published: 2021-09-11 17:28:04

Google Cloud Platform Fundamentals -  Notes on Development, Deployment and Monitoring.

Google Cloud platform provides essential services in development, deployment and monitoring. These services,tightly integrated into the Google Cloud platform  make it seamless to automate deployment, and monitor application's health. Let's take a dive into the services that Google provides to achieve these.

Development

1. Cloud Resource Repositories
Software developers use git to manage their source code trees, most software developers use either git instance or a hosted git provider. Cloud resource repositories is a hybrid between these two. Cloud resource repositories provides version control. Where one gets access to a private git repository and also access to an IAM permissions to protect it and it is also maintained by Google.  

2. Cloud Functions: 
These are like events, they are created like single purpose functions to respond to events without a server or runtime.
Cloud functions are such that you choose the events you care about. These declarations are called triggers. JavaScript functions are attached to the triggers. Cloud functions can be used in Microservice applications and also to support existing applications without worrying about scaling.


Deployment
The deployment manager is a template for declarative deployment. It is an infrastructure management service that automates the creation and management of your Google Cloud platform environment the template describes.
The template is created as a .yaml file. Declaratively, the deployment process is noted and deployment manager figures out the actions to create and  automate the deployment process.

Monitoring:
 Monitoring enables you respond with information to critical happenings, such as performance issues, etc.  Stack driver is used for monitoring, logging and diagnostics. It gives information to the application's health performance and availability.
My Taskforce Bootcamp Weekly Journal 2
Published: 2021-09-11 17:22:34

The past week at the boot camp was pleasant 👍. Maybe that's even underrating it. Here is my overall assessment of the week.

The soft skill sessions for this week were packed with lots of interactive group activities that required us to talk and get to know each other. Getting to know the team better was one of the reasons I would say the week was fun and allowed us to laugh other than seeing each other as mere competitors.

> Careful what you wish for?

What a dreadful phrase, will consider my wishes carefully from now on as I got to feel what it truly means. After all that talk 🗣 I was saying how the coding challenges were easy and all, this week they came to us on steroids 💪. Honestly, guys, don't take it personally 😂, it's just friendly feedback.

Tho giving us hard challenges isn't the best way to go, I mean yes we were given and yes some produced the codes quicker than others, but there was no **accountability**.

#### What do I mean by that?

It was more about submission other than reviewing 🧐, understanding someone's thinking process, and generating efficient, readable, and maintainable code. With this current setup, someone could plagiarize the solutions and no one would know 🤔.

🙋‍♂️ I would suggest we are given one coding challenge and we see the different ways everyone delivered, or splitting us into teams and seeing how we deliver the task would be better.

What I found helpful overall was hearing the feedback on my performance/behavior. I am eager to grow my professional skills so I welcome any feedback which I received in abundance. 

All in all, I can say it was a much better week, and can't wait for what's to come next.
Sense of time.py
Tags: productivity, python
Published: 2021-09-11 16:51:06

> The trouble is, you think you have time. - Jack Kornfield

This is my first blog, thought of starting with a quote :-).

With work from home being a new normal, we often get distracted by something and lost the track of time. Might Not be everyone, but people like me.

Research studies have proven that **A regular reminder of passage of time seems to have a definite good impact on one's efficiency and productivity**_(don't look it up!)_

So I have decided to create a very simple background process that reminds you the time every quarter-hour.

We are going to use python and crontab service in your MacOS.

```
#!/usr/bin/env python
import os
import time

# Say current time
os.system('say -v Samantha "The time is now ' + time.strftime("%I:%M %p") + '"')
```
_Simple, indeed_

As you can see, we have used say-command, which is a CLI for [Speech Synthesis Manager](https://developer.apple.com/documentation/applicationservices/speech_synthesis_manager). _I didn't like the default high-pitched male voice, so I changed to `-v Samantha`_

Put the above python snippet in a file, save it somewhere and copy the file path. In my case, it is `~/dev/scripts/sense_of_time.py`

Now, we are gonna use [crontab](https://ole.michelsen.dk/blog/schedule-jobs-with-crontab-on-mac-osx/) - _explained by one of my favourite blogger Ole Michelsen_

Open your terminal and run `crontab -e` to edit the job list. it will be empty, if you don't have any job configured.

We are gonna configure a new job now. Paste the below line in crontab job file,

```
 */15 * * * * /usr/local/bin/python3 ~/dev/scripts/sense_of_time.py
```

Explanation:
1. `*/15 * * * *` - cron expression tells when the job should run. Change this expression if you want it to run at different time interval.
2. `/usr/local/bin/python3` - path of python binary, _change it if your path is different_
3. `~/dev/scripts/sense_of_time.py` - path of your python file.

Now, save and close the file to install the cronjob, if you are using vim, press ESC, type `:wq` and hit enter.

you should see
```
$ crontab -e
crontab: installing new crontab
$
```

That's it!

When the time is *:15/30/45/00, you will get a voice reminder.

How cool is that!

See ya!
Hi there 👋
Tags: codenewbie, womenintech, introductions
Published: 2021-09-11 16:41:11

My name is Stefi. I am a speciality coffee lover, skier, occasional longboard skater and someone who might spend way too much time watching YouTube videos. In the near future I'd like to finish a triathlon and share things I'm learning on my journey in tech online including on this platform.

I come from Romania, Brasov and currently, I live in Spain, Barcelona. I'm quite introverted and I used think a lot about switching to tech.

Asking myself often "Who Are You?" and "Are You You?" helped me keep going. These questions come from a mini series I've seen on [YouTube](https://youtube.com/playlist?list=PLXYEaUHc07uZwOT63py0RTY8CKHOYnMaG).

![Shantell Martin asks, ‘Who are you?’](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuq4hf2dt0b7a98xv3fi.jpg)

My engineering journey started about two years ago. Although I didn’t pursue a computer science degree, I’ve naturally found my way to it. I’ve participated, hosted and presented at some tech meetups in Barcelona. 

For example, I've organized study sessions for the [Facebook Developer Circle](https://www.facebook.com/groups/DevCBarcelona/) in Barcelona and in December 2019 I spoke ​at ​ [​QueerJS​](https://queerjs.com/paris/) in Paris about [The importance of community when transitioning to tech](https://www.youtube.com/watch?v=kiK4bSfGOpc&ab_channel=QueerJS).

In addition to programming, I have over five years of experience in Digital Marketing and Communication roles.

In my spare time I also enjoy reading, spending time with friends, and when restrictions allow, independent and adventurous travel!


You can find me on [Twitter](https://twitter.com/Stefania_Rosca), [Github](https://github.com/stefi23) or [Linkedin](https://www.linkedin.com/in/stefaniarosca/). 

Nice to meet you 😊