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

Thursday, 16 May 2019

Redirect and Errors

Flask class has a redirect() function. When called, it returns a response object and redirects the user to another target location with specified status code.
Prototype of redirect() function is as below −
Flask.redirect(location, statuscode, response)

In the above function − 1.location parameter is the URL where response should be redirected. 2.statuscode sent to browser’s header, defaults to 302. 3.response parameter is used to instantiate response.

The following status codes are standardized − 1.HTTP_300_MULTIPLE_CHOICES 2.HTTP_301_MOVED_PERMANENTLY 3.HTTP_302_FOUND 4.HTTP_303_SEE_OTHER 5.HTTP_304_NOT_MODIFIED 6.HTTP_305_USE_PROXY 7.HTTP_306_RESERVED 8.HTTP_307_TEMPORARY_REDIRECT
The default status code is 302, which is for ‘found’. In the following example, the redirect() function is used to display the login page again when a login attempt fails.
from flask import Flask, redirect, url_for, render_template, request # Initialize the Flask application

app = Flask(__name__) @app.route('/') def index(): return render_template('log_in.html') @app.route('/login',methods = ['POST', 'GET']) def login(): if request.method == 'POST' and request.form['username'] == 'admin' : return redirect(url_for('success')) return redirect(url_for('index')) @app.route('/success') def success(): return 'logged in successfully' if __name__ == '__main__': app.run(debug = True)
Flask class has abort() function with an error code. Flask.abort(code)
The Code parameter takes one of following values − 1.400 − for Bad Request 2.401 − for Unauthenticated 3.403 − for Forbidden 4.404 − for Not Found 5.406 − for Not Acceptabl 6.415 − for Unsupported Media Type 7.429 − Too Many Requests

Let us make a slight change in the login() function in the above code. Instead of re-displaying the login page, if ‘Unauthourized’ page is to be displayed, replace it with call to abort(401).
from flask import Flask, redirect, url_for, render_template, request, abort

app = Flask(__name__) @app.route('/') def index(): return render_template('log_in.html') @app.route('/login',methods = ['POST', 'GET']) def login(): if request.method == 'POST': if request.form['username'] == 'admin' : return redirect(url_for('success')) else: abort(401) else: return redirect(url_for('index')) @app.route('/success') def success(): return 'logged in successfully' if __name__ == '__main__': app.run(debug = True)

Thursday, 2 May 2019

Finding a Year is leap or not in Python

@author python.learning
>>> def check_year(year):
...      if year%4==0 and year%100!=0 or year%400==0:
...            print ('leap year')
...      else:
               print ('not a leap year')
>>>  check_year(1972)
leap year
>>>  check_year(1975)
not a leap year



# or check with calendar
>>> import calendar
>>> print (calendar.isleap(1972) )
True
>>> print (calendar.isleap(1975) )
False

Sunday, 24 March 2019

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script by Harry J.W.Percival (Author)

By taking you through the development of a real web application from beginning to end, the second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) with Python. Youíll learn how to write and run tests before building each part of your app and then develop the minimum amount of code required to pass those tests. The result? Clean code that works.
In the process, youíll learn the basics of Django, Selenium, Git, jQuery and Mock, along with current web development techniques. If youíre ready to take your Python skills to the next level, this bookóupdated for Python 3.6óclearly demonstrates how TDD encourages simple designs and inspires confidence.

Dive into the TDD workflow, including the unit test/code cycle and refactoring
Use unit tests for classes and functions and functional tests for user interactions within the browser
Learn when and how to use mock objects and the pros and cons of isolated vs. integrated tests
Test and automate your deployments with a staging server
Apply tests to the third-party plugins you integrate into your site
Run tests automatically by using a Continuous Integration environment
Use TDD to build a REST API with a front-end Ajax interface 


Buy :

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script Paperback – 2017 by Harry J.W.Percival (Author) 

PDF Download :

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script Paperback – 2017 by Harry J.W.Percival (Author) 




Programming with MicroPython by Nicholas H. Tollervey (Author)

