Python features you'll want to repeat

File server on a computer with mobile access

You can access your file system by running a file server on your computer. Navigate to the desired directory that you want to access and run the following command:

# python version >=  3.X
python -m http.server
# python version >=  3.X
python3 -m http.server #for Linux

# If Python version >= 2.X and < 3.X
python -m SimpleHTTPServer
#default port: 8000

This command starts a file server that can be accessed on the same network. To access your files on a mobile device, simply connect to the same network (Wi-Fi or use the phone's access point on a laptop). Now open the browser in your phone.

<your-computer-ip>:port

Check your IP by running - ifconfig. Check your local IP

Example:

192.168.43.155:8000
And on the mobile phone, you will see the current directory

Convert CSV to JSON 1 line

If you're a programmer, you'll probably be lazy and want to automate pretty much everything you can, right?

Don't worry, the python will cover you. There are a lot of things that you can automate in just 4-5 lines of code. From installing cron jobs and reminders to uploading your favorite YouTube videos, you can do it all with a few lines in python.

Example - convert CSV to JSON
You can convert a CSV file to JSON with just one command in Python!

python -c "import csv,json;print json.dumps(list(csv.reader(open('your_csv_file.csv'))))"

Replace it with anyfile.csv and you will get JSON output!

Easy, right?

Comics

Yes, these are comics in python!

import antigravity

Will they add brackets in python?

from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance

A simple life lesson

>>> import this
>>> love = this
>>> this is love
True
>>> love is True
False
>>> love is False
False
>>> love is not True or False
True
>>> love is not True or False; love is love  
True

Put on Heart if you liked it and you learned something new!

You can also follow ME to receive notifications about new interesting articles.

FAQ

I am a beginner, how should I learn Python?

Look into the following series:

Can we cooperate with you?

If you have interesting projects and you need a python (web)developer, then you can contact me by mail or discord and LinkedIn for cooperation

Connect to me on

17