Python Forum
string parsing question ( I think)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string parsing question ( I think)
#1
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
Reply
#2
I can't find any references for code syntax
frequency = code'freq'
Shouldn't it be
frequency = code['freq'] 
?
Reply
#3
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
code'freq'
This is not a valid python syntax.
Reply
#5
Thanks. This code was from a website tutorial . The tutorial should not give out invalid syntax. I thought it was incorrect.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question about changing the string value of a list element jacksfrustration 4 1,988 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  String to List question help James_Thomas 6 2,332 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  syntax error question - string mgallotti 5 2,596 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  string indices must be integers when parsing Json ilknurg 3 9,874 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
Big Grin General programming question (input string)[ jamie_01 2 2,311 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 3,052 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 3,271 May-24-2021, 08:48 AM
Last Post: bowlofred
  Question on HTML formatting with set string in message Cknutson575 3 4,763 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  parsing question ridgerunnersjw 7 7,548 Oct-10-2020, 09:04 PM
Last Post: ridgerunnersjw
  parsing question ridgerunnersjw 3 2,820 Oct-06-2020, 02:06 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020