Shouldn't it be
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.
Did you install this package using the
-6parameter or did you use an outdated StaSh version for this installation? Normally, packages should now be installed only in
site-packages-2depending on the python version, but it seems like
xmlrpcis installed in
@bennr01 -- probably need to add xmlrpc to the blacklist...
It seems like in this case
xmlrpcis provided by the
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
masterbranch became a bit outdated,I just merged 152 commits from
master. This should include the fix as well as a version bump, so could you please try another
would appreciate any hints on how to debug this?
stashconf py_traceback 1,
stashconf py_pdb 1and
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
piphas 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...
stash: <class 'SyntaxError'>: invalid syntax (pip.py, line 2)
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/F47C5835-515B-4C73-93FB-38B132E4B000/Pythonista3/Documents/site-packages/stash/system/shruntime.py", line 545, in exec_py_file
code = compile(content, file_path, "exec", dont_inherit=True)
File "pip.py", line 2
python -m pip install SomePackage
SyntaxError: invalid syntax
It seems like StaSh is trying to execute the wrong file. You most likely have a file named
pip.pyin your current directory. Try executing
which pip | xargs rmto remove the wrong file.
@birkicht I just tried and was able to successfully install
colour. The error message you posted indicates that the file
$STASH_ROOT/bin/pip.pyis damaged (python cant parse it's contents). We have tests for the github repo, so we know that
pip.pyin the repo is working correctly. So the only other option I can think of is that StaSh tries to execute the wrong file.
To test this, could you please do the following:
stashconf py_traceback 1. This will enable full tracebacks.
which pipand post the output of this command here. This will tell us which file StaSh tries to execute. If you have a file named
pip.pyin your current directoy, this could cause the issues.
pip --verbose install colourannd post the output of this command here. This will show more output.