Re: Newbie question about Python syntax

2019-08-26 Thread Paul St George
On 25/08/2019 02:39, Cameron Simpson wrote: On 24Aug2019 21:52, Paul St George wrote: [snip]> Aside from "map" being a poor name (it is also a builtin Python function), it seems that one creates one of these to control how some rendering process is done. The class reference page you origina

Re: Newbie question about Python syntax

2019-08-24 Thread Cameron Simpson
On 24Aug2019 21:52, Paul St George wrote: Have you not got one of these handed to you from something? Or are you right at the outside with some "opaque" blender handle or something? (Disclaimer: I've never used Blender.) Thank you once again. If I understand your question, I am right outside

Re: Newbie question about Python syntax

2019-08-24 Thread Barry
Have you tried asking on a blender user mailing list for help with this problem? It seems that someone familiar with blender and its python interface should be able to help get you going. Barry > On 24 Aug 2019, at 20:52, Paul St George wrote: > >> On 24/08/2019 01:23, Cameron Simpson wrote:

Re: Newbie question about Python syntax

2019-08-24 Thread Paul St George
On 24/08/2019 01:23, Cameron Simpson wrote: On 23Aug2019 13:49, Paul St George wrote: Context: I am using Python to interrogate the value of some thing in Blender (just as someone else might want to use Python to look at an email in a Mail program or an image in Photoshop). Assumptions: So,

Re: Newbie question about Python syntax

2019-08-23 Thread Cameron Simpson
On 23Aug2019 13:49, Paul St George wrote: Context: I am using Python to interrogate the value of some thing in Blender (just as someone else might want to use Python to look at an email in a Mail program or an image in Photoshop). Assumptions: So, I want to look at the attribute of an instan

Re: Newbie question about Python syntax

2019-08-23 Thread Paul St George
On 22/08/2019 23:21, Kyle Stanley wrote: [snip] The tutorial that Terry was referring to was the one on docs.python.org, here's a couple of links for the sections he was referring to: Full section on classes: https://docs.python.org/3/tutorial/classes.html Section on instantiating objects from

Re: Newbie question about Python syntax

2019-08-22 Thread Kyle Stanley
> You are right, but it is even worse than you think. I do not have a tutorial so I have no examples to understand. The tutorial that Terry was referring to was the one on docs.python.org, here's a couple of links for the sections he was referring to: Full section on classes: https://docs.python.

Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George
On 22/08/2019 20:02, Terry Reedy wrote: On 8/22/2019 3:34 AM, Paul St George wrote: I have the Python API for the Map Value Node here: . All well and good. Now I just want to write a simple line of code such as: i

Re: Newbie question about Python syntax

2019-08-22 Thread Terry Reedy
On 8/22/2019 3:34 AM, Paul St George wrote: I have the Python API for the Map Value Node here: . All well and good. Now I just want to write a simple line of code such as: import bpy ... >>>print(bpy.types.Composi

Re: Newbie question about Python syntax

2019-08-22 Thread Chris Angelico
On Thu, Aug 22, 2019 at 9:20 PM Paul St George wrote: > > On 22/08/2019 11:49, Cameron Simpson wrote: > > On 22Aug2019 09:34, Paul St George wrote: > >> I have the Python API for the Map Value Node here: > >> . > >> > >>

Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George
On 22/08/2019 11:49, Cameron Simpson wrote: On 22Aug2019 09:34, Paul St George wrote: I have the Python API for the Map Value Node here: . All well and good. Now I just want to write a simple line of code such as:

Re: Newbie question about Python syntax

2019-08-22 Thread Cameron Simpson
On 22Aug2019 09:34, Paul St George wrote: I have the Python API for the Map Value Node here: . All well and good. Now I just want to write a simple line of code such as: import bpy print(bpy.types.CompositorNodeMapVa

Re: newbie question

2019-08-01 Thread Sidney Langweil
On Thursday, August 1, 2019 at 7:57:31 AM UTC-7, Calvin Spealman wrote: > Sorry, but you can't. If you have two python modules, neither has access to > things in the other without an import. > > That's the whole point of an import. > > On Thu, Aug 1, 2019 at 10:30 AM Sidney Langweil > wrote: >

Re: newbie question

2019-08-01 Thread Calvin Spealman
Sorry, but you can't. If you have two python modules, neither has access to things in the other without an import. That's the whole point of an import. On Thu, Aug 1, 2019 at 10:30 AM Sidney Langweil wrote: > A Python script invokes a function in another file in the same directory. > > I would

Re: RE newbie question

2018-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2018 12:37:29 -0700, TUA wrote: > My intention is to implement a max. length of 8 for an input string. The > above works well in all other respects, but does allow for strings that > are too long. if len(input_string) > 8: raise ValueError('string is too long') -- Steve --

Re: RE newbie question

2018-04-18 Thread Albert-Jan Roskam
On Apr 18, 2018 21:42, TUA wrote: > > import re > > compval = 'A123456_8' > regex = '[a-zA-Z]\w{0,7}' > > if re.match(regex, compval): >print('Yes') > else: >print('No') > > > My intention is to implement a max. length of 8 for an input string. The > above works well in all other respect

Re: RE newbie question

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

Re: RE newbie question

2018-04-18 Thread Ian Kelly
On Wed, Apr 18, 2018 at 1:57 PM, Rob Gaddi wrote: > On 04/18/2018 12:37 PM, TUA wrote: >> >> import re >> >> compval = 'A123456_8' >> regex = '[a-zA-Z]\w{0,7}' >> >> if re.match(regex, compval): >> print('Yes') >> else: >> print('No') >> >> >> My intention is to implement a max. length of

Re: RE newbie question

2018-04-18 Thread Rob Gaddi
On 04/18/2018 12:37 PM, TUA wrote: import re compval = 'A123456_8' regex = '[a-zA-Z]\w{0,7}' if re.match(regex, compval): print('Yes') else: print('No') My intention is to implement a max. length of 8 for an input string. The above works well in all other respects, but does allow for

RE newbie question

2018-04-18 Thread TUA
import re compval = 'A123456_8' regex = '[a-zA-Z]\w{0,7}' if re.match(regex, compval): print('Yes') else: print('No') My intention is to implement a max. length of 8 for an input string. The above works well in all other respects, but does allow for strings that are too long. What is

Re: newbie question re classes and self

2017-03-29 Thread Rick Johnson
On Tuesday, March 28, 2017 at 3:09:45 AM UTC-5, loial wrote: > Can I pass self(or all its variables) to a class? > Basically, how do I make all the variables defined in self > in the calling python script available to the python class > I want to call? Your question, as presented, is difficult to

Re: newbie question re classes and self

2017-03-28 Thread Terry Reedy
On 3/28/2017 4:09 AM, loial wrote: Can I pass self(or all its variables) to a class? In Python, every argument to every function is an instance of some class. The function can access any attribute of the arguments it receives with arg.attribute. -- Terry Jan Reedy -- https://mail.python.o

Re: newbie question re classes and self

2017-03-28 Thread Peter Otten
loial wrote: > Can I pass self(or all its variables) to a class? > > Basically, how do I make all the variables defined in self in the calling > python script available to the python class I want to call? Inside a method you can access attributes of an instance as self.whatever: >>> class A: ..

Re: newbie question

2016-03-29 Thread Sven R. Kunze
On 28.03.2016 17:34, ast wrote: "Matt Wheeler" a écrit dans le message de news:mailman.92.1458825746.2244.python-l...@python.org... On Thu, 24 Mar 2016 11:10 Sven R. Kunze, wrote: On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s

Re: newbie question

2016-03-28 Thread ast
"Matt Wheeler" a écrit dans le message de news:mailman.92.1458825746.2244.python-l...@python.org... On Thu, 24 Mar 2016 11:10 Sven R. Kunze, wrote: On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) t > (1, 2, 3, 4) I suppose

Re: newbie question

2016-03-24 Thread Sven R. Kunze
On 24.03.2016 14:22, Matt Wheeler wrote: On Thu, 24 Mar 2016 11:10 Sven R. Kunze, wrote: On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) t (1, 2, 3, 4) I suppose that's the better solution in terms of safety. It has the added advantage that t

Re: newbie question

2016-03-24 Thread Grant Edwards
On 2016-03-24, Steven D'Aprano wrote: > On Thu, 24 Mar 2016 09:49 pm, David Palao wrote: > >> Hi, >> Use "eval": >> s = "(1, 2, 3, 4)" >> t = eval(s) > > Don't use eval unless you absolutely, categorically, 100% trust the source > of the string. And then still don't use it. :) eval is only safe

Re: newbie question

2016-03-24 Thread Steven D'Aprano
On Thu, 24 Mar 2016 09:49 pm, David Palao wrote: > Hi, > Use "eval": > s = "(1, 2, 3, 4)" > t = eval(s) Don't use eval unless you absolutely, categorically, 100% trust the source of the string. Otherwise, you are letting the person who provided the string run any code they like on your computer.

Re: newbie question

2016-03-24 Thread Matt Wheeler
On Thu, 24 Mar 2016 11:10 Sven R. Kunze, wrote: > On 24.03.2016 11:57, Matt Wheeler wrote: > import ast > s = "(1, 2, 3, 4)" > t = ast.literal_eval(s) > t > > (1, 2, 3, 4) > > I suppose that's the better solution in terms of safety. > It has the added advantage that the enqui

Re: newbie question

2016-03-24 Thread Steven D'Aprano
On Thu, 24 Mar 2016 09:39 pm, ast wrote: > Hi > > I have a string which contains a tupe, eg: > > s = "(1, 2, 3, 4)" > > and I want to recover the tuple in a variable t > > t = (1, 2, 3, 4) > > how would you do ? py> import ast py> ast.literal_eval("(1, 2, 3, 4)") (1, 2, 3, 4) -- Steven

Re: newbie question

2016-03-24 Thread Sven R. Kunze
On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) t (1, 2, 3, 4) I suppose that's the better solution in terms of safety. -- https://mail.python.org/mailman/listinfo/python-list

