Reputation: 55
I feel like there is a simple solution to this but I am kinda new.
stat_input= input("Hello Mr. Jenner, what are you interested in tracking today?")
I use an input like this which later is used to call upon data and uses that data to calculate statistics and produce histogram charts / normal distributions.
It works quite nicely. Here are some examples where it is used.
cur.execute('SELECT {} FROM statdata'.format(stat_input))
np.array(stat_input).astype(np.float)
sigma = math.sqrt(np.var(stat_input))
So if I type threemonthdata
it will pull the array of data from my database and use it . Its great. However, I have one small problem
I understand that threemonthdata
refers to an array. Since I am creating charts, I want to use the input as the title so the chart title identifies what data I am drawing and using (as a reference in the future)
ax.set_title('stat_input')
This doesn't work
ax.set_title(' + stat_input + ')
Nor does this. I want the title to say Threemonthdata
. But if I input twomonthdata
I want it to say twomonthdata
and not give me the array of numbers.
Any ideas?
Upvotes: 1
Views: 41
Reputation: 49794
It looks like the issue you are facing is that you are passing the set_title()
a string 'stat_input'
, and not the variable stat_input
. You likely simply need to use:
ax.set_title(stat_input)
Upvotes: 0
Reputation: 6655
I have never played with psycopg's cursor
class. But, from what I can read, it appears that this one does the job for you of turning your string in place into a list whose name is the same as the referring string.
Thus what about defining another viariable to store the string before it is overriden ? As follows
stat_input_title = stat_input.capitalize()
cur.execute('SELECT {} FROM statdata'.format(stat_input))
Henceforth, stat_input_title
and stat_input
can be used together withouh conflicting.
ax.set_title(stat_input_title)
Upvotes: 1