Can distutils create empty files?

If all of my files are empty, do I have to store them into version control, or is there a way to make distutils create empty files during installation?

Asked by: Leonardo840 | Posted: 24-09-2021

Answer 1

In Python, files actually have a meaning! They mean that the folder they are in is a Python module. As such, they have a real role in your code and should most probably be stored in Version Control.

You could well imagine a folder in your source tree that is NOT a Python module, for example a folder containing only resources (e.g. images) and no code. That folder would not need to have a file in it. Now how do you make the difference between folders where distutils should create those files and folders where it should not ?

Answered by: Dexter873 | Posted: 25-10-2021

Answer 2

Is there a reason you want to avoid putting empty files in version control? If you do this you won't be able to import your packages from the source directory wihout first running distutils.

If you really want to, I suppose you can create in It has to be before running distutils.setup, so setup itself is able to find your packages:

from distutils import setup
import os

for path in [my_package_directories]:
    filename = os.path.join(pagh, '')
    if not os.path.exists(filename):
        init = open(filename, 'w')


but... what would you gain from this, compared to having the empty files there in the first place?

Answered by: Briony794 | Posted: 25-10-2021

Similar questions

import - Importing files in Python from

Suppose I have the following structure: app/ foo/, and share some common imports (logging, os, re, etc). Is it possible to import these three or four common modules from the file so I don't have to import them in every one of the files? Edit: My goal is to avoid having to import 5-6 m...

python - using

I am having difficulty understanding the usage scenarios or design goals of python's files in my projects. Assume that I have 'model' directory (refers as a package) which contains the following files I fo...

Global function in not accessible using Pylons + Python

I'm having trouble creating a global function accessible from within all classes. I receive an error from within that says: NameError: global name 'connectCentral' is not defined Here is my current code. project/model/__ init """The application's model objects""" import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy impor...

python - How to access variables from deeper parts of a package

I apologize for yet another question. I have the following package structure: +contrib | +database | In the top-level I define: USER='me'. If I import contrib from the command line, then I can access contrib.USER. N...

python - seemingly not working

New to Python. I'm on Windows and Python2.7. I have confirmed that my directory is setup in PYTHONPATH by looking in sys.path from IDLE. import sys print(sys.path) This shows me that c:\users\owner\documents\PythonProjects is definitely in the path. Furthermore in that directory I have a .py file which can be imported into IDLE. The trouble is c:\user\owner\documents\Pyth...

Can someone explain these few lines of python code file name usage for directories in Python

I use in my project with the following structure : project\ database\ test\ All is OK when I need to see database\ modules in with from import * But if I need to have some test co...

python - How to prevent nose from importing files?

Can the nose testing framework be instructed to only run tests in test_*.py files? In fact, doing nosetests A with the following directory structure: A/ B/ imports B, which I want to avoid. The reason for this is that the B module starts wi...

python - Why would I put code in files?

I am looking for what type of code would I put in files and what are the best practices related to this. Or, is it a bad practice in general ? Any reference to known documents that explain this is also very much appreciated.

Importing modules in Python and

I have been reading about the function of file. It is said that we need an empty file in the folder which contains modules, so that these modules can be imported. However, I tried adding a folder path to PYTHONPATH (Environment Variable in Windows 7). Although this folder does not contain an file, I can still import the modules from that folder. Cou...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python