Python Forum

Full Version: string parsing question ( I think)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
I can't find any references for code syntax
frequency = code'freq'
Shouldn't it be
frequency = code['freq'] 
?
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
code'freq'
This is not a valid python syntax.
Thanks. This code was from a website tutorial . The tutorial should not give out invalid syntax. I thought it was incorrect.