Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, 21 May 2019

The 11 Best Sites for Free Online Computer Programming Courses

Right now, there’s an abundant number of in-demand computer programming jobs, and an abundant number of free online programming courses to help you land one of those jobs—even without a traditional computer science degree.
We’ll show you where to find these excellent online programming classes. If you don’t know the first thing about programming, check out our introduction to what coding is.

1. MIT OpenCourseWare

The 11 Best Sites for Free Online Computer Programming Courses online programming courses mit opencourseware
MIT OpenCourseWare is incredible. Many years ago, when I was struggling through a Linear Algebra course in college, MIT OCW came to my rescue. Complete courses are available online for free, and you can go through them at your own pace.
That Linear Algebra course (no longer available, sadly) is a strong contender for The Best College Course I’ve Ever Taken. It was all video lectures, but the professor knew his stuff and he presented the material in an easy-to-digest manner. It truly validated MIT’s reputation as an educational institute.
So I’m confident that you’ll love MIT OCW’s Programming courses. The introductory ones are split into General Introductions, Language-Specific Courses, and Follow-Up Courses. For a full listing, browse the Computer Science section.

2. edX

The 11 Best Sites for Free Online Computer Programming Courses online programming courses edx
edX is a provider of free college-level online courses, jointly spearheaded by MIT and Harvard University. Not only are the courses available without charge, the organization itself is non-profit, so you can rest easy knowing that you won’t be exploited by ulterior motives.
Courses on edX can be Weekly or Self-Paced. Subjects span the entire range of topics you might find at any accredited university, but there’s a heavy skew towards Computer Science, Engineering, and Business & Management. They’re also divided into Introductory, Intermediate, and Advanced levels for your convenience.
edX also offers Certificate Programs, which are course curriculum that build toward mastery in a specific area, like Front-End Web Development or Data Science. These are handy for deeper learning.

3. Coursera

The 11 Best Sites for Free Online Computer Programming Courses online programming courses coursera
Coursera is a free online course platform that’s backed by Stanford University and venture capitalists. Coursera collaborates with various universities and organizations to provide their courses, and earns revenue through its Certificate programs.
What’s nice is that Coursera focuses on Specializations: sets of courses designed to build your skills in a particular topic, but not so comprehensively as a full program. For example, the “Data Structures and Algorithms” six-course specialization covers Basic Data Structures, Basic Algorithms, Graph Algorithms, String Algorithms, Advanced Algorithms, and Genome Assembly.
Note that not all courses are free, but many are. Courses are self-paced but have definite start and end dates, meaning you’ll have to go through them as they’re available. Today’s courses may not be there tomorrow, but new ones may show up in their place. 

4. PVTuts

