PyCalc

Calculate better

PyCalc Help

Startup.py


PyCalc is highly customizable, mainly through the use of the startup.py file. This is a file of Python code that is run each time PyCalc restarts. With startup.py you can:

PyCalc comes with a simple startup.py file to get you started. For instance, to convert from fahrenheit to celsius, it defines the ftoc() function. You can type ftoc(85) in the code entry box to see what 85 degrees fahrenheit is in celsius, because the startup.py file contains a definition for that function. Write your own functions to speed up your own personalized calculations.

You can place any standard Python code you'd like in the startup.py file.

Editing and Restoration

To view and edit the startup.py file, press Settings+Help in the upper-right, and then Edit startup.py. If you get into trouble and damage startup.py beyond your ability to repair it, there are a couple options for recovery (under Restore startup.py):

Be careful with these restore options — they are permanent and might delete any modifications you've made since you first installed PyCalc.

Imports

Python uses collections of related code called modules or packages to extend its functionality. PyCalc includes many of the standard Python packages and a few non-standard ones. However, these are not available to you automatically. To make a package/module available, you must "import" it. For example, you could place a line like import sympy into your startup.py file. To learn more about how this works, refer to the official Python documentation.

pycalcfun module

The provided startup.py file includes the line from pycalcfun import *. This line causes a large number of standard mathematical constants and functions to be imported into your environment. This is what makes it possible, for instance, for you to use the cos() function, since it's imported into your environment. Specifically, pycalcfun imports:

If you don't want to use those functions, you're free to remove the from pycalcfun import * line from startup.py, but beware that may disable many features you otherwise expected.

Function Definitions

Being able to define your own custom functions for easy access later is one of the most useful capabilities of PyCalc. In order to do this, you need to have some familiarity with Python. The official documentation is a good place to get started. The provided startup.py includes some examples that may be sufficient for learning about simple functions as well. For example:

def ftoc(f):
   return (f-32)/1.8

Constants

You may find it useful to define your own constants for use in your calculations. The provided startup.py includes several common physical constants, but is by no means exhaustive. Suppose you're a nuclear physicist and frequently use the mass of a proton in your calculations. You could define that in your startup.py like:

pm = 1.67262192e-27

And that might work fine for you. However, it's probably even better to define it like this:

pm = mpf("1.67262192e-27")

The issue is that the first approach results in a Python float value, which is fine for many purposes but may introduce some subtle precision issues. See the discussion under Input Modes for more details on this.

Note that in the second approach, the value is placed in quotation marks to make it a Python string. Then it's turned into a precision decimal value by the mpmath.mpf function.