Can this be easily done in Python?

2016-09-27 Thread TUA
Is the following possible in Python?

Given how the line below works

TransactionTerms = 'TransactionTerms'


have something like

TransactionTerms = 

that sets the variable TransactionTerms to its own name as string 
representation without having to specify it explicitly as in the line above
-- 
https://mail.python.org/mailman/listinfo/python-list


Newbie ARGPARSE question

2018-04-17 Thread TUA
I just discovered ARGPARSE 5 minutes ago and cannot figure this one out:

What does the Parser.add_argument() call have to look like when I need an
option 'add' that requires the mandatory parameters 'type' (string), 'size' 
(int), 'sid' (string) and must also handle the optional parameters 'comment' 
(string) and 'auto-start' (bool, defaults to TRUE).


Thanks to all helping me preserve my sanity!
-- 
https://mail.python.org/mailman/listinfo/python-list


ARGPARSE Newbie question

2018-04-17 Thread TUA
I'd like to create a script that handles a number of verbs with mandatory and 
/or optional parameters like listed in the table below.

Can ARGPARSE do this and how?

Thanks for all help!





Script  VerbMandatory parameters Optional 
parameters 
--
myprog.py   list---  verbose 

myprog.py   add sid(string), type (string), memory (int) comment 
(string), autostart (bool, default=TRUE)

myprog.py   memory  sid (string), memory (integer)

myprog.py   comment sid(string), comment (string)

myprog.py   restore sid(string), srcpath (string)

myprog.py   backup  sid(string), dstpath(string) 

myprog.py   remove  sid (string)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ARGPARSE Newbie question

2018-04-17 Thread TUA
Thanks for the pointers!
-- 
https://mail.python.org/mailman/listinfo/python-list


RE newbie question

2018-04-18 Thread TUA
import re

compval = 'A123456_8'
regex = '[a-zA-Z]\w{0,7}'

if re.match(regex, compval):
   print('Yes')
else:
   print('No')  


My intention is to implement a max. length of 8 for an input string. The above 
works well in all other respects, but does allow for strings that are too long.

What is the proper way to fix this?

Thanks for any help!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RE newbie question

2018-04-18 Thread TUA
Thanks much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Call function via literal name

2016-07-29 Thread TUA
Rather than do this:

if test['method'] == 'GET':
res = requests.get(test['endpoint'],auth=test['auth'], 
verify=False)
elif test['method'] == 'POST':
res = requests.post(test['endpoint'],   auth=test['auth'], 
verify=False, json=test['body'])
elif test['method'] == 'PUT':
res = requests.put(test['endpoint'],auth=test['auth'], 
verify=False, json=test['body'])
elif test['method'] == 'DELETE':
res = requests.delete(test['endpoint'], auth=test['auth'], 
verify=False)
elif test['method'] == 'HEAD':
res = requests.head(test['endpoint'],   auth=test['auth'], 
verify=False)  

I would like to call the requests method that corresponds to test['method'] by 
finding that function by name - how can I achieve that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Call function via literal name

2016-07-29 Thread TUA
On Friday, 29 July 2016 13:35:30 UTC-7, TUA  wrote:
> Rather than do this:
> 
> if test['method'] == 'GET':
> res = requests.get(test['endpoint'],auth=test['auth'], 
> verify=False)
> elif test['method'] == 'POST':
> res = requests.post(test['endpoint'],   auth=test['auth'], 
> verify=False, json=test['body'])
> elif test['method'] == 'PUT':
> res = requests.put(test['endpoint'],auth=test['auth'], 
> verify=False, json=test['body'])
> elif test['method'] == 'DELETE':
> res = requests.delete(test['endpoint'], auth=test['auth'], 
> verify=False)
> elif test['method'] == 'HEAD':
> res = requests.head(test['endpoint'],   auth=test['auth'], 
> verify=False)  
> 
> I would like to call the requests method that corresponds to test['method'] 
> by finding that function by name - how can I achieve that?

thanks gentlemen - that hit the spot!
-- 
https://mail.python.org/mailman/listinfo/python-list


JSON result parsing

2016-07-29 Thread TUA
Calls to my REST api may either return a dict (for single results) or a list of 
dicts (for multiple results).

I receive these results using the requests library.

I want to retrieve the value for a key 'ID' but only if I have a single result 
and, obviously, if ID is present.

How can I do this with pythonic elegance?

Thanks for all suggestions!
-- 
https://mail.python.org/mailman/listinfo/python-list


Peewee ORM questions

2018-11-13 Thread TUA
Hi all,

couldn't find a group for Peewee, so here I am:

Given a table structure of 

{'id': , 
 'username': , 
 'password': , 
 'created': , 
 'updated': }

Using playhouse.shortcuts:

def ListAll(model):
for row in model.select():
print(model_to_dict(row, exclude = (row.created, row.updated)))

still returns the created and updated columns

Broken? Or - way more likely - something I am doing wrong?

Thanks for all help!

Tua
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Peewee ORM questions

2018-11-13 Thread TUA


Brainfart has left the building

 print(model_to_dict(row, exclude = (row.created, row.updated))) 

should have been

 print(model_to_dict(row, exclude = (model.created, model.updated))) 
-- 
https://mail.python.org/mailman/listinfo/python-list


TKinter Newbie question

2019-01-17 Thread TUA
Why does the button frame in the code below not show?

I intend to have it displayed in between the notebook at the top and the fake 
statusbar at the bottom.

Thanks for any help!


from tkinter import ttk
import tkinter as tk

class MainForm():

def __init__(self, master):

self.master = master
self.master.title('Test')

nb = ttk.Notebook(self.master)

page_1 = ttk.Frame(nb)

nframe = ttk.LabelFrame(page_1, text='Frame', padding = 10)
tk.Label(nframe, padx = 10, pady = 5, text = 'Name').pack()
tk.Entry(nframe, width = 30).pack()
tk.Label(nframe, padx = 10, pady = 5, text = 'City').pack()
tk.Entry(nframe, width = 30).pack()
#
nframe.pack(fill="both", expand="yes", padx = 10, pady = 10)  # pad 
around the frame

nb.add(page_1, text = 'Tab #1')

nb.pack(expand = True, fill = "both")


#---
# button frame for Help button   why does it not show? 


#---
bf = ttk.Frame(self.master, relief = tk.SUNKEN)
tk.Button(bf, padx = 10, relief = tk.GROOVE, text = 'Help')
bf.pack(side = tk.BOTTOM, fill = tk.X)


#---
# fake a status bar from a label

#---
sb = tk.Label(self.master, text = ' Waiting for rain ...', bd = 1, 
anchor = tk.W, relief = tk.SUNKEN)
sb.pack(side = tk.BOTTOM, fill = tk.X)

def CloseApplication(self):
self.master.destroy()

def StartApplication():
root = tk.Tk()

MainForm(root)
root.mainloop()

if __name__ == '__main__':
StartApplication()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TKinter Newbie question

2019-01-18 Thread TUA
Thanks for your fresh pair of eyes!
-- 
https://mail.python.org/mailman/listinfo/python-list