Re: newbie question

2016-03-24 Thread Tim Chase
On 2016-03-24 11:49, David Palao wrote: >> s = "(1, 2, 3, 4)" >> >> and I want to recover the tuple in a variable t >> >> t = (1, 2, 3, 4) >> >> how would you do ? > > Use "eval": > s = "(1, 2, 3, 4)" > t = eval(s) Using eval() has security implications. Use ast.literal_eval for safety instead:

Re: newbie question

2016-03-24 Thread Matt Wheeler
>>> import ast >>> s = "(1, 2, 3, 4)" >>> t = ast.literal_eval(s) >>> t (1, 2, 3, 4) On 24 March 2016 at 10:39, ast wrote: > Hi > > I have a string which contains a tupe, eg: > > s = "(1, 2, 3, 4)" > > and I want to recover the tuple in a variable t > > t = (1, 2, 3, 4) > > how would you do ? > >

Re: newbie question

2016-03-24 Thread ast
"David Palao" a écrit dans le message de news:mailman.86.1458816553.2244.python-l...@python.org... Hi, Use "eval": s = "(1, 2, 3, 4)" t = eval(s) Best Thank you -- https://mail.python.org/mailman/listinfo/python-list

Re: newbie question

2016-03-24 Thread David Palao
Hi, Use "eval": s = "(1, 2, 3, 4)" t = eval(s) Best 2016-03-24 11:39 GMT+01:00 ast : > Hi > > I have a string which contains a tupe, eg: > > s = "(1, 2, 3, 4)" > > and I want to recover the tuple in a variable t > > t = (1, 2, 3, 4) > > how would you do ? > > > -- > https://mail.python.org/mailma

