Python Forum
string parsing question ( I think) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: string parsing question ( I think) (/thread-20004.html)



string parsing question ( I think) - diggee17 - Jul-23-2019

Hello, I'm new to python but I was formally a C language programmer for many years. I'm reviewing some code I found online and I don't understand some syntax which is below. I think it's a string parsing issue. Specifically I don't understand " code'freq' " The code is below
    f = open("/codes.txt", "r")
    for line in f:
        code = eval(line)
        print(code)
        pwm.frequency = code'freq'
Can someone help me with this and perhaps point me to an online tutorial for further study. Thanks Smile


RE: string parsing question ( I think) c0rrection this is a dictionary problem - diggee17 - Jul-23-2019

I can't find any references for code syntax
frequency = code'freq'
Shouldn't it be
frequency = code['freq'] 
?


RE: string parsing question ( I think) - buran - Jul-23-2019

can you provide information about the content of code.txt?
by the way you should avoid using eval as it is potentially not safe - i.e. depending on the content of codes.txt


RE: string parsing question ( I think) - Gribouillis - Jul-23-2019

code'freq'
This is not a valid python syntax.


RE: string parsing question ( I think) - diggee17 - Jul-24-2019

Thanks. This code was from a website tutorial . The tutorial should not give out invalid syntax. I thought it was incorrect.