python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
I run python33 scrupt SVtxt.py from Windows command line I want to print out the file contents to stdout. File contents: Vi kan inte längre underordna den vinster... Python script sentences i have tries to use: f=open('C:\Python33\Scripts\lang\langu\svtxt.txt','r') linef=f.readlines() f.close() print(linef)#gives error print(linef).decode(utf-8,ignore)#gives error ERROR: c:\Python33\Scripts\lang\langupython SVtxt.py Traceback (most recent call last): File SVtxt.py, line 8, in module print(linef).decode(utf-8,ignore) File C:\Python33\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 91-92: -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
The answer is on page:https://docs.python.org/3.3/howto/unicode.html#reading-and-writing-unicode-data The correct code: f=open('C:\Python33\Scripts\lang\langu\svtxt.txt','r', encoding='utf-8') linef=f.readlines() print(repr(linef)) -- https://mail.python.org/mailman/listinfo/python-list
Question about metacharacter '*'
Hi, I just begin to learn Python. I do not see the usefulness of '*' in its description below: The first metacharacter for repeating things that we'll look at is *. * doesn't match the literal character *; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once. For example, ca*t will match ct (0 a characters), cat (1 a), caaat (3 a characters), and so forth. It has to be used with other search constraints? Thanks, -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On Sun, Jul 6, 2014 at 4:51 AM, rxjw...@gmail.com wrote: Hi, I just begin to learn Python. I do not see the usefulness of '*' in its description below: The first metacharacter for repeating things that we'll look at is *. * doesn't match the literal character *; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once. For example, ca*t will match ct (0 a characters), cat (1 a), caaat (3 a characters), and so forth. It has to be used with other search constraints? (BTW, this is a regexp question, not really a Python question per se.) That's usually when it's useful, yeah. For example, [0-9] matches any of the characters 0 through 9. So to match a natural number written in decimal form, we might use the regexp [0-9][0-9]*, which matches the strings 1, 12, and 007, but not or Jeffrey. Another useful one is `.*` -- `.` matches exactly one character, no matter what that character is. So, `.*` matches any string at all. The power of regexps stems from the ability to mix and match all of the regexp pieces in pretty much any way you want. -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Why is it different from the example on the tutorial?
Hi, I type the following sample codes on Python, but it echoes differently. Regular expressions are compiled into pattern objects, which have methods for various operations such as searching for pattern matches or performing string substitutions. import re p = re.compile('ab*') p _sre.SRE_Pattern object at 0x... What I get on Python console: $ python Python 2.7.5 (default, Oct 2 2013, 22:34:09) [GCC 4.8.1] on cygwin Type help, copyright, credits or license for more information. import re p = re.compile('ab*') File stdin, line 1 p = re.compile('ab*') ^ SyntaxError: invalid syntax Thanks, -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On 2014-07-06 05:13, rxjw...@gmail.com wrote: What I get on Python console: $ python Python 2.7.5 (default, Oct 2 2013, 22:34:09) [GCC 4.8.1] on cygwin Type help, copyright, credits or license for more information. import re p = re.compile('ab*') File stdin, line 1 p = re.compile('ab*') ^ SyntaxError: invalid syntax Are you sure that you copied/pasted that directly from the console instead of transcribing it with some mistake? I just did the same thing at the console and it worked perfectly fine $ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. import re p = re.compile('ab*') -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
gintare g.statk...@gmail.com Wrote in message: The answer is on page:https://docs.python.org/3.3/howto/unicode.html#reading-and-writing-unicode-data The correct code: f=open('C:\Python33\Scripts\lang\langu\svtxt.txt','r', encoding='utf-8') linef=f.readlines() print(repr(linef)) But naturally the path should be fixed as well. Either use forward slashes, escape the backslashes, or use a raw string. f=open( r'C:\Python33\Scripts\lang\langu\svtxt.txt','r', encoding='utf-8') -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Webinar on How to Manage Your Python Open Source
Hey everyone, We are conducting a webinar this Wednesday about How to Manage Your Python Open Source. the session will be mainly about challenge of managing open-source components that are embedded in your Python projects. If you are interested please register in this form: https://attendee.gotowebinar.com/register/7034105107342895362 we hope to see you there :) Rafi, WhiteSource software. -- https://mail.python.org/mailman/listinfo/python-list
Re: cx_freeze and temporary files - security related question
On 5/21/14, 12:42 PM, Nagy László Zsolt wrote: I need to create an application for Windows 7 that runs from a flash drive. This program would be used to create remote backups of the pendrive. The pendrive contains sensitive data, so when I plug in the pendrive and run the program to make a backup, it should not leave any trace of operation on the windows system. The information is so sensitive that I was forbidden to use cloud storage. I was also forbidden to make backups to a local drive, or leave any trace on the host windows system. The question is this: if I create this program with Python 3.4 and cx_Freeze, then what should I expect. When the user starts the cx_freeze-d program from the flash drive, will it create temporary files on the system drive? Will it leave log files or store any permanent or temporary data on the system drive (maybe in the user's tmp folder) that can later be used to tell what drive was mounted, with what parameters the program was started etc. Thanks I am not sure about what temp files python might leave around, but if you are being ultimately paranoid about this, one risk that will be present is the possibility of leaving traces of data in the swap file. If the program doesn't specifically prohibit it, anything that is brought into memory (and the act of reading the pendrive will do this) might end up in the swap file. I can't imagine python having a run time option to force it to disable the swap file. If the data is as sensitive as they seem to want to treat it, perhaps you should follow the procedures of classified computing, which says that any storage medium exposed to classified computing becomes classified. This would say that you would use a dedicated machine to do these backups, and after doing them, you remove the hard disk from the machine and lock it up, only to be taken out for later backups. This level of paranoia says you don't need to be as concerned about figuring out what traces might be left, you assume they are and lock them up. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 8:54:42 AM UTC-4, Tim Chase wrote: On 2014-07-06 05:13, rxjw...@gmail.com wrote: What I get on Python console: $ python Python 2.7.5 (default, Oct 2 2013, 22:34:09) [GCC 4.8.1] on cygwin Type help, copyright, credits or license for more information. import re p = re.compile('ab*') File stdin, line 1 p = re.compile('ab*') ^ SyntaxError: invalid syntax Are you sure that you copied/pasted that directly from the console instead of transcribing it with some mistake? I just did the same thing at the console and it worked perfectly fine $ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. import re p = re.compile('ab*') -tkc Thanks. It did be caused by unclear copypaste. I shall be careful in future. When I enter: counter=100 counter 100 When I get match result: pattern='abcd' prog = re.compile(pattern) string='abcd' result = prog.match(string) result _sre.SRE_Match object at 0x6eda5e0 result.group(0) 'abcd' It looks like 'result' is different from a simple 'counter' variable. I do not yet find the definition of 'result' object. What do you call 'result' object? Where can I find it (what topic would be in a tutorial)? Thanks, -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote: When I get match result: pypattern='abcd' pyprog = re.compile(pattern) pystring='abcd' pyresult = prog.match(string) pyresult _sre.SRE_Match object at 0x6eda5e0 pyresult.group(0) 'abcd' It looks like 'result' is different from a simple 'counter' variable. I do not yet find the definition of 'result' object. What do you call 'result' object? Where can I find it (what topic would be in a tutorial)? Thanks, One of the most powerful features of Python,,, for the noob,,, be documentation strings. With Python you need not buy expensive books, or venture into seedy and dangerous alley ways of the inter-webs, no, all you need to do is do that which any young and inexperienced lad would do when he finds himself in a troubling situation: YELL FOR HELP! The built-in function help will answer all your questions,,, considering you ask the correct questions of course!,,, but always remember the advice of a wise man and don't become the boy who cried wolf one too many times! -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On 06/07/2014 14:38, rxjw...@gmail.com wrote: On Sunday, July 6, 2014 8:54:42 AM UTC-4, Tim Chase wrote: On 2014-07-06 05:13, rxjw...@gmail.com wrote: What I get on Python console: $ python Python 2.7.5 (default, Oct 2 2013, 22:34:09) [GCC 4.8.1] on cygwin Type help, copyright, credits or license for more information. import re p = re.compile('ab*') File stdin, line 1 p = re.compile('ab*') ^ SyntaxError: invalid syntax Are you sure that you copied/pasted that directly from the console instead of transcribing it with some mistake? I just did the same thing at the console and it worked perfectly fine $ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. import re p = re.compile('ab*') -tkc Thanks. It did be caused by unclear copypaste. I shall be careful in future. When I enter: counter=100 counter 100 When I get match result: pattern='abcd' prog = re.compile(pattern) string='abcd' result = prog.match(string) result _sre.SRE_Match object at 0x6eda5e0 result.group(0) 'abcd' It looks like 'result' is different from a simple 'counter' variable. I do not yet find the definition of 'result' object. What do you call 'result' object? Where can I find it (what topic would be in a tutorial)? Thanks, help(result) Help on SRE_Match object: class SRE_Match(builtins.object) | The result of re.match() and re.search(). etc https://docs.python.org/3/library/re.html#module-re https://docs.python.org/3/library/re.html#match-objects https://docs.python.org/3/library/re.html#re.match https://docs.python.org/3/library/re.html#re.search https://docs.python.org/3/library/re.html#regular-expression-examples A slight aside, would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
In article 21e704ee-648b-423d-8682-11cb310a3...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote: When I get match result: pypattern='abcd' pyprog = re.compile(pattern) pystring='abcd' pyresult = prog.match(string) pyresult _sre.SRE_Match object at 0x6eda5e0 pyresult.group(0) 'abcd' It looks like 'result' is different from a simple 'counter' variable. I do not yet find the definition of 'result' object. What do you call 'result' object? Where can I find it (what topic would be in a tutorial)? Thanks, One of the most powerful features of Python,,, for the noob,,, be documentation strings. I guess I must still be a noob, because I still find them pretty useful! More generically, Python supports introspection, which means you can ask an object to tell you things about itself. Let's say you've got an object, foo. Here's some useful things you can do to learn more about it: * As Rick points out, you can do help(foo). This is probably the place to start. * You can print dict(foo), which just prints out the attributes the object has. This is really handy when you vaguely remember that a class has some operation, but can't remember the exact name. For example, I use two different database packages, and can never remember which has sort() and which has order_by(). * You can print foo itself, to find out its value, but this can get tricky, since sometimes objects print themselves in confusing ways. Printing repr(foo) will usually get you more detail. * You can print type(foo), to find out exactly what it is (useful when even printing repr() doesn't explain what's going on). -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Mon, Jul 7, 2014 at 12:34 AM, Roy Smith r...@panix.com wrote: * You can print type(foo), to find out exactly what it is (useful when even printing repr() doesn't explain what's going on). And very VERY occasionally, print(id(type(foo))) comes in handy, because two types might look the same, but an isinstance check looks (modulo subclassing) at type identity. :) But yes, the info Roy listed is normally what you'll be wanting. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On 06/07/2014 15:34, Roy Smith wrote: * You can print foo itself, to find out its value, but this can get tricky, since sometimes objects print themselves in confusing ways. Printing repr(foo) will usually get you more detail. For the OP the pretty print module is usually better than plain old print https://docs.python.org/3/library/pprint.html#module-pprint. I use it like this from pprint import pprint as pp The iPython shell (and presumably others as well) also does a better job of displaying objects than print. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
On Sunday, July 6, 2014 4:05:10 AM UTC-5, gintare wrote: The correct code: f=open(snip-path,'r', encoding='utf-8') linef=f.readlines() print(repr(linef)) Yes but do you understand why? And even if you DO understand why, you should explain the details because the neophytes are always watching! _ _ o_O? ...what, me worry? Now don't misunderstand me, i am happy that you took the time to report to us that you found the answer! Yes, nothing is more aggravating than writing a long, thoughtful, and elegant answer, and then have the OP come back and say: Oh i found the answer, but thanks anyway But really, kudos to you for at least making the effort to report. Because the only thing worse than a report without context is no report at all! Indeed, then we end up with unresolved threads and our community mojo suffers but i digress! Now, we must explain WHY this new code works, and WHY the old code failed. SIMPLE! file.readlines() returns a list, with each value of the list representing a line of the file. Nothing wrong with using readlines() of course, UNTIL you try to pass the value of readlines into the print() function, ah-aH-AH! So the direct reason for failure is due to the fact that the print() function ONLY handles strings, not list objects. So in light of this problem there are a few solutions: 1. Cast the list into a string, which you did using the repr() function, although you can also use the str() function, or use string formatting if formatting makes sense (in this case formatting does not make sense). 2. Use a different method of the file object which returns a string instead of a list-of-lines. Your code seems to make no use of line-ified-data-structures, so why burn cycles creating one? PS: We could use a few more members of the female persuasion in this community, so thanks for dropping by and hope to see you posting in the future! We desperately need something fair to offset the reeking of smelly socks, stinky armpits, and the stomach churning *stench* of illogical naming conventions! -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 10:18:53 AM UTC-4, Rick Johnson wrote: On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote: When I get match result: pypattern='abcd' pyprog = re.compile(pattern) pystring='abcd' pyresult = prog.match(string) pyresult _sre.SRE_Match object at 0x6eda5e0 pyresult.group(0) 'abcd' It looks like 'result' is different from a simple 'counter' variable. I do not yet find the definition of 'result' object. What do you call 'result' object? Where can I find it (what topic would be in a tutorial)? Thanks, One of the most powerful features of Python,,, for the noob,,, be documentation strings. With Python you need not buy expensive books, or venture into seedy and dangerous alley ways of the inter-webs, no, all you need to do is do that which any young and inexperienced lad would do when he finds himself in a troubling situation: YELL FOR HELP! The built-in function help will answer all your questions,,, considering you ask the correct questions of course!,,, but always remember the advice of a wise man and don't become the boy who cried wolf one too many times! Thanks. I do not want to waste everyone's time. For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. (Sorry again, that problem may be about Cygwin, not Python. Excuse me to mention that here. Of course, your help post consumes your time. Thanks again. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On 2014-07-06 13:09, Devin Jeanpierre wrote: On Sun, Jul 6, 2014 at 4:51 AM, rxjw...@gmail.com wrote: Hi, I just begin to learn Python. I do not see the usefulness of '*' in its description below: The first metacharacter for repeating things that we'll look at is *. * doesn't match the literal character *; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once. For example, ca*t will match ct (0 a characters), cat (1 a), caaat (3 a characters), and so forth. It has to be used with other search constraints? (BTW, this is a regexp question, not really a Python question per se.) That's usually when it's useful, yeah. For example, [0-9] matches any of the characters 0 through 9. So to match a natural number written in decimal form, we might use the regexp [0-9][0-9]*, which matches the strings 1, 12, and 007, but not or Jeffrey. Another useful one is `.*` -- `.` matches exactly one character, no matter what that character is. So, `.*` matches any string at all. Not quite. It won't match a '\n' unless the DOTALL flag is turned on. The power of regexps stems from the ability to mix and match all of the regexp pieces in pretty much any way you want. -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: Flashlights [was Re: PEP8 and 4 spaces]
On Saturday, July 5, 2014 5:15:32 AM UTC-5, Steven D'Aprano wrote: (By the way, outside of the USA, flashlights in the rest of the English- speaking world are usually called torches, so called because, like the old-fashioned burning torch, they provide light.) Well Steven all i can hope is that one day you and i will be working on a project together, and you will ask me for a touch, and when i return with a petrol soaked rag burning on the end of twig and proceed to light your hair on fire, hopefully at that moment, you will THEN gain a healthy respect for logical naming conventions! You see, just as a proper programming language utilize the punishments of Exceptions for illogical behaviors, life utilizes the power of pain for even greater effect. Ah, what's that old adage about doing the same things over and over but expecting different results? Oh well, maybe someone can chime in... SHALL WE RINSE AND REPEAT MR.D'APRANO? A few minutes googling would have given you the answer: flashlights are called flashlights because originally you could only flash them on and off. Due to the high power requirements and the low battery capacities at the time, leaving the torch switched on would burn out the filament, exhaust the battery, or both. So what you're telling me is that in the early days of the portable light the function of the device was so terrible that the best all one could hope for was limited intermittent functionality with a great chance of destroying the device simply in the course of its normal use? Wow, and people actually paid money for these devices? Sounds like window 95 all over again! SNIP HISTORY LESSON *yawn* So far from being an illogical term, the name flashlight actually gives you a glimpse into the historical background of the invention. Yes, because when my power goes out, and i need to get to the electrical panel during a torrential rainstorm, at 2am in the morning, after a long day working in the company of idiots, and then coming home to a nagging significant other, and then my dog dies... whist i tromp through the mud and the muck, at least my mind will be at peace knowing the historical significance of an illogical naming convention coined for a device that was so impractical as to render itself completely useless... THANKS FLASHLIGHT @_@! -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
rxjw...@gmail.com wrote: I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. To quit help try hitting the 'q' key. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 9:34:44 AM UTC-5, Roy Smith wrote: * You can print dict(foo), which just prints out the attributes the object has. Looks like a typo there. I think you probably meant to say dir(foo) INTERACTIVE SESSION: Python 2.x py l = range(5) py l [0, 1, 2, 3, 4] py dict(l) Traceback (most recent call last): File pyshell#2, line 1, in module dict(l) TypeError: cannot convert dictionary update sequence element #0 to a sequence py dir(l) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
In related news, the regexp I gave for numbers will match 1a. -- Devin On Sun, Jul 6, 2014 at 8:32 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 2014-07-06 13:09, Devin Jeanpierre wrote: On Sun, Jul 6, 2014 at 4:51 AM, rxjw...@gmail.com wrote: Hi, I just begin to learn Python. I do not see the usefulness of '*' in its description below: The first metacharacter for repeating things that we'll look at is *. * doesn't match the literal character *; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once. For example, ca*t will match ct (0 a characters), cat (1 a), caaat (3 a characters), and so forth. It has to be used with other search constraints? (BTW, this is a regexp question, not really a Python question per se.) That's usually when it's useful, yeah. For example, [0-9] matches any of the characters 0 through 9. So to match a natural number written in decimal form, we might use the regexp [0-9][0-9]*, which matches the strings 1, 12, and 007, but not or Jeffrey. Another useful one is `.*` -- `.` matches exactly one character, no matter what that character is. So, `.*` matches any string at all. Not quite. It won't match a '\n' unless the DOTALL flag is turned on. The power of regexps stems from the ability to mix and match all of the regexp pieces in pretty much any way you want. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
In article 6fd77d6a-3487-474b-bb96-8da6ab800...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: On Sunday, July 6, 2014 9:34:44 AM UTC-5, Roy Smith wrote: * You can print dict(foo), which just prints out the attributes the object has. Looks like a typo there. I think you probably meant to say dir(foo) This is true. Good catch. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 10:03:48 AM UTC-5, rxj...@gmail.com wrote: Thanks. I do not want to waste everyone's time. Oh NOW you tell us! I could be ranting about flashlights, but here i am wasting time with you again! For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. How about YOU confirm your OWN usage. I am confident the help function works just fine, can you prove otherwise? We're here to help not to write code for you like slaves. Remember GIGO! After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. Surely you have a simple Python command line available? Last i heard GvR was giving them away for free! Can you open one and try some interactive musings? If the only tool in your toolbox is a hammer, well, you know the rest... -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 5:43:55 PM UTC+5:30, rxj...@gmail.com wrote: Hi, I type the following sample codes on Python, but it echoes differently. Regular expressions are compiled into pattern objects, which have methods for various operations such as searching for pattern matches or performing string substitutions. import re p = re.compile('ab*') p What I get on Python console: $ python Python 2.7.5 (default, Oct 2 2013, 22:34:09) [GCC 4.8.1] on cygwin Type help, copyright, credits or license for more information. import re p = re.compile('ab*') File stdin, line 1 p = re.compile('ab*') ^ SyntaxError: invalid syntax 1. For *using* regular exps match is fine For *hacking in the interpreter* I find findall more convenient. match and findall take the same arguments 2. I wouldn't bother with compile at least at the start 3. Use raw strings for patterns even if it does not seem necessary (below) $ python Python 2.7.7 (default, Jun 3 2014, 16:16:56) [GCC 4.8.3] on linux2 Type help, copyright, credits or license for more information. from re import findall findall(r'ab*', 'abcd') ['ab'] findall(r'ab*', 'abcdab') ['ab', 'ab'] findall(r'ab*', 'abcdabbb') ['ab', 'abbb'] -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
On 7/6/2014 10:52 AM, Rick Johnson wrote: So the direct reason for failure is due to the fact that the print() function ONLY handles strings, not list objects. print(object()) object object at 0x020D2140 print(['abc', 'cdf']) ['abc', 'cdf'] Since the original poster did not copy the traceback from the print error, it is unclear what the error was. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On Sunday, July 6, 2014 10:50:13 AM UTC-5, Devin Jeanpierre wrote: In related news, the regexp I gave for numbers will match 1a. Well of course it matched, because your pattern defines one or more consecutive digits. So it will match the 1 of 1a and the 11 of 11a likewise. As an aside i prefer to only utilize a character set when nothing else will suffice. And in this case r[0-9][0-9]* can be expressed just as correctly (and less noisy IMHO) as r\d\d*. INTERACTIVE SESSION: Python 2.x # Note: Grouping used for explicitness. # # Using character sets: import re re.search(r'([0-9][0-9]*)', '1a').groups() ('1',) re.search(r'([0-9][0-9]*)', '11a').groups() ('11',) re.search(r'([0-9][0-9]*)', '111aaa222').groups() ('111',) # # Same result without charactor sets: re.search(r'(\d\d*)', '1a').groups() ('1',) re.search(r'(\d\d*)', '11a').groups() ('11',) re.search(r'(\d\d*)', '111aaa222').groups() ('111',) -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
[CONTINUED FROM LAST REPLY...] Likewise if your intent is to filter out any match strings which contain non-digits, then define the start and stop points of the pattern: # Match only if all are digits re.match(r'\d\d*$', '111aaa222') # fails # Match only if all are digits and, # allow leading white-space re.match(r'\s*\d\d*$', ' 111') _sre.SRE_Match object at 0x026D8410 # But not trailing space! re.match(r'\s*\d\d*$', ' 111 ') # fails -- https://mail.python.org/mailman/listinfo/python-list
How do you use `help` when write your code
Hi Pythonistas I often heard people mention use help(ob) as a way of documentation look up. Personally I seldom/never do that. My normal workflow is use ipython, obj? or obj?? for quick look up or use docs.python.org for a detailed read. Do you use `help`? How does it integrate into your workflow? Or instead, what similar tools do you use? Regards. shiyao -- 吾輩は猫である。ホームーページはhttp://introo.me。 -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
In article d8f8d76d-0a47-4f59-8f09-da2a44cc1...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: As an aside i prefer to only utilize a character set when nothing else will suffice. And in this case r[0-9][0-9]* can be expressed just as correctly (and less noisy IMHO) as r\d\d*. Even better, r\d+ re.search(r'(\d\d*)', '111aaa222').groups() ('111',) re.search(r'(\d+)', '111aaa222').groups() ('111',) Oddly enough, I prefer character sets to the backslash notation, but I suppose that's largely because when I first learned regexes, that new-fangled backslash stuff hadn't been invented yet. :-) I know I've said this before, but people should put more effort into learning regex. There are lots of good tools in Python (startswith, endswith, split, in, etc) which handle many of the most common regex use cases. Regex is also not as easy to use in Python as it is in a language like Perl where it's baked into the syntax. As a result, pythonistas tend to shy away from regex, and either never learn the full power, or let their skills grow rusty. Which is a shame, because for many tasks, there's no better tool. -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
On Sunday, July 6, 2014 11:14:26 AM UTC-5, Terry Reedy wrote: On 7/6/2014 10:52 AM, Rick Johnson wrote: So the direct reason for failure is due to the fact that the print() function ONLY handles strings, not list objects. print(object()) object object at 0x020D2140 print(['abc', 'cdf']) ['abc', 'cdf'] Hmm, you are correct Terry, i must have been confusing file#write() and print() when i wrote all that nonsense. Thanks for pointing out the error. Since the original poster did not copy the traceback from the print error, it is unclear what the error was. I'm wondering what she is expecting this line to do: print(linef).decode(utf-8,ignore) My understanding is that print is a one way destination to a stream, and the only return value would be the default None. Urm, last time i got myself into trouble by not testing, not letting that happen again! O:-) INTERACTIVE SESSION: Python 2.x py from __future__ import print_function py print([1,2,3]) [1, 2, 3] py print(print([1,2,3])) [1, 2, 3] None py returnvalue = print([1,2,3]) [1, 2, 3] py repr(returnvalue) 'None' Seems like she'd better do the decoding before printing, or am i wrong again? -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On Sunday, July 6, 2014 11:47:38 AM UTC-5, Roy Smith wrote: Even better, r\d+ re.search(r'(\d\d*)', '111aaa222').groups() ('111',) re.search(r'(\d+)', '111aaa222').groups() ('111',) Yes, good catch! I had failed to reduce your original pattern down to it's most fundamental aspects for the sake of completeness, and instead, opted to modify it in a manner that mirrored your example. Oddly enough, I prefer character sets to the backslash notation, but I suppose that's largely because when I first learned regexes, that new-fangled backslash stuff hadn't been invented yet. :-) Ha, point taken! :-) Character sets really shine when you need a fixed range of letters or numbers which are NOT defined by one of the special characters of \d \D \W \w, etc... Say you want to match any letters between c and m or the digits between 3 and 6. Defining that pattern using OR'd char literals would be a massive undertaking! Another great use of character sets is skipping chars that don't match a target. For instance, a python comment will start with one hash char and proceedeth to the end of the line,,, which when accounting for leading white-space,,, could be defined by the pattern: r'\s*#[^\n]' Regex is also not as easy to use in Python as it is in a language like Perl where it's baked into the syntax. As a result, pythonistas tend to shy away from regex, and either never learn the full power, or let their skills grow rusty. Which is a shame, because for many tasks, there's no better tool. Agreed, but unfortunately like many other languages, Python has decided to import all the illogical of regex syntax from other languages instead of creating a new regex syntax that is consistent and logical. They did the same thing with Tkinter, and what a nightmare! And don't misunderstand my statements, i don't intend that we should create a syntax of verbosity, NO, we *CAN* keep the syntax succinct whist eliminating the illogical and inconsistent aspects that plague our patterns. Will regex ever be easy to learn, probably not, but they can be easier to use if only we put on our big boy pants and decide to do something about it! -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On Mon, 07 Jul 2014 00:36:23 +0800, Shiyao Ma wrote: Hi Pythonistas I often heard people mention use help(ob) as a way of documentation look up. Personally I seldom/never do that. My normal workflow is use ipython, obj? or obj?? for quick look up or use docs.python.org for a detailed read. Do you use `help`? How does it integrate into your workflow? I frequently use the help() function. (By the way, a little trivia for you: although the help function is in the built-in namespace, it is not actually a built-in! When you start Python interactively, the site.py script runs automatically, creates the help() function, and monkey-patches it into the builtins namespace.) I rarely use ipython, I use the regular Python interactive interpreter, so obj? and obj?? aren't an option. My usual workflow is to have at least one Python interpreter open at all times. If I don't remember the parameters for a method or function, I'll call help(class.method) or help(function). If I'm not sure what the method is called, I'll usually call help(class) or help(module). If there are too many things in the class or module, I'll use dir() to inspect it first. I have a monkey-patched version of dir() which takes a second argument, a glob, to filter the list of names returned: py len(dir(os)) # Too much! 312 py dir(os, 'env') ['_putenv', '_unsetenv', 'environ', 'environb', 'getenv', 'getenvb', 'putenv', 'supports_bytes_environ', 'unsetenv'] py dir(os, 'env*') ['environ', 'environb'] -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On Sunday, July 6, 2014 12:38:23 PM UTC-5, Rick Johnson wrote: r'\s*#[^\n]' Well, there i go not testing again! r'\s*#[^\n]*' -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On 2014-07-06 17:52, Steven D'Aprano wrote: I have a monkey-patched version of dir() which takes a second argument, a glob, to filter the list of names returned: py len(dir(os)) # Too much! 312 py dir(os, 'env') ['_putenv', '_unsetenv', 'environ', 'environb', 'getenv', 'getenvb', 'putenv', 'supports_bytes_environ', 'unsetenv'] py dir(os, 'env*') ['environ', 'environb'] And for those of us that don't have Steven's monkey-patched dir() call, I tend to do it with a list comprehension: [s for s in dir(obj) if 'env' in s] {output here} This works nicely for even more complex tests: [s for s in dir(obj) if not s.startswith('_')] {list of public properties/methods} [s for s in dir(obj) if callable(getattr(obj, s))] {list of callable attributes} [s for s in dir(obj) if isinstance(getattr(obj, s), basestring)] {list of string attributes} -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On 06/07/2014 16:03, rxjw...@gmail.com wrote: Thanks. I do not want to waste everyone's time. For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. (Sorry again, that problem may be about Cygwin, not Python. Excuse me to mention that here. Of course, your help post consumes your time. Thanks again. Don't bother about wasting our time as that's what we're here for :) There is a tutor mailing list that you might feel more comfortable on. See https://mail.python.org/mailman/listinfo/tutor or gmane.comp.python.tutor -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
What is the difference between matchObj.group() and matchObj.group(0)
Hi, I cannot get the difference between matchObj.group() and matchObj.group(0), Although there definitions are obvious different. And group() mentions 'tuple'. tuple means all the elements in line object? Match Object Methods Description group(num=0) This method returns entire match (or specific subgroup num) groups() This method returns all matching subgroups in a tuple (empty if there weren't any) I run the following code. Even I add more words to line object, Both have the same output. Could you clarify this question? Thanks again. #!/usr/bin/python import re line = Cats are smarter than dogs matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I) if matchObj: print matchObj.group() : , matchObj.group() print matchObj.group(1) : , matchObj.group(1) print matchObj.group(2) : , matchObj.group(2) else: print No match!! -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On Sunday, July 6, 2014 11:36:23 AM UTC-5, Shiyao Ma wrote: I often heard people mention use help(ob) as a way of documentation look up. Personally I seldom/never do that. My normal workflow is use ipython, obj? or obj?? for quick look up or use docs.python.org for a detailed read. Do you use `help`? How does it integrate into your workflow? Or instead, what similar tools do you use? For me i use a very simple graphical IDE for writing code, and i have a Python interactive console for testing snippets here or there when needed. I just abhor bloatware like Eclise! I also have no use for debuggers or line breaks or any of that childish nonsense. *Real* programmers possess keen detective that can root out bugs with nothing more than a few well placed print statements and some good old fashioned eyeball analysis. Besides, writing rock solid interfaces is prerequisite for programmer happiness. That means type checking inputs to function and classes so you don't propagate errors ten miles from the source of the problem before they get raised by Python (Tkinter i'm looking at angrily you now!), then you spend two day analyzing miles of implicit trace-back messages only to find out a parameter was illegal and could have been caught at input! ARE YOU KIDDING ME! And, as Mr.D'Aprano has stated, many of the built-in functions like dir are in need of refining. But i go a step further than mere monkey patching, and have decided long ago that too much of the introspection of Python is broken in ways that can only be repaired via an introspection mini-language, which i have incorporated directly into my custom shell. Besides, who really enjoys typing help(obj) or dir(obj) Both of those function require more effort to type than the information for which they provide, much of which is too verbose anyhow. I mean really, what is GvR's excuse for not adding some filtering to dir? He could do it in a backwards compatible manner, but no, he refuses, and instead, decides to fracture a community over a print function! BUT I DIGRESS! And i've never used ipyhon, but if that question mark does what i think it does then i'm yet again reminded that great minds do, in fact, think alike! What i'm saying is that the built-in functions of help, dir, type, id, repr, str, etc... are enough for the neophyte however they are woefully inadequate for a pythonista like myself. In fact, the more i use this language the more i realize how much i need to change to make it useful for me, which reminds me that i need to get cracking on that fork again. Although i don't know why i bother to mention that fork anyway since it will most likely be my little private toy anyway. I have yet to be convinced that this community deserves any of my contributions, and instead, they will suffer my grievances. -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
In article 53b98cf2$0$29985$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I have a monkey-patched version of dir() which takes a second argument, a glob, to filter the list of names returned: Neat idea, but globs are for wimps. All the cool kids are using regexes. See that other thread over there == -- https://mail.python.org/mailman/listinfo/python-list
How to write this repeat matching?
Hi, On Python website, it says that the following match can reach 'abcb' in 6 steps: . A step-by-step example will make this more obvious. Let's consider the expression a[bcd]*b. This matches the letter 'a', zero or more letters from the class [bcd], and finally ends with a 'b'. Now imagine matching this RE against the string abcbd. The end of the RE has now been reached, and it has matched abcb. This demonstrates how the matching engine goes as far as it can at first, and if no match is found it will then progressively back up and retry the rest of the RE again and again. It will back up until it has tried zero matches for [bcd]*, and if that subsequently fails, the engine will conclude that the string doesn't match the RE at all. . I write the following code: ... import re line = abcdb matchObj = re.match( 'a[bcd]*b', line) if matchObj: print matchObj.group() : , matchObj.group() print matchObj.group(0) : , matchObj.group() print matchObj.group(1) : , matchObj.group(1) print matchObj.group(2) : , matchObj.group(2) else: print No match!! . In which I have used its match pattern, but the result is not 'abcb' Only matchObj.group(0): abcdb displays. All other group(s) have no content. How to write this greedy search? Thanks, -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On 06/07/2014 19:48, Rick Johnson wrote: *Real* programmers possess keen detective that can root out bugs with nothing more than a few well placed print statements and some good old fashioned eyeball analysis. In the 21st century real programmers are using the logging module so they don't have to mess around. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: cx_freeze and temporary files - security related question
On Jul 6, 2014, at 9:21 AM, Richard Damon rich...@damon-family.org wrote: On 5/21/14, 12:42 PM, Nagy László Zsolt wrote: I need to create an application for Windows 7 that runs from a flash drive. This program would be used to create remote backups of the pendrive. The pendrive contains sensitive data, so when I plug in the pendrive and run the program to make a backup, it should not leave any trace of operation on the windows system. The information is so sensitive that I was forbidden to use cloud storage. I was also forbidden to make backups to a local drive, or leave any trace on the host windows system. The question is this: if I create this program with Python 3.4 and cx_Freeze, then what should I expect. When the user starts the cx_freeze-d program from the flash drive, will it create temporary files on the system drive? Will it leave log files or store any permanent or temporary data on the system drive (maybe in the user's tmp folder) that can later be used to tell what drive was mounted, with what parameters the program was started etc. Thanks I am not sure about what temp files python might leave around, but if you are being ultimately paranoid about this, one risk that will be present is the possibility of leaving traces of data in the swap file. If the program doesn't specifically prohibit it, anything that is brought into memory (and the act of reading the pendrive will do this) might end up in the swap file. I can't imagine python having a run time option to force it to disable the swap file. If the data is as sensitive as they seem to want to treat it, perhaps you should follow the procedures of classified computing, which says that any storage medium exposed to classified computing becomes classified. This would say that you would use a dedicated machine to do these backups, and after doing them, you remove the hard disk from the machine and lock it up, only to be taken out for later backups. This level of paranoia says you don't need to be as concerned about figuring out what traces might be left, you assume they are and lock them up. — Furthermore, I don’t know about Windows, but on many UNIX-like OSs, the file system preserves the time the file was last accessed. If the goal is truly to leave no traces of the fact that the a group of files was backed up, this pretty well would be a red flag that they had been. -Bill -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the difference between matchObj.group() and matchObj.group(0)
On 2014-07-06 19:26, rxjw...@gmail.com wrote: Hi, I cannot get the difference between matchObj.group() and matchObj.group(0), Although there definitions are obvious different. And group() mentions 'tuple'. tuple means all the elements in line object? Match Object Methods Description group(num=0) This method returns entire match (or specific subgroup num) groups() This method returns all matching subgroups in a tuple (empty if there weren't any) I run the following code. Even I add more words to line object, Both have the same output. Could you clarify this question? matchObj.group(g) returns what was captured by group g. If you don't specify the group, it'll assume that you want group 0, which is the entire part of the string that matched. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to write this repeat matching?
On 2014-07-06 19:57, rxjw...@gmail.com wrote: Hi, On Python website, it says that the following match can reach 'abcb' in 6 steps: . A step-by-step example will make this more obvious. Let's consider the expression a[bcd]*b. This matches the letter 'a', zero or more letters from the class [bcd], and finally ends with a 'b'. Now imagine matching this RE against the string abcbd. The end of the RE has now been reached, and it has matched abcb. This demonstrates how the matching engine goes as far as it can at first, and if no match is found it will then progressively back up and retry the rest of the RE again and again. It will back up until it has tried zero matches for [bcd]*, and if that subsequently fails, the engine will conclude that the string doesn't match the RE at all. . I write the following code: ... import re line = abcdb matchObj = re.match( 'a[bcd]*b', line) if matchObj: print matchObj.group() : , matchObj.group() print matchObj.group(0) : , matchObj.group() print matchObj.group(1) : , matchObj.group(1) print matchObj.group(2) : , matchObj.group(2) else: print No match!! . In which I have used its match pattern, but the result is not 'abcb' That's because the example has 'abcb', but you have: line = abcdb (You've put a 'd' in it.) Only matchObj.group(0): abcdb displays. All other group(s) have no content. There are no capture groups in your regex, only group 0 (the entire matched part). How to write this greedy search? -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
In article mailman.11552.1404673207.18130.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: On 06/07/2014 19:48, Rick Johnson wrote: *Real* programmers possess keen detective that can root out bugs with nothing more than a few well placed print statements and some good old fashioned eyeball analysis. In the 21st century real programmers are using the logging module so they don't have to mess around. The problem with the logging module is you can configure it to do pretty much anything, which is another way of saying if it's not configured right (perhaps because you're running your application in an environment it wasn't designed for), your output disappears into the ether. I can't tell you how many times I've given up fighting with logging and just done open(/tmp/x).write(my debugging message\n) when all else failed. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
On Thu, Jul 3, 2014 at 10:31 AM, Tobiah tshep...@rcsreg.com wrote: Coworker takes PEP8 as gospel and uses 4 spaces to indent. I prefer tabs. I recently converted from tabs to spaces. I probably still have some code that uses tabs, but most of my personal stuff has been converted. I like tabs. Tabs work better for me than spaces, because I know how to use them. Also, some make tools insist on tabs. Also, where many people like 4 spaces or 8 spaces, I prefer tabs expanded to 3 columns. But I finally acknowledged that some very smart people don't understand tabs, or don't want to learn how to use them. Also, I figured out how to get python files to use spaces and Makefile's to use tabs, using some slight vim configuration. So I'm using 4 spaces now. It's nice not having to ignore the relevant pep8 and pylint warnings anymore. And I don't miss tabs nearly as much as I thought I would. In fact, I'm not sure I miss them at all. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
On Sun, Jul 6, 2014 at 1:25 PM, Dan Stromberg drsali...@gmail.com wrote: I like tabs. Tabs work better for me than spaces, because I know how to use them. Also, some make tools insist on tabs. Those tools are just as broken as the ones that only work with spaces. Fortunately, I can't even remember the last time I had to edit a Makefile. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
In article mailman.11557.1404674726.18130.python-l...@python.org, Dan Stromberg drsali...@gmail.com wrote: On Thu, Jul 3, 2014 at 10:31 AM, Tobiah tshep...@rcsreg.com wrote: Coworker takes PEP8 as gospel and uses 4 spaces to indent. I prefer tabs. I recently converted from tabs to spaces. I probably still have some code that uses tabs, but most of my personal stuff has been converted. I like tabs. Tabs work better for me than spaces, because I know how to use them. Also, some make tools insist on tabs. Why should the fact that Make requires tabs affect how you edit Python code? -- https://mail.python.org/mailman/listinfo/python-list
Re: How to write this repeat matching?
On Sun, Jul 6, 2014 at 12:57 PM, rxjw...@gmail.com wrote: I write the following code: ... import re line = abcdb matchObj = re.match( 'a[bcd]*b', line) if matchObj: print matchObj.group() : , matchObj.group() print matchObj.group(0) : , matchObj.group() print matchObj.group(1) : , matchObj.group(1) print matchObj.group(2) : , matchObj.group(2) else: print No match!! . In which I have used its match pattern, but the result is not 'abcb' You're never going to get a match of 'abcb' on that string, because 'abcb' is not found anywhere in that string. There are two possible matches for the given pattern over that string: 'abcdb' and 'ab'. The first one matches the [bcd]* three times, and the second one matches it zero times. Because the matching is greedy, you get the result that matches three times. It cannot match one, two or four times because then there would be no 'b' following the [bcd]* portion as required by the pattern. Only matchObj.group(0): abcdb displays. All other group(s) have no content. Calling match.group(0) is equivalent to calling match.group without arguments. In that case it returns the matched string of the entire regular expression. match.group(1) and match.group(2) will return the value of the first and second matching group respectively, but the pattern does not have any matching groups. If you want a matching group, then enclose the part that you want it to match in parentheses. For example, if you change the pattern to: matchObj = re.match('a([bcd]*)b', line) then the value of matchObj.group(1) will be 'bcd' -- https://mail.python.org/mailman/listinfo/python-list
Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
On Sunday, July 6, 2014 1:14:38 PM UTC-5, wxjm...@gmail.com wrote: Le dimanche 6 juillet 2014 18:53:34 UTC+2, Rick Johnson a écrit : [...] Seems like she'd better do the decoding before printing No or am i wrong again? Yes s = 'abc需' sys.stdout.encoding 'unicode' print(s) abc需 sys.stdout.encoding = 'cp437' sys.stdout.encoding 'cp437' print(s) Traceback (most recent call last): File eta last command, line 1, in module File D:\jm\jmpy\eta\eta40beta2\etastdio.py, line 158, in write s = s.encode(self.pencoding).decode('cp1252') File C:\Python32\lib\encodings\cp437.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 4-5: character maps to undefined print(s.encode(sys.stdout.encoding, 'replace')) 'abcé??' sys.stdout.encoding = 'cp850' sys.stdout.encoding 'cp850' print(s) Traceback (most recent call last): File eta last command, line 1, in module File D:\jm\jmpy\eta\eta40beta2\etastdio.py, line 158, in write s = s.encode(self.pencoding).decode('cp1252') File C:\Python32\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 4-5: character maps to undefined print(s.encode(sys.stdout.encoding, 'replace')) 'abcé??' # and so on sys.stdout.encoding = 'cp1252') File eta last command, line 1 sys.stdout.encoding = 'cp1252') ^ SyntaxError: invalid syntax # oops sys.stdout.encoding = 'cp1252' print(s) abc需 sys.stdout.encoding = 'mac-roman' print(s) abcŽÏÛ print(s.encode(sys.stdout.encoding, 'replace')) 'abc需' sys.stdout.encoding = 'utf-8' print(s.encode(sys.stdout.encoding, 'replace')) 'abc需' sys.stdout.encoding = 'utf-16-le' print(s.encode(sys.stdout.encoding, 'replace')) 'abc需' sys.stdout.encoding = 'utf-32-be' print(s.encode(sys.stdout.encoding, 'replace')) 'abc需' jmf Oh my, all that code just so you can handle glyphs with squiggly little accent marks? Are you so afraid you'll forget how to pronounce the words without them? I wonder how those simpleton Americans are able to pronounce words without a tutorial? Boggles the mind really, BOGGLES THE MIND! For the remainder of your bloated Unicode char set that defines symbols, and cute little miniature fractions, and snowmen, and all sorts of ridiculous scrawl... what a waste of time! You know, instead of bending over backwards to include every selfish char man in his complete and utter stupidity can muster, when are we going to realize that keyboards can only contain a very *finite* number of keys before they become unusable. If you want to draw shapes and scrawl to a screen, USE THE CORRECT DAMN TOOL! In this day and age of globalism, when are we going to unite under a single form of written communication. And if not for the sake of programmers, i can think of an even more important reason,,, for the sake of miscommunications and animosity. How many fights and wars have been started simply on the grounds of a miscommunication? THE MINDS OF LITTLE MEN ARE CONSUMED WITH EMOTIONAL IDENTITIES AND THE PURSUIT OF CREATING SYMBOLS THAT DEFINE THOSE IDENTITIES The true free man does not belong to any imaginary group, he does not pay allegiance to any one country, or any one religion, or any one sports team (if at all), no, he is free and belongs to group defined by a single word, a group from which he does NOT choose, but a group from which he is *BOUND*: THAT GROUP BE HUMANITY! My keyboard has every char i could ever need to express myself sufficiently across a medium that requires redundant pecking of keys on a keyboard. This is the form of communication we have achieved thus far, so until we can evolve past this pecking olymics, we would be wise to keep our pecking to a minimum and employ a ubiquitous written language that is elegant and simplistic, and optimized for typing. I'm sorry but i guess i'm just too practical for all this nonsense. To me Unicode is just like automobiles. Everyone has their own color and brand, and this one has a butt warmer and that one has a vanity mirror, when in fact all automobiles serve the same purpose of transportation. Although, unlike automobiles where i can choose to drive ONLY my car, with Unicode i'm forced to interface with your selfish idea of what a car should be. I just want to get from point A to point B without being pulled over and arrested because you were partying with three prostitutes who forgot their crack pipe under the seat! But don't bother listening to me anyway, and go on with your selfish pursuits, continue dividing people instead of uniting them, continue creating a world that is superfluously complex by your own hand -- but don't be surprised when this monstrosity comes crashing down on top of
Re: cx_freeze and temporary files - security related question
On 7/6/14, 3:04 PM, William Ray Wing wrote: Furthermore, I don’t know about Windows, but on many UNIX-like OSs, the file system preserves the time the file was last accessed. If the goal is truly to leave no traces of the fact that the a group of files was backed up, this pretty well would be a red flag that they had been. -Bill I don't think the OP was concerned about leaving hints on the pen drive that it was backed up, but on the machine used to back it up. This is why my suggestion is, if you are concerned about leaving traces, lock up the drive with all the traces, just like you probably do all the backups. Then you can know that there aren't any traces left behind that you didn't think of. -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On 07/06/2014 08:03 AM, rxjw...@gmail.com wrote: snip Thanks. I do not want to waste everyone's time. For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. (Sorry again, that problem may be about Cygwin, not Python. Excuse me to mention that here. Of course, your help post consumes your time. Thanks again. I'm curious as to why you're using Cygwin Python. Cygwin is great for using Unix/Linux programs that are not available in Windows, but there are Windows-native versions of Python available. I would suggest that you would be better off installing Python directly into Windows instead of going round-about with Cygwin. If you do this, I would also suggest that you install Python 3 instead of Python 2, but you may have to find a different tutorial. Although I suspect that part of your problems are that the tutorial you're using IS for Python 3 rather than the 2.7 you are using. Really, there aren't a lot of differences between 2 and 3, but the differences ARE very significant. And 3 is definitely the better, as well as the future. (Aside: I do have Cygwin installed on my Windows system, but I have pretty much given up on using Windows. I find Linux far superior and more comfortable to use, and it gets away from Big-Brotherish Microsoft. I do use it occasionally, but I think the last time I ran it was at least two months ago.) -=- Larry -=- -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is it different from the example on the tutorial?
On Sunday, July 6, 2014 4:32:14 PM UTC-4, Larry Hudson wrote: On 07/06/2014 08:03 AM, rxjw...@gmail.com wrote: snip Thanks. I do not want to waste everyone's time. For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. (Sorry again, that problem may be about Cygwin, not Python. Excuse me to mention that here. Of course, your help post consumes your time. Thanks again. I'm curious as to why you're using Cygwin Python. Cygwin is great for using Unix/Linux programs that are not available in Windows, but there are Windows-native versions of Python available. I would suggest that you would be better off installing Python directly into Windows instead of going round-about with Cygwin. If you do this, I would also suggest that you install Python 3 instead of Python 2, but you may have to find a different tutorial. Although I suspect that part of your problems are that the tutorial you're using IS for Python 3 rather than the 2.7 you are using. Really, there aren't a lot of differences between 2 and 3, but the differences ARE very significant. And 3 is definitely the better, as well as the future. (Aside: I do have Cygwin installed on my Windows system, but I have pretty much given up on using Windows. I find Linux far superior and more comfortable to use, and it gets away from Big-Brotherish Microsoft. I do use it occasionally, but I think the last time I ran it was at least two months ago.) -=- Larry -=- Thanks. In fact, I have both Cygwin and Windows version Python, but I incorrectly thought that Cygwin version Python would be closer to Linux than Windows Python. Another thing, I find that Windows Python have a GUI interface. It is good, but it does not have command history as Cygwin has. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
In article d8f8d76d-0a47-4f59-8f09-da2a44cc1...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: As an aside i prefer to only utilize a character set when nothing else will suffice. And in this case r[0-9][0-9]* can be expressed just as correctly (and less noisy IMHO) as r\d\d*. Even better, r\d+ I tend tot do that too, even though technically the two are not perfectly equivalent. With the re.LOCALE flag LC_ctype is also affected, which affects what is captured by \d but not by [0-9] -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: Flashlights [was Re: PEP8 and 4 spaces]
On Mon, Jul 7, 2014 at 1:41 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: Well Steven all i can hope is that one day you and i will be working on a project together, and you will ask me for a touch, and when i return with a petrol soaked rag burning on the end of twig and proceed to light your hair on fire, hopefully at that moment, you will THEN gain a healthy respect for logical naming conventions! Let's reverse that. Suppose you're the one who is asking for something to illuminate your task - what item will you request? Remember, the person who provides it will be exactly what you're suggesting of yourself - a literal-minded genie. http://tvtropes.org/pmwiki/pmwiki.php/Main/LiteralGenie http://tvtropes.org/pmwiki/pmwiki.php/Main/JackassGenie ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
On 2014-07-06 18:41, Albert-Jan Roskam wrote: In article d8f8d76d-0a47-4f59-8f09-da2a44cc1...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: As an aside i prefer to only utilize a character set when nothing else will suffice. And in this case r[0-9][0-9]* can be expressed just as correctly (and less noisy IMHO) as r\d\d*. Even better, r\d+ I tend tot do that too, even though technically the two are not perfectly equivalent. With the re.LOCALE flag LC_ctype is also affected, which affects what is captured by \d but not by [0-9] \d also matches more than just [0-9] in Unicode. -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On Mon, Jul 7, 2014 at 5:15 AM, Roy Smith r...@panix.com wrote: In article mailman.11552.1404673207.18130.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: On 06/07/2014 19:48, Rick Johnson wrote: *Real* programmers possess keen detective that can root out bugs with nothing more than a few well placed print statements and some good old fashioned eyeball analysis. In the 21st century real programmers are using the logging module so they don't have to mess around. The problem with the logging module is you can configure it to do pretty much anything, which is another way of saying if it's not configured right (perhaps because you're running your application in an environment it wasn't designed for), your output disappears into the ether. I can't tell you how many times I've given up fighting with logging and just done open(/tmp/x).write(my debugging message\n) when all else failed. But the important thing is that you log. There's a VAST difference between logging and interactive debugging: logging can debug something that happened once and didn't recur, interactive debugging requires that you create the problem on command. Have you ever had a bug where someone else finds it and then doesn't give you full repro steps? Or where you find it yourself and declare it intermittent? Proper logging (and hey, Python's pretty helpful with exceptions) can mean that you find that just by browsing backward. There are times when you have to go for the Real Programmer debugging style. Pretend the program is a black box, no source code available, nothing. (Maybe that's because it really is like that, or maybe it's just easier to strace a process and watch for the failures than it is to hunt down the source code for the exact version you're running.) Or pretend the code has no direct correlation to what happens, owing to an interpreter bug. (Again, it really can be; imagine a refcount bug in a Python C API function.) Debugging those problems gives you an appreciation for the ease of double-click the line in the traceback, or hit F4, and go straight to the cause of the error. Python gives us an insane amount of help (I say insane because sometimes there have been performance questions surrounding tracebacks), although at the end of the day, debugging is something people. not tools, do. No matter how good Python's traceback handling is, it becomes useless if you wrap everything in try: ... except: print('Something went wrong'). As Alice's father told her, a tool's intended function is almost beside the point. Ultimately it's only as good as the person who wields it. http://alice.wikia.com/wiki/Memory ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about metacharacter '*'
The reason I did not use \d\d* or \d+ or ^\d+$ or any number of more-correct things was because the OP was new to regexps. -- Devin On Sun, Jul 6, 2014 at 3:49 PM, MRAB pyt...@mrabarnett.plus.com wrote: On 2014-07-06 18:41, Albert-Jan Roskam wrote: In article d8f8d76d-0a47-4f59-8f09-da2a44cc1...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: As an aside i prefer to only utilize a character set when nothing else will suffice. And in this case r[0-9][0-9]* can be expressed just as correctly (and less noisy IMHO) as r\d\d*. Even better, r\d+ I tend tot do that too, even though technically the two are not perfectly equivalent. With the re.LOCALE flag LC_ctype is also affected, which affects what is captured by \d but not by [0-9] \d also matches more than just [0-9] in Unicode. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
Shiyao Ma i...@introo.me writes: My normal workflow is use ipython, obj? or obj?? for quick look up or use docs.python.org for a detailed read. I don't use IPython. I'm glad it exists for those who want it. I frequently use Python on hosts not entirely under my control, where I don't have authority to install new packages, and which only have stock Python installed. So I have to be familiar with IDLE and the standard Python interactive shell. I also find IPython of questionable value when teaching Python to newcomers: its interactive features diverge quite markedly from what is available when writing Python code in a file, so it turns out to be too distracting for someone learning the language. Using the standard Python interactive shell, at least, means what a newcomer learns t the shell is almost entirely transferable to what they need to do to get code into a module's source code. As for the powerful features available in IPython, I find that I get most of them from a Python-aware programmer's editor like Emacs, which also gives me a powerful interactive environment that does more than only Python code. So it would be, IMO, a mistake for me to become too reliant on IPython-specific functionality. It's a high, specific investment that doesn't pay off well on other machines (which commonly don't have it immediately available) or other languages which I need to use. Do you use `help`? How does it integrate into your workflow? I very often use ‘help(foo)’ at the Python interactive prompt, to get a quick reference to what an object's attributes and features are. There are two common cases where ‘help(foo)’ is unable to help: * If ‘foo’ is a function written without using keyword-only args, but needing to have a bunch of keyword arguments, the signature will often be the uninformative ‘foo(*args, **kwargs)’. A docstring is crucial here, but it's too often wrong or absent. I look forward to more and more functions migrating to use keyword-only arguments for these cases, so the function signature can become much more informative in ‘help’. * If ‘foo’ is a function implemented in an extension (non-Python) module, the signature ‘foo(...)’ is utterly useless. Here, again, the docstring is crucial; and it is frequently just a terse one-liner with no good explanation. Even the standard library is rife with unhelpful function docstrings of this kind. Other than those caveats, I find browsing ‘help(foo)’ output is very helpful in an interactive session, not least for getting information quickly about an unknown object I've generated from some third-party function call. It is a very good feature that ‘help(foo)’ for a class instance shows the help of the class: it can be used indiscriminately, and is thus easier to recommend as a mental habit. Or instead, what similar tools do you use? I have the ‘python-doc’ and ‘python3-doc’ packages installed locally, and this gives instant access to the whole Python documentation in my browser without any lag or network dependency. The ‘logging’ module is a standard feature and makes it much easier to emit informative debugging statements that (unlike ad-hoc ‘print’ calls) *don't* need to be removed later. Logging can also reveal a lot about the objects while the program is running, as a valuable complement to the ‘help’ feature and online documentation. -- \ “Puritanism: The haunting fear that someone, somewhere, may be | `\ happy.” —Henry L. Mencken | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
In article mailman.11564.1404687291.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: But the important thing is that you log. I 'spose. Let's see. Yesterday we generated 133 GB of log files. And Sunday is a slow day :-) Have you ever had a bug where someone else finds it and then doesn't give you full repro steps? Are there people like that where you are? Weird. There are times when you have to go for the Real Programmer debugging style. Pretend the program is a black box, no source code available, nothing. Yup; strace and tcpdump are two of my best friends. The source code only tells you what the program is *supposed* to do. Strace tells you what it did. And tcpdump tells you what it said. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
Dan Stromberg drsali...@gmail.com writes: But I finally acknowledged that some very smart people don't understand tabs, or don't want to learn how to use them. One day, you may reach the further realisation that those same very smart people *do* understand tabs, and *do* know how to use them — and nevertheless choose not to put them in source code, for good reasons. Also, I figured out how to get python files to use spaces and Makefile's to use tabs, using some slight vim configuration. The makefile syntax is one of the excellent examples of why it's a terrible idea to use tab characters in source code. It's also an excellent example of how a poor design decision (a line beginning with U+0020 SPACE is semantically different from a line beginning with U+0009 CHARACTER TABULATION) can be irrevocable – the syntax can't be changed now, without breaking compatibility for countless makefiles out there already – and cause endless confusion and wasted effort dealing with it. Using a mature, well-customised, language-agnostic programmer's editor does make it much better: Vim and Emacs can both seamlessly handle “tabs are forbidden by default” as a configuration choice, along with “tabs are necessary in make files, using spaces in the wrong place is an error” at the same time. So I'm using 4 spaces now. It's nice not having to ignore the relevant pep8 and pylint warnings anymore. And I don't miss tabs nearly as much as I thought I would. In fact, I'm not sure I miss them at all. Hooray! Welcome to the light :-) -- \ “The best ad-libs are rehearsed.” —Graham Kennedy | `\ | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: flask sql cann't insert Variable in VALUES
Thank you CA learn so much from your words -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On 06Jul2014 15:15, Roy Smith r...@panix.com wrote: In article mailman.11552.1404673207.18130.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: In the 21st century real programmers are using the logging module so they don't have to mess around. The problem with the logging module is you can configure it to do pretty much anything, which is another way of saying if it's not configured right (perhaps because you're running your application in an environment it wasn't designed for), your output disappears into the ether. I can't tell you how many times I've given up fighting with logging and just done open(/tmp/x).write(my debugging message\n) when all else failed. Indeed. I have a cs.logutils module, which is almost entirely support for the logging module (standard setups, funky use cases), but it also defines two functions, X and D, thus: def X(fmt, *args): msg = str(fmt) if args: msg = msg % args sys.stderr.write(msg) sys.stderr.write(\n) sys.stderr.flush() def D(fmt, *args): ''' Print formatted debug string straight to sys.stderr if D_mode is true, bypassing the logging modules entirely. A quick'n'dirty debug tool. ''' global D_mode if D_mode: X(fmt, *args) I use X() for ad hoc right now debugging and D() for turn on at need debugging. Surprisingly handy. Many many of my modules have from cs.logutils import X, D at the top. Cheers, Cameron Simpson c...@zip.com.au How do you know I'm Mad? asked Alice. You must be, said the Cat, or you wouldn't have come here. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
On Mon, 07 Jul 2014 11:00:59 +1000, Ben Finney wrote: The makefile syntax is one of the excellent examples of why it's a terrible idea to use tab characters in source code. Hmmm... I'm not sure that conclusion follows. I think that makefile syntax is an example of why it is a terrible idea to give spaces and tabs different semantics, not that tabs themselves are harmful. It's also an excellent example of how a poor design decision (a line beginning with U+0020 SPACE is semantically different from a line beginning with U+0009 CHARACTER TABULATION) can be irrevocable Yes. Design your public APIs cleanly and clearly from the start. The story of makefiles is a warning of the dark side to release early, release often, and the dangers of using alpha software in production: [quote] Why the tab in column 1? Yacc was new, Lex was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history. -- Stuart Feldman [end quote] -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On Mon, Jul 7, 2014 at 10:53 AM, Ben Finney b...@benfinney.id.au wrote: There are two common cases where ‘help(foo)’ is unable to help: * If ‘foo’ is a function written without using keyword-only args, but needing to have a bunch of keyword arguments, the signature will often be the uninformative ‘foo(*args, **kwargs)’. A docstring is crucial here, but it's too often wrong or absent. I look forward to more and more functions migrating to use keyword-only arguments for these cases, so the function signature can become much more informative in ‘help’. Most common cause of this problem is when a function ought to have functools.wraps but didn't. if DEBUG: debug = print else: @functools.wraps(print) def debug(*a, **kw): pass Without wraps(), the non-debug-mode version of debug() is completely unhelpful. There's another issue with help(), and that's when it's used on a large class - it's not that it's unhelpful, it's more that the useful information gets lost in the spam of a pile of dunder functions. Check out help(1) for instance. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you use `help` when write your code
On Mon, Jul 7, 2014 at 10:52 AM, Roy Smith r...@panix.com wrote: In article mailman.11564.1404687291.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: But the important thing is that you log. I 'spose. Let's see. Yesterday we generated 133 GB of log files. And Sunday is a slow day :-) Heh, that's a bit bigger in scale than most of what I work with... but yes. I have a log file of the from and to addresses of every email that goes through my spam filter, and whether it was marked spam or ham; the expectation is that any mail that doesn't bounce (the server will reject prior to this log based on certain rules) will be in the log, so if anyone asks about something, I can grep the log for an address. It's a fairly compact log, and this is a fairly small site, so the growth is a lot slower than 133GB/day! But the principle's the same: log today so you can find a problem tomorrow. Have you ever had a bug where someone else finds it and then doesn't give you full repro steps? Are there people like that where you are? Weird. Yes, sadly, there are people just about everywhere. (Despite my post being in response to one of yours, Roy, I still partly felt that I was addressing Rick. Hence the slightly odd wording of something that, for most of us, is a duh matter.) There are times when you have to go for the Real Programmer debugging style. Pretend the program is a black box, no source code available, nothing. Yup; strace and tcpdump are two of my best friends. The source code only tells you what the program is *supposed* to do. Strace tells you what it did. And tcpdump tells you what it said. That's about it, yeah. I tend to find both strace and tcpdump rather too spammy for most usage, so any time I reach for those tools, it's usually with some tight filtering - and even that's not always helpful. The last thing I straced was a (closed-source) game that was having some problems (cross-platform, I'm one of a very small number of Linux testers), and it was running at well over 100 FPS... and each frame involved quite a few system calls. Yeah, that was spammy. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
On Mon, Jul 7, 2014 at 12:28 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The story of makefiles is a warning of the dark side to release early, release often, and the dangers of using alpha software in production: [quote] Why the tab in column 1? Yacc was new, Lex was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history. -- Stuart Feldman [end quote] Perhaps. Or perhaps it's a warning about the importance of version 0 of a piece of software: you release early, release often, but you start with version 0.1, where the standard backward compat guarantees don't hold. You get some feedback, and then when you finally release version 1.0, you start promising not to mess people's stuff up; but before that, anything might change. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
open() and EOFError
Are there any circumstances where merely *opening* a file (before reading it) can raise EOFError? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Saving
Hi, I’ve been looking forever for this and I cant get it. I need to know how to save my code and save as programs because I write code and I run it but then I cant save it for later. Please help and thank you for your time.-- https://mail.python.org/mailman/listinfo/python-list
Re: open() and EOFError
Steven D'Aprano wrote: Are there any circumstances where merely *opening* a file (before reading it) can raise EOFError? I don't think so. As far as I know, the only built-in thing that raises EOFError is input() (and raw_input() in Py2). -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Programmer's text editor (was: Saving)
mrwhackad...@gmail.com writes: I need to know how to save my code and save as programs because I write code and I run it but then I cant save it for later. You can write Python code using any text editor. You will do well to use a text editor which is deliberately designed for programming and other related editing tasks. I would also recommend that a programmer's text editor should: * Be licensed as free software — the tool should be able to be improved and maintained and distributed to you by any party sufficiently motivated, not locked up by any single party. * Work the same on all major platforms — you should not need to abandon a tool you like merely because you switch to a different machine for a while. * Be mature with a strong track record — a text editor which has been around for some decades, and still has a large following, has demonstrated it can survive many different trends in programming tools. * Well-supported with its own vibrant community — you don't necessarily need to join such a community, but you will greatly benefit from the fact that a tool has robust community support. That the tool is free software is a significant contributor to this. * Be indefinitely customisable to meet new needs — this ensures that anyone sufficiently motivated can allow you to use the tool you already know for new tasks that come along. Having a strong community of support will mean that most tasks are already supported in the tool by people who came before you. * Properly support many programming languages and related formats — this is an outcome of the tool being community-supported, mature, and highly customisable. The tool should, in its standard installation, already support major programming languages and formats, and have a simple way to add supporting plug-ins as you need them. I know of two obvious text editors that meet these criteria: * Vim URL:http://www.vim.org/ URL:https://en.wikipedia.org/wiki/Vim_%28text_editor%29 * Emacs URL:https://www.gnu.org/software/emacs/ URL:https://en.wikipedia.org/wiki/Emacs If you're using a *nix style operating system such as GNU+Linux, you will have both of these available for installation from the operating system. Please help and thank you for your time. I hope that helps. Familiarising yourself with a strong, free-software, cross-platform text editor is an essential investment in programming. Good hunting! -- \ “We have clumsy, sputtering, inefficient brains…. It is a | `\ *struggle* to be rational and objective, and failures are not | _o__) evidence for an alternative reality.” —Paul Z. Myers, 2010-10-14 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Saving
On 06Jul2014 23:03, mrwhackad...@gmail.com mrwhackad...@gmail.com wrote: I need to know how to save my code and save as programs because I write code Please help and thank you for your time. Please tell a bit more about your work environment (editors, IDEs, computer OS, etc). The basic answer to your question is to edit the code in a file of its own, and to run it is a separate action, from that file. As an example, my coding environment contains an editor window and a shell (command line) window. (Plus doco in a web browser, etc, as needed.) So open a file with a useful name (start with program1.py, but pick something more apt depending on the task) and open an editor on that file. When ready to test, save the file (probably a single key command in most editors, or the ever popular File-Save menu option). Then in another window, run it: python program1.py So you don't write code, test and _then_ save. You write code and save. Then test from the saved file. Cheers, Cameron Simpson c...@zip.com.au I'm Bubba of Borg. Y'all fixin' to be assimilated. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 and 4 spaces
On Mon, 07 Jul 2014 11:00:59 +1000, Ben Finney wrote: The makefile syntax is one of the excellent examples of why it's a terrible idea to use tab characters in source code. It's also an excellent example of how a poor design decision (a line beginning with U+0020 SPACE is semantically different from a line beginning with U+0009 CHARACTER TABULATION) can be irrevocable – the syntax can't be changed now, without breaking compatibility for countless makefiles out there already – and cause endless confusion and wasted effort dealing with it. When makefile syntax came into being, there were ASCII TAB characters, with a value of 9, and ASCII SPC characters, with a value of 32 (and there may not even have been those). The former is a control character, which has specific semantics associated with it; the latter is a printable character, which is usually printed and interpreted as itself (although in this particular case, the printed representation is hard to see on most output devices). This mailing list doesn't seem to mind that lines beginning with ASCII SPC characters are semantically different from lines beginning with ASCII LF characters, although many detractors of Python seem unduly fixated on it. -- https://mail.python.org/mailman/listinfo/python-list
[issue21926] Bundle C++ compiler with Python on Windows
New submission from Ben Lucato: I am wondering if it is at all on the roadmap to bundle a C compiler with Python on Windows, given that installing libraries with C extensions is very confusing on Windows. For example, to install NumPy on Windows you end up either having to download the right version of Visual Studio or install it from the list of precompiled libraries at http://www.lfd.uci.edu/~gohlke/pythonlibs/. The problem is, either of those solutions feel quite bloated and aren't easily apparent when searching for fixes online. BTW, since this is my first issue I looked around for a guide on how to submit issues but I couldn't find one - so I hope I'm raising it right. -- components: Windows messages: 222395 nosy: Ben.Lucato priority: normal severity: normal status: open title: Bundle C++ compiler with Python on Windows versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21926 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9554] test_argparse.py: use new unittest features
Roundup Robot added the comment: New changeset f240ca6345c8 by Berker Peksag in branch 'default': Issue #9554: Use modern unittest features in test_argparse. http://hg.python.org/cpython/rev/f240ca6345c8 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9554 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9554] test_argparse.py: use new unittest features
Berker Peksag added the comment: Thanks Denver and Radu. And thanks for the review, Ezio. -- assignee: - berker.peksag resolution: - fixed stage: commit review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9554 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2403] Add figleaf coverage metrics
Changes by Berker Peksag berker.pek...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2403 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21597] Allow turtledemo code pane to get wider.
Lita Cho added the comment: Hey Terry, So the reason why the tearing is a lot slower in 06/09 patch is because the canvas is using the turtle.ScrolledCanvas widget. Everytime the window resizes, it is calling a callback to `onResize` - `adjustScrolls` to update the scrollbars. When I comment out that binding in turtle.py (line 358) it still tears, but it snaps back a lot quicker. The main widget is already a 2x2 grid (ScrolledCanvas). I tried just returning the ScrolledCanvas, but that didn't work either. I will try to ask in stackoverflow tomorrow and seeing what they say! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21597 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14121] add a convenience C-API function for unpacking iterables
Stefan Behnel added the comment: Ok. This has been idling long enough to just close it. -- resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14121 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21923] distutils.sysconfig.customize_compiler will try to read variable that has not been initialized
Ned Deily added the comment: Thanks for the patch, Alex, and sorry about the bug. The fix looks good. I've added a test that should be valid whether or not a compiler is available and, I hope, on Windows (I haven't tested it there). -- stage: - patch review versions: +Python 3.5 -Python 3.2, Python 3.3 Added file: http://bugs.python.org/file35872/issue21923_3x.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21923 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21923] distutils.sysconfig.customize_compiler will try to read variable that has not been initialized
Changes by Ned Deily n...@acm.org: Added file: http://bugs.python.org/file35873/issue21923_27.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21923 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12523] 'str' object has no attribute 'more' [/usr/lib/python3.2/asynchat.py|initiate_send|245]
Mark Lawrence added the comment: Just close this as asynchat is deprecated from 3.2. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12523 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21323] CGI HTTP server not running scripts from subdirectories
Konstantin S. Solnushkin added the comment: Hi, I am curious about the fate of this issue -- whether it will be recognised as a bug (possibly a regression bug). Remember, it worked in Python 3.3 but stopped working in 3.4. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21323 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21052] Consider dropping ImportWarning for empty sys.path_hooks and sys.meta_path
Masami HIRATA added the comment: Hi, I can reproduce this issue with the following steps. $ uname -a Linux ashrose 3.2.0-65-generic #99-Ubuntu SMP Fri Jul 4 21:03:29 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux $ python3.4 --version Python 3.4.1 $ touch spam.txt $ python3.4 -Wa -c class A: pass; a = open('spam.txt') sys:1: ResourceWarning: unclosed file _io.TextIOWrapper name='spam.txt' mode='r' encoding='UTF-8' _frozen_importlib:2150: ImportWarning: sys.meta_path is empty _frozen_importlib:2150: ImportWarning: sys.meta_path is empty _frozen_importlib:2150: ImportWarning: sys.meta_path is empty _frozen_importlib:2150: ImportWarning: sys.meta_path is empty _frozen_importlib:2150: ImportWarning: sys.meta_path is empty ... $ python3.4 -Wa -c a = open('spam.txt') sys:1: ResourceWarning: unclosed file _io.TextIOWrapper name='spam.txt' mode='r' encoding='UTF-8' $ python3.4 -Wa -c class A: pass; open('spam.txt') -c:1: ResourceWarning: unclosed file _io.TextIOWrapper name='spam.txt' mode='r' encoding='UTF-8' $ -- nosy: +msmhrt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21052 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602742] itemconfigure returns incorrect text property of text items
Francisco Martín Brugué added the comment: Hi, just a question: the status of this issue is pending but it seems to be already resolved/duplicated. Means that this issue can be closed? Thansk in advance! -- nosy: +francismb status: pending - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602742 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602742] itemconfigure returns incorrect text property of text items
Changes by Berker Peksag berker.pek...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602742 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21923] distutils.sysconfig.customize_compiler will try to read variable that has not been initialized
Alex Gaynor added the comment: Test looks reasonable to me. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21923 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21927] BOM appears in stdin when using Powershell
New submission from Jason R. Coombs: Consider this simple example in Powershell (Windows 8.1): C:\Users\jaraco cat .\print-input.py import sys print(next(sys.stdin)) C:\Users\jaraco echo foo | .\print-input.py foo The BOM (byte order mark) appears in the standard input stream. When using cmd.exe, the BOM is not present. This behavior occurs in CP1252 as well as CP65001. I suspect that Python should be detecting/stripping and possibly honoring the BOM when decoding input on stdin. This issue is present in Python 3.4.0 and Python 3.4.1. I have not tested other Python versions. -- components: Unicode, Windows messages: 222406 nosy: ezio.melotti, haypo, jason.coombs priority: normal severity: normal status: open title: BOM appears in stdin when using Powershell versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21927 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10374] distutils[2] should recreate scripts in the build tree
Mark Lawrence added the comment: I always find distutils anything but easy :) -- components: -Distutils2 nosy: +BreamoreBoy, dstufft versions: +Python 3.4, Python 3.5 -3rd party, Python 2.7, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10374 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16438] Numeric operator predecence confusing
Mark Lawrence added the comment: I find the numeric operator predecence simply wrong, not confusing, so +1 from me for applying the attached patch from ktt3ja. It's as simple as possible but no simpler :) -- nosy: +BreamoreBoy versions: +Python 3.5 -Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16438 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1565071] update Lib/plat-linux2/IN.py
Mark Lawrence added the comment: Related issues via #12619 include #3990 and #19554. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1565071 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4256] argparse: provide a simple way to get a programmatically useful list of options
Changes by Mark Lawrence breamore...@yahoo.co.uk: -- nosy: +paul.j3 versions: +Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4256 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6114] distutils build_ext path comparison only based on strings
Changes by Mark Lawrence breamore...@yahoo.co.uk: -- components: -Distutils2 nosy: +dstufft versions: +Python 3.4, Python 3.5 -3rd party, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6114 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20135] FAQ need list mutation answers
Roundup Robot added the comment: New changeset 3881c12fa3ae by Ezio Melotti in branch '2.7': #20135: move FAQ about mutable default arguments to the programming FAQs page. http://hg.python.org/cpython/rev/3881c12fa3ae New changeset 3b7b0f5aac1e by Ezio Melotti in branch '3.4': #20135: move FAQ about mutable default arguments to the programming FAQs page. http://hg.python.org/cpython/rev/3b7b0f5aac1e New changeset f2a36b01ac02 by Ezio Melotti in branch 'default': #20135: merge with 3.4. http://hg.python.org/cpython/rev/f2a36b01ac02 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20135 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21597] Allow turtledemo code pane to get wider.
Lita Cho added the comment: I also put this patch out there. This doesn't have the PaneWindow, but I manually widen the text pane. This would be the compromise if I can't figure out the tearing due to the sash moving. -- Added file: http://bugs.python.org/file35874/turtledemo_grid.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21597 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20135] FAQ need list mutation answers
Ezio Melotti added the comment: I moved the FAQ about mutable default arguments to the programming FAQs page. I was going to do a review about new FAQ, but it since I had several comments I just tried to rewrite it and make a new patch. Do you think this is clear enough? -- Added file: http://bugs.python.org/file35875/issue20135.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20135 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20135] FAQ need list mutation answers
Mark Lawrence added the comment: +1 from me, I thought it was crystal clear. -- nosy: +BreamoreBoy versions: +Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20135 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1581182] Definition of a character is wrong
Changes by Ezio Melotti ezio.melo...@gmail.com: -- resolution: - duplicate stage: needs patch - resolved status: languishing - closed superseder: - Issues in Unicode HOWTO ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1581182 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20906] Issues in Unicode HOWTO
Ezio Melotti added the comment: See also #1581182. -- stage: - needs patch versions: +Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20906 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1660009] continuing problem with httplib multiple set-cookie headers
Mark Lawrence added the comment: msg179391 states this is fixed in Python 3 so we can close this as out of date. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1660009 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com