Python Forum
how to easily create a list of already existing item
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to easily create a list of already existing item
#7
Without a reason it is difficult answer your question. A module can ask for it's filename and even get hold of it's own code. You could then parse the code to learn everything you want. But that would be hard and I don't know why you would ever want to do it.

You could use locals() to get a dictionary of all the variables that exist in the current scope/namespace. You could parse the keys to select variables to collect in you list. You could use dir() to get similar info in the form of a list.

The statement "There are no stupid questions" is a lie. This is a stupid question. It is stupid because it is pointless. If you can think of a reason why you might want to collect a bunch of variables into a collection it ceases being pointless and stupid. If you post the reason why you want to know this (other than curiosity) it provides a context that will help others understand and answer your question. "I want to open up a window that shows me the values of all my program variables. How could I do that?" is not a stupid, pointless question. Do you have a question like that?
Reply


Messages In This Thread
RE: how to easily create a list of already existing item - by deanhystad - Dec-29-2021, 09:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,671 May-01-2023, 09:06 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,626 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
Question Finding string in list item jesse68 8 1,985 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Remove an item from a list contained in another item in python CompleteNewb 19 5,956 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  count item in list korenron 8 3,577 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  Create SQLite columns from a list or tuple? snakes 6 8,895 May-04-2021, 12:06 PM
Last Post: snakes
  Time.sleep: stop appending item to the list if time is early quest 0 1,909 Apr-13-2021, 11:44 AM
Last Post: quest
  Create variable and list dynamically quest_ 12 4,584 Jan-26-2021, 07:14 PM
Last Post: quest_
  How to run a pytest test for each item in a list arielma 0 2,405 Jan-06-2021, 10:40 PM
Last Post: arielma
  How to create a linked list and call it? loves 12 4,705 Nov-22-2020, 03:50 PM
Last Post: loves

Forum Jump:

User Panel Messages

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