Re: Newbie question about text encoding

2015-03-09 Thread Rustom Mody
On Monday, March 9, 2015 at 12:05:05 PM UTC+5:30, Steven D'Aprano wrote: > Chris Angelico wrote: > > > As to the notion of rejecting the construction of strings containing > > these invalid codepoints, I'm not sure. Are there any languages out > > there that have a Unicode string type that require

Re: Newbie question about text encoding

2015-03-08 Thread Chris Angelico
On Mon, Mar 9, 2015 at 5:34 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> As to the notion of rejecting the construction of strings containing >> these invalid codepoints, I'm not sure. Are there any languages out >> there that have a Unicode string type that requires that all >> codepoi

Re: Newbie question about text encoding

2015-03-08 Thread Steven D'Aprano
Chris Angelico wrote: > As to the notion of rejecting the construction of strings containing > these invalid codepoints, I'm not sure. Are there any languages out > there that have a Unicode string type that requires that all > codepoints be valid (no surrogates, no U+FFFE, etc)? U+FFFE and U+FFF

Re: Newbie question about text encoding

2015-03-08 Thread Marko Rauhamaa
Ben Finney : > Steven D'Aprano writes: > >> '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a > Unicode string of a lone surrogate should be an error. Then we're back to square one: >>> b'\x80'.decode('utf-8', errors='surrogateescape') '

