Re: Python source repo
On 2016-09-10 15:27:07 +, Steve D'Aprano said: Never mind. I got bored and frustrated and Ctrl-C'ed the process and ran it again. This time it took about 15 seconds to complete. Out of curiosity I checked for python debugger with "attach" feature (aking to gdb/lldb) and I found a few but I figure one has to know some hg internal in order to inspect where it hung up. Btw I experienced similar, sporadic issues with hg in past, I had the impression those were network-related, not reproducible on my side anyway. -- Andrea -- https://mail.python.org/mailman/listinfo/python-list
Override property setter of base class in Python 3
Example code: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @A.prop.setter def prop(self, value): print("Setting new value",value) super().prop = value b = B(0) b.prop=10 Result: Setting new value 10 Traceback (most recent call last): File "test.py", line 22, in b.prop=10 File "test.py", line 18, in prop super().prop = value AttributeError: 'super' object has no attribute 'prop' This seems to be working: class B(A): @A.prop.setter # MAGIC HERE! def prop(self, value): print("Setting new value",value) A.prop.fset(self, value) # MAGIC HERE! How can I remove the magic? E.g. referencing the base class name directly, and using some internal name "fset"? Also, consider this: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @A.prop.setter def prop(self, value): print("Setting new value in B:",value) A.prop.fset(self, value) # How use the MRO here? class C(A): @A.prop.setter def prop(self, value): print("Setting new value in C:",value) A.prop.fset(self, value) # How use the MRO here? class D(B,C): pass d = D(0) d.prop=10 Result: Setting new value in B: 10 What if I want to use the "property setter of the superclass"? E.g. the one that is the next in the MRO? Thanks, Laszlo -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3
By the way, I know that I can use a "property virtualizer", something like this: import inspect class A: def __init__(self, prop=0): self.__prop = prop def _prop_get(self): return self.__prop def _prop_set(self, value): self.prop_set(value) def prop_set(self, value): print("Setting prop value in A to", value) self.__prop = value prop = property(_prop_get, _prop_set) class B(A): def prop_set(self, value): print("Setting prop value in B to", value) super().prop_set(value) class C(A): def prop_set(self, value): print("Setting prop value in C to", value) super().prop_set(value) class D(B,C): pass d = D(0) d.prop=10 But this solution almost defeats the purpose of properties. E.g. a property should look like an attribute, and its behaviour should be manipulated through its name (and not another special method that must be exposed to subclasses.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3
On Sun, Sep 11, 2016 at 8:02 PM, Nagy László Zsolt wrote: > But this solution almost defeats the purpose of properties. E.g. a > property should look like an attribute, and its behaviour should be > manipulated through its name (and not another special method that must > be exposed to subclasses.) Even the problem seems to rather defeat the purpose of a property. A property should be very simple - why do you need to override it and call super()? Doesn't this rather imply that you've gone beyond the normal use of properties *already*? Subclassing and overriding are part of the interface of a class, albeit an interface that only a subset of other classes will use. Think carefully about why, if this is meant to be made available, it isn't simply a method call. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3
> Even the problem seems to rather defeat the purpose of a property. A > property should be very simple - why do you need to override it and > call super()? Doesn't this rather imply that you've gone beyond the > normal use of properties *already*? I'm not sure about that. I'm going to send a USE CASE in a separate message. > > Subclassing and overriding are part of the interface of a class, > albeit an interface that only a subset of other classes will use. > Think carefully about why, if this is meant to be made available, it > isn't simply a method call. Properties are also part of the class interface. I don't see any good reason why property get and set methods should not be overridden in subclasses. Provisional syntax: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @super.prop.getter def prop(self): print("Getting value",super().prop) return super().prop @super.prop.setter def prop(self, value): print("Setting new value",value) super().prop = value The only problem is that we cannot access "the property setter implementation of the superclass" easily. There is already a standard working way to overcome this: property virtualizer methods. (See my second email.) That pattern *allows attribute like access and polimorphism at the same time*, but at the cost of making the class interface more difficult and harder to understand. I only asked for a way to remove the seemingly neccessary bolierplate code ("syntax noise") and make it cleaner. Laszlo -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
> Even the problem seems to rather defeat the purpose of a property. A > property should be very simple - why do you need to override it and > call super()? Doesn't this rather imply that you've gone beyond the > normal use of properties *already*? Here are some of my classes that can represent data: "FormField" - a field of a form that have some properties (name, label, description, required or not, value etc.) They are available as properties e.g. formfield.value, formfield.required etc. "Form" - a collection of FormFields that can be used to validate the form as a whole. Some data structures are represented in FormField and Form instances. They are *often* represented to the user on a user interface. But *sometimes* they are used in other ways. The user interface is built on top of a "Widget" class, that knows how to build ui elements for the user (in this case: in a web browser). It can send/receive messages to/from the browser. Widget objects also have basic properties (for example: color, size, parent widget etc.) Whenever a property is changed on a widget object, the change is accounted for, goes through some buffering and sent to the browser. When I do "widget.visible = False" then it will (eventually) send a message to the browser and execute javascript code something like this: jQuery("#some_widget_id").hide() When a FormField needs a visual representation, then I create subclasses that inherit from both Widget and FormField. For example, a "TextField" class. Some properties that are defined in FormField must also be represented visually. The synchronization between property values and visual elements is done with messages/events. For example, when I do textfield.value = "some value" then the property value is updated internally in the FormField, but it also creates a message that will be sent to the browser and update the value attribute of the element. As a result, the user will also see that the value has been changed. On the other hand, when the user changes the value in the field, a message is pushed from the browser to the TextField object, and that will also change the value of the corresponding textfield.value property. The "value of a form field" must have a unified interface. So when I do " textfield.value = some_value " then I expect that the changed value will be represented on the UI *if it has an UI representation*. The widget needs to be able to intercept property value changes. One solution would be to make FormField an observable object, define separate events for these property changes (e.g. EVT_VALUE_CHANGED), and let TextField listen to these events. But this is even more difficult than using simple methods and overriding them. We know that there will only be a single chain of observers. Using an observable pattern that can have many observers for a single event seems to be an overkill. Using overriden setter methods instead of properties is still better than using the observable/observer pattern. Much more simple and easier to understand. Does this go beyond the normal use of properties? You decide. I'm open to suggestions. What other pattern can I use for this problem? Here are the possibilities I see: * Use property virtualizers - too much syntax noise, but at least boilerplate code is contained within the class and it works as expected (this is what I use now) * Use getter/setter methods instead of properties - non-pythonic * Use the observable pattern, emit events for property changes and make others listen for it - too general and too difficult for this problem, harder to understand * Propose a new syntax that allows proper overriding of property getter/setter methods without too much syntax noise Laszlo -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3
On Sun, Sep 11, 2016 at 9:17 PM, Nagy László Zsolt wrote: >> Subclassing and overriding are part of the interface of a class, >> albeit an interface that only a subset of other classes will use. >> Think carefully about why, if this is meant to be made available, it >> isn't simply a method call. > > Properties are also part of the class interface. I don't see any good > reason why property get and set methods should not be overridden in > subclasses. Right, I'm not saying they aren't; I'm just saying that properties are intended for simpler purposes than you'll normally need subclassing for. I'll wait for your follow-up email with a use case. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: How to split value where is comma ?
>I have worked places where they put stuff like this at the bottom of emails >sent to the person sitting next to them :) -raising entropy-ly yrs- Robin >Becker Cannot do anything about it. It is not on my MTA client and it is added by the company server :( If it depended on my I will remove it but I can not do that. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
On Sun, Sep 11, 2016 at 9:31 PM, Nagy László Zsolt wrote: > The "value of a form field" must have a unified interface. So when I do > " textfield.value = some_value " then I expect that the changed value > will be represented on the UI *if it has an UI representation*. The > widget needs to be able to intercept property value changes. > > Does this go beyond the normal use of properties? You decide. I'm open > to suggestions. What other pattern can I use for this problem? Yes, I believe it does. (Others may disagree. This is a design question and very much a matter of style, not hard fact.) I would have an explicit action "set_content" which will set the value of an input field, the inner text of a textarea, the checked state of a check box, etc. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to split value where is comma ?
On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola wrote: >>I have worked places where they put stuff like this at the bottom of emails >>sent to the person sitting next to them :) -raising entropy-ly yrs- Robin >>Becker > > Cannot do anything about it. It is not on my MTA client and it is added by > the company server :( > > If it depended on my I will remove it but I can not do that. Haven't you been reading what we've been saying? COMPLAIN. Go to whoever you can in the company and muster up support for the removal. Tell your bosses how stupid it makes the company look. Or just use a different mail server. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to split value where is comma ?
On 2016-09-08 09:27:20 +, Joaquin Alzola said: Cannot do anything about it. It is not on my MTA client and it is added by the company server :( If it depended on my I will remove it but I can not do that. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. At least use a signature (conventionally marked by double dash, space, newline) so the part that's automatically added by the mail system is clearly separated from the body of your message. -- Andrea -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
Yes, I believe it does. (Others may disagree. This is a design question and very much a matter of style, not hard fact.) I would have an explicit action "set_content" which will set the value of an input field, the inner text of a textarea, the checked state of a check box, etc. In other words, you would use simple getter and setter methods instead of properties. It is the simplest solution. (And I believe, it is non-pythonic, but that is just an opinion.) I would like to hear other opinions. -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
Nagy László Zsolt wrote: > >> Yes, I believe it does. (Others may disagree. This is a design >> question and very much a matter of style, not hard fact.) I would have >> an explicit action "set_content" which will set the value of an input >> field, the inner text of a textarea, the checked state of a check box, >> etc. > In other words, you would use simple getter and setter methods instead > of properties. It is the simplest solution. (And I believe, it is > non-pythonic, but that is just an opinion.) > > I would like to hear other opinions. Disregarding potential implementation obstacles I think it would be clean and clear if you could access a property foo in a base class with super().foo and set it with super().foo = value It looks like the get part already works: >>> class A: ... @property ... def foo(self): return "foo" ... >>> class B(A): ... @property ... def foo(self): return super().foo.upper() ... >>> A().foo 'foo' >>> B().foo 'FOO' -- https://mail.python.org/mailman/listinfo/python-list
iterating over multi-line string
Hey; I have a multi-line string that's the result of reading a file filled with 'dirty' text. I read the file in one swoop to make data cleanup a bit easier - getting rid of extraneous tabs, spaces, newlines, etc. That part's done. Now, I want to collect data in each section of the data. Sections are started with a specific header and end when the next header is found. ^1\. Upgrade to the latest version of Apache HTTPD ^2\. Disable insecure TLS/SSL protocol support ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have TLS 1.2 enabled ^4\. Disable HTTP TRACE Method for Apache [[snip]] There's something like 60 lines of worthless text before that first header line so I thought I'd skip through them with: x=0 # Current index hx=1 # human readable index rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] hdr = re.compile(rgs) for l in data.splitlines(): while not hdr.match(l): next(l) print(l) which resulted in a typeerror stating that str is not an iterator. More googling resulted in: iterobj = iter(data.splitlines()) for l in iterobj: while not hdr.match(l): next(iterobj) print(l) I'm hoping to see that first header; however, I'm getting another error: Traceback (most recent call last): File "./testies.py", line 30, in next(iterobj) StopIteration I'm not quite sure what that means... Does that mean I got to the end of data w/o finding my header? Thanks for any hints/tips/suggestions. Doug O'Leary -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
On 09/11/2016 08:28 AM, Peter Otten wrote: Nagy László Zsolt wrote: Yes, I believe it does. (Others may disagree. This is a design question and very much a matter of style, not hard fact.) I would have an explicit action "set_content" which will set the value of an input field, the inner text of a textarea, the checked state of a check box, etc. In other words, you would use simple getter and setter methods instead of properties. It is the simplest solution. (And I believe, it is non-pythonic, but that is just an opinion.) I would like to hear other opinions. Disregarding potential implementation obstacles I think it would be clean and clear if you could access a property foo in a base class with super().foo and set it with super().foo = value It looks like the get part already works: class A: ... @property ... def foo(self): return "foo" ... class B(A): ... @property ... def foo(self): return super().foo.upper() ... A().foo 'foo' B().foo 'FOO' Yes, the get part works. The set part is a pain, and a bit ugly: super(B, B).foo.__set__(self, value) There is an issue for this on the tracker: http://bugs.python.org/issue14965 -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: iterating over multi-line string
Hey; Never mind; I finally found the meaning of stopiteration. I guess my google-foo is a bit weak this morning. Thanks Doug -- https://mail.python.org/mailman/listinfo/python-list
more python3 regex?
Hey This one seems like it should be easy but I'm not getting the expected results. I have a chunk of data over which I can iterate line by line and print out the expected results: for l in q.findall(data): # if re.match(r'(Name|")', l): # continue print(l) $ ./testies.py | wc -l 197 I would like to skip any line that starts with 'Name' or a double quote: $ ./testies.py | perl -ne 'print if (m{^Name} || m{^"})' Name IP Address,Site, "",,7 of 64 Name,IP Address,Site, "",,,8 of 64 Name,IP Address,Site, "",,,9 of 64 Name,IP Address,Site, "",,,10 of 64 Name,IP Address,Site, "",,,11 of 64 Name IP Address,Site, $ ./testies.py | perl -ne 'print unless (m{^Name} || m{^"})' | wc -l 186 When I run with the two lines uncommented, *everything* gets skipped: $ ./testies.py $ Same thing when I use a pre-defined pattern object: skippers = re.compile(r'Name|"') for l in q.findall(data): if skippers.match(l): continue print(l) Like I said, this seems like it should be pretty straight forward so I'm obviously missing something basic. Any hints/tips/suggestions gratefully accepted. Doug O'Leary -- https://mail.python.org/mailman/listinfo/python-list
Re: iterating over multi-line string
Doug OLeary wrote: > Hey; > > I have a multi-line string that's the result of reading a file filled with > 'dirty' text. I read the file in one swoop to make data cleanup a bit > easier - getting rid of extraneous tabs, spaces, newlines, etc. That > part's done. > > Now, I want to collect data in each section of the data. Sections are > started with a specific header and end when the next header is found. > > ^1\. Upgrade to the latest version of Apache HTTPD > ^2\. Disable insecure TLS/SSL protocol support > ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have > TLS 1.2 enabled ^4\. Disable HTTP TRACE Method for Apache > [[snip]] > > There's something like 60 lines of worthless text before that first header > line so I thought I'd skip through them with: > > x=0 # Current index > hx=1 # human readable index > rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] > hdr = re.compile(rgs) > for l in data.splitlines(): > while not hdr.match(l): > next(l) > print(l) > > which resulted in a typeerror stating that str is not an iterator. More > googling resulted in: > > iterobj = iter(data.splitlines()) > > for l in iterobj: > while not hdr.match(l): > next(iterobj) > print(l) > > I'm hoping to see that first header; however, I'm getting another error: > > Traceback (most recent call last): > File "./testies.py", line 30, in > next(iterobj) > StopIteration > > I'm not quite sure what that means... Does that mean I got to the end of > data w/o finding my header? > > Thanks for any hints/tips/suggestions. If you nest the loops you don't just skip the lines before the first, but before every header. Unless your data ends with a header the inner loop will eventually run out of lines without seeing another header. Here are two clean (I think) ways to capture the lines starting with the first header. (1) Do-it-yourself, with a generator: def rest(lines, isheader): lines = iter(lines) for line in lines: if isheader(line): yield line # the first header break yield from lines # all lines following the first headder for line in rest(data.splitlines(), hdr.match): print(line) (2) Using the itertools from Python's standard library: import itertools def is_no_header(line): return hdr.match(line) is None for line in itertools.dropwhile(is_no_header, data.splitlines()): print(line) Both versions work with file objects, you just have to tell print not to add a newline with print(line, end="") -- https://mail.python.org/mailman/listinfo/python-list
Re: more python3 regex?
Doug OLeary wrote: > Hey > > This one seems like it should be easy but I'm not getting the expected > results. > > I have a chunk of data over which I can iterate line by line and print out > the expected results: > > for l in q.findall(data): > # if re.match(r'(Name|")', l): > # continue > print(l) > > $ ./testies.py | wc -l > 197 > > I would like to skip any line that starts with 'Name' or a double quote: > > $ ./testies.py | perl -ne 'print if (m{^Name} || m{^"})' > Name IP Address,Site, > "",,7 of 64 > Name,IP Address,Site, > "",,,8 of 64 > Name,IP Address,Site, > "",,,9 of 64 > Name,IP Address,Site, > "",,,10 of 64 > Name,IP Address,Site, > "",,,11 of 64 > Name IP Address,Site, > > $ ./testies.py | perl -ne 'print unless (m{^Name} || m{^"})' | wc -l > 186 > > > When I run with the two lines uncommented, *everything* gets skipped: > > $ ./testies.py > $ > > Same thing when I use a pre-defined pattern object: > > skippers = re.compile(r'Name|"') > for l in q.findall(data): > if skippers.match(l): > continue > print(l) > > Like I said, this seems like it should be pretty straight forward so I'm > obviously missing something basic. > > Any hints/tips/suggestions gratefully accepted. Add a print() to the matching case to see where you messed up, e. g. for line in q.findall(data): if re.match(r'(Name|")', line): print("SKIPPING", repr(line)) continue print(line) In the future try to provide small self-contained scripts that others can run. That will also make your own debugging experience more pleasant ;) Had you tried $ cat oleary.py import re lines = """\ foo show "bar" skip Name skip Name show "baz" show baz show """.splitlines() for line in lines: if re.match(r'^(Name|")', line): continue print(line) $ python3 oleary.py foo show Name show "baz" show baz show you could easily have convinced yourself that both the loop and the regex work as expected. By the way, many simple text-processing problems can be solved without regular expressions. Most Python users will spell a simple filter like the above above as for line in lines: if not line.startswith(("Name", '"')): print(line) or similar. -- https://mail.python.org/mailman/listinfo/python-list
Re: Override property setter of base class in Python 3 - USE CASE
> Yes, the get part works. The set part is a pain, and a bit ugly: > > super(B, B).foo.__set__(self, value) > > There is an issue for this on the tracker: > http://bugs.python.org/issue14965 > Thank you Ethan! The superprop pure Python implementation is very promising. ( http://bugs.python.org/file37546 ) I can use that instead of my "property virtualizers" until Python built in support becomes available. :-) -- https://mail.python.org/mailman/listinfo/python-list
sphinx (or other means to document python)
Excuse me for being frustrated (!) (with documenting python with Sphinx) I have a source file myfile.py which contains documentation with "docstrings" I am trying to have Sphinx create the pdf (from latex) I have run through sphinx-quickstart - which creates build, source (there is some conf.py somewhere also) 1) myfile.py (should be in source?) 2) Do I need any additional programs to read docstrings and conv them to latex/pdf? (I recall answering "yes" to some question during sphinx-quickinstall) 3) Do I have to have an index.rst AND myfile.py? 4) Can I have ONE file that has my code AND documentation? (like what noweb allows me to do) 5) I have tried several times - but \f[ or \f$ does not work to embed TeX/LaTeX pycco seems far, far, far simpler - but the output is html noweb is great - except not very easy to embed comments in *.py and extract them Bottom line Is there a COMPLETE (I mean COMPLETE) example I can read about using sphinx? That complete example should have source, build, conf.py, etc etc - some user written code, some index.rst, etc etc etc and the latex/pdf (or html) should build with "make html" or "make latex" thanks! (I KNOW it is NOT that difficult - but for the life of me, I cannot figure sphinx - in part because it seems to need several files, several changes/configurations - and simply having a *.py with doctrings does not seem to be sufficient) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python source repo
On 9/10/2016 11:27 AM, Steve D'Aprano wrote: On Sun, 11 Sep 2016 01:04 am, Steve D'Aprano wrote: I ran hg fetch to update the CPython repo. I use pull (to local repository) and update (working directory) separately in the following script (pull.bat), based on either the devguide or what TortoiseHg uses. /35 and /27 are shares. hg --repository .\36 pull --verbose --config ui.merge=internal:merge ssh://h...@hg.python.org/cpython hg --repository .\36 update --verbose hg --repository .\35 update --verbose hg --repository .\27 update --verbose It has been stuck on "adding changesets" for half an hour. I have run the above (or earlier versions) perhaps 100s of times and cannot remember anything like that. The pull output just now is pulling from ssh://h...@hg.python.org/cpython searching for changes all local heads known remotely adding changesets adding manifests adding file changes added 70 changesets with 185 changes to 126 files 'adding changesets' is very quickly (.1 second?, or less?) followed by 'adding manifests' and 'adding file changes'. Even a full second delay after 'adding changesets' would be unusual. The most substantial delay is the download time before the last line is printed. Total time: about 5 seconds, normal for this many pulls. I don't know if that's because the process has locked up, Something is definitely 'locked up'. Never mind. I got bored and frustrated and Ctrl-C'ed the process and ran it again. This time it took about 15 seconds to complete. For me, even less for the changes above. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: iterating over multi-line string
On 9/11/2016 11:34 AM, Doug OLeary wrote: Hey; I have a multi-line string that's the result of reading a file filled with 'dirty' text. I read the file in one swoop to make data cleanup a bit easier - getting rid of extraneous tabs, spaces, newlines, etc. That part's done. Now, I want to collect data in each section of the data. Sections are started with a specific header and end when the next header is found. ^1\. Upgrade to the latest version of Apache HTTPD ^2\. Disable insecure TLS/SSL protocol support ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have TLS 1.2 enabled ^4\. Disable HTTP TRACE Method for Apache [[snip]] There's something like 60 lines of worthless text before that first header line so I thought I'd skip through them with: x=0 # Current index hx=1 # human readable index rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] hdr = re.compile(rgs) for l in data.splitlines(): while not hdr.match(l): next(l) print(l) which resulted in a typeerror stating that str is not an iterator. More googling resulted in: You are iterating in two different ways. Not surprising it does not work. The re is also unnecessary. The following seems to do what you want and is much simpler. data = '''\ junk more junk ^1\. upgrade ^2\. etc ''' data = data[data.index(r'^1\.'):] print(data) # ^1\. upgrade ^2\. etc -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: pymssql
Thanks heaps for your comments, manage to get it work using the as_dict` parameter of the `cursor` object, cus=conn.cursor(as_dict=True) cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud") for row in cus: print(row['budget_code'],row['budget_description'],row['rate_type']) cheers, On Sat, Sep 10, 2016 at 3:22 PM, Miki Tebeka wrote: > > for row in cus: > >print(row.budget_code) > > > > > > NameError: name 'budget_code' is not defined > You'll need to use a DictCursor to be able to access rows by name and not > position (which IMO is the preferred way). > > cus = conn.cursor(pymysql.cursors.DictCursor) > cus.execute("SELECT * FROM glbud ") > for row in cus: > print(row['budget_code']) > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Inconsistencies
On 10.09.2016 15:00, Chris Angelico wrote: Some things are absolute hard facts. There is no way in which 1 will ever be greater than 2, ergo "1 is less than 2" is strictly true, and not a matter of opinion. If you hear someone trying to claim otherwise, would you let him have his opinion, or would you treat it as incorrect? I don't know exactly if it's clear that one would need to make a distinction between real/physical-world facts and pure-logic facts. "1 < 2" is by definition "true" (construction of natural numbers) not by real-world evidence. IIRC, the quote is about real-world matters. There is some merit in this. For instance, Python 2 had a lower-level consistency in the division operator than Python 3 has. According to Py2, integers and floats are fundamentally different beasts, and when you divide an int by an int, you get an int, not a float. Py3 says "well, you probably REALLY meant to divide a number by a number", so it gives you a float back, unless you explicitly ask for floor division. Py2 is more consistent on a lower level of abstraction. Py3 is more consistent on a higher level of abstraction (modulo the oddities at extremely large numbers). Both have merit, but in a high level language, the Py3 way is usually [1] better. But the consistency of call-by-object-reference is at the same high level as the consistency of call-by-value or call-by-name. I can explain Python's assignment model to someone fairly easily, using pencil and paper, without any reference to "low level" or "high level" concepts. And Python is extremely internally consistent; *every* assignment behaves the exact same way. How does "import x" compare with "from x import y"? Easy: the former is "x = some_module_object", and the latter is "y = some_module_object.y", and either way, it's regular assignment. How does parameter passing work? You take the value of the argument as evaluated in the caller, and assign it to the parameter in the function. What about default arguments? They're evaluated when the function's defined, and assigned to the parameter when it's called. Function definition itself is the same thing - it's assigning a function object to a name. Python handles every one of them the same way. I don't care one iota about how voltages inside a CPU operate. I don't generally even care about machine code - let other people worry about that, people more expert than I am. Discussions about how the core dev and the novice see Python's consistencies are nothing to do with those levels. To go back to your original point, that a newbie is better at recognizing inconsistencies... maybe, in a sense, but they also get a lot of false positives. Ultimately, "consistent" means that there's a single pattern that explains everything; if you're unaware of that pattern, you won't know that it's consistent. ChrisA [1] Even in Python, there are places where low-level consistency is better, because Python is a glue language. But in general, it's better for Python to be consistent with humans than with C APIs. The last sentence is the part why I love Python. :) I could not agree more with what you said above, so I hope this will put the discussion in better perspective, especially when people here trying to be overly absolute in their views (which was the quote about). Cheers, Sven -- https://mail.python.org/mailman/listinfo/python-list
mssql date format
Hi, I am pulling data from an mssql server database and got a date in this format: 733010 please advise what of date is this and how to i convert it to a readable date? i use pyssql to connect to the database and pull data fro the database. thanks in advance, cheers -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Inconsistencies
On Mon, Sep 12, 2016 at 6:30 AM, Sven R. Kunze wrote: > > I could not agree more with what you said above, so I hope this will put the > discussion in better perspective, especially when people here trying to be > overly absolute in their views (which was the quote about). > Strange that you think I'm a more moderate position. I have some _extremely_ strong views about absolutes (they come from the Creator of the Universe), and it's not just abstract concepts like numbers that have absolutes. There are hard-and-fast facts about the world, and even about human nature, that stem from the way we were made. However, lengthy discussion of such things is WAY off topic here. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: mssql date format
On 2016-09-12 01:37, sum abiut wrote: Hi, I am pulling data from an mssql server database and got a date in this format: 733010 please advise what of date is this and how to i convert it to a readable date? i use pyssql to connect to the database and pull data fro the database. Does the date "30 November 2007" look reasonable for that data? If it does, it's a """proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1""" (from the docs): import datetime datetime.datetime.fromordinal(733010) datetime.datetime(2007, 11, 30, 0, 0) -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Inconsistencies
On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: > I have some _extremely_ strong views about absolutes (they come from the > Creator of the Universe) ... By “Universe” do you mean “everything that exists”? So if the Creator exists, then the Creator, too, must be part of the Universe. So whoever created the Universe also created the Creator... -- https://mail.python.org/mailman/listinfo/python-list
Re: more python3 regex?
On Monday, September 12, 2016 at 6:21:57 AM UTC+12, Peter Otten wrote: > By the way, many simple text-processing problems can be solved without > regular expressions. The old JWZ quote instantly comes to mind... -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Inconsistencies
On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D’Oliveiro wrote: > On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: >> I have some _extremely_ strong views about absolutes (they come from the >> Creator of the Universe) ... > > By “Universe” do you mean “everything that exists”? So if the Creator exists, > then the Creator, too, must be part of the Universe. > > So whoever created the Universe also created the Creator... No, God isn't part of the universe, any more than an author is part of his novel. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: mssql date format
On Mon, Sep 12, 2016 at 11:15 AM, MRAB wrote: > On 2016-09-12 01:37, sum abiut wrote: >> >> Hi, >> I am pulling data from an mssql server database and got a date in this >> format: 733010 >> please advise what of date is this and how to i convert it to a readable >> date? >> >> i use pyssql to connect to the database and pull data fro the database. >> > Does the date "30 November 2007" look reasonable for that data? And if it doesn't, try selecting now() from the database, which should give you today's date and time. Possibly cast that to the same type of date that you're working with. If that gives you an easily readable result, you may have some kind of custom "date stored as integer" field, which you'd have to discuss with your DB admin. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Inconsistencies
On 2016-09-12 03:26, Chris Angelico wrote: On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D’Oliveiro wrote: On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: I have some _extremely_ strong views about absolutes (they come from the Creator of the Universe) ... By “Universe” do you mean “everything that exists”? So if the Creator exists, then the Creator, too, must be part of the Universe. So whoever created the Universe also created the Creator... No, God isn't part of the universe, any more than an author is part of his novel. Is this the five minute argument or the full half hour? :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: more python3 regex?
Hey, all; The print suggestion was the key clue. Turned out my loop was slurping the whole of data in one big line. Searching for a line that begins with Name when it's in the middle of the string is... obviously not going to work so well. Took me a bit to get that working and, once I did, I realized I was on the wrong track altogether. In perl, if possible, I will read a file entirely as manipulation of one large data structure is easier in some ways. Even with perl, though, that approach is the wrong one for this data. While I learned lots, the key lesson is forcing data to match an algorithm works as well in python as it does in perl. Go figure. My 200+ script that didn't work so well is now 63 lines, including comments... and works perfectly. Outstanding! Thanks for putting up with noob questions Doug -- https://mail.python.org/mailman/listinfo/python-list