It's an exciting time to get involved with MicroPython, the re-implementation of Python 3 for microcontrollers and embedded systems. This practical guide delivers the knowledge you need to roll up your sleeves and create exceptional embedded projects with this lean and efficient programming language. If you're familiar with Python as a programmer, educator, or maker, you're ready to learn-and have fun along the way.

 Author Nicholas Tollervey takes you on a journey from first steps to advanced projects. You'll explore the types of devices that run MicroPython, and examine how the language uses and interacts with hardware to process input, connect to the outside world, communicate wirelessly, make sounds and music, and drive robotics projects. Work with MicroPython on four typical devices: PyBoard, the micro:bit, Adafruit's Circuit Playground Express, and ESP8266/ESP32 boards Explore a framework that helps you generate, evaluate, and evolve embedded projects that solve real problems Dive into practical MicroPython examples: 

visual feedback, input and sensing, GPIO, networking, sound and music, and robotics Learn how idiomatic MicroPython helps you express a lot with the minimum of resources Take the next step by getting involved with the Python community

Buy :

Programming with MicroPython Paperback – 6 Oct 2017 by Nicholas H. Tollervey (Author) 

PDF Download :

Programming with MicroPython Paperback – 6 Oct 2017 by Nicholas H. Tollervey (Author) 




Saturday, 23 March 2019

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author)

If you are a Python developer who wants to master the world of data science, then this book is for you. Some knowledge of data science is assumed.

Buy :

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author) 

PDF Download :

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author) 


Friday, 22 March 2019

Numerical Python: A Practical Techniques Approach for Industry 1st Edition, Kindle Edition by Robert Johansson (Author)

Numerical Python by Robert Johansson shows you how to leverage the numerical and mathematical modules in Python and its Standard Library as well as popular open source numerical Python packages like NumPy, FiPy, matplotlib and more to numerically compute solutions and mathematically model applications in a number of areas like big data, cloud computing, financial engineering, business management and more.
After reading and using this book, you'll get some takeaway case study examples of applications that can be found in areas like business management, big data/cloud computing, financial engineering (i.e., options trading investment alternatives), and even games.
Up until very recently, Python was mostly regarded as just a web scripting language. Well, computational scientists and engineers have recently discovered the flexibility and power of Python to do more. Big data analytics and cloud computing programmers are seeing Python's immense use. Financial engineers are also now employing Python in their work. Python seems to be evolving as a language that can even rival C++, Fortran, and Pascal/Delphi for numerical and mathematical computations. 

Buy :


PDF Download :


Tuesday, 19 March 2019

Python for Data Mining Quick Syntax Reference Paperback – Import, 20 Dec 2018 by Valentina Porcu (Author)

Learn how to use Python and its structures, how to install Python, and which tools are best suited for data analyst work. This book provides you with a handy reference and tutorial on topics ranging from basic Python concepts through to data mining, manipulating and importing datasets, and data analysis.

Python for Data Mining Quick Syntax Reference covers each concept concisely, with many illustrative examples. You'll be introduced to several data mining packages, with examples of how to use each of them. 

The first part covers core Python including objects, lists, functions, modules, and error handling. The second part covers Python's most important data mining packages: NumPy and SciPy for mathematical functions and random data generation, pandas for dataframe management and data import, Matplotlib for drawing charts, and scikitlearn for machine learning.  

What You'll Learn
  • Install Python and choose a development environment
  • Understand the basic concepts of object-oriented programming
  • Import, open, and edit files
  • Review the differences between Python 2.x and 3.x
Who This Book Is For

Programmers new to Python's data mining packages or with experience in other languages, who want a quick guide to Pythonic tools and techniques.
 
Buy :
PDF Download :
 

Friday, 15 March 2019

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More

An indispensable collection of practical tips and real-world advice for tackling common Python problems and taking your code to the next level. Features interviews with high-profile Python developers who share their tips, tricks, best practices, and real-world advice gleaned from years of experience.

