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

AttributeError: 'str' object has no attribute 'write' #5

Open
bionade24 opened this issue Mar 22, 2020 · 2 comments
Open

AttributeError: 'str' object has no attribute 'write' #5

bionade24 opened this issue Mar 22, 2020 · 2 comments

Comments

@bionade24
Copy link

Python Version: 3.8.2
Code:

    def delete_package_line(self, file):
        sed = Sed()
        try:
            sed.no_autoprint = True
            sed.regexp_extended = False
            sed.load_string("/{0}/d".format(self.package))
            sed.apply(file, output=file)
            print("applied")
        except SedException as e:
            print(e.message)
            raise

When I change sed.no_autoprint to False, I get no error but I doesn't work either. Calling pythonsed -e /name/d success.txt worked fine.

Traceback (most recent call last):
  File "./ci.py", line 7, in <module>
    parser.main(argv[1:])
  File "/home/oskar/workspace/aur-ci/aurci/parser.py", line 30, in main
    commands(args.command, args.package, args.verbose, args.quiet)
  File "/home/oskar/workspace/aur-ci/aurci/parser.py", line 17, in commands
    getattr(command_class[0](package, verbosity, output), command_class[1])()
  File "/home/oskar/workspace/aur-ci/aurci/bootstrap.py", line 42, in pull
    self.delete_package_line("success.txt")
  File "/home/oskar/workspace/aur-ci/aurci/general.py", line 18, in delete_package_line
    sed.apply(file, "test.txt")
  File "/usr/lib/python3.8/site-packages/PythonSed/sed.py", line 179, in apply
    self.printline(self.PS)
  File "/usr/lib/python3.8/site-packages/PythonSed/sed.py", line 139, in printline
    print(line, file=self.output)
AttributeError: 'str' object has no attribute 'write'
@GillesArcas
Copy link
Owner

There are two problems. Biggest in pythonsed: using a filename as output parameter was not implemented. This is fixed now and tested in continuous integration. Second problem is you used same file name for input and output. As the process starts by creating the output file, this implies erasing at the same time the input file (something like "type tmp.txt > tmp.txt"). There is no control for that. Thanks for reporting.

@bionade24
Copy link
Author

Thanks for clarifiying this. Hopefully it works. Thanks for making this performant lib.

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

2 participants