Python Forum

Full Version: file directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
newbie here - please be gentle :)

Having a path error when trying to run a file in the terminal

Path:
/Users/linardsberzins/Desktop/weatherterm/weatherterm/core/unit.py

Error:
No such file or directory

command:
python ~/Users/linardsberzins/Desktop/weatherterm/weatherterm/core/unit.py

Any advice appreciated

[Image: GQFc0Rw]

thanks
have you tried:
from command window:
cd /Users/linardsberzins/Desktop/weatherterm/weatherterm/core/
# if that works:
python /Users/linardsberzins/Desktop/weatherterm/weatherterm/core/unit.py
also, make sure letter case is correct
you seem to be missing some files from the github project: image

be sure to install both requirements
pip install -r requirements.txt
pip install -r requirements_dev.txt

and then try to test it with
python -m weatherterm -u Fahrenheit -a SWXX2372:1:SW -p WeatherComParser -td
Thank you @Cryptus

I just added the first class call in unit.py not that far yet :)

Will try @Larz60+ approach now.

Thank you for help

@Larz60+ and @Cryptus

file contents:
unit.py
from enum import auto, unique
from .base_enum import EBasenum

@unique
class Unit(BaseEnun):
    CELSIUS = auto()
    FAHRENHEIT = auto()
base_enum.py
from enum import Enum

class BaseEnum(Enum):
    def _generate_next_value_(self, name, start, count, last_value):
        return name
parser_loader.py
import os
import re
import inspect

def _get_parser_list(dirname):
    files = [f.replace('.py', '')
             for f in os.listdir(dirname)
             if not f.startswitch('__')]
    return files

def _import_parsers(parserfiles):
    m = re.compile('.+parsers$', re.I)
    _modules = __import__('weatherterm.parsers',
                          globals(),
                          locals(),
                          parserfiles,
                          0)
    _parsers = [(k, v) for k, v in inspect.getmembers(_modules)
                if inspect.ismodule(v) and m.match(k)]
    _classes = dict()
    
    for k, v in _parsers:
        _classes.update({k: v for k, v in inspect.getmembers(v)
                         if inspect.isclass(v) and m.match(k)})
        return _classes
    
    def load(dirname):
        parserfiles = _get_parser_list(dirname)
        return _import_parsers(parserfiles)
Error:
File "/Users/linardsberzins/Desktop/weatherterm/weatherterm/core/unit.py", line 2, in <module>
    from .base_enum import EBasenum
ImportError: attempted relative import with no known parent package