News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: .  (Read 2703 times)

creeperton

  • Hero Member
  • *****
  • Posts: 604
    • View Profile
.
« on: October 31, 2014, 01:07:08 pm »
.
« Last Edit: November 16, 2015, 01:44:56 am by creeperton »

Gideon Zhi

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 3532
    • View Profile
    • Aeon Genesis
Re: Python Homework: trying to make a generic function to append stuff
« Reply #1 on: October 31, 2014, 02:04:59 pm »
You're not doing anything with the output from eval. It's evaluating, but because you're not assigning the end result to anything, that result gets lost to the ether. Try something along the lines of:

Code: [Select]
listName = eval(newList)
print listName

Also, you want to be careful of your PEP8 identifier names.

tryphon

  • Hero Member
  • *****
  • Posts: 722
    • View Profile
Re: Python Homework: trying to make a generic function to append stuff
« Reply #2 on: October 31, 2014, 06:10:44 pm »
The result of :
Code: [Select]
my_list.append(my_element)is None. The side-effect is now that my_list contains one more item.

So I guess GideonZhi's code would result in displaying None.

Maybe :

Code: [Select]
eval(newList)
eval('print ' + listName)

Also, newList is a bad name because it's a string, not a list, and it describes a command (so append_cmd would be better).

Kiyoshi Aman

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 2262
  • Browncoat Captain
    • View Profile
    • Aerdan's Blog
Re: Python Homework: trying to make a generic function to append stuff
« Reply #3 on: October 31, 2014, 07:38:34 pm »
Protip: If you put your lists in a dict you don't have to eval() a damn thing.

creeperton

  • Hero Member
  • *****
  • Posts: 604
    • View Profile
.
« Reply #4 on: November 01, 2014, 09:02:12 am »
.
« Last Edit: November 16, 2015, 01:44:49 am by creeperton »