Keepin constants, configuration values, etc. in Python - dedicated module or what?
I am developing some code which runs on a (remote from me most of the
time) Beaglebone Black single board computer. It reads various items
of data (voltages, currents, temperatures, etc.) using both a 1-wire
bus system and the Beaglebone's ADC inputs. The values are stored
at hourly intervals into a database which is regularly rsync'ed
across to my home system where I use the values for monitoring etc.
Associated with each value are various parameters, i.e. for each ADC
input of the Beaglebone there is the ADC input number, a short name
for the value, a conversion factor and a description. Similarly for
the 1-wire inputs there is the 1-wire filesystem filename, a short
name for the data and a longer description.
I am puzzling where and how to keep these configuration values. My
current design has them in dedicated tables in the database but this
is rather clumsy in many ways as there's an overhead reading them
every time the program needs them and changing them isn't particularly
convenient at the Beaglebone doesn't have a GUI so it has to be done
using SQL from the command line.
Does it make sense to add them to the modules which handle the reading
of the inputs? I already have modules defining classes called Adc and
OneWire, is it a reasonable approach to add the configuration to these
as, probably, dictionaries? Modifying it would be pretty simple -
just edit the python source (one of the easiest things for me to do on
the Beaglebone as my sole access is via ssh/command line).
Thus I'd have something like (apologies for any syntax errors):-
cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"],
"StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"],
"LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"}
(It might be better to makes those lists dictionaries, but it shows
the idea)
Are there any better ways of doing this? E.g. some sort of standard
configuration file format that Python knows about? I would actually
quite like to keep the configuration data separate from the code as it
would simplify using the data at the 'home' end of things as I'd just
need to copy the configuration file across. This was why the database
approach appealed at first as all I need to do is copy the database
and everything is in there.
I'm not really expecting quick/glib answers, just some ideas and
comments on the various ways of doing this and their advantages and
disadvantages.
--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
Python code in presentations
Hello list, I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: - the layout is simple - the code and code output are clearly identified - a line of code can be highlighted while presenting http://nedbatchelder.com/text/iter.html I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On 30.09.2014 13:50, Jean-Michel Pichavant wrote: Hello list, I'm currently writing a presentation to help my co-workers ramp up on new features of our tool (written in python (2.7)). I have some difficulties presenting code in an efficient way (with some basic syntax highlights). I need to be catchy about the code I'm presenting otherwise the presentation will fail and I would be better saying to my co-workers "RTFM", cause there is a manual. So I really need to make them realize the code I'm presenting will benefit them (they're not software engineers, python is just a tool, their expertise and focus is aimed at something else, don't blame them :) ) Right now the method I'm using is write the code in notepad++, use a plugin (NppExport) to copy paste code into powerpoint. After using it a little bit, I'm really not satisfied with this method, it's expensive and all this copy paste stuff is driving me crazy. Not to mention that the syntax highlight from notepads renders like crap in powerpoint. I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: - the layout is simple - the code and code output are clearly identified - a line of code can be highlighted while presenting http://nedbatchelder.com/text/iter.html I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). Right now I'm so not satisfied by my current method that I'm about to make the presentation showing the code from the file directly, alt-tabing between the slides and the code. At least it's cheap. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. I can't answer your question, but thanks for the great presentation on iterables! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On Tue, Sep 30, 2014 at 8:46 AM, Tom P wrote: > On 30.09.2014 13:50, Jean-Michel Pichavant wrote: >> >> Hello list, >> >> I'm currently writing a presentation to help my co-workers ramp up on new >> features of our tool (written in python (2.7)). >> >> I have some difficulties presenting code in an efficient way (with some >> basic syntax highlights). I need to be catchy about the code I'm presenting >> otherwise the presentation will fail and I would be better saying to my >> co-workers "RTFM", cause there is a manual. >> >> So I really need to make them realize the code I'm presenting will benefit >> them (they're not software engineers, python is just a tool, their expertise >> and focus is aimed at something else, don't blame them :) ) >> >> Right now the method I'm using is write the code in notepad++, use a >> plugin (NppExport) to copy paste code into powerpoint. >> After using it a little bit, I'm really not satisfied with this method, >> it's expensive and all this copy paste stuff is driving me crazy. Not to >> mention that the syntax highlight from notepads renders like crap in >> powerpoint. >> >> I wonder if some people in this list who have successfully presented >> python code have some tips about doing the proper way. Ned's presentations >> for pycons are to me one example of successful code presentation: >>- the layout is simple >>- the code and code output are clearly identified >>- a line of code can be highlighted while presenting >> >> http://nedbatchelder.com/text/iter.html >> >> I have access to powerpoint, or any tool under linux (I don't have access >> to Mac's stuff). >> >> Right now I'm so not satisfied by my current method that I'm about to make >> the presentation showing the code from the file directly, alt-tabing between >> the slides and the code. At least it's cheap. I like that idea. It offers everything you need I'm a little at a loss that you are concentrating on showing code to users. Are you also showing how your tool works to solve the problems that they will need to solve with it? >> >> JM >> >> >> >> >> >> -- IMPORTANT NOTICE: >> >> The contents of this email and any attachments are confidential and may >> also be privileged. If you are not the intended recipient, please notify the >> sender immediately and do not disclose the contents to any other person, use >> it for any purpose, or store or copy the information in any medium. Thank >> you. >> > > I can't answer your question, but thanks for the great presentation on > iterables! > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re:Keepin constants, configuration values, etc. in Python - dedicated module or what?
[email protected] Wrote in message: > I am developing some code which runs on a (remote from me most of the > time) Beaglebone Black single board computer. It reads various items > of data (voltages, currents, temperatures, etc.) using both a 1-wire > bus system and the Beaglebone's ADC inputs. The values are stored > at hourly intervals into a database which is regularly rsync'ed > across to my home system where I use the values for monitoring etc. > > Associated with each value are various parameters, i.e. for each ADC > input of the Beaglebone there is the ADC input number, a short name > for the value, a conversion factor and a description. Similarly for > the 1-wire inputs there is the 1-wire filesystem filename, a short > name for the data and a longer description. > > I am puzzling where and how to keep these configuration values. My > current design has them in dedicated tables in the database but this > is rather clumsy in many ways as there's an overhead reading them > every time the program needs them and changing them isn't particularly > convenient at the Beaglebone doesn't have a GUI so it has to be done > using SQL from the command line. It is very useful for the database to be self contained and self describing. Among other things it means that you can easily take a snapshot at any time, and that snapshot is not tied to any specific version of the code. As for changing with sql, you can always add a configuration utility when using sql becomes a nuisance, or introduces errors. The key thing is to manage change. You need to decide which things are conceivably going to change and how you'll manage both the change itself and the inevitable split between prechange data and post. One kind of change might be fixing the spelling of battery. No biggie, just let new accesses get the new one. Another kind might be the addition of a new instance of an adc converter. Not a problem, as long as you don't reuse an old name. And presumably you never remove an old name from the config. More troublesome is adding a new kind of data. You have to decide whether it's worth generalizing the code to anticipate the change, or just admit that the code will grow at that point and that old code won't deal with the new data. > > Does it make sense to add them to the modules which handle the reading > of the inputs? I already have modules defining classes called Adc and > OneWire, is it a reasonable approach to add the configuration to these > as, probably, dictionaries? Modifying it would be pretty simple - > just edit the python source (one of the easiest things for me to do on > the Beaglebone as my sole access is via ssh/command line). > Nope, read it from the db. You still might be loading it to a cfg variable, however. > Thus I'd have something like (apologies for any syntax errors):- > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > (It might be better to makes those lists dictionaries, but it shows > the idea) Actually it's probably better to use named tuples. All those lists are apparently of identical length with identical meaning of a given element offset. But if named tuple isn't flexible,enough, you probably need a new class. > > Are there any better ways of doing this? E.g. some sort of standard > configuration file format that Python knows about? I would actually > quite like to keep the configuration data separate from the code as it > would simplify using the data at the 'home' end of things as I'd just > need to copy the configuration file across. This was why the database > approach appealed at first as all I need to do is copy the database > and everything is in there. > > I'm not really expecting quick/glib answers, just some ideas and > comments on the various ways of doing this and their advantages and > disadvantages. Main next question is whether you can restart each system when you add to the configuration. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > I would actually > quite like to keep the configuration data separate from the code as it > would simplify using the data at the 'home' end of things as I'd just > need to copy the configuration file across. This was why the database > approach appealed at first as all I need to do is copy the database > and everything is in there. Of course > Are there any better ways of doing this? E.g. some sort of standard > configuration file format that Python knows about? Umm this is getting to be a FAQ... Maybe it should go up somewhere? Yes there are dozens: - ini - csv - json - yml - xml - pickle - And any DBMS of your choice I guess Ive forgotten as many as Ive listed!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On Tuesday, September 30, 2014 5:21:00 PM UTC+5:30, Jean-Michel Pichavant wrote: > Hello list, > I'm currently writing a presentation to help my co-workers ramp up on new > features of our tool (written in python (2.7)). > I have some difficulties presenting code in an efficient way (with some basic > syntax highlights). I need to be catchy about the code I'm presenting > otherwise the presentation will fail and I would be better saying to my > co-workers "RTFM", cause there is a manual. > So I really need to make them realize the code I'm presenting will benefit > them (they're not software engineers, python is just a tool, their expertise > and focus is aimed at something else, don't blame them :) ) > Right now the method I'm using is write the code in notepad++, use a plugin > (NppExport) to copy paste code into powerpoint. > After using it a little bit, I'm really not satisfied with this method, it's > expensive and all this copy paste stuff is driving me crazy. Not to mention > that the syntax highlight from notepads renders like crap in powerpoint. > I wonder if some people in this list who have successfully presented python > code have some tips about doing the proper way. Ned's presentations for > pycons are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > http://nedbatchelder.com/text/iter.html > I have access to powerpoint, or any tool under linux (I don't have access to > Mac's stuff). > Right now I'm so not satisfied by my current method that I'm about to make > the presentation showing the code from the file directly, alt-tabing between > the slides and the code. At least it's cheap. Org mode's babel system is touted for exactly this: http://www.jstatsoft.org/v46/i03/paper [I must confess that Ive not quite got my teeth into it] -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On 9/30/14 7:50 AM, Jean-Michel Pichavant wrote: I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: - the layout is simple - the code and code output are clearly identified - a line of code can be highlighted while presenting http://nedbatchelder.com/text/iter.html Thanks for the hat-tip! The problem with my presentations is that the production tool-chain is only approachable by programmers, and probably not even all of them! I have a tendency toward custom-written purely text-based tools that give me lots of control at the expense of ease of use. The source of that presentation is here: https://github.com/nedbat/iter You'll notice there's a Makefile... I have access to powerpoint, or any tool under linux (I don't have access to Mac's stuff). I don't know how to get the highlighting (both static and dynamic) in a WYSIWYG presentation tool. :( -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
- Original Message - > From: "Joel Goldstick" > Cc: [email protected] > Sent: Tuesday, 30 September, 2014 3:01:38 PM > Subject: Re: Python code in presentations > > I'm a little at a loss that you are concentrating on showing code to > users. Are you also showing how your tool works to solve the > problems > that they will need to solve with it? > >> > >> JM We write python code using the tools I've mentioned, these tools are nothing more than code snippets, custom classes, decorators and modules. Using them is all about writing python code. However we all have the kind of "quick and dirty" knowledge of python, writing python code is not our core expertise. That is why I thought showing how simple and elegant python can be could provoke some visual shock, making them think "I want to do that". Possibly the wrong approach, I'll tell you that after the presentation :) . JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
-- On Tue, Sep 30, 2014 1:50 PM CEST Jean-Michel Pichavant wrote: >Hello list, > >I'm currently writing a presentation to help my co-workers ramp up on new >features of our tool (written in python (2.7)). > >I have some difficulties presenting code in an efficient way (with some basic >syntax highlights). I need to be catchy about the code I'm presenting >otherwise the presentation will fail and I would be better saying to my >co-workers "RTFM", cause there is a manual. > >So I really need to make them realize the code I'm presenting will benefit >them (they're not software engineers, python is just a tool, their expertise >and focus is aimed at something else, don't blame them :) ) > >Right now the method I'm using is write the code in notepad++, use a plugin >(NppExport) to copy paste code into powerpoint. >After using it a little bit, I'm really not satisfied with this method, it's >expensive and all this copy paste stuff is driving me crazy. Not to mention >that the syntax highlight from notepads renders like crap in powerpoint. > >I wonder if some people in this list who have successfully presented python >code have some tips about doing the proper way. Ned's presentations for pycons >are to me one example of successful code presentation: > - the layout is simple > - the code and code output are clearly identified > - a line of code can be highlighted while presenting > >http://nedbatchelder.com/text/iter.html > >I have access to powerpoint, or any tool under linux (I don't have access to >Mac's stuff). > >Right now I'm so not satisfied by my current method that I'm about to make the >presentation showing the code from the file directly, alt-tabing between the >slides and the code. At least it's cheap. Have you considered using Ipython Notebook? Your browser would replace ppt. -- https://mail.python.org/mailman/listinfo/python-list
Re: Re:Keepin constants, configuration values, etc. in Python - dedicated module or what?
Dave Angel wrote: > [email protected] Wrote in message: > > I am puzzling where and how to keep these configuration values. My > > current design has them in dedicated tables in the database but this > > is rather clumsy in many ways as there's an overhead reading them > > every time the program needs them and changing them isn't particularly > > convenient at the Beaglebone doesn't have a GUI so it has to be done > > using SQL from the command line. > > It is very useful for the database to be self contained and self > describing. Among other things it means that you can easily take > a snapshot at any time, and that snapshot is not tied to any > specific version of the code. As for changing with sql, you can > always add a configuration utility when using sql becomes a > nuisance, or introduces errors. > I guess I can write a script to do the change but it's more code to write and maintain as opposed to simply editing a configuration file with tools I know well. > The key thing is to manage change. You need to decide which > things are conceivably going to change and how you'll manage both > the change itself and the inevitable split between prechange data > and post. One kind of change might be fixing the spelling of > battery. No biggie, just let new accesses get the new one. > Another kind might be the addition of a new instance of an adc > converter. Not a problem, as long as you don't reuse an old > name. And presumably you never remove an old name from the > config. > The only things really likely to change (and may change regularly) are the conversion factors, drifting voltage references etc. will inevitably require these to be recalibrated every so often. Other than that it's just typos or me deciding to change the name of something. > More troublesome is adding a new kind of data. You have to decide > whether it's worth generalizing the code to anticipate the > change, or just admit that the code will grow at that point and > that old code won't deal with the new data. > There's a separate module for each input type (just ADC and 1-wire at the moment), I don't anticipate any more though I suppose there might be digital inputs one day. So a configuration [file] for each type seems to make sense, generalising it would be more trouble than it's worth I think. > > > > Does it make sense to add them to the modules which handle the reading > > of the inputs? I already have modules defining classes called Adc and > > OneWire, is it a reasonable approach to add the configuration to these > > as, probably, dictionaries? Modifying it would be pretty simple - > > just edit the python source (one of the easiest things for me to do on > > the Beaglebone as my sole access is via ssh/command line). > > > > Nope, read it from the db. You still might be loading it to a cfg > variable, however. > > > Thus I'd have something like (apologies for any syntax errors):- > > > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > > > (It might be better to makes those lists dictionaries, but it shows > > the idea) > > Actually it's probably better to use named tuples. All those lists > are apparently of identical length with identical meaning of a > given element offset. But if named tuple isn't flexible,enough, > you probably need a new class. > > > > > Are there any better ways of doing this? E.g. some sort of standard > > configuration file format that Python knows about? I would actually > > quite like to keep the configuration data separate from the code as it > > would simplify using the data at the 'home' end of things as I'd just > > need to copy the configuration file across. This was why the database > > approach appealed at first as all I need to do is copy the database > > and everything is in there. > > > > I'm not really expecting quick/glib answers, just some ideas and > > comments on the various ways of doing this and their advantages and > > disadvantages. > > Main next question is whether you can restart each system when you > add to the configuration. > Yes, restarting isn't a problem, the Beaglebone is dedicated to this task and doesn't control anything so restarts are not an issue. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
SNI support in python 2.7 for Locust load tests
Hello,
At the beginning - welcome everyone, as this is my first post here. I'm not an
active Python developer now, but I have general knowledge of the language.
I'm trying to use locust (http://locust.io/) to run load test of one site we're
developing. Everything was running nice and smooth until we switch the servers
to use SNI. SNI is not officially supported in python 2.7.5 but Locust doesn't
work on python3 as it uses gevent which AFAIK are supported for python2 only. I
finally managed to run our scripts on local Ubuntu after upgrading python to
2.7.8 from utopic repository but I can't replicate the same on target CentOS
where the scripts are supposed to be executed. I tried compiling python from
http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz, I even tried
unpacking sources of Ubuntu python2.7 package (from
http://se.archive.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7_2.7.8.orig.tar.gz),
patching them with TLS1_1 and TLS1_2 support from
https://bugs.python.org/file30761/python-2.7.5-tls1.1-and-tls1.2.patch) and
still no luck. I do monkey patch in Locust startup file according to
http://stackoverflow.com/a/19477363 (oth
erwise it wouldn't work on Ubuntu as well) but still I get error stack as
attached below. I also checked with pip list that all python packages have the
same versions on both systems. Any idea what I'm missing on the target load
test system which I have in Ubuntu?
Regards,
Reddy
...
[2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 503, in put
[2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: return self.request('PUT',
url, data=data, **kwargs)
[2014-09-30 14:19:41,771] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/locust/clients.py", line 111, in request
[2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: response =
self._send_request_safe_mode(method, url, **kwargs)
[2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/locust/clients.py", line 155, in
_send_request_safe_mode
[2014-09-30 14:19:41,772] ip-x-x-x-x/ERROR/stderr: return
requests.Session.request(self, method, url, **kwargs)
[2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 451, in
request
[2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: resp = self.send(prep,
**send_kwargs)
[2014-09-30 14:19:41,773] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 557, in send
[2014-09-30 14:19:41,774] ip-x-x-x-x/ERROR/stderr: r = adapter.send(request,
**kwargs)
[2014-09-30 14:19:41,774] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 362, in send
[2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: timeout=timeout
[2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py",
line 516, in urlopen
[2014-09-30 14:19:41,775] ip-x-x-x-x/ERROR/stderr: body=body, headers=headers)
[2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py",
line 308, in _make_request
[2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: conn.request(method, url,
**httplib_request_kw)
[2014-09-30 14:19:41,776] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/httplib.py", line 995, in request
[2014-09-30 14:19:41,777] ip-x-x-x-x/ERROR/stderr: self._send_request(method,
url, body, headers)
[2014-09-30 14:19:41,777] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/httplib.py", line 1029, in _send_request
[2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr: self.endheaders(body)
[2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/httplib.py", line 991, in endheaders
[2014-09-30 14:19:41,778] ip-x-x-x-x/ERROR/stderr:
self._send_output(message_body)
[2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/httplib.py", line 848, in _send_output
[2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: self.send(message_body)
[2014-09-30 14:19:41,779] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/httplib.py", line 817, in send
[2014-09-30 14:19:41,780] ip-x-x-x-x/ERROR/stderr: self.sock.sendall(datablock)
[2014-09-30 14:19:41,792] ip-x-x-x-x/ERROR/stderr: File
"/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py",
line 203, in sendall
[2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: return
self.connection.sendall(data)
[2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File
"build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 977, in sendall
[2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File
"build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 849, in _raise_ssl_error
[2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: OpenSSL.SSL
[20
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
Rustom Mody wrote: > On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > > > I would actually > > quite like to keep the configuration data separate from the code as it > > would simplify using the data at the 'home' end of things as I'd just > > need to copy the configuration file across. This was why the database > > approach appealed at first as all I need to do is copy the database > > and everything is in there. > > Of course > > > Are there any better ways of doing this? E.g. some sort of standard > > configuration file format that Python knows about? > > Umm this is getting to be a FAQ... > Maybe it should go up somewhere? > > Yes there are dozens: > - ini > - csv > - json > - yml > - xml > - pickle > - And any DBMS of your choice > > I guess Ive forgotten as many as Ive listed!! Yes, I know, I've found most of those. I'm really asking for help in choosing which to use. I think I can reject some quite quickly:- ini - doesn't work so well with lists/dictionaries (though possible) csv - rather difficult to edit json - one of the most likely possibilities, but prefer yml yml - front runner if I go for configuration files xml - horrible, nasty to edit, etc. I don't like XML! :-) pickle - not user editable as I understand it dbms - current solution in sqlite3 as described What I'm really asking for is how to choose between:- DBMS - present solution, keeps config with data easily but more code and less easy to change yml - easy to edit config, keeps data separate from code but needs YAML installed and separate files to manage python - just keep config in the modules/classes, not easy to use at 'both ends' (home and remote), otherwise quite simple My requirements are:- Easy to change, i.e.human readable format which can be edited simply as I have to do this via a terminal/ssh. Easy to use at local end as well as remote end, the remote end is where it lives and is the 'driver' as it were but I need to know the configuration at the local end as well. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
might this be of interest (though old)? https://wiki.python.org/moin/ConfigParserShootout Cheers Jon N -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On 9/30/2014 7:35 AM, [email protected] wrote: Thus I'd have something like (apologies for any syntax errors):- cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} (It might be better to makes those lists dictionaries, but it shows the idea) Using configparser.ConfigParser to read an ini-format seems like a good idea. I use it for my own numerous fixed format data file definitions, and it's been convenient and even extensible. [LeisureVolts] Description=Leisure Battery Voltage Code=AIN0 Value=0.061256 [StarterVolts] Description=Starter Battery Voltage Code=AIN1 Value=0.060943 [LeisureAmps1] Description=Leisure Battery Current Code=AIN2 Value=0.423122 I've set it up so I can understand abbreviations for the field names, for when I want to be lazy. Some of my values are dictionaries, which looks like this in my files (an alternate spelling of one of the above entries): LeisureVolts=desc:Leisure Battery Voltage code:AIN2 value:0.061256 It's simple to hook into ConfigParser to get whatever meaning you'd like, and whatever verification you'd find necessary. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Tuesday, September 30, 2014 8:48:15 PM UTC+5:30, [email protected] wrote: > Rustom Mody wrote: > > On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote: > > > I would actually > > > quite like to keep the configuration data separate from the code as it > > > would simplify using the data at the 'home' end of things as I'd just > > > need to copy the configuration file across. This was why the database > > > approach appealed at first as all I need to do is copy the database > > > and everything is in there. > > Of course > > > Are there any better ways of doing this? E.g. some sort of standard > > > configuration file format that Python knows about? > > Umm this is getting to be a FAQ... > > Maybe it should go up somewhere? > > Yes there are dozens: > > - ini > > - csv > > - json > > - yml > > - xml > > - pickle > > - And any DBMS of your choice > > I guess Ive forgotten as many as Ive listed!! > Yes, I know, I've found most of those. I'm really asking for help in > choosing which to use. I think I can reject some quite quickly:- > xml - horrible, nasty to edit, etc. I don't like XML! :-) Heh! Youve proved yourself a pythonista! > ini - doesn't work so well with lists/dictionaries (though possible) > csv - rather difficult to edit Have you tried with comma=tab? > yml - front runner if I go for configuration files Yeah my favorite as well > json - one of the most likely possibilities, but prefer yml Seems to be most popular nowadays -- maybe related to being almost yaml and in the standard lib > pickle - not user editable as I understand it Well not in any reasonably pleasant way! > What I'm really asking for is how to choose between:- > python - just keep config in the modules/classes, not easy to use > at 'both ends' (home and remote), otherwise quite simple Can work at a trivial level. As soon as things get a bit larger data and code mixed up is a recipe for mess up. -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Wed, Oct 1, 2014 at 2:39 AM, Rustom Mody wrote: >> python - just keep config in the modules/classes, not easy to use >> at 'both ends' (home and remote), otherwise quite simple > > Can work at a trivial level. > > As soon as things get a bit larger data and code mixed up is a recipe for > mess up. True, but it's certainly possible to break out the config data into an importable module that conceptually just provides constants. Technically it's code, yes, but it'll normally be code that looks like your standard "name = value" config file: # docs for first option # more docs # examples # etcetera first_option =123 # docs for second option second_option = 234 Is that Python code, or is it a sectionless INI file, or what? There's no difference. And you get expressions for free - simple stuff like "7*24*60*60" to represent the number of seconds in a week (for people who aren't intimately familiar with 604800), or calculations relative to previous data, or whatever. Sometimes it's helpful to have just a little code in your data. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Tuesday, September 30, 2014 10:22:12 PM UTC+5:30, Chris Angelico wrote: > On Wed, Oct 1, 2014 at 2:39 AM, Rustom Mody wrote: > >> python - just keep config in the modules/classes, not easy to use > >> at 'both ends' (home and remote), otherwise quite simple > > Can work at a trivial level. > > As soon as things get a bit larger data and code mixed up is a recipe for > > mess up. > True, but it's certainly possible to break out the config data into an > importable module that conceptually just provides constants. > Technically it's code, yes, but it'll normally be code that looks like > your standard "name = value" config file: > # docs for first option > # more docs > # examples > # etcetera > first_option =123 > # docs for second option > second_option = 234 > Is that Python code, or is it a sectionless INI file, or what? Yeah I was going to say that this is possible > There's no difference. But there is! Its code that looks like data. > And you get expressions for free - simple stuff like > "7*24*60*60" to represent the number of seconds in a week (for people > who aren't intimately familiar with 604800), or calculations relative > to previous data, or whatever. Sometimes it's helpful to have just a > little code in your data. Not free at all. Power of code means cost of code See http://www.w3.org/2001/tag/doc/leastPower.html I'd reiterate though what I first said: In this case its probably ok if the code (=data) does not cross trivial limits -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Wed, Oct 1, 2014 at 3:01 AM, Rustom Mody wrote: >> And you get expressions for free - simple stuff like >> "7*24*60*60" to represent the number of seconds in a week (for people >> who aren't intimately familiar with 604800), or calculations relative >> to previous data, or whatever. Sometimes it's helpful to have just a >> little code in your data. > > Not free at all. Power of code means cost of code > See http://www.w3.org/2001/tag/doc/leastPower.html It's free once you've already decided (for other reasons) to make your config file use Python syntax, at which point you've already paid the cost of code. But you're quite right, allowing code does have costs. Most notably, you have to quote your strings; although the direct benefits you get (line continuation, unambiguous handling of leading/trailing spaces, etc) may outweigh that on their own. > I'd reiterate though what I first said: In this case its probably > ok if the code (=data) does not cross trivial limits I'd agree, where "trivial limits" is defined by each individual item. Going with straight Python code is fine for huge projects with long config files, as long as each config entry is itself simple. You even get a form of #include: "from otherfile import *". ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Tuesday, September 30, 2014 10:46:21 PM UTC+5:30, Chris Angelico wrote: > On Wed, Oct 1, 2014 at 3:01 AM, Rustom Mody wrote: > >> And you get expressions for free - simple stuff like > >> "7*24*60*60" to represent the number of seconds in a week (for people > >> who aren't intimately familiar with 604800), or calculations relative > >> to previous data, or whatever. Sometimes it's helpful to have just a > >> little code in your data. > > Not free at all. Power of code means cost of code > > See http://www.w3.org/2001/tag/doc/leastPower.html > It's free once you've already decided (for other reasons) to make your > config file use Python syntax, at which point you've already paid the > cost of code. But you're quite right, allowing code does have costs. > Most notably, you have to quote your strings; although the direct > benefits you get (line continuation, unambiguous handling of > leading/trailing spaces, etc) may outweigh that on their own. > > I'd reiterate though what I first said: In this case its probably > > ok if the code (=data) does not cross trivial limits > I'd agree, where "trivial limits" is defined by each individual item. > Going with straight Python code is fine for huge projects with long > config files, as long as each config entry is itself simple. You even > get a form of #include: "from otherfile import *". Well in programming we sometimes use strict/formal methods and sometimes more informal. In this case using configparser or pyyaml or whatever means that the config file's syntax is rigorously fixed by that library On the other hand if you impose a convention: Constants file-module has NOTHING but constants, thats a non-formal convention and thats ok. If however you mix it up with other (real) code, you'll get a bloody mess. This kind of stuff "7*24*60*60" is borderline and in my experience its a slippery slope that ends up being more trouble than its worth. Experience being emacs where because in lisp code and data are the same, all kinds of design messes are perpetrated -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
Rustom Mody wrote: > > > # docs for first option > > # more docs > > # examples > > # etcetera > > first_option =123 > > > # docs for second option > > second_option = 234 > > > Is that Python code, or is it a sectionless INI file, or what? > > Yeah I was going to say that this is possible > > > There's no difference. > > But there is! Its code that looks like data. > The main trouble with this approach is that I need some way to have the python/config file available at the 'home' end of this as well as at the 'remote' end. I guess I could write a copy of the file into the database but then I have the editing issue again, changing it becomes messy. If it's not in the database then how do I 'tie' it to the data? -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: SNI support in python 2.7 for Locust load tests
On 30.09.2014 16:50, Reddy wrote: > Hello, > > At the beginning - welcome everyone, as this is my first post here. I'm not > an active Python developer now, but I have general knowledge of the language. > > I'm trying to use locust (http://locust.io/) to run load test of one site > we're developing. Everything was running nice and smooth until we switch the > servers to use SNI. SNI is not officially supported in python 2.7.5 but > Locust doesn't work on python3 as it uses gevent which AFAIK are supported > for python2 only. I finally managed to run our scripts on local Ubuntu after > upgrading python to 2.7.8 from utopic repository but I can't replicate the > same on target CentOS where the scripts are supposed to be executed. I tried > compiling python from > http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz, I even tried > unpacking sources of Ubuntu python2.7 package (from > http://se.archive.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7_2.7.8.orig.tar.gz), > patching them with TLS1_1 and TLS1_2 s > upport from > https://bugs.python.org/file30761/python-2.7.5-tls1.1-and-tls1.2.patch) and > still no luck. I do monkey patch in Locust startup file according to > http://stackoverflow.com/a/19477363 (oth > erwise it wouldn't work on Ubuntu as well) but still I get error stack as > attached below. I also checked with pip list that all python packages have > the same versions on both systems. Any idea what I'm missing on the target > load test system which I have in Ubuntu? Hello, you have two options: Python 2.7.9 implements PEP 466 "Network Security Enhancements for Python 2.7.x" including TLS 1.1, 1.2 and SNI support. 2.7.9 will be released shortly. You could try the 2.7 branch from hg.python.org. Use PyOpenSSL instead of Python's ssl module. It supports SNI, too. Regards Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Wed, Oct 1, 2014 at 3:31 AM, Rustom Mody wrote:
> On the other hand if you impose a convention: Constants file-module has
> NOTHING but constants, thats a non-formal convention and thats ok.
>
> If however you mix it up with other (real) code, you'll get a bloody mess.
> This kind of stuff "7*24*60*60" is borderline and in my experience
> its a slippery slope that ends up being more trouble than its worth.
Agreed, and which side of the border it's on is a matter of opinion.
Suppose you were writing an INI-style parser - would you include this
feature? I probably wouldn't include arithmetic, as it's usually more
effort than it's worth, but it isn't a bad feature inherently. I'd
definitely not include backreferencing (FOO = "bar", followed by
FOO_LEN = len(FOO) or something), or the ability to chain assignments
(FOO = BAR = 0), so those would be advised against in the convention
docs. On the other hand, a quoted string requirement ("foo\nbar")
makes a huge amount of sense in certain contexts, and I can imagine
implementing quite a lot of a programming language's string literal
syntax.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
On Wed, Oct 1, 2014 at 3:30 AM, wrote: > The main trouble with this approach is that I need some way to have > the python/config file available at the 'home' end of this as well as > at the 'remote' end. I guess I could write a copy of the file into > the database but then I have the editing issue again, changing it > becomes messy. If it's not in the database then how do I 'tie' it to > the data? That's a design question. Maybe it's better for you to do your config in the database. I usually find that these config files include database credentials (server, port, user name, password), so they have to be (a) outside the database, (b) outside source control, and (c) separately configurable for test and production systems, even if they run on the exact same hardware. So for those situations, it makes more sense to have them in a script or INI file, rather than the database. Your situation may well be completely different. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On 09/30/2014 02:50 PM, Jean-Michel Pichavant wrote: I wonder if some people in this list who have successfully presented python code have some tips about doing the proper way. Ned's presentations for pycons are to me one example of successful code presentation: - the layout is simple - the code and code output are clearly identified - a line of code can be highlighted while presenting I use to use Emacs + python-mode + htmlize to export snippets to HTML and then open the HTML with LibreOffice then copy-paste from Writer to Impress. -- https://mail.python.org/mailman/listinfo/python-list
Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
Neil D. Cerutti wrote: > On 9/30/2014 7:35 AM, [email protected] wrote: > > Thus I'd have something like (apologies for any syntax errors):- > > > > cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"], > > "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"], > > "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"} > > > > (It might be better to makes those lists dictionaries, but it shows > > the idea) > > Using configparser.ConfigParser to read an ini-format seems like a good > idea. I use it for my own numerous fixed format data file definitions, > and it's been convenient and even extensible. > > [LeisureVolts] > Description=Leisure Battery Voltage > Code=AIN0 > Value=0.061256 > > [StarterVolts] > Description=Starter Battery Voltage > Code=AIN1 > Value=0.060943 > > [LeisureAmps1] > Description=Leisure Battery Current > Code=AIN2 > Value=0.423122 > That's OK except that it doesn't associate the different sections in any way, I need another level which includes these to indicate that these are values read from the ADC. There's another collection of config data for values read from the 1-wire bus. I guess I could have two config files, one for ADC and one for 1-wire. In fact I think that's the best approach so far. Ini format files are human readable (and more to the point editable), I can store them in the same directory as the database so they will get carried around with the data and the configparser module is built-in. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re[2]: Teaching Python
I use Chris Roffey's "Coding Club - Python Basics (Level 1)" and "Coding Club - Python: Next Steps (Level 2)" I also use the Turtle material from "Python for Kids" These are 11+ year old kids in week long, 3 hour/day summer camps on the Raspberry Pi and Python. The Level 2 book is for the 2nd camp (for those who want to go further). Brian Grawburg Wilson, NC -- https://mail.python.org/mailman/listinfo/python-list
how to parse standard algebraic notation
Hi, I am trying to learn Python while solving exercises. I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative. I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3) Do you have any ideas or suggestions? I don't want to use existing modules as this is meant to be a didactic experience. Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: how to parse standard algebraic notation
On 09/30/2014 01:53 PM, math math wrote: Hi, I am trying to learn Python while solving exercises. I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative. I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3) Do you have any ideas or suggestions? I don't want to use existing modules as this is meant to be a didactic experience. Regards This depends on things you have not yet told us. In particular -- what "standard algebraic notation"? For x-squared: x**2 ? or perhaps x^2 ? or something else like some Unicode characters or HTML to get a small superscript 2 above an x. Once you give an example of what your input looks like, we can start hashing out how to read it. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Restarting Python
Since the developers of Python decided to make Python 3 non backward compatible, I can't help but wonder why they don't think a command to restart would be a useful addition? -- https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On 2014-09-30, Seymore4Head wrote: > Since the developers of Python decided to make Python 3 non backward > compatible, I can't help but wonder why they don't think a command to > restart would be a useful addition? Uh... what? Does that make any sense to anybody else? -- Grant Edwards grant.b.edwardsYow! My nose feels like a at bad Ronald Reagan movie ... gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Using namedtuple with sqlite, surely it can do better than the example
In the namedtuple documentation there's an example:-
EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title,
department, paygrade')
import sqlite3
conn = sqlite3.connect('/companydata')
cursor = conn.cursor()
cursor.execute('SELECT name, age, title, department, paygrade FROM
employees')
for emp in map(EmployeeRecord._make, cursor.fetchall()):
print emp.name, emp.title
(I've deleted the csv bit)
Surely having to match up the "name, age, title, department,
paygrade" between the tuple and the database can be automated, the
example is rather pointless otherwise. At the very least one should
use the same variable instance for both, but it should be possible to
get the tuple names from the database.
--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On 9/30/14 5:15 PM, Seymore4Head wrote: Since the developers of Python decided to make Python 3 non backward compatible, I can't help but wonder why they don't think a command to restart would be a useful addition? Starting a process over again in the same way is not something that is easy to do from within the process. How are you running Python? Is it difficult to start it again? -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On Tue, 30 Sep 2014 18:05:20 -0400, Ned Batchelder wrote: >On 9/30/14 5:15 PM, Seymore4Head wrote: >> Since the developers of Python decided to make Python 3 non backward >> compatible, I can't help but wonder why they don't think a command to >> restart would be a useful addition? >> > >Starting a process over again in the same way is not something that is >easy to do from within the process. How are you running Python? Is it >difficult to start it again? It is not difficult to start again. It just seems like restart is a missing command. I see many questions asking how to do it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On 9/30/2014 5:15 PM, Seymore4Head wrote: Since the developers of Python decided to make Python 3 non backward compatible, This is a trollish exaggeration. > I can't help but wonder why they don't think a command to restart would be a useful addition? More trollishness. Python does not have 'commands'. Feature additions are independent of the changes make in 3.0. 2.7 got many new features, and even now is getting a few new security features. One cannot have opinions about something they do not think of. If you want to propose a new feature, just do that. Describe a use case and how the feature would look, using current Python syntax, and how it would operate. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Using namedtuple with sqlite, surely it can do better than the example
[email protected] wrote: > In the namedtuple documentation there's an example:- > > EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, > department, paygrade') > > import sqlite3 > conn = sqlite3.connect('/companydata') > cursor = conn.cursor() > cursor.execute('SELECT name, age, title, department, paygrade FROM > employees') for emp in map(EmployeeRecord._make, cursor.fetchall()): > print emp.name, emp.title > > (I've deleted the csv bit) > > Surely having to match up the "name, age, title, department, > paygrade" between the tuple and the database can be automated, the > example is rather pointless otherwise. At the very least one should > use the same variable instance for both, but it should be possible to > get the tuple names from the database. It's an example meant to convey the basic idea -- you can add bells and whistles in your actual code. Something like #!/usr/bin/env python3 import sqlite3 import functools from collections import namedtuple def make_namedtuple_row_factory(): last_pair = (None, None) # description, rowtype @functools.lru_cache(maxsize=500) def make_rowtype(description): return namedtuple("Row", [column[0] for column in description])._make def make_namedtuple_is_make(cursor, row): nonlocal last_pair this_description = cursor.description last_description, last_rowtype = last_pair if last_description is this_description: return last_rowtype(row) this_rowtype = make_rowtype(this_description) last_pair = this_description, this_rowtype return this_rowtype(row) return make_namedtuple_is_make db = sqlite3.connect("companydata") cursor = db.cursor() cursor.row_factory = make_namedtuple_row_factory() for employee in cursor.execute( 'SELECT name, age, title, department, paygrade FROM employees'): print(employee.name, employee.title) might be easy to use and have acceptable performance, but most of the code distracts from the namedtuple usage. -- https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On Tue, 30 Sep 2014 18:58:50 -0400, Terry Reedy wrote: >On 9/30/2014 5:15 PM, Seymore4Head wrote: >> Since the developers of Python decided to make Python 3 non backward >> compatible, > >This is a trollish exaggeration. > > > I can't help but wonder why they don't think a command to >> restart would be a useful addition? > >More trollishness. Python does not have 'commands'. > >Feature additions are independent of the changes make in 3.0. 2.7 got >many new features, and even now is getting a few new security features. > >One cannot have opinions about something they do not think of. > >If you want to propose a new feature, just do that. Describe a use case >and how the feature would look, using current Python syntax, and how it >would operate. Bad day? -- https://mail.python.org/mailman/listinfo/python-list
Re: Using namedtuple with sqlite, surely it can do better than the example
On 30/09/2014 22:32, [email protected] wrote: In the namedtuple documentation there's an example:- EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade') import sqlite3 conn = sqlite3.connect('/companydata') cursor = conn.cursor() cursor.execute('SELECT name, age, title, department, paygrade FROM employees') for emp in map(EmployeeRecord._make, cursor.fetchall()): print emp.name, emp.title (I've deleted the csv bit) Surely having to match up the "name, age, title, department, paygrade" between the tuple and the database can be automated, the example is rather pointless otherwise. At the very least one should use the same variable instance for both, but it should be possible to get the tuple names from the database. I'm not sure what you're trying to achieve but I've found it easy to use the sqlite Row object see https://docs.python.org/3/library/sqlite3.html#row-objects -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On 30/09/2014 22:27, Grant Edwards wrote: On 2014-09-30, Seymore4Head wrote: Since the developers of Python decided to make Python 3 non backward compatible, I can't help but wonder why they don't think a command to restart would be a useful addition? Uh... what? Does that make any sense to anybody else? Short answer no. Long answer definitely not. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Python code in presentations
On Tue, Sep 30, 2014 1:50 PM CEST Jean-Michel Pichavant wrote: > >I'm currently writing a presentation to help my co-workers ramp up on new > >features of our tool (written in python (2.7)). > > > >I have some difficulties presenting code in an efficient way (with some > >basic syntax highlights). [...] In article , Albert-Jan Roskam wrote: > Have you considered using Ipython Notebook? Your browser would replace ppt. +1 on that suggestion. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to parse standard algebraic notation
On Wed, Oct 1, 2014 at 6:53 AM, math math wrote:
> I want to basically write a program that inputs a polynomial in standard
> algebraic notation and outputs its derivative.
>
> I know that I need to get the exponent somehow, but I am not sure how to
> accomplish this in python (3.3)
As Gary says, the form of input is really the critical part. How will
users type these?
One simple cheat you could do would be to prompt for each term
separately - something like this:
exponent = int(input("What is the highest exponent used? "))
terms = []
while exponent:
terms.append(input("Enter coefficient of x^%d: " % exponent))
exponent -= 1
terms.append(input("Enter constant term: "))
You could do something similar with a GUI toolkit like tkinter or
pygtk, too; provide input fields for the coefficients, and labels in
between that say "x² + " etc.
Otherwise, you're going to be primarily bound by the keyboard - your
program is useless if it takes longer to key data into it than to do
the work manually. Python 3.3 has excellent Unicode support, and
Unicode has excellent support for mathematical notations, so you
should be able to produce nice-looking output; but mathematical
notation is much easier to write on a blackboard than on a computer's
keyboard. (And even though some keyboards are black, like the one I'm
using right now, it doesn't make it any easier. Sorry.) Gary's
suggestions of the double asterisk and caret are two commonly-used
notations for exponentiation in computers, so either would make some
sense. Otherwise, you could come up with some other notation, but
mainly, it has to be typeable.
But hey! Once you have something you can type unambiguously, we can
help you parse that into something you can make use of! That part's
not too hard.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Restarting Python
On Wed, Oct 1, 2014 at 9:16 AM, Seymore4Head wrote: > On Tue, 30 Sep 2014 18:58:50 -0400, Terry Reedy > wrote: > >>On 9/30/2014 5:15 PM, Seymore4Head wrote: >>> Since the developers of Python decided to make Python 3 non backward >>> compatible, >> >>This is a trollish exaggeration. >> >> > I can't help but wonder why they don't think a command to >>> restart would be a useful addition? >> >>More trollishness. Python does not have 'commands'. >> >>Feature additions are independent of the changes make in 3.0. 2.7 got >>many new features, and even now is getting a few new security features. >> >>One cannot have opinions about something they do not think of. >> >>If you want to propose a new feature, just do that. Describe a use case >>and how the feature would look, using current Python syntax, and how it >>would operate. > > Bad day? No, that's not Terry having a bad day and taking it out on you. That's you making a vague proposal with dubious justification, and Terry coming back to you asking for clarification. As he says, you need to propose new features by saying what they'd do, how they'd do it, and why they should be implemented. Ignore Python's history here, just look at where the language currently is and where you're suggesting it go. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: SNI support in python 2.7 for Locust load tests
Reddy writes: > ... > I'm trying to use locust (http://locust.io/) to run load test of one site > we're developing. Everything was running nice and smooth until we switch the > servers to use SNI. SNI is not officially supported in python 2.7.5 A recent post in this list regarding missing SNI support in Python 2.x got as a suggestion to use the "backports.ssl" package on PyPI. -- https://mail.python.org/mailman/listinfo/python-list
