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

NameError: name 'self' is not defined #17

Closed
NerevarineRule opened this issue Jan 24, 2019 · 2 comments · Fixed by #48
Closed

NameError: name 'self' is not defined #17

NerevarineRule opened this issue Jan 24, 2019 · 2 comments · Fixed by #48

Comments

@NerevarineRule
Copy link

Hi,

I am trying to convert .stdf files into .txt files by following the example you provided in stdf2text.
Below snippet is the portion that creates a parser and add a TextWriter sink into the the parser and then executes the parser. For some reason, I keep getting the following error:
NameError: name 'self' is not defined

Below is my code and the error traceback message .
Even if I use TextWriter without any argument. it still causes the same issue.
Could you please provide your insights into what could potentially be causing this?

Thanks,
Peter

import pystdf.V4
from pystdf.IO import Parser
from pystdf.Mapping import StreamMapper
from pystdf.V4 import pir, prr, mpr
from pystdf.Writers import TextWriter
from pystdf.Pipeline import DataSource

.... Skipping other irrelevant portions like regex, etc... ....

for file in os.listdir(curpath):
if FID.search(file) == None:
continue

else:
    if __name__ == "__main__":
        if len(sys.argv) < 2:
                print("Usage: %s <stdf file>" % (sys.argv[0]))
        else:
            f = open(sys.argv[1],'rb')
            fout = open(FID.search(file).group(1) + '.txt','w')
            p = Parser(inp=f)
            writer = TextWriter(stream=fout)
            p.addSink(writer)
            p.parse()
            print('parse complete')
            f.close()

And I keep getting the following errors:

Traceback (most recent call last):
File "dlog_script.py", line 179, in
p.parse()
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/IO.py", line 183, in parse
self.parse_records(count)
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/IO.py", line 165, in parse_records
self.send((recType, fields))
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/Pipeline.py", line 33, in new_fn
action(sink, *args)
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/Writers.py", line 58, in after_send
self.delimiter.join([self.text_format(data[0], i, val) for i, val in enumerate(data[1])]))
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/Writers.py", line 58, in
self.delimiter.join([self.text_format(data[0], i, val) for i, val in enumerate(data[1])]))
File "/home/peterle/python3/lib/python3.6/site-packages/pystdf/Writers.py", line 44, in text_format
return self.delimiter.join([str(v) for v in value])
NameError: name 'self' is not defined

@bgstech
Copy link

bgstech commented Mar 13, 2019

There's a static method in Writers.py that references "self.delimiter". Static methods aren't bound to a specific object so they don't have access to "self". As a workaround change line 44 in pystdf/Writers.py to use just a constant '|' for the delimiter and you'll be all set, e.g.

        return self.delimiter.join([str(v) for v in value])

becomes:

        return '|'.join([str(v) for v in value])

Not ideal since the delimiter for that class might be set differently, but enough to get you going.

@matt-beyer
Copy link

This issue results in the current version of pystdf failing on it's own example files. (ex., data/demofile.stdf and the other ones ... it fails once it hits the GDR records).

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

Successfully merging a pull request may close this issue.

3 participants