简体   繁体   中英

Python - Calling a function from a class

I'm having some trouble calling a function which is within a class in python.

Here is my folder hierarchy.
~/Code/program/main.py
~/Code/program/dc_functions/dcfunc.py
~/Code/program/dc_functions/ init .py

Basically, I want to use a function from dcfunc.py inside of main.py. How would I do this?

Relevant contents of dcfunc.py:

import subprocess, string, os, sys

class dcfunc:
    #Create raw Audio track(Part of Dreamcast Disc format) + Burn track to disk.

    def __init__(self):
        self.self = "self"  

    def burnaudiotrack(device):
        **CODE***

Thanks for any suggestions!

You need your init.py file to be named __init__.py

then use

from dc_functions.dcfunc import function_name

And you'll have acccess to the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM