Python - Use of Files Flashcards

Understand why organized files are required for Python code success

1
Q

Why do you need to understand other people’s Python files?

A

You need to understand other people’s Python files so that you:

  • Learn from examples and best practices.
  • Learn how to reuse code effectively, saving time and effort.
  • Learn how to debug and maintain code, especially in collaborative projects.
  • Enhance your own programming by exposure to different coding styles and approaches.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to study other people’s Python files?

A

To learn from other people’s code:

  • Read the code systematically, starting from imports to main functions.
  • Look at comments and documentation to understand the intent.
  • Run the code and observe its behavior.
  • Modify parts of the code and note the effects.
  • Use tools like Integrated Development Environment (IDEs) to navigate and understand complex code structures.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How much time should be spent studying existing code before actually writing meaningful code?

A

Balance time between studying existing code and writing new code. As a guideline:

  • Spend the initial 20% of your study time examining well-written code from others.
  • Gradually shift towards 80% hands-on coding as you gain familiarity.
  • Continuously revisit others’ code to reinforce learning and discover new techniques.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name 5 or more places where to find Python code for study?

A

Here are a number of ideas as to where to self-study, some of which will be covered in these flash-cards:

  • GitHub repositories related to projects or topics you’re interested in.
  • Code-sharing platforms like GitLab and Bitbucket.
  • Open-source software projects.
  • Python Package Index (PyPI) to explore packages and their source code.
  • Websites like Stack Overflow to view solutions and code snippets.
  • Coding challenge websites such as LeetCode, HackerRank, and Codecademy.
  • Sample code in Python documentation and tutorials.
  • Books on Python programming often include code examples.
  • Project documentation of frameworks, e.g., Django or Flask.
  • Articles and blogs from experienced Python developers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name at least 3 places where to find open source software Python projects?

A