Re: Newbie question about text encoding

2015-03-08 Thread random832
On Sun, Mar 8, 2015, at 22:09, Ben Finney wrote: > Steven D'Aprano writes: > > > '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a Unicode > string of a lone surrogate should be an error. > > Shouldn't the error type be a ValueError, though? T

Re: Newbie question about text encoding

2015-03-08 Thread Rustom Mody
On Monday, March 9, 2015 at 7:39:42 AM UTC+5:30, Cameron Simpson wrote: > On 07Mar2015 22:09, Steven D'Aprano wrote: > >Rustom Mody wrote: > >>[...big snip...] > >> Some parts are here some earlier and from my memory. > >> If details wrong please correct: > >> - 200 million records > >> - Containi

Re: Newbie question about text encoding

2015-03-08 Thread Chris Angelico
On Mon, Mar 9, 2015 at 1:09 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> '\udd00' should be a SyntaxError. > > I find your argument convincing, that attempting to construct a Unicode > string of a lone surrogate should be an error. > > Shouldn't the error type be a ValueError, though? The

Re: Newbie question about text encoding

2015-03-08 Thread Ben Finney
Steven D'Aprano writes: > '\udd00' should be a SyntaxError. I find your argument convincing, that attempting to construct a Unicode string of a lone surrogate should be an error. Shouldn't the error type be a ValueError, though? The statement is not, to my mind, erroneous syntax. -- \ “P

Re: Newbie question about text encoding

2015-03-08 Thread Cameron Simpson
On 07Mar2015 22:09, Steven D'Aprano wrote: Rustom Mody wrote: [...big snip...] Some parts are here some earlier and from my memory. If details wrong please correct: - 200 million records - Containing 4 strings with SMP characters - System made with python and mysql. SMP works with python, brea

Re: Newbie question about text encoding

2015-03-08 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> '\udd00' is a valid str object: >> >> Is it though? Perhaps the bug is not UTF-8's inability to encode lone >> surrogates, but that Python allows you to create lone surrogates in >> the first place. That's not a rhetorical q

Re: Newbie question about text encoding

2015-03-08 Thread Chris Angelico
On Mon, Mar 9, 2015 at 5:25 AM, Steven D'Aprano wrote: > Perhaps the bug is not UTF-8's inability to encode lone > surrogates, but that Python allows you to create lone surrogates in the > first place. That's not a rhetorical question. It's a genuine question. As to the notion of rejecting the co

Re: Newbie question about text encoding

2015-03-08 Thread Chris Angelico
On Mon, Mar 9, 2015 at 5:25 AM, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Chris Angelico : >> >>> Once again, you appear to be surprised that invalid data is failing. >>> Why is this so strange? U+DD00 is not a valid character. > > But it is a valid non-character code point. > >>> It is

Re: Newbie question about text encoding

