degrees V0.1.1 Documentation
python_developer
编辑于 2026年04月19日 07:47

Back to PyPI: https://pypi.org/project/degrees/

Contents

  • Introduction

  • Class

    • Degree

  • Functions

    • degree2radius

    • radius2degree

    • convert_to_360

  • Changelog

Introduction

A python lib for degree calculations and conversions

Importing

Just type import degrees.

Class

class degrees.Degree(number)

class degrees.Degree(degree_obj)

class degrees.Degree(degree=0, minute=0, second=0)

Creating a Degree object

代码块
Python
自动换行
复制代码
>>> degrees.Degree(1)
1°
>>> degrees.Degree(2, 3, 4)
2°3'4"
>>> degrees.Degree(1, second=2)
1°0'2"
>>> degrees.Degree(1, 3)
1°3'
>>> degrees.Degree(0, -1)
-1'
>>> degrees.Degree(2, -4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    degrees.Degree(2, -4)
    ~~~~~~^^^^^^
  File "/degrees.py", line 32, in __init__
    raise ValueError("if degree is not 0, minute and second must be positive integer")
ValueError: if degree is not 0, minute and second must be positive integer
复制成功

staticmethod from_str(string)

Return a degree object from a string.

staticmethod from_iter(iterable)

Return a degree object from an iterable.

functools.cached_property total_seconds

The total seconds of a degree object.

deg

The degree of a degree object(without sign).

min

The minute of a degree object(without sign).

sec

The second of a degree object(without sign).

sign

The sign of a degree object.

Note

The attributes of Degree are read-only.

Functions

def degree2radius(x: Degree, /)

Convert angle x from a degree object to radians.

def radius2degree(x: Union[int, float], /)

Convert angle x from radians to a degree object.

def convert_to_360(x: Degree, /)

Be using for angle normalization.

Other

version_info

The degree version info(it is like sys.version_info).

Changelog

  1. Simplified class _Type(for type annotation), you can use it on Python 3.8+(in the previous version, it only supports Python 3.12+).

  2. Rewrite the method Degree.__hash__. Now it can execute perfectly.

  3. Added methods: Degree.from_string, Degree.from_iter, property Degree.total_seconds.

  4. Added Degree.deg, Degree.min and Degree.sec in the document.

  5. Yanked Degree 0.1.0.

  6. Moved the documentation to Bilibili.

Write in the end

If you found the bug in the code, you can email me at snake830@vip.163.com. I'm happy to receive the advice!

Which platform for the documentation?