Sharpen your Python skills as you dive deep into the Python programming language with Serious Python. You'll cover a range of advanced topics like multithreading and memorization, get advice from experts on things like designing APIs and dealing with databases, and learn Python internals to help you gain a deeper understanding of the language itself. Written for developers and experienced programmers, Serious Python brings together over 15 years of Python experience to teach you how to avoid common mistakes, write code more efficiently, and build better programs in less time.

As you make your way through the book's extensive tutorials, you'll learn how to start a project and tackle topics like versioning, layouts, coding style, and automated checks. You'll learn how to package your software for distribution, optimize performance, use the right data structures, define functions efficiently, pick the right libraries, build future-proof programs, and optimize your programs down to the bytecode. You'll also learn how to:

- Make and use effective decorators and methods, including abstract, static, and class methods
- Employ Python for functional programming using generators, pure functions, and functional functions
- Extend flake8 to work with the abstract syntax tree (AST) to introduce more sophisticated automatic checks into your programs
- Apply dynamic performance analysis to identify bottlenecks in your code
- Work with relational databases and effectively manage and stream data with PostgreSQL

If you've been looking for a way to take your Python skills from good to great, Serious Python will help you get there. Learn from the experts and get seriously good at Python with Serious Python!


Buy :

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More Paperback – Import, 27 Dec 2018 by Julien Danjou 

PDF Download :

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More Paperback – Import, 27 Dec 2018 by Julien Danjou 


Thursday, 14 March 2019

Classic Computer Science Problems in Python

Classic Computer Science Problems in Python presents dozens of coding challenges, ranging from simple tasks like finding items in a list with a binary sort algorithm to clustering data using k-means.

Classic Computer Science Problems in Python deepens your Python language skills by challenging you with time-tested scenarios, exercises, and algorithms. As you work through examples in search, clustering, graphs, and more, you'll remember important things you've forgotten and discover classic solutions to your "new" problems

Key Features
·   Breadth-first and depth-first search algorithms
·   Constraints satisfaction problems
·   Common techniques for graphs
·   Adversarial Search
·   Neural networks and genetic algorithms
·   Written for data engineers and scientists with experience using Python.
For readers comfortable with the basics of Python

About the technology
Python is used everywhere for web applications, data munging, and powerful machine learning applications. Even problems that seem new or unique stand on the shoulders of classic algorithms, coding techniques, and engineering principles. Master these core skills, and you’ll be ready to use Python for AI, data-centric programming, deep learning, and the other challenges you’ll face as you grow your skill as a programmer.

David Kopec teaches at Champlain College in Burlington, VT and is the author of Manning’s Classic Computer Science Problemsin Swift.

Buy :

Classic Computer Science Problems in Python 

PDF Download :

Classic Computer Science Problems in Python 



Python for the Busy Java Developer: The Language, Syntax, and Ecosystem Kindle Edition by Deepak Sarda (Author)

Are you a seasoned Java developer who wishes to learn Python? Perhaps you’ve just joined a project where a chunk of system integration code is written in Python. Or maybe you need to implement a report generation module in the next sprint and your colleague mentioned that Python would be the perfect tool for the job. In any case, if you are in a situation where you have to pick up the Python programming language overnight, this book is just for you! 
Hit the ground running and gain a fast-paced overview of what the Python language is all about, the syntax that it uses and the ecosystem of libraries and tools that surround the language. This concise book doesn’t spend time on details from an introductory programming course or document every single Python feature. Instead, Python for the Busy Java Developer is designed for experienced Java developers to obtain sufficient familiarity with the language and dive into coding, quickly.
What You'll Learn
  • Discover the fundamentals of the core Python language and how they compare to Java
  • Understand Python syntax and the differences between Python 2.x and 3.x
  • Explore the Python ecosystem, its standard libraries, and how to implement them
Who This Book Is For
Working programmers who are comfortable with Java or another object-oriented programming language such as C#
Buy :


PDF Download :



Popular Posts

Categories

Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (83) R (68) Selenium Webdriver (2) Software (13) SQL (27)