cx_Oracle clause IN using a variable
Hi all,
I don't know if it is the correct place to set this question, however,
I'm using cx_Oracle to query an Oracle database.
I've a problem to use the IN clause with a variable.
My statement is
sql = "SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN (:arg_1)"
where arg_1 is retrive by a dictionary
that is build so
my_dict = {'location':"X",
'oracle_user':'user',
'oracle_password':'pass',
'dsn':'dsn',
'mailto':'[email protected]',
'codes':"CNI,CNP"}
args = (dict['codes'],)
con = cx_Oracle.connect(my_dict["oracle_user"],
my_dict["oracle_password"],
my_dict["dsn"])
cur = con.cursor()
cur.execute(sql,args)
rs = cur.fetchall()
but it doesn't work in the sense that doesn't return anything
If i use the statment without variable
SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN ('CNI','CNP')
the query works
what is wrong?
suggestions?
regards
beppe
--
http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle clause IN using a variable
Il giorno martedì 16 ottobre 2012 19:23:22 UTC+2, Hans Mulder ha scritto:
> On 16/10/12 15:41:58, Beppe wrote:
>
> > Hi all,
>
> > I don't know if it is the correct place to set this question, however,
>
> > I'm using cx_Oracle to query an Oracle database.
>
> > I've a problem to use the IN clause with a variable.
>
> > My statement is
>
> >
>
> > sql = "SELECT field1,field2,field3
>
> > FROM my_table
>
> > WHERE field_3 IN (:arg_1)"
>
> >
>
> > where arg_1 is retrive by a dictionary
>
> > that is build so
>
> >
>
> > my_dict = {'location':"X",
>
> > 'oracle_user':'user',
>
> > 'oracle_password':'pass',
>
> > 'dsn':'dsn',
>
> > 'mailto':'[email protected]',
>
> > 'codes':"CNI,CNP"}
>
> >
>
> > args = (dict['codes'],)
>
> >
>
> >
>
> > con = cx_Oracle.connect(my_dict["oracle_user"],
>
> > my_dict["oracle_password"],
>
> > my_dict["dsn"])
>
> >
>
> > cur = con.cursor()
>
> > cur.execute(sql,args)
>
> > rs = cur.fetchall()
>
> >
>
> > but it doesn't work in the sense that doesn't return anything
>
> >
>
> > If i use the statment without variable
>
> >
>
> > SELECT field1,field2,field3
>
> > FROM my_table
>
> > WHERE field_3 IN ('CNI','CNP')
>
> >
>
> > the query works
>
> >
>
> > what is wrong?
>
>
>
> You only have a single placeholder variable,
>
> so your statement is equivalent to
>
>
>
> SELECT field1,field2,field3
>
> FROM my_table
>
> WHERE field_3 IN ('CNI,CNP')
>
>
>
> Presumably 'CNI,CNP' is not a valid value for field_3,
>
> thus your query finds no records.
>
>
>
> > suggestions?
>
>
>
> To verify that you have the correct syntax, try it
>
> with a single value first:
>
>
>
> my_dict = {'location':"X",
>
> 'oracle_user':'user',
>
> 'oracle_password':'pass',
>
> 'dsn':'dsn',
>
> 'mailto':'[email protected]',
>
> 'codes':"CNI"}
>
>
>
> It that produces some of the records you want, then the
>
> question is really: can you somehow pass a list of values
>
> via a single placeholder variable?
>
>
>
> I'm, not a cx_Oracle expert, but I think the answer is "no".
>
>
>
>
>
> If you want to pass exactly two values, then the work-around
>
> would be to pass them in separate variables:
>
>
>
> my_dict = {'location':"X",
>
> 'oracle_user':'user',
>
> 'oracle_password':'pass',
>
> 'dsn':'dsn',
>
> 'mailto':'[email protected]',
>
> 'code1':"CNI",
>
> 'code2':"CNP"}
>
>
>
> sql = """SELECT field1,field2,field3
>
> FROM my_table
>
> WHERE field_3 IN (:arg_1, :arg_2)"""
>
> args = (my_dict['code1'],my_dict['code2'])
>
>
>
>
>
> If the number of codes can vary, you'll have to generate a
>
> query with the correct number of placholders in it. Mabye
>
> something like this (untested):
>
>
>
> my_dict = {'location':"X",
>
> 'oracle_user':'user',
>
> 'oracle_password':'pass',
>
> 'dsn':'dsn',
>
> 'mailto':'[email protected]',
>
> 'codes':"Ornhgvshy,vf,orggre,guna,htyl"}
>
>
>
>
>
> args = my_dict['codes'].split(",")
>
> placeholders = ','.join(":x%d" % i for i,_ in enumerate(args))
>
>
>
> sql = """SELECT field1,field2,field3
>
> FROM my_table
>
> WHERE field_3 IN (%s)""" % placeholders
>
>
>
> con = cx_Oracle.connect(my_dict["oracle_user"],
>
> my_dict["oracle_password"],
>
> my_dict["dsn"])
>
>
>
> cur = con.cursor()
>
> cur.execute(sql,args)
>
> rs = cur.fetchall()
>
>
>
>
>
> Hope this helps,
>
>
>
> -- HansM
Thanks a lot of to ian and hans for your explanations that have allowed me to
resolve my problem and above all to understand the why I was wrong.
regards
beppe
--
http://mail.python.org/mailman/listinfo/python-list
Re: wxPython SQLite and Reportlab demo
On 25 Feb, 08:33, Tim Roberts wrote: > Beppe wrote: > > >I would recommend this my little work on sourceforge. > > >http://sourceforge.net/projects/pyggybank/ > > >you can download an exe (pyggy_w32.7z) make with py2exe > >and the source (pyggy_source.7z) > >the project is named Pyggy Bank. > > Nowhere, in either this announcement or your sourceforge.net page, do you > say a single word about what this application actually is. > > Just a few sentences describing what the application does would go a long > way toward stirring up interest in this app. > -- > Tim Roberts, [email protected] > Providenza & Boekelheide, Inc. Right Tim, I will improve this as soon as possible. regards Beppe -- http://mail.python.org/mailman/listinfo/python-list
[TKinter]How to set LabelFrames font and color from option file
Hi to everybody, I don't succeed in planning the value of the font and color in the LabelFrames using the option_db file, such as *LabelFrame*font: Helvetica 14 *LabelFrame*foreground: red exist a list of the keywordses to use? thanks beppe -- https://mail.python.org/mailman/listinfo/python-list
Re: [TKinter]How to set LabelFrames font and color from option file
Il giorno giovedì 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > Beppe wrote: > > > I don't succeed in planning the value of the font and color in the > > LabelFrames using the option_db file, such as > > > > *LabelFrame*font: Helvetica 14 > > *LabelFrame*foreground: red > > > > exist a list of the keywordses to use? > > >>> import tkinter as tk > >>> root = tk.Tk() > >>> lf = tk.LabelFrame(root) > >>> lf["class"] > 'Labelframe' > > Do you spot the difference? The class of the LabelFrame widget is Labelframe > with a lowercase f. Once you change your database entries to > > *Labelframe*font: Helvetica 14 > *Labelframe*foreground: red > > everything should work as expected. perfect, it works too much well, even my buttons now are helvetica 14 and red ;( -- https://mail.python.org/mailman/listinfo/python-list
Re: [TKinter]How to set LabelFrames font and color from option file
Il giorno giovedì 14 dicembre 2017 16:36:24 UTC+1, Peter Otten ha scritto: > Beppe wrote: > > > Il giorno giovedì 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > >> Beppe wrote: > >> > >> > I don't succeed in planning the value of the font and color in the > >> > LabelFrames using the option_db file, such as > >> > > >> > *LabelFrame*font: Helvetica 14 > >> > *LabelFrame*foreground: red > >> > > >> > exist a list of the keywordses to use? > >> > >> >>> import tkinter as tk > >> >>> root = tk.Tk() > >> >>> lf = tk.LabelFrame(root) > >> >>> lf["class"] > >> 'Labelframe' > >> > >> Do you spot the difference? The class of the LabelFrame widget is > >> Labelframe with a lowercase f. Once you change your database entries to > >> > >> *Labelframe*font: Helvetica 14 > >> *Labelframe*foreground: red > >> > >> everything should work as expected. > > > > perfect, it works too much well, even my buttons now are helvetica 14 and > > red ;( > > I does what you tell it to do. Remove the second wildcard if you only want > to change the Labelframe style: > > *Labelframe.font: Helvetica 14 > *Labelframe.foreground: red Does that mean buttons inerith text from labelframe?!?! it looks so. -- https://mail.python.org/mailman/listinfo/python-list
Re: [TKinter]How to set LabelFrames font and color from option file
Il giorno giovedì 14 dicembre 2017 17:29:36 UTC+1, Beppe ha scritto: > Il giorno giovedì 14 dicembre 2017 16:36:24 UTC+1, Peter Otten ha scritto: > > Beppe wrote: > > > > > Il giorno giovedì 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > > >> Beppe wrote: > > >> > > >> > I don't succeed in planning the value of the font and color in the > > >> > LabelFrames using the option_db file, such as > > >> > > > >> > *LabelFrame*font: Helvetica 14 > > >> > *LabelFrame*foreground: red > > >> > > > >> > exist a list of the keywordses to use? > > >> > > >> >>> import tkinter as tk > > >> >>> root = tk.Tk() > > >> >>> lf = tk.LabelFrame(root) > > >> >>> lf["class"] > > >> 'Labelframe' > > >> > > >> Do you spot the difference? The class of the LabelFrame widget is > > >> Labelframe with a lowercase f. Once you change your database entries to > > >> > > >> *Labelframe*font: Helvetica 14 > > >> *Labelframe*foreground: red > > >> > > >> everything should work as expected. > > > > > > perfect, it works too much well, even my buttons now are helvetica 14 and > > > red ;( > > > > I does what you tell it to do. Remove the second wildcard if you only want > > to change the Labelframe style: > > > > *Labelframe.font: Helvetica 14 > > *Labelframe.foreground: red > > Does that mean buttons inerith text from labelframe?!?! it looks so. ok, so it seems working *Labelframe*font: Helvetica 14 *Labelframe*foreground: red *Button*foreground: black *Button*font: Verdana 10 -- https://mail.python.org/mailman/listinfo/python-list
Re: [TKinter]How to set LabelFrames font and color from option file
Il giorno giovedì 14 dicembre 2017 19:28:53 UTC+1, Gene Heskett ha scritto:
> On Thursday 14 December 2017 10:00:07 Beppe wrote:
>
> > Il giorno giovedì 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha
> scritto:
> > > Beppe wrote:
> > > > I don't succeed in planning the value of the font and color in the
> > > > LabelFrames using the option_db file, such as
> > > >
> > > > *LabelFrame*font: Helvetica 14
> > > > *LabelFrame*foreground: red
> > > >
> > > > exist a list of the keywordses to use?
> > > >
> > > >>> import tkinter as tk
> > > >>> root = tk.Tk()
> > > >>> lf = tk.LabelFrame(root)
> > > >>> lf["class"]
> > >
> > > 'Labelframe'
> > >
> > > Do you spot the difference? The class of the LabelFrame widget is
> > > Labelframe with a lowercase f. Once you change your database entries
> > > to
> > >
> > > *Labelframe*font: Helvetica 14
> > > *Labelframe*foreground: red
> > >
> > > everything should work as expected.
> >
> > perfect, it works too much well, even my buttons now are helvetica 14
> > and red ;(
> In that event, you can label the text buttons like this:
>
> "checkbutton1"
> "CamSW"
> ('Hack',12)
>
> For a different font.
>
> I'd assume ('green') might work, but haven't tried it since it
> cannot be changed with the halpin state. Then it would be useful to
> report status w/o having the put an led underline under it for state.
> That would save a considerable acreage in screen real estate if it were
> possible on an already busy linuxcnc gui. IMO the enforced blank space
> around text is also a huge waster of screen real estate.
>
> You can find some tut's on doing all this in the linuxcnc
> Documentation.pdf, downloadable from linuxcnc.org, in my version
> starting on page 366. Under "pyvcp" If you know of others, plz advise.
>
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
> soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page <http://geneslinuxbox.net:6309/gene>
linuxcnc.org ?!?! wow...very cool...
--
https://mail.python.org/mailman/listinfo/python-list
[Tkinter]Validation to multiple Entry widgets
hi all,
I would validate values input, on key, in multiple Entry widgets create at run
time
I wrote this snip but even if the entry are created and the callback work well
the relative value is missing
#!/usr/bin/python3
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.vcmd = (self.register(self.validate),
'%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
self.pack()
self.init_ui()
def init_ui(self):
my_list = (2.14,18.3,76.4,2.38,0.425,2.68,1.09,382,8.59,0.495)
for i in my_list:
#this work
#w = tk.Entry(self, bg='white')
#this doesn't work
w = tk.Entry(self, bg='white', validate = 'key', validatecommand
= self.vcmd)
w.insert(tk.END, i)
w.pack()
def validate(self, action, index, value_if_allowed,
prior_value, text, validation_type,
trigger_type, widget_name):
# action=1 -> insert
if(action=='1'):
if text in '0123456789.-+':
try:
float(value_if_allowed)
return True
except ValueError:
return False
else:
return False
else:
return True
root = tk.Tk()
app = Application(master=root)
app.mainloop()
tips?
regards beppe
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter]Validation to multiple Entry widgets
Il giorno sabato 17 febbraio 2018 20:21:53 UTC+1, Peter Otten ha scritto: > Beppe wrote: > > > I would validate values input, on key, in multiple Entry widgets create at > > run time > > > > I wrote this snip but even if the entry are created and the callback work > > well the relative value is missing > > > my_list = (2.14,18.3,76.4,2.38,0.425,2.68,1.09,382,8.59,0.495) > > > > for i in my_list: > > #this work > > #w = tk.Entry(self, bg='white') > > #this doesn't work > > w = tk.Entry(self, bg='white', validate = 'key', > > validatecommand = self.vcmd) w.insert(tk.END, i) > > w.pack() > > > > def validate(self, action, index, value_if_allowed, > > prior_value, text, validation_type, > > trigger_type, widget_name): > > # action=1 -> insert > > When you add > > print(text) > > here to debug your code the old-fashioned way you'll note that text is, e. > g. '2.14' and thus will not pass the `text in ...` test below. yeah, thank you very much, I change if text in '0123456789.-+': with if text: and it works now thank you, Peter > > > if(action=='1'): > > if text in '0123456789.-+': > > try: > > float(value_if_allowed) > > return True > > except ValueError: > > return False > > else: > > return False > > else: > > return True > > > > > > root = tk.Tk() > > app = Application(master=root) > > app.mainloop() > > > > > > tips? > > > > regards beppe -- https://mail.python.org/mailman/listinfo/python-list
[ANN] Biovarase ver 2
Biovarase has been updated to version 2, The project has been migrated from python 2.7 to python 3.5 Biovarase is an application to manage clinical quality control data. The purpose of Quality Control Assurance in a clinical laboratory is to allow the control of the performances of an analytical procedure showing an alarm as soon as the trial doesn't result in the degree to respect the defined analytical rules. Biovarase furthermore calculates the classical statistical parameters for the quality control assurance ,e.g. sd, cv%, avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using data retrived from: Current databases on biologic variation: pros, cons and progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most recent specifications made available in 2014. It uses even the famous Westgard's rules to monitor results dataset. All the data are managed by SQLite database and matplotlib. To show levey jennings graph, in the main windows select a test and choose the relative batch. To deactivate/activate a result make double click on it. To insert, update or delete a batch or a result open from File/Batchs and results. To export data to a temp excel file click on File/Export. Biovarase requires Python 3 Biovarase use Tkinter and matplotlib All source code on https://github.com/1966bc/Biovarase I'made it for fun :(. I would appreciate any suggestions you might have. regards beppe -- https://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Biovarase ver 2
Il giorno lunedì 19 febbraio 2018 23:02:43 UTC+1, Chris Angelico ha scritto: > On Tue, Feb 20, 2018 at 8:45 AM, Beppe wrote: > > > > Biovarase has been updated to version 2, > > > > The project has been migrated from python 2.7 to python 3.5 > > > > Biovarase is an application to manage clinical quality control data. > > > > The purpose of Quality Control Assurance in a clinical laboratory is to > > allow the control of the performances of an analytical procedure showing an > > alarm as soon as the trial doesn't result in the degree to respect the > > defined analytical rules. Biovarase furthermore calculates the classical > > statistical parameters for the quality control assurance ,e.g. sd, cv%, > > avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using > > data retrived from: Current databases on biologic variation: pros, cons and > > progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most > > recent specifications made available in 2014. > > It uses even the famous Westgard's rules to monitor results dataset. > > All the data are managed by SQLite database and matplotlib. > > To show levey jennings graph, in the main windows select a test and choose > > the relative batch. > > To deactivate/activate a result make double click on it. > > To insert, update or delete a batch or a result open from File/Batchs and > > results. > > To export data to a temp excel file click on File/Export. > > > > Biovarase requires Python 3 > > Biovarase use Tkinter and matplotlib > > > > All source code on > > > > https://github.com/1966bc/Biovarase > > > > I'made it for fun :(. > > I would appreciate any suggestions you might have. > > Cool! Good to see. > > A few small suggestions, but nothing major. All your git commits are > "file upload" apart from the occasional web edit; I would recommend > getting familiar with command-line git and making commits with useful > messages. (I was hoping to have a look at the changes that you did for > Py2 -> Py3, but couldn't find them in the pile of big changes.) I'd > also suggest getting an actual LICENSE or COPYING file, since your > README says your code is GPL'd. And you may want to look into the > formatting of your README - there are a few things that probably > should be turned into bulleted lists rather than flowing as > paragraphs. But otherwise, cool! I like to see this sort of thing > published and open sourced. > > ChrisA Well, I don't manage a lot of git hub yet but I will surely keep in mind of your suggestions. Publishing this project and others is the least one that I can do for thanking the python's programmer community of the things that I have learned ...I believe even that I must also work hard on my English thank you very much for your attention Chris -- https://mail.python.org/mailman/listinfo/python-list
[ANN] Biovarase ver 2.8
Biovarase has been updated to version 2.8 Biovarase is an application to manage clinical quality control data. The purpose of Quality Control Assurance in a clinical laboratory is to allow the control of the performances of an analytical procedure showing an alarm as soon as the trial doesn't result in the degree to respect the defined analytical rules. Biovarase furthermore calculates the classical statistical parameters for the quality control assurance ,e.g. sd, cv%, avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using data retrived from: Current databases on biologic variation: pros, cons and progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most recent specifications made available in 2014. It uses even the famous Westgard's rules to monitor results dataset. All the data are managed by SQLite database and matplotlib. Biovarase requires Python =>3.5 tkinter matplotlib xlwt last changelog 2018-11-24 Change the redrew mechanism, now Biovarase doesn't rebuild the graph from scratch when you select a batch, but update only the data. Add Quick Data Analysis function on the menu to analyze the last dataset for every test and relative bacth. Add histogram to plot frequency distribution of a dataset. Some minor refactoring on main.py code. We deserve an updating to version 2.8. ;) All source code on https://github.com/1966bc/Biovarase thank you for reading. regards beppe -- https://mail.python.org/mailman/listinfo/python-list
[ANN] Biovarase ver 4.2
Biovarase has been updated to version 4.2 Biovarase is an application to manage clinical quality control data. The purpose of Quality Control Assurance in a clinical laboratory is to allow the control of the performances of an analytical procedure showing an alarm as soon as the trial doesn't result in the degree to respect the defined analytical rules. Biovarase furthermore calculates the classical statistical parameters for the quality control assurance ,e.g. sd, cv%, avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using data retrived from: Current databases on biologic variation: pros, cons and progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most recent specifications made available in 2014. It uses even the famous Westgard's rules to monitor results dataset. All the data are managed by SQLite database and matplotlib. Biovarase requires Python =>3.5 tkinter matplotlib xlwt last changelog 2018-12-25 Hi all and merry christmas, this is the new 4.2 version of Biovarase. I' ve use this powerfull tool, Spyder, to refactoring all the project. It's very cool;) Change widgets.py to tools.py because it seems widgets it' s a reserved word in deep python tk file Clean, with the Spider help, very much code lines. All source code on https://github.com/1966bc/Biovarase thank you for reading. regards beppe -- https://mail.python.org/mailman/listinfo/python-list
Converting tuple of lists of variable length into dictionary
hi to everybody, I must turn a tuple of lists into a dictionary.
something like
(['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm', 'n', 'o'])
note that the length af each list is variable
must return
a ['b', 'c', 'd', 'e', 'f']
b ['a', 'c', 'd', 'e', 'f']
c ['a', 'b', 'd', 'e', 'f']
d ['a', 'b', 'c', 'e', 'f']
e ['a', 'b', 'c', 'd', 'f']
f ['a', 'b', 'c', 'd', 'e']
g ['h', 'i']
h ['g', 'i']
i ['g', 'h']
l ['m', 'n', 'o']
m ['l', 'n', 'o']
n ['l', 'm', 'o']
o ['l', 'm', 'n']
I have done this but it doesn't convince a lot me.
my_tuple = (['a','b','c','d','e','f'],
['g','h','i',],
['l','m','n','o'],)
my_dict = {}
LETTERS = []
for letters in my_tuple:
LETTERS = letters[:]
for letter in sorted(LETTERS):
if my_dict.has_key(str(letter)):
my_dict.append(letters)
else:
letters.remove(str(letter))
my_dict[letter]= letters
letters = LETTERS[:]
for k,v in sorted(my_dict.iteritems()):
print k,v
Suggestions?
regards
beppe
--
https://mail.python.org/mailman/listinfo/python-list
Re: Converting tuple of lists of variable length into dictionary
Il giorno domenica 18 ottobre 2015 13:00:44 UTC+2, Peter Otten ha scritto:
> Beppe wrote:
>
> > hi to everybody, I must turn a tuple of lists into a dictionary.
> >
> > something like
> >
> > (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm', 'n', 'o'])
> >
> > note that the length af each list is variable
> >
> > must return
> >
> > a ['b', 'c', 'd', 'e', 'f']
> > b ['a', 'c', 'd', 'e', 'f']
> > c ['a', 'b', 'd', 'e', 'f']
> > d ['a', 'b', 'c', 'e', 'f']
> > e ['a', 'b', 'c', 'd', 'f']
> > f ['a', 'b', 'c', 'd', 'e']
> > g ['h', 'i']
> > h ['g', 'i']
> > i ['g', 'h']
> > l ['m', 'n', 'o']
> > m ['l', 'n', 'o']
> > n ['l', 'm', 'o']
> > o ['l', 'm', 'n']
>
> What do you want to do with items that occur in more than one list?
>
> If there are no such duplicate items it's easy:
>
> >>> lists = (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm',
> 'n', 'o'])
> >>> d = {
> ... c: items[:i] + items[i+1:]
> ... for items in lists
> ... for i, c in enumerate(items)
> ... }
> >>> pprint.pprint(d)
> {'a': ['b', 'c', 'd', 'e', 'f'],
> 'b': ['a', 'c', 'd', 'e', 'f'],
> 'c': ['a', 'b', 'd', 'e', 'f'],
> 'd': ['a', 'b', 'c', 'e', 'f'],
> 'e': ['a', 'b', 'c', 'd', 'f'],
> 'f': ['a', 'b', 'c', 'd', 'e'],
> 'g': ['h', 'i'],
> 'h': ['g', 'i'],
> 'i': ['g', 'h'],
> 'l': ['m', 'n', 'o'],
> 'm': ['l', 'n', 'o'],
> 'n': ['l', 'm', 'o'],
> 'o': ['l', 'm', 'n']}
hi Peter, you are right, no duplicates are admitted between lists,
anyway your solution,works on python 3 but not on 2.
however beautiful list comprehension solution.
I will try to suit it for the python version i need
regards
beppe
--
https://mail.python.org/mailman/listinfo/python-list
Re: Converting tuple of lists of variable length into dictionary
Il giorno domenica 18 ottobre 2015 14:35:53 UTC+2, Chris Angelico ha scritto:
> On Sun, Oct 18, 2015 at 11:23 PM, Beppe wrote:
> > hi Peter, you are right, no duplicates are admitted between lists,
> > anyway your solution,works on python 3 but not on 2.
> > however beautiful list comprehension solution.
> > I will try to suit it for the python version i need
>
> Should work fine on 2.7. What Py2 version are you running?
>
> ChrisA
Python2.6
Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> lists = (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm','n',
>>> 'o'])
>>>
... d = {c: items[:i] + items[i+1:] for items in lists for i, c in
enumerate(items)}
File "", line 2
d = {c: items[:i] + items[i+1:] for items in lists for i, c in
enumerate(items)}
^
SyntaxError: invalid syntax
--
https://mail.python.org/mailman/listinfo/python-list
Re: Converting tuple of lists of variable length into dictionary
Il giorno domenica 18 ottobre 2015 14:47:34 UTC+2, Peter Otten ha scritto:
> Beppe wrote:
>
> > Il giorno domenica 18 ottobre 2015 13:00:44 UTC+2, Peter Otten ha scritto:
> >> Beppe wrote:
> >>
> >> > hi to everybody, I must turn a tuple of lists into a dictionary.
> >> >
> >> > something like
> >> >
> >> > (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm', 'n', 'o'])
> >> >
> >> > note that the length af each list is variable
> >> >
> >> > must return
> >> >
> >> > a ['b', 'c', 'd', 'e', 'f']
> >> > b ['a', 'c', 'd', 'e', 'f']
> >> > c ['a', 'b', 'd', 'e', 'f']
> >> > d ['a', 'b', 'c', 'e', 'f']
> >> > e ['a', 'b', 'c', 'd', 'f']
> >> > f ['a', 'b', 'c', 'd', 'e']
> >> > g ['h', 'i']
> >> > h ['g', 'i']
> >> > i ['g', 'h']
> >> > l ['m', 'n', 'o']
> >> > m ['l', 'n', 'o']
> >> > n ['l', 'm', 'o']
> >> > o ['l', 'm', 'n']
> >>
> >> What do you want to do with items that occur in more than one list?
> >>
> >> If there are no such duplicate items it's easy:
> >>
> >> >>> lists = (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm',
> >> 'n', 'o'])
> >> >>> d = {
> >> ... c: items[:i] + items[i+1:]
> >> ... for items in lists
> >> ... for i, c in enumerate(items)
> >> ... }
> >> >>> pprint.pprint(d)
> >> {'a': ['b', 'c', 'd', 'e', 'f'],
> >> 'b': ['a', 'c', 'd', 'e', 'f'],
> >> 'c': ['a', 'b', 'd', 'e', 'f'],
> >> 'd': ['a', 'b', 'c', 'e', 'f'],
> >> 'e': ['a', 'b', 'c', 'd', 'f'],
> >> 'f': ['a', 'b', 'c', 'd', 'e'],
> >> 'g': ['h', 'i'],
> >> 'h': ['g', 'i'],
> >> 'i': ['g', 'h'],
> >> 'l': ['m', 'n', 'o'],
> >> 'm': ['l', 'n', 'o'],
> >> 'n': ['l', 'm', 'o'],
> >> 'o': ['l', 'm', 'n']}
> >
> > hi Peter, you are right, no duplicates are admitted between lists,
> > anyway your solution,works on python 3 but not on 2.
> > however beautiful list comprehension solution.
> > I will try to suit it for the python version i need
>
> The above code will work without changes in Python 2.7. For older Python
> versions you can replace the dict comprehension with a generator expression:
>
> >>> d = dict(
> ... (c, items[:i] + items[i+1:])
> ... for items in lists
> ... for i, c in enumerate(items)
> ... )
> >>> pprint.pprint(d)
> {'a': ['b', 'c', 'd', 'e', 'f'],
> 'b': ['a', 'c', 'd', 'e', 'f'],
> 'c': ['a', 'b', 'd', 'e', 'f'],
> 'd': ['a', 'b', 'c', 'e', 'f'],
> 'e': ['a', 'b', 'c', 'd', 'f'],
> 'f': ['a', 'b', 'c', 'd', 'e'],
> 'g': ['h', 'i'],
> 'h': ['g', 'i'],
> 'i': ['g', 'h'],
> 'l': ['m', 'n', 'o'],
> 'm': ['l', 'n', 'o'],
> 'n': ['l', 'm', 'o'],
> 'o': ['l', 'm', 'n']}
>
> I have no Python below 2.7 ready to test, but this version should work for
> Python 2.4 and above. If you find explict loops easier to understand:
>
> >>> d = {}
> >>> for items in lists:
> ... for i, c in enumerate(items):
> ... assert c not in d
> ... d[c] = items[:i] + items[i+1:]
> ...
>
> should work for Python 2.3 and above (untested). I have smuggled in an
> assertion that checks for duplicate keys.
spectacular...:)
both version work fine on 2.6
I'm shooting 'print' everywhere to understand what are you do...
thank you very much
ciao
beppe
--
https://mail.python.org/mailman/listinfo/python-list
Set static attributes...maybe.
hi to everybody,
in the following scrip I try to call the function read_parameters () but
returns me that wants two arguments!?!?!
My intent is to have in the class, Engine (), some static attributes that can
be used by other instances without to redefine this every time.
These matters could be for example a path or a connection to a database.
suggestions?
regards
beppe
class Master(object):
def __init__(self,):
pass
class Engine(Master):
dict_parameters = {}
def __init__(self,):
super(Engine, self).__init__()
@staticmethod
def read_parameters(self,path):
self.dict_parameters = {1:"a",2:"b"}
def check_parameters(self):
self.read_parameters("hello_world")
foo=Engine()
foo.check_parameters()
p.s.
I'm on Debian 6
--
https://mail.python.org/mailman/listinfo/python-list
Re: Set static attributes...maybe.
Il giorno lunedì 18 agosto 2014 19:13:08 UTC+2, Chris Kaynor ha scritto:
> On Mon, Aug 18, 2014 at 10:00 AM, Beppe wrote:
>
>
> hi to everybody,
>
> in the following scrip I try to call the function read_parameters () but
> returns me that wants two arguments!?!?!
>
> My intent is to have in the class, Engine (), some static attributes that can
> be used by other instances without to redefine this every time.
>
> These matters could be for example a path or a connection to a database.
>
> suggestions?
>
>
>
> regards
>
> beppe
>
>
>
> class Master(object):
>
> def __init__(self,):
>
> pass
>
>
>
> class Engine(Master):
>
> dict_parameters = {}
>
> def __init__(self,):
>
> super(Engine, self).__init__()
>
>
>
> @staticmethod
>
> def read_parameters(self,path):
>
>
>
> self.dict_parameters = {1:"a",2:"b"}
>
>
>
> What you probably want here, based on your description is (untested):
> @classmethod
> def read_parameters(cls, path): # Note, the name is "cls". This is not
> required, but is convention, similar to "self".
>
>
> cls.dict_parameters = {1:"a",2:"b"}
>
>
> @staticmethod creates a method that does not receive any special parameter,
> so the signature would be "def read_parameters(path)".
>
>
>
>
>
> Note that, personally, I would name the method "parse_parameters" to make it
> clearer what it does.
>
>
>
>
>
> def check_parameters(self):
>
> self.read_parameters("hello_world")
Perfet,
class Master(object):
def __init__(self,):
pass
class Engine(Master):
def __init__(self,):
super(Engine, self).__init__()
@classmethod
def parse_parameters(cls, path):
cls.dict_parameters = {1:"a",2:"b"}
def check_parameters(self):
self.parse_parameters("hello_world")
def __str__(self):
return "dict_parameters: %s" % self.dict_parameters
foo = Engine()
foo.check_parameters()
bar = Engine()
foobar = Engine()
print foo
print bar
print foobar
IDLE 2.6.6 No Subprocess
>>>
dict_parameters: {1: 'a', 2: 'b'}
dict_parameters: {1: 'a', 2: 'b'}
dict_parameters: {1: 'a', 2: 'b'}
thanks a lot Chris
--
https://mail.python.org/mailman/listinfo/python-list
[ANN] Biovarase version 0..1
[ANN] Biovarase Biovarase version 0.1 has been released. This is the first announcement about Biovarase on this list. Biovarase is an application to manage clinical quality control data. This is the Tkinter version. The purpose of Quality Control Assurance in a clinical laboratory is to allow the control of the performances of an analytical procedure showing an alarm as soon as the trial doesn't result in degree to respect the defined analytical rules. Biovarase furthermore calculates the classical statistical parameters for the quality control assurance ,e.g. sd, cv%, avg, and even the Imp(%), Bias(%) and TEa (total allowable error) using data retrived from: Current databases on biologic variation: pros, cons and progress Scand J Clin Lab Invest 1999;59:491-500. updated with the most recent specifications made available in 2014. It use even the famous Westgard's rules to monitor results dataset. All the data are managed by SQLite database and matplotlib. To show levey jennings graph, in the main windows select a tests and coiche a relative batch. To insert, update or delete a batch or a result open from File/Batchs and results. To export data on a temp excel file click on File/Export. Biovarase requires Python 2.7.9 and matplotlib 1.4.2-3.1 All source code on https://github.com/1966bc/Biovarase I'made it for fun :(. I would appreciate any suggestions you might have. regards beppe -- https://mail.python.org/mailman/listinfo/python-list
Circular iteration on tuple starting from a specific index
hi all
I've a tuple, something like
x = ("A","B","C","D","E","F","G","H",)
I would want to iterate on all tuple's elements
starting from a specific index
something like
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = ("A","B","C","D","E","F","G","H",)
>>> for i in x[2:]:
... print i
...
C
D
E
F
G
H
>>>
with the difference that I would want to restart from the beginning when I
reach the end of the tupla
C
D
E
F
G
H
A
B
I would want to make a circular iteration
suggestions?
regards
beppe
--
https://mail.python.org/mailman/listinfo/python-list
Re: Circular iteration on tuple starting from a specific index
Il giorno martedì 30 maggio 2017 18:51:50 UTC+2, MRAB ha scritto:
> On 2017-05-30 17:25, Beppe wrote:
> > hi all
> >
> > I've a tuple, something like
> >
> > x = ("A","B","C","D","E","F","G","H",)
> >
> > I would want to iterate on all tuple's elements
> > starting from a specific index
> >
> >
> > something like
> >
> > Python 2.7.9 (default, Jun 29 2016, 13:08:31)
> > [GCC 4.9.2] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> x = ("A","B","C","D","E","F","G","H",)
> >>>> for i in x[2:]:
> > ... print i
> > ...
> > C
> > D
> > E
> > F
> > G
> > H
> >>>>
> >
> >
> >
> > with the difference that I would want to restart from the beginning when I
> > reach the end of the tupla
> >
> >
> > C
> > D
> > E
> > F
> > G
> > H
> > A
> > B
> >
> > I would want to make a circular iteration
> >
> > suggestions?
> >
> How about this:
> x = ("A","B","C","D","E","F","G","H",)
> offset = 2
>
> for i in x[offset : ] + x[ : offset]:
> print i
great also this MRAB, thank
--
https://mail.python.org/mailman/listinfo/python-list
Re: Circular iteration on tuple starting from a specific index
Il giorno martedì 30 maggio 2017 18:43:42 UTC+2, Ian ha scritto:
> On Tue, May 30, 2017 at 10:25 AM, Beppe wrote:
> > hi all
> >
> > I've a tuple, something like
> >
> > x = ("A","B","C","D","E","F","G","H",)
> >
> > I would want to iterate on all tuple's elements
> > starting from a specific index
> >
> >
> > something like
> >
> > Python 2.7.9 (default, Jun 29 2016, 13:08:31)
> > [GCC 4.9.2] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> x = ("A","B","C","D","E","F","G","H",)
> >>>> for i in x[2:]:
> > ... print i
> > ...
> > C
> > D
> > E
> > F
> > G
> > H
> >>>>
> >
> >
> >
> > with the difference that I would want to restart from the beginning when I
> > reach the end of the tupla
> >
> >
> > C
> > D
> > E
> > F
> > G
> > H
> > A
> > B
> >
> > I would want to make a circular iteration
> >
> > suggestions?
>
> for i in (x[2:] + x[:2]):
> print(i)
>
> Or using the itertools module you could chain islices together but
> that's more verbose and probably overkill as long as the tuples are
> small.
great
in fact
print x[2:]
print x[:2]
print x[2:] + x[:2]
return
('C', 'D', 'E', 'F', 'G', 'H')
('A', 'B')
('C', 'D', 'E', 'F', 'G', 'H', 'A', 'B')
thank you Ian
--
https://mail.python.org/mailman/listinfo/python-list
Re: Circular iteration on tuple starting from a specific index
Il giorno mercoledì 31 maggio 2017 00:18:40 UTC+2, [email protected] ha scritto: > Hi Beppe ! > > There are some powerful tools in the standard *itertools* module, you > should have a look at it :) > https://docs.python.org/3/library/itertools.html > > This is what I would do to cycle over you iterable without making > several copies of it. > > ``` > from itertools import islice, chain > > def cycle_once(iterable, start): > return chain(islice(iterable, start, None), islice(iterable, start)) > > my_iterable = ('A','B','C','D','E','F','G','H') > > for e in cycle_once(my_iterable, 2): > print(i) > ``` for e in cycle_once(my_iterable, 2): print(e) perfect, thanks > > Ps: I am pretty new to how a mailing list works. If I answered the wrong > way, do not hesitate to tell me :) -- https://mail.python.org/mailman/listinfo/python-list