2015-03-08 Thread Marko Rauhamaa
Steven D'Aprano : > Marko Rauhamaa wrote: >> '\udd00' is a valid str object: > > Is it though? Perhaps the bug is not UTF-8's inability to encode lone > surrogates, but that Python allows you to create lone surrogates in > the first place. That's not a rhetorical question. It's a genuine > questio

Re: Newbie question about text encoding

2015-03-08 Thread Steven D'Aprano
Rustom Mody wrote: > On Saturday, March 7, 2015 at 4:39:48 PM UTC+5:30, Steven D'Aprano wrote: >> Rustom Mody wrote: >> > This includes not just bug-prone-system code such as Java and Windows >> > but seemingly working code such as python 3. >> >> What Unicode bugs do you think Python 3.3 and abo

Re: Newbie question about text encoding

2015-03-08 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Chris Angelico : > >> Once again, you appear to be surprised that invalid data is failing. >> Why is this so strange? U+DD00 is not a valid character. But it is a valid non-character code point. >> It is quite correct to throw this error. > > '\udd00' is a valid str o

Re: Newbie question about text encoding

2015-03-08 Thread Chris Angelico
On Sun, Mar 8, 2015 at 7:09 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Once again, you appear to be surprised that invalid data is failing. >> Why is this so strange? U+DD00 is not a valid character. It is quite >> correct to throw this error. > > '\udd00' is a valid str object: > >>>>

Re: Newbie question about text encoding

2015-03-08 Thread Marko Rauhamaa
Chris Angelico : > Once again, you appear to be surprised that invalid data is failing. > Why is this so strange? U+DD00 is not a valid character. It is quite > correct to throw this error. '\udd00' is a valid str object: >>> '\udd00' '\udd00' >>> '\udd00'.encode('utf-32') b'\xff\xfe

Re: Newbie question about text encoding

2015-03-08 Thread Steven D'Aprano
Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Steven D'Aprano : >> >>> Marko Rauhamaa wrote: >>> That said, UTF-8 does suffer badly from its not being a bijective mapping. >>> >>> Can you explain? >> >> In Python terms, there are bytes objects b that don't satisfy: >> >>b.d

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 6:20 PM, Marko Rauhamaa wrote: > * it still isn't bijective between str and bytes: > >>>> '\udd00'.encode('utf-8', errors='surrogateescape') >Traceback (most recent call last): > File "", line 1, in >UnicodeEncodeError: 'utf-8' codec can't encode character

Re: Newbie question about text encoding

2015-03-07 Thread Rustom Mody
On Saturday, March 7, 2015 at 4:39:48 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > This includes not just bug-prone-system code such as Java and Windows but > > seemingly working code such as python 3. > > What Unicode bugs do you think Python 3.3 and above have? Literal/Legalisti

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Steven D'Aprano : > For those cases where you do wish to take an arbitrary byte stream and > round-trip it, Python now provides an error handler for that. > > py> import random > py> b = bytes([random.randint(0, 255) for _ in range(1)]) > py> s = b.decode('utf-8') > Traceback (most recent call

Re: Newbie question about text encoding

2015-03-07 Thread Rustom Mody
On Saturday, March 7, 2015 at 11:41:53 AM UTC+5:30, Terry Reedy wrote: > On 3/6/2015 11:20 AM, Rustom Mody wrote: > > > = > > pp = "💩" > > print (pp) > > = > > Try open it in idle3 and you get (at least I get): > > > > $ idle3 ff.py > > Traceback (most recent call last): > >Fil

Re: Newbie question about text encoding

2015-03-07 Thread Rustom Mody
On Saturday, March 7, 2015 at 11:49:44 PM UTC+5:30, Mark Lawrence wrote: > On 07/03/2015 17:16, Marko Rauhamaa wrote: > > Mark Lawrence: > > > >> It would clearly help if you were to type in the correct UK English > >> accent. > > > > Your ad-hominem-to-contribution ratio is alarmingly high. > > >

Re: Newbie question about text encoding

