Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pawk
-
I was trying to see if I could get pawk working. I installed it with pip install python-awk. However I can't figure out how to run it, probably under Stash.
Awk is a very useful tool and I was hoping I could get it working in Pythonista.
-
So what happens when you type pawk into the StaSH commandline?
-
This is what my console looks like:
[~/Documents]$ pip install python-awk
Querying PyPI ...
Downloading package ...
Opening: https://files.pythonhosted.org/packages/63/2b/bd27d449ba2f102d9b2b8dfe09446abeebcd292d10ce264c4b0660155af9/python-awk-0.0.5.tar.gzSave as: /private/var/mobile/Containers/Data/Application/7864CBEC-94B6-4103-AA16-C07C89C5C69C/tmp//python-awk-0.0.5.tar.gz (5424 bytes)
5424 [100.00%]
Extracting archive file ...
Archive extracted.
Running setup file ...
Package installed: python-awk
Installing dependency: jtutils
Querying PyPI ...
Downloading package ...
Opening: https://files.pythonhosted.org/packages/e7/66/e17c5c7cf390e4b45c2ffc2adb3ad6e575ab0ff0bc647061f43c6fb2001e/jtutils-0.0.6.tar.gzSave as: /private/var/mobile/Containers/Data/Application/7864CBEC-94B6-4103-AA16-C07C89C5C69C/tmp//jtutils-0.0.6.tar.gz (6706 bytes)
6706 [100.00%]
Extracting archive file ...
Archive extracted.
Running setup file ...
Package installed: jtutils
Dependency available in Pythonista bundle : requests
Dependency available in Pythonista bundle : beautifulsoup4
Installing dependency: argparse
Querying PyPI ...
Downloading package ...
Opening: https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whlSave as: /private/var/mobile/Containers/Data/Application/7864CBEC-94B6-4103-AA16-C07C89C5C69C/tmp//argparse-1.4.0-py2.py3-none-any.whl (23000 bytes)
23000 [100.00%]
Installing wheel: argparse-1.4.0-py2.py3-none-any.whl...
Extracting wheel..
Extraction finished, running handlers...
Running handler 'WHEEL information checker'...
Wheel generated by: bdist_wheel (0.24.0)
Running handler 'dependency handler'...
Running handler 'top_level.txt installer'...
Copying /private/var/mobile/Containers/Data/Application/7864CBEC-94B6-4103-AA16-C07C89C5C69C/tmp/wheel_tmp/argparse-1.4.0-py2.py3-none-any.whl/argparse.py -> /private/var/mobile/Containers/Shared/AppGroup/B86CEE4E-E4A9-4BB4-9CA7-6E13BDA2C2A4/Pythonista3/Documents/site-packages-2/argparse.py
Running handler 'console_scripts installer'...
No entry_points.txt found, skipping.
Cleaning up...
Package installed: argparse
Dependency available in Pythonista bundle : six
[~/Documents]$ pawk
stash: pawk: command not found[~/Documents]$ cd site-packages-2
[site-packages-2]$ cd pawk
[pawk]$ pawk
import: command not found
from: command not found
if: command not found
fix_broken_pipe(): command not found
pawk.pawk(): command not foundpawk is meant to be run from the command line.
-
-
Try editing the file pawk/pawk and add a "3" to the end of the first line:
- #!/usr/bin/env python --> #!/usr/bin/env python3
For safety's sake do the same thing to the file pawk/pawk.py.
-
stash does not support the #! stuff, hence why it is saying import command not found. Nor will it be able to change the interpreter version!
-
I tried running pawk.py in Stash in various ways but nothing produces an output (interestingly, no errors either).
However, I installed pawk in site-packages-2 using Stash while running Python v2.7. When I tried doing the install running v3.6, I got:
[~/Documents]$ pip install python-awk
<class 'ImportError'>: This package should not be accessible on Python 3 Either you are trying to run from the python-future src folder or your installation of python-future is corrupted. -
FWIW a mini-version of awk.
import re import sys class MiniPythonAwk(object): def __init__(self, files, FS=None): self.FS = FS self.FILES = files def run(self): # BEGIN code block starts count = 0 # BEGIN code block ends FS = self.FS NR = 0 for FILEINDEX, FILENAME in enumerate(self.FILES): FNR = 0 fp = open(FILENAME) for SS in fp: NR += 1 FNR += 1 if self.FS: S = SS.rstrip().split(self.FS) else: S = SS.split() NF = len(S) # ACTION code block starts if re.search('ff', SS) or (S[1] == '5') : count += 1 print("{}:{}:".format(FILENAME, NR), SS.rstrip()) # ACTION code block ends fp.close() # END code block starts print("Count:", count) # END code block ends if __name__ == '__main__': files = sys.argv[1:] if len(files): MiniPythonAwk(files).run() ''' test_input1.txt 1 2 3 4 5 6 7 8 9 test_input2.txt aa bb cc dd ee ff gg hh ii python mini_python_awk.py test_input1.txt test_input2.txt test_input1.txt:2: 4 5 6 test_input2.txt:5: dd ee ff Count: 2 '''
-
@ihf https://github.com/alecthomas/pawk/blob/master/setup.py#L10-L12 is clear that Python 2 is no longer supported.
-
Maybe open an issue at https://github.com/alecthomas/pawk/issues