Open-source software projects:

  • GitHub Explore: Visit https://github.com/explore to discover trending open-source projects.
  • SourceForge: A platform hosting a variety of open-source projects across different domains (https://sourceforge.net/).
  • Google Summer of Code Archives: Provides a list of projects that have participated in Google’s annual open-source program (https://summerofcode.withgoogle.com/archive/).
  • Apache Software Foundation: Hosts a collection of open-source software projects (https://www.apache.org/).
  • Open Source Initiative: Offers a comprehensive list of open-source licenses and associated projects (https://opensource.org/).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name at least 4 recommended resources on Python development?

A

Recommended articles and blogs resources written by experienced Python developers:

  • Medium: Search for Python-related topics on https://medium.com/tag/python.
  • Real Python: Offers tutorials, articles, and tips at https://realpython.com/.
  • Towards Data Science: A Medium publication focusing on data science, with many Python articles (https://towardsdatascience.com/).
  • Dev.to: A community of developers sharing knowledge, including Python articles (https://dev.to/t/python).
  • PyBites: A platform with articles and challenges to improve Python skills (https://pybit.es/).
  • Python Blogs: A directory of Python-focused blogs (https://www.pythonblogs.com/).
  • Use search engines with keywords like “Python development blog” or “experienced Python developer articles” to find more content.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the foundation of Python code?

A

Familiarize yourself with the concept of a Python module—a single file with a .py extension—as it’s the building block for organizing code.

Then learn how to create, run, and import modules, as this is fundamental for accessing and understanding the structure of Python programs you’ll study.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a single Python file called?

A

A single Python file is a module that can be composed and updated by a developer. When it is run, however, the Python interpreter creates a duplicate, compiled file identified with the file suffix, .pyc, which is only updated when its base .py file is updated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

A

Python files are identifyed by a file name’s suffixes.

A .py file is a text file in which Python code is written.

A .pyc file is a duplicate of the .py text file that is compiled by the Python interpreter after it is first run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A Python program might rely upon a collection of .py files. Identify at least one guide that provides directions for .py file organization.

A

.py files are generally organized by the projects they support. For specific organizing ideas, however, consult these guides:

  • The Python.org provides the PEP 8 – Style Guide for Python Code, at https://peps.python.org/pep-0008/.
  • The Hitchhiker’s Guide to Python at https://docs.python-guide.org/ is also a good reference.
  • Real Python at https://realpython.com/ also offers practical advice on Pythonic code organization and writing effective modules and packages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

XXXXXXXXXXXXXXXXXXXXXXX

A

While Python code is written by developers, quite a bit of that code is copied and pasted (imported) between developers from one module to another.

Collections of modules are also exchanged which also must adhere to clear organizational guidelines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Named 4 ways Python files are grouped.

A

Python modules are grouped by:

module

package

library

framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are Python packages managed and shared?

A

A package is identified as a directory that holds modules, with the directory name being the package name.

Using standard directory organization, the first directory in a stream of directories (called a “treeview”) is called the “root directory”

To further identify a package directory, its root must also contain an empty file named __init__.py.

Using the Python import statementThere are several types of statements used to import packages:

import my_package
xxxxxxxxxxxx more including dot notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is a Python library managed and shared?

A

A Python Library contains a collection of project-related information (dependencies), such as modules, packages, documentation, configuration data, message templates, classes, and more.

The specifics of library creation are too extensive for describing in this flashcard, except to say that once assembled, it is uploaded to the Python Package Index where it can be shared.

Libraries can be installed by using a PIP command.

Once installed (moved to your computer if not already there) it can be imported using the “import” command, followed by the library name. Example:
import new_library

The libarary can also be rename when imported using the “as” command. Example:
import new_libary as nl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How is a Python framework accessed?

A

framework: A Python web framework is a software library that provides a collection of modules and tools that offer a structured (guided) foundation to streamline and automate the development of web applications.

Python frameworks range from open-source solutions favored by individual developers and organizations to “enterprise-grade development solutions,” which are commercially supported web frameworks designed for professional and business applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

XXXX discussing import

A

Automated sharing is accomplished by using an “import” statement. Example:
* import example_mod.py

Shared modules can be renamed to more closely reflect their relationship with the current project by using the word “as” in the import statement. Example:
* import example.py as small project.py

17
Q

xxxx How does the Python interpreter find the old modules to be imported into new modules?

A

The Python interpreter finds the code to be copied by its exact name. This could be the name of a .py file or a package, which refers to a directory in which the module is found.

To start the processes, the interpreter searches for the name in the following locations:

  • The current directory
  • The directories listed in the computer’s PYTHONPATH environment variable. This is pre-setup list of directories that the interpreter automatically searches which can be modified and updated as needed.
  • The standard library directory which refers to the location where Python’s built-in and standard modules reside. This is often found in a subdirectory (??? to what?) called “LIB”. Its exact path varies based on the operating system and how Python was installed.
18
Q

What exactly occures when the import statement is invoked?

A

Here’s a simple breakdown of what happens:

Search: Python looks for the module’s file by checking the current directory, PYTHONPATH, and standard library directories.

Compile to Bytecode: If the module is being used for the first time or has been updated, Python converts the human-readable code in the .py file into a format it can understand more quickly, called bytecode, and stores this in a director that includes the following in its name: __pycache__.

Execute: Python runs the bytecode to set up the new module. All the classes, functions, and code found in the old module are read and executed from the compiled bytecode into the new module.

Cache: The new module is stored in memory so that any subsequent import calls during the same Python session can use it without repeating the search and execution steps.

19
Q

How do I know what information I should import and why?

A
20
Q

What is in Python’s Standard Library and why are public modules important?

A

The Python Programming Language installs over 200 modules which together are known as the “Python Standard Library.”

There are tens of thousands more shared modules, however, that support Python programming beyond Python’s standard library.

To identify what modules might apply to your project, visit pypi.org to explore the Python Package Index.

21
Q

What is PIP

A

PIP stands for Python Package Index (PyPI).

PIP is an app disributed with Python that is used to automate the installation, upgrading, configuration, and removal of Python packages, which are Python files stored in specific computer directories.

22
Q

How can I find useful modules?

A

When online, go to pypi.org. On the home page under the “search projects” field, click “browse projects.”

In the “Filter by Classifier” list, scroll to “Intended Audience.”

Select an “audience,” then read through the results for ideas on how Python code can be used.

23
Q

Can PIP used within an IDE?

A

xxxx

24
Q

What are virtual environments and why are they important for managing project dependencies

A
25
Q

Why should a developer strive to write modular code and how does it facilitate maintenance and testing.

A
26
Q
A
27
Q
A

Setup: Install Python and an IDE.
Syntax: Learn Python’s basic syntax.
File Handling: Understand Python file and directory operations.
Study Code: Examine code from other developers.
Write Code: Practice by writing your own Python scripts.
Debugging: Learn to troubleshoot and fix errors.
Projects: Apply skills to real-world projects.
Community: Engage with other Python users for feedback and collaboration.