Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't use a string pattern on a bytes-like object #18

Closed
diggy128 opened this issue Jul 25, 2018 · 4 comments
Closed

TypeError: can't use a string pattern on a bytes-like object #18

diggy128 opened this issue Jul 25, 2018 · 4 comments

Comments

@diggy128
Copy link

Trying to replace a string in files inside a directory I get the following error:
Dry run: No files will be changed Using 1 patterns: 'xxx' -> 'yyy' Found 6617 files in: .eclipse/ Traceback (most recent call last): File "/usr/bin/repren", line 534, in <module> dry_run=options.dry_run) File "/usr/bin/repren", line 409, in rewrite_files rewrite_file(path, patterns, do_renames=do_renames, do_contents=do_contents, by_line=by_line, dry_run=dry_run) File "/usr/bin/repren", line 375, in rewrite_file counts = transform_file(transform, path, dest_path, by_line=by_line, dry_run=dry_run) File "/usr/bin/repren", line 339, in transform_file counts = transform_stream(transform, stream_in, stream_out, by_line=by_line) File "/usr/bin/repren", line 307, in transform_stream (new_line, new_counts) = transform(line) File "/usr/bin/repren", line 374, in <lambda> transform = lambda contents: multi_replace(contents, patterns, source_name=path) File "/usr/bin/repren", line 209, in multi_replace for match in regex.finditer(input_str): TypeError: can't use a string pattern on a bytes-like object

The exact command given is: repren --from xxx --to yyy --dry-run .eclipse/

My guess is that this happens because there are binary files in the directory.

Could there be an option to skip binary files?

@jlevy
Copy link
Owner

jlevy commented Aug 3, 2018

Ah. I'm guessing you're running on Python 3. This is (still for now) a Python 2.7 tool. Does running with Python 2.7 work?

@diggy128
Copy link
Author

In OpenSUSE Leap 15 the shebang directive is #!/usr/bin/python3, so I'm guessing this is why it fails. I don't know where that comes from though.

@jlevy
Copy link
Owner

jlevy commented Oct 17, 2018

Probably it was installed via "pip" for python3. Re-install with a python2 pip and you'll be fine. Closing but adding #19 for future.

@jlevy jlevy closed this as completed Oct 17, 2018
@jamesray1
Copy link

jamesray1 commented Oct 29, 2018

sudo python3.7 get-pip.py7;
sudo pip2.7 install repren # add a hyphen with pip-2.7 if not using Ubuntu or Arch Linux / Manjaro.

Added the above to #20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants