iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
👻

Project Creation - Live Puzzle Programming Series

に公開
<< Back -- Index -- Next >>

This is the third installment of the "Live Puzzle Programming" series. While creating a puzzle application, I will write blog-style posts about what I thought, considered, and investigated during the creation process.

This time, we start by creating the project directory.

Deciding on the Project Structure

Previously, in Java projects, I used to create at least the following three directories:

  • src
  • doc
  • test

Now, since I am developing in Python this time, it seems best to follow Python conventions. I immediately performed a Google search for "Python directory structure." Various people have different opinions, making it unclear which one to adopt. Also, being a beginner, I don't quite understand concepts like packages or modules yet.

I will decide on the directory structure based on the following site, which was relatively easy to understand:

【図で解説】Python アプリケーション推奨のフォルダ構成(ディレクトリ構成)

  • okoze (Project root)
    • okoze (Package)
      • __init__.py
      • __main__.py (Module)
    • docs
    • tests

Creating the Project

Let's create the project. Launch Eclipse and create the project following these steps:

  1. Select [File] [New] [PyDev Project] from the menu.
    • Set the project name to "okoza" and click the "Finish" button.
  2. Select [File] [New] [PyDev Package] from the menu.
    • Confirm that the source folder is set to "/okoze".
    • Set the name to "okoza" and click the "Finish" button.
  3. Select [File] [New] [PyDev Module] from the menu.
    • Confirm the source folder and package.
    • Set the name to "__main__" and click the "Finish" button.
    • Select "Module: Main" as the template and click the "OK" button.
  4. Select [File] [New] [Folder] from the menu.
    • Create a "docs" folder directly under the project root.
  5. Similarly, create a "tests" folder.

Following these operations, the structure looks like this:

"__init__.py" is created automatically in step 2. "Python" is created automatically in step 1. I changed the "@author:OGAWA Keiji" part in "__main__.py" because it defaults to the Windows login username. To change it automatically, add the following line to "eclipse.ini" located in the same directory as "eclipse.exe".

-Duser.name=OGAWA Keiji

Running the Project

Add the following line to __main__.py and save it so that you can verify the execution.

    print('Hello, world!')

Right-click on the "okoze module" and select [Run] [Python Run] from the popup menu. If it goes well, 'Hello, world!' will be displayed on the console screen.

The site I referred to earlier explains the following method for execution:

python -m project_name

It seems that __init__.py will not be executed unless you include the -m option. I tested this by opening the console, and that was exactly the case. In Eclipse, running it using the previous method did not execute __init__.py. Therefore, I opened [Run] [Run Configurations] from the menu and changed the arguments as follows, which allowed __init__.py to be executed.

I also took the opportunity to change the name and add it to my favorites.

To be continued

"Integration with GitHub" remains. That's all for now. See you in the next part.


<< Back -- Index -- Next >>

Discussion