Python Forum
How to read module/class from list of strings?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read module/class from list of strings?
#2
This is related to your other post? https://python-forum.io/thread-40853.html

You cannot "convert" string_wrong into correct. string_wrong is a str and correct is list containing the return value of a function call. What you could do is evaluate the python expresssion in string_wrong. It might return the same result.
correct = [5 + 2]
wrong = "[5 + 2]"
resolved = eval(wrong)
print(correct)
print(wrong)
print(resolved)
Output:
[7] [5 + 2] [7]
Be aware that eval(expression) executes the expression, any valid expression. The expression could add two numbers, or it could format your hard drive. Only use eval() if you know what expressions will be evaluated.
Reply


Messages In This Thread
RE: How to read module/class from list of strings? - by deanhystad - Oct-04-2023, 03:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyYAML read list of int zisco 2 413 Apr-02-2024, 12:36 PM
Last Post: zisco
  Trying to understand strings and lists of strings Konstantin23 2 874 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  problem in using int() with a list of strings akbarza 4 833 Jul-19-2023, 06:46 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,697 May-01-2023, 09:06 PM
Last Post: deanhystad
  Help with Logical error processing List of strings dmc8300 3 1,164 Nov-27-2022, 04:10 PM
Last Post: Larz60+
  My code displays too much output when importing class from a module lil_e 4 1,274 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  read a text file, find all integers, append to list oldtrafford 12 3,868 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
Question How to move a class to a custom module? python300 4 1,639 Mar-08-2022, 09:19 PM
Last Post: python300
  Splitting strings in list of strings jesse68 3 1,859 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,991 Oct-03-2021, 05:16 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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