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

  • Home
  • SEARCH
  • 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 8663769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:04:04+00:00 2026-06-12T17:04:04+00:00

I want to create a kind of utility class which contains only static methods

  • 0

I want to create a kind of utility class which contains only static methods which are callable by the name class prefix. Looks like I’m doing something wrong 🙂

Here is my small class:

class FileUtility():

    @staticmethod
    def GetFileSize(self, fullName):
        fileSize = os.path.getsize(fullName)
        return fileSize

    @staticmethod
    def GetFilePath(self, fullName):
        filePath = os.path.abspath(fullName)
        return filePath

Now my “main” method:

from FileUtility import *
def main():
        path = 'C:\config_file_list.txt'
        dir = FileUtility.GetFilePath(path)
        print dir

and I got an error: unbound method GetFilePath() must be called with FileUtility instance as first argument (got str instance instead).

A have a few questions here:

  1. What am I doing wrong? Should not the static method be callable by classname?
  2. Do I really need a utility class, or are there other ways to achieve the same in Python?
  3. If I try to change the code in main I’m getting: TypeError: GetFilePath() takes exactly 1 argument (2 given)

The new main:

from FileUtility import *
def main():
    objFile = FileUtility()
    path = 'H:\config_file_list.txt'
    dir = objFile.GetFilePath(path)
    print dir
  • 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-06-12T17:04:05+00:00Added an answer on June 12, 2026 at 5:04 pm

    You’re getting the error because you’re taking a self argument in each of those functions. They’re static, you don’t need it.

    However, the ‘pythonic’ way of doing this is not to have a class full of static methods, but to just make them free functions in a module.

    #fileutility.py:
    
    def get_file_size(fullName):
        fileSize = os.path.getsize(fullName)
        return fileSize
    
    
    def get_file_path(fullName):
        filePath = os.path.abspath(fullName)
        return filePath
    

    Now, in your other python files (assuming fileutility.py is in the same directory or on the PYTHONPATH)

    import fileutility
    
    fileutility.get_file_size("myfile.txt")
    fileutility.get_file_path("that.txt")
    

    It doesn’t mention static methods specifically, but if you’re coming from a different language, PEP 8, the python style guide is a good read and introduction to how python programmers think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create some kind of row image that looks like that but
I want to create my own kind of a SeekBar which means I want
I want to create a dialog that contains some kind of text element (JLabel/JTextArea
I want to make this kind of query: create procedure something @name varchar(13) as
I want to create a board class from canvas, which will allow to track
Basically i want to create XMLDesigner kind of thing in Flex, using which user
I want to create a Circluar Determinate ProgressBar, the kind which shows the Progress
Im new to android and I want to create kind of CRUD with SQLite.
I want to create some kind of AJAX script or call that continuously will
I want create wordpress website into which I want create user management... That means

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.