• bennr01

    First of, you can move your *_patient_list into the Patient class to reduce global variables.

    class Patient(object):
        master_patient_list = []  # this should be shared among all Patients
        def __init__(self, ...):
            ...
            self.master_patient_class.append(self)
    

    Second, I think you want something like this for example:

    class Physician(Employee):
        illness2doctor = {}  # shared dict mapping illness -> doctor for illness
    
        def __init__(self, name):
             # just as example
             self.name = name
    
        @classmethod
        def register_doctor(cls, doctor, illness):
            assert not illness in cls.illness2doctor  # prevent overwrite
            cls.illness2doctor[illness] = doctor
    
        @classmethod
        def get_doctor_for(cls, patient):
            illness = patient.illness
            if illness not in cls.illness2doctor:
                raise KeyError("No doctor for illness")
            return cls.illness2doctor[illness]
    
    
    # --- usage ---
    # create a new physician
    alice = Physician(name="Alice")
    # alice can treat "Broken Leg"
    Physician.register_doctor(alice, "Broken Leg")
    
    # now we can get the doctor for patient1
    print(Physician.get_doctor_for(patient1).name)
    # -> should print "Alice"
    

    posted in Pythonista read more
  • bennr01

    [s[i:i+2] for s in a for i in range(0, len(s), 2)]

    Replace 2 with chunk length.

    posted in Pythonista read more
  • bennr01

    @trey

    You can also use six by running pip -6 install…, but I’ve found modules installed into Python 3 that way from Python 2 StaSh to be unreliable. You can import them, but sometimes they don’t work, and pip list doesn’t show them in either StaSh 2 or 3. So I just wouldn’t do it.

    -6 does not use six, it just tells pip to use the shared site-packages directory so that you can install a package for both interpreters. Some packages may distribute different files depending on the installing python version which may cause the problems. Also, since pip stores information about the installed packages within site-packages, you must specify -6 for pip show too (pip -6 show).

    posted in Pythonista read more
  • bennr01

    StaSh runs on both py2 and py3, though not all commands support py3. pip uses the python interpreter StaSh was launched with and installs the package into the version specific site-packages directory. You can use the -6 option to tell pio that it should install a package into the shared site-packages directory.

    You can force StaSh to use a specific python version by long-pressing the Run-Button and choosing the "run with python X" option.

    posted in Pythonista read more
  • bennr01

    @JonB said:

         data=read(f)
    

    Shouldn't it be f.read()?

    I have to find all the numerical values in that text file and compute their sum. How can I do this in Pythonista?

    Assuming each line has exactly one numerical value:

    
    def read_ints_from_file(filepath):
        """
        Read integers from file path filepath.
        """
        values = []
        # open file read-only
        with open(filepath, "r") as fin:
            # read file line by line
            for line in fin:
                # remove any leading/trailing whitespace characters and convert to integer
                v = int(line.strip())
                values.append(v)
        return values
    
    # example usage. sum() calculates the sum of the argument(s)
    print(sum(read_ints_from_file("path/to/textfile.txt")))
    
    

    If the file contains text other than the numbers, you should look into regular expressions (using re) to find the values.

    posted in Pythonista read more
  • bennr01

    /private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/site-packages/xmlrpc/__init__.py

    Did you install this package using the -6 parameter or did you use an outdated StaSh version for this installation? Normally, packages should now be installed only in site-package-3 or site-packages-2 depending on the python version, but it seems like xmlrpc is installed in site-packages...

    @JonB said:

    @bennr01 -- probably need to add xmlrpc to the blacklist...

    It seems like in this case xmlrpc is provided by the future package.

    posted in Pythonista read more
  • bennr01

    @mikael said:

    @bennr01, a big thank you! for all you do to keep us stashed & pipped.

    It's always a pleasure. Though in this case, the fix was made by yjqiang.

    posted in Pythonista read more
  • bennr01

    After looking into this issue for a bit, it seems like the same bug as in Issue #364. This should have been fixed 12 months ago, just a month after the latest version bump for master. So it is possible that you have a version installed before that version bump.

    So, since it seems like the master branch became a bit outdated,I just merged 152 commits from dev into master. This should include the fix as well as a version bump, so could you please try another selfupdate?

    posted in Pythonista read more
  • bennr01

    would appreciate any hints on how to debug this?

    In general, stashconf py_traceback 1, stashconf py_pdb 1 and pip --verbose install pythonista-gestures.

    I just tried and could not replicate the error (it installs successfully).

    Error matches a stash issue.

    I think that one is a different issue. StaSh pip has two installers: one for source install (via setup.py) and one for wheels (.whl). The linked issue was regarding the source install, while this issue is with wheel installations. Also, I think we already fixed the linked issue, but I am not sure...

    posted in Pythonista read more
  • bennr01

    pip -6 install <package> should work.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!