2015-03-07 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> That said, UTF-8 does suffer badly from its not being >>> a bijective mapping. >> >> Can you explain? > > In Python terms, there are bytes objects b that don't satisfy: > >b.decode('utf-8').encode('utf-8') == b Are

Re: Newbie question about text encoding

2015-03-07 Thread Dan Sommers
On Sat, 07 Mar 2015 19:00:47 +, Mark Lawrence wrote: > Isn't pathlib > https://docs.python.org/3/library/pathlib.html#module-pathlib > effectively a more recent attempt at smoothing or even removing (some > of) the bumps? Has anybody here got experience of it as I've never > used it? I almos

Re: Newbie question about text encoding

2015-03-07 Thread Albert-Jan Roskam
--- Original Message - > From: Chris Angelico > To: > Cc: "python-list@python.org" > Sent: Saturday, March 7, 2015 6:26 PM > Subject: Re: Newbie question about text encoding > > On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: >> See: >&

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Dan Sommers : > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that filesystems contain files in > hierarch

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 18:34, Dan Sommers wrote: On Sun, 08 Mar 2015 05:13:09 +1100, Chris Angelico wrote: On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: Correct. Linux pathnames a

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 5:34 AM, Dan Sommers wrote: > I think we're all agreeing: not all file systems are the same, and > Python doesn't smooth out all of the bumps, even for something that > seems as simple as displaying the names of files in a directory. And > that's *after* we've agreed that

Re: Newbie question about text encoding

2015-03-07 Thread Dan Sommers
On Sun, 08 Mar 2015 05:13:09 +1100, Chris Angelico wrote: > On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: >> On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: >> >>> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> Correct. Linux pathnames are octet strings regardless o

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 17:16, Marko Rauhamaa wrote: Mark Lawrence : It would clearly help if you were to type in the correct UK English accent. Your ad-hominem-to-contribution ratio is alarmingly high. Marko You've been a PITA ever since you first joined this list, what about it? -- My fellow Py

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 5:02 AM, Dan Sommers wrote: > On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: > >> On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: > >>> Correct. Linux pathnames are octet strings regardless of the locale. >>> >>> That's why Linux developers should refer to

Re: Newbie question about text encoding