The 11 Best Sites for Free Online Computer Programming Courses online programming courses pvtuts
PVTuts is a free online repository of video courses for learning programming languages. It hasn’t been updated since 2013, but the video library is still a great resource for newbies. Just know that these courses are strictly about language syntax and nothing else.
Available topics include four general programming languages (C++, C#, Java, and SQL) and six web programming languages (HTML, CSS, JavaScript, PHP, ASP.NET, and XML).

5. Udacity

The 11 Best Sites for Free Online Computer Programming Courses online programming courses udacity
Udacity is yet another online course platform, but unlike MIT OCW, edX, and Coursera, Udacity strictly focuses on topics related to programming, data science, and engineering. No math, no social sciences, no humanities. It’s all about technology, and arguably better for it.
The goal of Udacity is to prepare you for occupational success in one of its tech-related fields. The platform places a lot of attention on its Nanodegree Programs, which are compact curriculums (usually completed in under a year) designed to get you job-ready as quickly as possible. But Nanodegrees cost anywhere from $100 to $500 each.
Don’t want to pay anything? That’s fine. You can eschew the whole curriculum-based approach and stick to individual free courses.

6. Udemy

The 11 Best Sites for Free Online Computer Programming Courses online programming courses udemy
Udemy is an online education marketplace where anyone can create (and even sell) their own courses for others to consume. This is quite the double-edged sword: it allows skilled folks to share their knowledge without an education degree, but you have to wade through a lot of crap to find it.
The programming courses on Udemy range across all kinds of topics. You’ll find everything from Python-based data crunching to the basics of ethical hacking, from Java fundamentals to master-level web development. You’ll also find a lot of courses related to game development.
5 Free Game Development Software Tools to Make Your Own Games 5 Free Game Development Software Tools to Make Your Own GamesFree game development software is a great way to start video game making. We've compiled the best game software on the market.READ MORE
Note: Never pay full price for a Udemy course! The Udemy marketplace frequently holds massive sales, slashing prices anywhere from 50 to 90 percent off. While you wait, check out the best free Udemy courses.

7. Free Code Camp or The Odin Project

The 11 Best Sites for Free Online Computer Programming Courses online programming courses freecodecamp
If your goal is to become a proficient web developer, whether front-end or back-end, then I highly recommend either Free Code Camp (which teaches HTML, CSS, JavaScript, and React) or The Odin Project (which teaches HTML, CSS, JavaScript, Ruby on Rails).
These two are comprehensive courses, both 100 percent free, that will take you from zero to hero at your own pace. Even if you have no coding experience at all, you’ll be fine. Expect to invest several months from start to finish so you can really understand the concepts taught. Don’t rush it.

8. Khan Academy

The 11 Best Sites for Free Online Computer Programming Courses online programming courses khanacademy
Khan Academy is one of the internet’s greatest treasures. This non-profit education platform has been a wonderful source of free education for the past decade, and it’s only getting better. Want to learn Calculus? Biology? World History? How to do your taxes or invest your money? It’s all here.
To be fair, the Computer Science and Computer Programming sections are playing catch-up, which is why it’s so low on this list. You can only learn JavaScript at the moment, plus the basics of algorithms and cryptography, but it’s certainly worth keeping an eye on.

9. YouTube


YouTube is very hit or miss. Thousands of tutorial playlists exist, but too many of them are superficial or downright wrong. Of the ones that seem promising, a good chunk of them are incomplete. And of the ones that are complete, a significant portion are outdated.
That being said, if you have a discerning eye, YouTube can be a great resource for learning how to program. Start with our roundup of the best YouTube programming tutorials.
The 17 Best YouTube Programming Tutorials The 17 Best YouTube Programming TutorialsIn this post, we'd like to point you to some of the best YouTube programming series we've found. All of these are sufficient for getting your feet wet as a newbie programmer.READ MORE

10. OpenCourser

The 11 Best Sites for Free Online Computer Programming Courses online programming courses opencourser
OpenCourser isn’t an education platform like the other sites listed here. Rather, it’s a search engine that aggregates thousands of free online courses from around the web and brings them to your fingertips.
As of this writing, over 900 free online programming courses are cataloged by OpenCourser, with many more added every day. Yes, you’ll find a bunch of courses from edX, Coursera, Udacity, etc. but you’ll also find some from elsewhere, like Saylor Academy. At the very least, it’s a convenient way to search many of the above platforms at once.

11. Codecademy

The 11 Best Sites for Free Online Computer Programming Courses online programming courses codecademy
Codecademy is a series of interactive online courses that aim to teach you the basics of a handful of programming languages and frameworks. Each course is a gamified, step-by-step process that holds your hand all the way from beginning to end.
But a word of warning before you dive into Codecademy: the things you’ll learn here are extremely basic and superficial. Codecademy teaches you how to write code, but it doesn’t teach you how to think like a programmer. Many first-time newbies end up frustrated because they don’t know what to do with the knowledge they’ve picked up.
If you have prior coding experience and simply want to learn the syntax of a new language, then Codecademy is actually pretty useful. If you consider yourself a beginner, then you should avoid Codecademy for now.
Why You Shouldn't Learn to Code With Codeacademy Why You Shouldn't Learn to Code With CodeacademyWhat's wrong with Codecademy? For those who want to learn coding, the instructional site is one of the best to begin with. But does Codecademy teach you to think like a coder?READ MORE

Notable Mention: Lynda

The 11 Best Sites for Free Online Computer Programming Courses online programming courses lynda
Lynda is home to over 6,000 different online courses spread across 12 tech-related fields (e.g. Animation, CAD, IT, Marketing, Photography) and hundreds of more specific topics of interest. With over 670 courses, the Programming category makes up a huge chunk of Lynda’s content.
Topics covered include Foundational Programming Concepts, Database Management, Game Development, Mobile Development, Web Development, and, of course, courses for individual programming languages. What’s nice is that courses are divided into Beginner, Intermediate, and Advanced levels, so you can always find the ones most relevant to you.
Lynda is a paid platform that costs $20/mo, but there’s a trick you can use to access Lynda courses for free.
How to Use Lynda.com for Free From Your Local Library How to Use Lynda.com for Free From Your Local LibraryIf you live in the US or Canada, chances are you have completely free and unrestricted access to Lynda through your library. Here's the easy process to enroll on Lynda.com through your library.READ MORE

More Tips for Computer Programming Newbies

If you stick with it and decide to pursue programming as a career, check out our tips for programming interview preparation. On the other hand, you may find that programming is too difficult: signs that programming isn’t for you.
6 Signs That You Are Not Meant to Be a Programmer 6 Signs That You Are Not Meant to Be a ProgrammerNot everyone is cut out to be a programmer. If you aren't completely sure that you're meant to be a programmer, here are some signs that may point you in the right direction.READ MORE
Explore more about: Online CoursesProgramming.

Tuesday, 9 April 2019

Python Delete File

Delete a File

To delete a file, you must import the OS module, and run its os.remove() function:

Example

Remove the file "demofile.txt":
import os
os.remove("demofile.txt")

Check if File exist:

To avoid getting an error, you might want to check if the file exists before you try to delete it:

Example

Check if file exists, then delete it:
import os
if os.path.exists("demofile.txt"):
  os.remove("demofile.txt")
else:
  print("The file does not exist")

Delete Folder

To delete an entire folder, use the os.rmdir() method:

Example

Remove the folder "myfolder":
import os
os.rmdir("myfolder")
Note: You can only remove empty folders.

Python File Write

Write to an Existing File

To write to an existing file, you must add a parameter to the open() function:
"a" - Append - will append to the end of the file
"w" - Write - will overwrite any existing content

Example

Open the file "demofile2.txt" and append content to the file:
f = open("demofile2.txt""a")
f.write("Now the file has more content!")
f.close()

#open and read the file after the appending:f = open("demofile2.txt""r")
print(f.read())
Show Python »
C:\Users\My Name>python demo_file_append.py
Hello! Welcome to demofile2.txt            
This file is for testing purposes.         
Good Luck!Now the file has more content!   
                                           
                                           

Example

Open the file "demofile3.txt" and overwrite the content:
f = open("demofile3.txt""w")
f.write("Woops! I have deleted the content!")
f.close()

#open and read the file after the appending:f = open("demofile3.txt""r")
print(f.read())
Show Python »
C:\Users\My Name>python demo_file_write.py
Woops! I have deleted the content!        
                                          
                                          

Note: the "w" method will overwrite the entire file.

Create a New File

To create a new file in Python, use the open() method, with one of the following parameters:
"x" - Create - will create a file, returns an error if the file exist
"a" - Append - will create a file if the specified file does not exist
"w" - Write - will create a file if the specified file does not exist

Example

Create a file called "myfile.txt":
f = open("myfile.txt""x")
Result: a new empty file is created!

Example

Create a new file if it does not exist:
f = open("myfile.txt""w")

Python File Open

Open a File on the Server

Assume we have the following file, located in the same folder as Python:
demofile.txt
Hello! Welcome to demofile.txt
This file is for testing purposes.
Good Luck!
To open the file, use the built-in open() function.
The open() function returns a file object, which has a read() method for reading the content of the file:

Example

f = open("demofile.txt""r")
print(f.read())
Show Python »
C:\Users\My Name>python demo_file_open.py
Hello! Welcome to demofile.txt           
This file is for testing purposes.       
Good Luck!                               
                                         
                                         


Read Only Parts of the File

By default the read() method returns the whole text, but you can also specify how many characters you want to return:

Example

Return the 5 first characters of the file:
f = open("demofile.txt""r")
print(f.read(5))
Show Python »
C:\Users\My Name>python demo_file_open2.py
Hello                                     
                                          
                                          



Read Lines

You can return one line by using the readline() method:

Example

Read one line of the file:
f = open("demofile.txt""r")
print(f.readline())
Show Python »
C:\Users\My Name>python demo_file_readline.py
Hello! Welcome to demofile.txt               
                                             
                                             

By calling readline() two times, you can read the two first lines:

Example

Read two lines of the file:
f = open("demofile.txt""r")
print(f.readline())
print(f.readline())
Show Python »
C:\Users\My Name>python demo_file_readline2.py
Hello! Welcome to demofile.txt                
This file is for testing purposes.            
                                              
                                              

By looping through the lines of the file, you can read the whole file, line by line:

Example

Loop through the file line by line:
f = open("demofile.txt""r")
for x in f:
  print(x)
Show Python »
C:\Users\My Name>python demo_file_readline3.py
Hello! Welcome to demofile.txt                
This file is for testing purposes.            
Good Luck!                                    
                                              
                                              


Close Files

It is a good practice to always close the file when you are done with it.

Example

Close the file when you are finish with it:
f = open("demofile.txt""r")
print(f.readline())
f.close()
Show Python »
C:\Users\My Name>python demo_file_close.py
Hello! Welcome to demofile.txt            
                                          
                                          

Note: You should always close your files, in some cases, due to buffering, changes made to a file may not show until you close the file.

Python File Open

File handling is an important part of any web application.
Python has several functions for creating, reading, updating, and deleting files.

File Handling

The key function for working with files in Python is the open() function.
The open() function takes two parameters; filename, and mode.
There are four different methods (modes) for opening a file:
"r" - Read - Default value. Opens a file for reading, error if the file does not exist
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
"x" - Create - Creates the specified file, returns an error if the file exists
In addition you can specify if the file should be handled as binary or text mode
"t" - Text - Default value. Text mode
"b" - Binary - Binary mode (e.g. images)

Syntax

To open a file for reading it is enough to specify the name of the file:
f = open("demofile.txt")
The code above is the same as:
f = open("demofile.txt""rt")
Because "r" for read, and "t" for text are the default values, you do not need to specify them.
Note: Make sure the file exists, or else you will get an error.