Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3608098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:27:33+00:00 2026-05-18T21:27:33+00:00

I have a PyQt application that reads and writes data files. I am including

  • 0

I have a PyQt application that reads and writes data files. I am including a ‘version number’ in each file written. This is a simple number similar to: 1.2 or something (major and minor versions).

I am doing this so that I can change the format of these data files in future versions and then still correctly parse them simply by checking to see what the version is inside the file.

My question is what is the best practice for keeping this number stored inside the app itself. I.e. do I just hard-code the app version number into the class that is responsible for reading and writing files? Or should I have some sort of object/variable stored at the top-level of the app and somehow access it from the class responsible for reading and writing these files. If the latter, how do I store it and how do I access it?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:27:34+00:00Added an answer on May 18, 2026 at 9:27 pm

    First, version the data format separately from the app, if not already doing so. Second, have separate classes for newer versions of the format. If the format is completely backwards compatible, you can drop the classes for older versions. As for the file structure, you could have something like:

    • DF
      • __init__.py
      • dfbase.py
      • v1_1
        • __init__.py
        • format.py
      • v2_0
        • __init__.py
        • format.py

    where “df” stands for the data format name. The package initialization files import the appropriate packages and define a structure or function to make them accessible. The top-level __init__.py should also define a factory function to create data format objects, so you don’t have to.

    DF/__init__.py:

    from df.dfbase import DFBase
    from v1_1 import DF as DF1
    from v2_0 import DF as DF2
    versions = {
      '1.0': DF1, # let's say minor versions are fully backwards compatible
      '1.1': DF1, 
      '2.0': DF2
    }
    def create(file):
        """Factory function. Loads data from 'file', returns a DF of the appropriate 
        version.
        """
        ...
    

    DF/v1_1/__init__.py:

    __version__ = '1.1'
    # previous versions that this one is backwards compatible with
    previous = ['1.0']
    from format import DF
    

    DF/v1_1/format.py:

    from df import DFBase
    
    class DF(DFBase):
        ...
    

    DF/v2_0/__init__.py:

    __version__ = '2.0'
    from format import DF
    

    With a little more coding in DF/__init__.py, you could automate the import and registration of format versions.

    import glob, sys
    from ndf.ndfbase import NDFBase
    
    formats={}
    
    for ver in glob.iglob('v*_*'):
        pkg = '{0}.{1}'.format(__package__, ver)
        __import__(pkg)
        formats[sys.modules[pkg].__version__] = sys.modules[pkg]
        if hasattr(sys.modules[pkg], 'previous'):
            for prev in sys.modules[pkg].previous:
                formats[prev] = sys.modules[pkg]
    
    def create(file):
        """Factory function. Loads data from 'file', returns a DF of the appropriate 
        version.
        """
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very data-centric application, written in Python / PyQt. I'm planning to
Surely this is possible? I have been hunting through PyQt tutorials and documentation but
I'm writing a GUI application that regularly retrieves data through a web connection. Since
I have a PyQt program, in this program I start a new thread for
I have a Qt/C++ application that exposes some custom C++ classes via DBus methods
I have a fairly simple PyQt application in which I'm placing instances of a
I have a custom subclass of a QTreeView in a pyqt application. I'm trying
I have installed PyQT from this URL: http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-Py2.6-gpl-4.7.7-1.exe I have Python 2.6 installed. My
I have a list of actions on a menu in PyQt, one for each
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.