2015-03-07 Thread Dan Sommers
On Sun, 08 Mar 2015 04:59:56 +1100, Chris Angelico wrote: > On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> Correct. Linux pathnames are octet strings regardless of the locale. >> >> That's why Linux developers should refer to filenames using bytes. >> Unfortunately, Python itself viola

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 4:50 AM, Marko Rauhamaa wrote: >> There are two things happening here: >> >> 1) The underlying file system is not UTF-8, and you can't depend on >> that, > > Correct. Linux pathnames are octet strings regardless of the locale. > > That's why Linux developers should refer to

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: >> File names encoded with Latin-X are quite commonplace even in UTF-8 >> locales. > > That is not a problem with UTF-8, though. I don't understand how > you're blaming UTF-8 for that. I'm saying it creates practical proble

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 4:14 AM, Marko Rauhamaa wrote: > See: > >$ mkdir /tmp/xyz >$ touch /tmp/xyz/ > \x80' >$ python3 >Python 3.3.2 (default, Dec 4 2014, 12:49:00) >[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux >Type "help", "copyright", "credits" or "license" for more

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Mark Lawrence : > It would clearly help if you were to type in the correct UK English > accent. Your ad-hominem-to-contribution ratio is alarmingly high. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Chris Angelico : > If you really REALLY can't use the bytes() type to work with something > that is, yaknow, bytes, then you could use an alternative encoding > that has a value for every byte. It's still not Unicode text, so it > doesn't much matter which encoding you use. But it's much better to

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 16:48, Marko Rauhamaa wrote: Mark Lawrence : On 07/03/2015 16:25, Marko Rauhamaa wrote: Here's an example: b = b'\x80' Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping from str objects to bytes objects. Python 2 might, Python 3 doesn't. Python

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 3:54 AM, Marko Rauhamaa wrote: > You can't operate on file names and text files using Python strings. Or > at least, you will need to add (nontrivial) exception catching logic. You can't operate on a JPG file using a Unicode string, nor an array of integers. What of it? You

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 3:54 AM, Marko Rauhamaa wrote: >> All you've proven is that there are bit patterns which are not UTF-8 >> streams... > > And that causes problems. Demonstrate. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Mar 8, 2015 at 3:25 AM, Marko Rauhamaa wrote: > Marko Rauhamaa wrote: >> That said, UTF-8 does suffer badly from its not being >> a bijective mapping. > >> Here's an example: >> >>b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 3:40 AM, Mark Lawrence wrote: >> Here's an example: >> >> b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >> from str objects to bytes objects. >> > > Python 2 might, Python 3 doesn't. He was talking about this line of code: b.de

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Mark Lawrence : > On 07/03/2015 16:25, Marko Rauhamaa wrote: >> Here's an example: >> >> b = b'\x80' >> >> Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping >> from str objects to bytes objects. > > Python 2 might, Python 3 doesn't. Python 3.3.2 (default, Dec 4 2014, 1

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 16:25, Marko Rauhamaa wrote: Chris Angelico : On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: Steven D'Aprano : Marko Rauhamaa wrote: That said, UTF-8 does suffer badly from its not being a bijective mapping. Can you explain? In Python terms, there are bytes object

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 3:25 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >>> Steven D'Aprano : >>> Marko Rauhamaa wrote: > That said, UTF-8 does suffer badly from its not being > a bijective mapping. Can you ex

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >> Steven D'Aprano : >> >>> Marko Rauhamaa wrote: >>> That said, UTF-8 does suffer badly from its not being a bijective mapping. >>> >>> Can you explain? >> >> In Python terms, there are bytes objects b that don't

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> That said, UTF-8 does suffer badly from its not being >>> a bijective mapping. >> >> Can you explain? > > In Python terms, there are bytes objects b that don't satisfy: > >b.decode('utf-

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Steven D'Aprano : > Marko Rauhamaa wrote: > >> That said, UTF-8 does suffer badly from its not being >> a bijective mapping. > > Can you explain? In Python terms, there are bytes objects b that don't satisfy: b.decode('utf-8').encode('utf-8') == b Marko -- https://mail.python.org/mailman/l

Re: Newbie question about text encoding

2015-03-07 Thread Steven D'Aprano
Marko Rauhamaa wrote: > That said, UTF-8 does suffer badly from its not being > a bijective mapping. Can you explain? As far as I am aware, every code point has one and only one valid UTF-8 encoding, and every UTF-8 encoding has one and only one valid code point. There are *invalid* UTF-8 encod

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 11:09, Steven D'Aprano wrote: Rustom Mody wrote: This includes not just bug-prone-system code such as Java and Windows but seemingly working code such as python 3. What Unicode bugs do you think Python 3.3 and above have? Methinks somebody has been drinking too much loony ju

Re: Newbie question about text encoding

2015-03-07 Thread Mark Lawrence
On 07/03/2015 12:02, Chris Angelico wrote: On Sat, Mar 7, 2015 at 10:53 PM, Marko Rauhamaa wrote: The main dream was a fixed-width encoding scheme. People thought 16 bits would be enough. The dream is so precious and true to us in the West that people don't want to give it up. So... use Pike,

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sat, Mar 7, 2015 at 10:53 PM, Marko Rauhamaa wrote: > The main dream was a fixed-width encoding scheme. People thought 16 bits > would be enough. The dream is so precious and true to us in the West > that people don't want to give it up. So... use Pike, or Python 3.3+? ChrisA -- https://mail

Re: Newbie question about text encoding

2015-03-07 Thread Marko Rauhamaa
Steven D'Aprano : > Rustom Mody wrote: >> My conclusion: Early adopters of unicode -- Windows and Java -- were >> punished for their early adoption. You can blame the unicode >> consortium, you can blame the babel of human languages, particularly >> that some use characters and some only (the equi

Re: Newbie question about text encoding

2015-03-07 Thread Chris Angelico
On Sat, Mar 7, 2015 at 10:09 PM, Steven D'Aprano wrote: > Stop using MySQL, which is a joke of a database[1], and use Postgres which > does not have this problem. I agree with the recommendation, though to be fair to MySQL, it is now possible to store full Unicode. Though personally, I think the

Re: Newbie question about text encoding

2015-03-07 Thread Steven D'Aprano
Rustom Mody wrote: > On Thursday, March 5, 2015 at 7:36:32 PM UTC+5:30, Steven D'Aprano wrote: [...] >> Chris is suggesting that going from BMP to all of Unicode is not the hard >> part. Going from ASCII to the BMP part of Unicode is the hard part. If >> you can do that, you can go the rest of the

Re: Newbie question about text encoding

2015-03-06 Thread Terry Reedy
On 3/6/2015 11:20 AM, Rustom Mody wrote: = pp = "💩" print (pp) = Try open it in idle3 and you get (at least I get): $ idle3 ff.py Traceback (most recent call last): File "/usr/bin/idle3", line 5, in main() File "/usr/lib/python3.4/idlelib/PyShell.py", line 1562, in m

Re: Newbie question about text encoding

2015-03-06 Thread Rustom Mody
On Friday, March 6, 2015 at 8:20:22 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: > > [snip example of an analogous situation with NULs] > > > Strawman. > > Sigh. If I had a dollar for every time somebody c

Re: Newbie question about text encoding

2015-03-06 Thread Steven D'Aprano
random...@fastmail.us wrote: > My point is there are very few > problems to which "count of Unicode code points" is the only right > answer - that UTF-32 is good enough for but that are meaningfully > impacted by a naive usage of UTF-16, to the point where UTF-16 is > something you have to be "saf

Re: Newbie question about text encoding

2015-03-06 Thread Chris Angelico
On Sat, Mar 7, 2015 at 3:20 AM, Rustom Mody wrote: > C's string is not bug-prone its plain buggy as it cannot represent strings > with nulls. > > I would not go that far for UTF-16. > It is bug-inviting but it can also be implemented correctly C's standard library string handling functions are re

Re: Newbie question about text encoding

2015-03-06 Thread Chris Angelico
On Sat, Mar 7, 2015 at 1:50 AM, Steven D'Aprano wrote: > Rustom Mody wrote: > >> On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: > > [snip example of an analogous situation with NULs] > >> Strawman. > > Sigh. If I had a dollar for every time somebody cried "Strawman!" when

Re: Newbie question about text encoding

2015-03-06 Thread Steven D'Aprano
Rustom Mody wrote: > On Friday, March 6, 2015 at 10:50:35 AM UTC+5:30, Chris Angelico wrote: [snip example of an analogous situation with NULs] > Strawman. Sigh. If I had a dollar for every time somebody cried "Strawman!" when what they really should say is "Yes, that's a good argument, I'm afr

Re: Newbie question about text encoding

2015-03-06 Thread random832
On Fri, Mar 6, 2015, at 09:11, Chris Angelico wrote: > To prevent people from putting three paragraphs of lipsum in and > calling it a username. Limiting by UTF-8 bytes or UTF-16 units works just as well for that. > So you truncate to the desired length, then if the first character of > the trimm

Re: Newbie question about text encoding

2015-03-06 Thread Chris Angelico
On Sat, Mar 7, 2015 at 1:03 AM, wrote: > On Fri, Mar 6, 2015, at 08:39, Chris Angelico wrote: >> Number of code points is the most logical way to length-limit >> something. If you want to allow users to set their display names but >> not to make arbitrarily long ones, limiting them to X code poin

Re: Newbie question about text encoding

2015-03-06 Thread random832
On Fri, Mar 6, 2015, at 08:39, Chris Angelico wrote: > Number of code points is the most logical way to length-limit > something. If you want to allow users to set their display names but > not to make arbitrarily long ones, limiting them to X code points is > the safest way (and preferably do an N

  1   2   3   4   5   6   7   8   9   10   >