Re: Variables in a loop, Newby question

2013-12-27 Thread vanommen . robert
Hello everyone, I have been away for a while.
I have been reading all the good advises and want to explain why I want to read 
the temperatures separately from the main script. It takes a long time to read 
out 10 temperatures. About 10 seconds. So that’s the reason why I had the idea 
to create a separate script and I thought by making te variables Global I could 
access them by other scripts. Now I know that’s not the purpose of Global.
Maybe I can create a loop that keeps running simultaneously with the rest of 
the script. 
I’ve downloaded a great student book about Python and learning a lot.
Thanks for all the answers and I’ll post more questions in the future, I’m sure 
of it.
Greetings Robert
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Google Groups + this list

2013-12-27 Thread rurpy
On 12/26/2013 05:41 AM, Chris Angelico wrote:
> On Thu, Dec 26, 2013 at 4:13 PM,   wrote:
>> On 12/25/2013 09:17 PM, Chris Angelico wrote:
>>>[...]
>>> Or maybe I should have just filtered everything from Google Groups
>>> into the bit bucket, because responding just creates threads like
>>> this. Do you honestly think that would be better? No response at all
>>> if the post comes from GG?
>>
>> Do you really think that if *you* ignore Google Groups, then
>> Google Groups posters will get "no response at all"?  Could
>> you please turn down your ego a little?
> 
> That's not what I said, 

On rereading, my interpretation of your statement still seems 
legitimate.  If you don't clarify, then my response can only 
be: yes, that *is* (in effect) what you said.

> and you're still ignoring the primary thrust
> of my posts. 

I wasn't sure what your "primary thrust" was, I asked you 
to remind me and you failed to respond.

If you're referring to, 
  "Why, rurpy, do you continue to support, apologize for, 
  and argue in favour of, a piece of software that is "

1. You are continuing to try to misdirect from, *my* primary 
thrust: that in your zeal to make people stop using GG you 
crossed a line by posting some derogatory claims about GG 
that you can not support. I am still waiting for a credible 
explanation from you about how you know that GG is corrupting 
whitespace.

2. I've addressed why I oppose trying to drive people away 
from GG many times, among others in:
  https://groups.google.com/d/msg/comp.lang.python/FFAe5sJ7kQ4/SXXunRofxtEJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/9txi2cB7ppMJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/WRZDOzZd76oJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/41hZ3Si5G0cJ
  https://groups.google.com/d/msg/comp.lang.python/Rxw7H4yNGh4/jKu57BLvqIUJ
  https://groups.google.com/d/msg/comp.lang.python/wh9MzFEHDMM/iwZKSMeRwjQJ
Those are some from 2012 (don't have time to find 2013 ones). 
Many are direct responses to you, most or all are in threads 
you posted in.  Please, instead of just ignoring what I wrote
and repeating the same charges ad infinitum, point out why 
the answers I've already given are wrong.

3. I answered you in a previous post in this thread referring 
you to my explanation of your issue in a concurrent reply to 
Ned B.  Unfortunately that previous post got stuck in the ether
somewhere and just popped out this morning (not your fault of 
course that it wasn't available till now).

4. Virtually all of my responses in the GG wars have been 
only in response to correct or point out some inaccurate 
(IMO) information posted by someone else (often you): that 
Usenet/mailing list/whatever is easy to use as GG, that 
"the community" opposes posts from GG, that the majority 
of people here don't read posts from GG, that GG is 
irredeemably "broken", the alternatives have no significant
problems, that reading GG posts make you go blind, and many 
more I can't recall.  Seldom if ever have I initiated any of 
these debates and have ignored many erroneous or inflammatory 
posts that I could (and perhaps should) have responded to.   

> I'm done debating this with you; I'll continue to push
> people toward options that don't have bugs that inflict themselves on
> everyone else, 

It is the "pushing" I object to.  I've repeatedly said 
if you want tell people about other options you think are 
better and why, I'm all for it.  But making up negative 
stuff up about GG (or anything that you personally don't 
like) should  be totally unacceptable here, and I think it 
is a shame (and sadly illustrative of the deterioration 
of this group) that you (and some others) proudly announce 
your intent to continue.

> and if you continue apologizing for something that
> needs to be fixed, that's your business.

I'm not "apologizing" for GG.  I have acknowledged the problems
their FUd quoting creates.  I have in my own small way tried 
to improve things.  You seem to think though that your opinion 
of how to deal with the problem should be the law.  Again I 
ask you to check your ego. 

Finally, I remind you that the only reason I am in this thread 
is because *you* posted some negative claims about GG that you 
can't support and aren't man enough to admit to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unicode to human readable format

2013-12-27 Thread tomasz . kaczorek
hello,
can I ask you for help? when I try to print s[0] i vane the message: 
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: 
ordinal not in range(128). 
how to solve my problem, please?


regards,
t.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-27 Thread Rustom Mody
On Fri, Dec 27, 2013 at 11:53 AM, Dan Stromberg wrote:
> On Thu, Dec 26, 2013 at 9:43 PM, Rustom Mody  wrote:
>> 2. Always write strings with a u" prefix
> 3.0, 3.1 and 3.2 don't understand this, but 3.3 does.

Ok
I was writing this under the assumption that 2 is really entrenched
whereas 3.n is dispensable when 3.n+1 comes out
At least on my debian box 3.2 recently got obsoleted and removed when
3.3 came out.

>
> In a project I wanted to run on 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and 3.3,

Obviously my assumption may not always be 'assumable' eg sometime ago
there was someone who wanted to port his old working python app to 3.
2to3 was not working because he was using string exceptions (His code
was 1.something!!)


-- 

http://blog.languager.org
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-27 Thread Chris Angelico
On Fri, Dec 27, 2013 at 9:51 PM, Rustom Mody  wrote:
> On Fri, Dec 27, 2013 at 11:53 AM, Dan Stromberg wrote:
>> On Thu, Dec 26, 2013 at 9:43 PM, Rustom Mody  wrote:
>>> 2. Always write strings with a u" prefix
>> 3.0, 3.1 and 3.2 don't understand this, but 3.3 does.
>
> Ok
> I was writing this under the assumption that 2 is really entrenched
> whereas 3.n is dispensable when 3.n+1 comes out
> At least on my debian box 3.2 recently got obsoleted and removed when
> 3.3 came out.

That's true except for the "comes out" part. Just because python.org
has released a newer 3.x Python doesn't mean everyone has it; Debian
Wheezy (the current stable) ships with 3.2, and Debian Squeeze (the
current oldstable, still supported and will be until some time 2014
probably) ships 3.1. So for scripts that need to be deployed onto one
of the most popular Linux distributions, supporting only 3.3 is pretty
much out of the question. And Red Hat, generally, is supported for
even longer. I don't know what Python versions are going to still be
around for the next ten years, but the easiest way to check would
probably be to see what RHEL support dates and Python versions are.

However, I do broadly agree. For controlled environments, you should
be able to slide from 3.1 to 3.2 to 3.3 to 3.4 on whatever schedule
you choose, and happily drop support for the older versions. But in
less controlled environments, that's a bit harder.

Probably within the next 5 years, it'll become reasonably plausible to
support nothing older than 2.6, and then all those 3.x compatibility
__future__s will be all you need. Well, most of what you need. There
are still fundamental issues with functions not taking Unicode
strings, but that's going to be a problem whatever you do. But life'll
be a lot easier.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-27 Thread Steven D'Aprano
Chris Angelico wrote:

> However, I do broadly agree. For controlled environments, you should
> be able to slide from 3.1 to 3.2 to 3.3 to 3.4 on whatever schedule
> you choose, and happily drop support for the older versions. But in
> less controlled environments, that's a bit harder.
> 
> Probably within the next 5 years, it'll become reasonably plausible to
> support nothing older than 2.6, 

It's already reasonable to support nothing older than 2.6, or 2.7 for that
matter.

The *first* question you have to ask is, which third-party libraries do I
rely on? Those libraries will set the minimum system requirement. Beyond
that, you have total freedom to support as many or as few versions as you
like. Ask yourself:

- Which operating systems do I intend to support?

If the answer is "Windows only", you pretty much can pick whichever version
of Python you like, since all versions of Python are equally difficult (or
easy) to install on Windows. Likewise for Mac.

If the answer includes Linux or Unix, then the next question to ask is:

- Shall I support only the OS-provided version(s) of Python?

If so, then you need to work out which version(s) of Python are common to
all the OSes you intend to support. E.g. there are currently supported
versions of Centos and RHEL that provide Python 2.4. If you intend to
support those versions of Centos and RHEL, then you need to support Python
2.4. If you are prepared to drop support for such systems, then you can
drop support for 2.4 and move on to 2.5 or 2.6. It depends on how much
extra effort you wish to go to in order to support what percentage of your
users. Personally, I find it very annoying when vendors expect you to
upgrade perfectly adequate, still supported systems, and so I try to target
2.4+ when I can. (Also, I am still running a Centos system with 2.4, so I'm
scratching my own itch.)

On the other hand, I once tried to target Python 2.3+. That decision lasted
about two days. The amount of functionality missing from 2.3 compared to
2.4 makes it too painful.

Alternatively, if you don't care about the OS-provided Python (perhaps
you're providing your own, or you expect your users to install from
source), then I think it is acceptable to target 2.7 and 3.3 or better
(e.g. drop support for 3.1 and 3.2). 3.0 is not supported at all -- it was
a buggy release and was quickly dropped for 3.1. If you're not constrained
by "yum python3" or "apt-get python3", then 3.3 is probably the version you
should aim for.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unicode to human readable format

2013-12-27 Thread Steven D'Aprano
[email protected] wrote:

> hello,
> can I ask you for help? when I try to print s[0] i vane the message:
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1:
> ordinal not in range(128). how to solve my problem, please?

What version of Python?

What operating system?

What environment are you running in? IDLE? The shell or cmd.exe? Powershell?
xterm? Something else?

Please copy and paste the complete traceback, starting from the line

Traceback (most recent call last):

to the end.

Please print repr(s[0]) and show us the output.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-27 Thread Chris Angelico
On Fri, Dec 27, 2013 at 10:34 PM, Steven D'Aprano
 wrote:
> Alternatively, if you don't care about the OS-provided Python (perhaps
> you're providing your own, or you expect your users to install from
> source), then I think it is acceptable to target 2.7 and 3.3 or better
> (e.g. drop support for 3.1 and 3.2). 3.0 is not supported at all -- it was
> a buggy release and was quickly dropped for 3.1. If you're not constrained
> by "yum python3" or "apt-get python3", then 3.3 is probably the version you
> should aim for.

That's about the size of it. I'm quite happy to work with a 3.4 alpha,
but when it comes to installation instructions, "get this and compile
it" is a lot less helpful than "install python3 via your OS package
manager" (especially since compiling Python from source also means
getting the development versions of whatever modules you need -
apt-getting a bunch of -dev packages, or whatever - and if you don't
get them, some modules mightn't work even though core Python does).
Hence I'd like to stick to OS-provided versions *where reasonable* -
I'm not going to warp my code around Python 2.4 unless there's a large
slab of users on that, but I will restrict myself to Pike 7.8.700
because it's worth the effort.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unicode to human readable format

2013-12-27 Thread Ned Batchelder

On 12/27/13 5:43 AM, [email protected] wrote:

hello,
can I ask you for help? when I try to print s[0] i vane the message: 
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: 
ordinal not in range(128).
how to solve my problem, please?


regards,
t.



For help with the fundamentals, you can read or watch this PyCon 
presentation:  Pragmatic Unicode, or, How Do I Stop the Pain? 
http://nedbatchelder.com/text/unipain.html




--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: unicode to human readable format

2013-12-27 Thread Dave Angel
On Fri, 27 Dec 2013 02:43:58 -0800 (PST), [email protected] 
wrote:
can I ask you for help? when I try to print s[0] i vane the 
message: UnicodeEncodeError: 'ascii' codec can't encode characters in 
position 0-1: ordinal not in range(128). 

how to solve my problem, please?


First, what version of what os, and what version of python? 

Next,  what terminal are you running,  or what ide, and do you have 
stdout redirected? 

Finally what does your program look like, or at least tell us the 
type and represents of s [0].


Bottom line is that s [0] contains a code point that's larger than 7f 
and print is convinced that your terminal can handle only ASCII.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-27 Thread Ned Batchelder

On 12/27/13 12:04 AM, Travis McGee wrote:

The Python.org site says that the future is Python 3, yet whenever I try
something new in Python, such as Tkinter which I am learning now,
everything seems to default to Python 2. By this I mean that, whenever I
find that I need to install another package, it shows up as Python 2
unless I explicitly specify Python 3.

What's the deal? If I want to make a distributable software package,
should it be 2 or 3? Enquiring minds want to know.


Choosing between 2 and 3 should be done the same way any version 
decision is made: examine all of your dependencies (libraries, help 
online, skilled helpers available, hosting options, books, etc), then 
choose the highest version that supports them.  Some people still find 
that the answer is 2, but many are finding that it is now 3.  There's a 
lot of FUD about Python 3, don't listen to it.


Certainly don't be thrown by the "default" of 2.  It doesn't matter what 
most people do, or how your operating system is configured, what matters 
is whether you have what you need.


Note that on sensible operating systems, "python" will continue to mean 
Python 2, and "python3" will mean Python 3.  This will help perpetuate 
the notion that Python 3 is the outlier, but it's the only way to keep 
software working properly.  Don't let it color your perceptions.


If you are going to support both 2 and 3, in addition to the other good 
suggestions in this thread, the six module on PyPI can help with the 
differences.


--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Google Groups + this list

2013-12-27 Thread Dave Angel

On Thu, 26 Dec 2013 12:04:22 -0800 (PST), [email protected] wrote:

On 12/26/2013 05:41 AM, Chris Angelico wrote:
> On Thu, Dec 26, 2013 at 4:13 PM,   wrote:
>> On 12/25/2013 09:17 PM, Chris Angelico wrote:
>>>[...]
>>> Or maybe I should have just filtered everything from Google 

Groups
>>> into the bit bucket, because responding just creates threads 

like
>>> this. Do you honestly think that would be better? No response 

at all

>>> if the post comes from GG?
>>
>> Do you really think that if *you* ignore Google Groups, then
>> Google Groups posters will get "no response at all"?  Could
>> you please turn down your ego a little?
> 
> That's not what I said, 



On rereading, my interpretation of your statement still seems 
legitimate.  If you don't clarify, then my response can only 
be: yes, that *is* (in effect) what you said.


It was and still is clear to me what Chris meant. With such a filter, 
clearly he would be making no response at all to such a post.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


String Template

2013-12-27 Thread t . giuseppe
Hello

I'm rewriting a program previously written in C #, and trying to keep the same 
configuration file, I have a problem with untapped strings.

The previous configuration files provide an input template string of this type:

 


This string is parsed and the values are replaced with the actual values 
written to a log file (apache), then he is given the variable name.

Taking for example a classic line of apache log:

0.0.0.0 - [27/Dec/2013: 00:56:51 +0100] "GET / webdav / HTTP/1.1" 404 524 "-" 
"Mozilla/5.0 (Windows, U, Windows NT 5.1, en-US , rv: 1.9.2.12) Gecko/20101026 
Firefox/3.6.12 "

Is there any way to pull out the values so arranged as follows:

ip = 0.0.0.0
date = 27/Dec/2013: 00:56:51 +0100
url = / webdav /

Tnx
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String Template

2013-12-27 Thread Chris Angelico
On Fri, Dec 27, 2013 at 11:55 PM,   wrote:
> I'm rewriting a program previously written in C #, and trying to keep the 
> same configuration file, I have a problem with untapped strings.

Not sure what you mean by "untapped" here?

> Taking for example a classic line of apache log:
>
> 0.0.0.0 - [27/Dec/2013: 00:56:51 +0100] "GET / webdav / HTTP/1.1" 404 524 "-" 
> "Mozilla/5.0 (Windows, U, Windows NT 5.1, en-US , rv: 1.9.2.12) 
> Gecko/20101026 Firefox/3.6.12 "
>
> Is there any way to pull out the values so arranged as follows:
>
> ip = 0.0.0.0
> date = 27/Dec/2013: 00:56:51 +0100
> url = / webdav /
>

(Aside: Do you really have spaces in your URLs? That seems odd.)

One common way to implement this sort of thing is with a regular
expression. You can either derive a regex from your config file, or
have users directly manage the regex.

For the specific case of parsing the Apache common log format, there's
plenty of material around. This page [1] has a tidy regex that'll do
the job, and this module [2] purports to create a parser by reading
the configuration line that creates it. I don't know anything about
either, save that they came up in a Google search for 'python apache
common log', along with a whole lot of other decent-looking results.

But for a more general solution - supposing you have piles and piles
of those parser strings - I'd be inclined to write a preparser that
reads your config file and derives regex patterns. It needs to figure
out what's a placeholder and what's literal text, then escape the
literal text (if there are regex metacharacters in it) and come up
with some sort of capturing sequence for the placeholder. I don't know
what you'd want there; possibly (.*?) will be the best (that means
"capture any number of characters, as few as possible"). But you know
your data far better than I do.

ChrisA

[1] http://www.seehuhn.de/blog/52
[2] https://pypi.python.org/pypi/apachelog/1.0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Experiences/guidance on teaching Python as a first programming language

2013-12-27 Thread Steven D'Aprano
On Thu, 19 Dec 2013 19:38:51 -0500, Roy Smith wrote:

> Does anybody ever use D?  I looked at it a few years ago.  It seemed
> like a very good concept.  Sort of C++, with the worst of the crap torn
> out. If nothing else, with the preprocessor torn out :-)
> 
> Did it ever go anywhere?

Apparently Facebook are now working with it:

http://www.fastcolabs.com/3019948/more-about-d-language-and-why-facebook-is-experimenting-with-it



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Brython (Python in the browser)

2013-12-27 Thread Roy Smith
In article <[email protected]>,
 Pierre Quentel  wrote:

> Hi,
> 
> Ever wanted to use Python instead of Javascript for web client programming ? 
> Take a look at Brython, an implementation of Python 3 in the browser, with an 
> interface with DOM elements and events
> 
> Its use is very simple :
> - load the Javascript library brython.js : 

Re: Brython (Python in the browser)

2013-12-27 Thread jonas . thornvall
Den fredagen den 27:e december 2013 kl. 07:14:35 UTC+1 skrev Pierre Quentel:
> Hi,
> 
> 
> 
> Ever wanted to use Python instead of Javascript for web client programming ? 
> Take a look at Brython, an implementation of Python 3 in the browser, with an 
> interface with DOM elements and events
> 
> 
> 
> Its use is very simple :
> 
> - load the Javascript library brython.js : 

Python in the news

2013-12-27 Thread Travis McGee

From Twitter:

RT @cjbrummitt Python kills security guard at Sanur Hyatt, Bali (Ind). 
bit.ly/1fLCWvn < bad coding has CONSEQUENCES, ppl!

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Thursday, December 26, 2013 8:29:15 PM UTC-5, Roy Smith wrote:
> In article <[email protected]>,
> 
>  [email protected] wrote:
> 
> 
> 
> > > In [1]: import time
> 
> > > In [2]: time.time()
> 
> > > Out[2]: 1388085670.1567955
> 
> > 
> 
> > OK i did what you said but I am only getting 2 decimal places.  
> 
> > Why is this and what can I do to get the millisecond?  
> 
> 
> 
> What operating system are you on?  The Python time routines can only 
> 
> return as much precision as the operating system makes available.

I use Ubuntu 12.10.  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
 I pretty much stopped using Windows 4 
> 
> years ago.
> 
I got off the plantation over a year ago and have not looked back. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Thursday, December 26, 2013 11:54:41 PM UTC-5, Dave Angel wrote:
> On Thu, 26 Dec 2013 20:03:34 -0500, Terry Reedy  
> 
> wrote:
> 
> > On 12/26/2013 5:48 PM, Dave Angel wrote:
> 
> > > You're probably on Windows,  which does time differently.
> 
> 
> 
> > With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional 
> 
> digits.
> 
> >  >>> import time; time.time()
> 
> > 1388105935.971099
> 
> 
> 
> > With 2.7, same machine, I only get 3.
> 
> 
> 
> The way I recall it,  Windows time is a mess. To get better than 10 
> 
> ms resolution you needed to use time.clock, but that isn't epoch 
> 
> time. Trickier solutions existed, depending on exactly what the 
> 
> problem was. But judging from your test, 3.3 built those gyrations 
> 
> into the stdlib. I dunno,  I pretty much stopped using Windows 4 
> 
> years ago.
> 
> 
> 
> -- 
> 
> DaveA

I am on Ubuntu 12.10.   I am still working with the 2 decimal places. Sometime 
ago i had this issue and I forget how i solved it. maybe i used datetime? 
thanks!  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Dave Angel
On Fri, 27 Dec 2013 07:40:29 -0800 (PST), [email protected] 
wrote:
I am on Ubuntu 12.10.   I am still working with the 2 decimal 
places. Sometime ago i had this issue and I forget how i solved it. 
maybe i used datetime? thanks!


Now I'm stumped.  2.7.3 on Ubuntu 12.04 and time.time gives me 6 
decimals. Of course it's a float, so you could get more or fewer. But 
if you're only seeing 2, something else is different.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article <[email protected]>,
 [email protected] wrote:

> I am on Ubuntu 12.10.   I am still working with the 2 decimal places. 
> Sometime ago i had this issue and I forget how i solved it. maybe i used 
> datetime? thanks!  

That's strange.  Linux should give you time to the microsecond, or 
something in that range.

Please post the *exact* code you're running.  The code you posted 
earlier is obviously only a fragment of some larger program, so we can 
only guess what's happening.  Assuming your program is in a file called 
"prog.py", run the following commands and copy-paste the output:

cat /etc/lsb-release

uname -a

python --version

cat prog.py

python prog.py
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Brython (Python in the browser)

2013-12-27 Thread Johannes Schneider

On 27.12.2013 07:14, Pierre Quentel wrote:

Hi,

Ever wanted to use Python instead of Javascript for web client programming ? 
Take a look at Brython, an implementation of Python 3 in the browser, with an 
interface with DOM elements and events

Its use is very simple :
- load the Javascript library brython.js : 

Re: cascading python executions only if return code is 0

2013-12-27 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> On Thu, 26 Dec 2013 23:29:30 -0500, Roy Smith  declaimed the
> following:
> 
> >
> >NTP is never supposed to move the clock backwards.  If your system clock 
> >is fast, it's supposed to reduce the rate your clock runs until it's 
> >back in sync.  Well, maybe it only does that for small corrections?
> 
>   Especially likely when one considers that M$ Windows only does a time
> synch once a week.

When I attempt to reason about what is possible and what is impossible 
in a program, I assume a sane universe.  Windows violates that 
assumption.  I am not responsible for what happens after that.

People complain that Python 3 has been out for 5 years and the world is 
still dragging its feet upgrading from Python 2.  NTP has been around 
for almost 30 years.

Keeping a bunch of clocks on a network in sync is a solved problem.  The 
world really needs to move on to new problems like how to deal with more 
than 2^32 devices on a network.  Or how to deal with languages where 26 
letters isn't enough.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-27 Thread Rustom Mody
On Fri, Dec 27, 2013 at 10:12 PM, Roy Smith wrote:
> In article ,
>  Dennis Lee Bieber  wrote:
>
>> On Thu, 26 Dec 2013 23:29:30 -0500, Roy Smith  declaimed the
>> following:
>>
>> >
>> >NTP is never supposed to move the clock backwards.  If your system clock
>> >is fast, it's supposed to reduce the rate your clock runs until it's
>> >back in sync.  Well, maybe it only does that for small corrections?
>>
>>   Especially likely when one considers that M$ Windows only does a time
>> synch once a week.
>
> When I attempt to reason about what is possible and what is impossible
> in a program, I assume a sane universe.

Hmm...
Any clues for a pathway to this alternate universe?
:D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT]Royal pardon for codebreaker Turing

2013-12-27 Thread Mark Lawrence

On 24/12/2013 05:07, Steven D'Aprano wrote:

On Tue, 24 Dec 2013 00:32:31 +, Mark Lawrence wrote:


Maybe of interest to some of you
http://www.bbc.co.uk/news/technology-25495315


While I'm happy for Alan Turing, may he rest in peace, I think the
thousands of other homosexuals who have been prosecuted for something
which shouldn't be a crime in the first place might be a bit peeved that
he is singled out for a pardon.

Personally, I think that people ought to throw a party celebrating
Turing's rehabilitation, and do it right outside the Russian Embassy.



Any particular reason for the restriction to Russian Embassy?

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Brython (Python in the browser)

2013-12-27 Thread Pierre Quentel
Le vendredi 27 décembre 2013 15:56:33 UTC+1, [email protected] a écrit :
> Den fredagen den 27:e december 2013 kl. 07:14:35 UTC+1 skrev Pierre Quentel:
> 
> > Hi,
> 
> > 
> 
> > 
> 
> > 
> 
> > Ever wanted to use Python instead of Javascript for web client programming 
> > ? Take a look at Brython, an implementation of Python 3 in the browser, 
> > with an interface with DOM elements and events
> 
> > 
> 
> > 
> 
> > 
> 
> > Its use is very simple :
> 
> > 
> 
> > - load the Javascript library brython.js : 

Re: cascading python executions only if return code is 0

2013-12-27 Thread Mark Lawrence

On 27/12/2013 01:44, Chris Angelico wrote:

On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith  wrote:

In article ,
  Ethan Furman  wrote:


Mostly I don't want newbies thinking "Hey!  I can use assertions for all my
confidence testing!"


How about this one, that I wrote yesterday;

 assert second >= self.current_second, "time went backwards"

I think that's pretty high up on the "can never happen" list.


assert second >= self.current_second, "user changed the clock"

ChrisA



assert "shoot admin who gave user too much privilege" ?

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Brython (Python in the browser)

2013-12-27 Thread Pierre Quentel
Le vendredi 27 décembre 2013 17:12:09 UTC+1, Johannes Schneider a écrit :
> On 27.12.2013 07:14, Pierre Quentel wrote:
> 
> > Hi,
> 
> >
> 
> > Ever wanted to use Python instead of Javascript for web client programming 
> > ? Take a look at Brython, an implementation of Python 3 in the browser, 
> > with an interface with DOM elements and events
> 
> >
> 
> > Its use is very simple :
> 
> > - load the Javascript library brython.js : 

Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:
> In article <[email protected]>,
> 
>  [email protected] wrote:
> 
> 
> 
> > I am on Ubuntu 12.10.   I am still working with the 2 decimal places. 
> 
> > Sometime ago i had this issue and I forget how i solved it. maybe i used 
> 
> > datetime? thanks!  
> 
> 
> 
> That's strange.  Linux should give you time to the microsecond, or 
> 
> something in that range.
> 
> 
> 
> Please post the *exact* code you're running.  The code you posted 
> 
> earlier is obviously only a fragment of some larger program, so we can 
> 
> only guess what's happening.  Assuming your program is in a file called 
> 
> "prog.py", run the following commands and copy-paste the output:
> 
> 
i cant run it that way.  i tried using the python prompt in terminal but got 
nothing.  but here is all the code relevant to this issue:
#all the imports
import sys
import posixpath
import time
from time import strftime
from datetime import datetime
import os
import wx
import cPickle as pickle
import gnuradio.gr.gr_threading as _threading


#the function that writes the time values
 def update(self, field_values):

now = datetime.now()

#logger ---
#  new line to write on
self.logfile.write('\n')
#  write date, time, and seconds from the epoch
self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
self.logfile.write('%s\t'%(time.time()))
# list to store dictionary keys in tis order
keys = ["duid", "nac",  "tgid", "source", "algid", "kid"]
# loop through the keys in the right order
for k in keys:
#  get the value of the current key
f = field_values.get(k, None)
# if data unit has value...
if f:
#  output the value with trailing tab
self.logfile.write('%s\t'%(str(f)))  
# if data unit doesnt have this value print a tab
else:
self.logfile.write('\t')
#end logger 

#if the field 'duid' == 'hdu', then clear fields
if field_values['duid'] == 'hdu':
self.clear()
elif field_values['duid'] == 'ldu1':
self.clear()
elif field_values['duid'] == 'ldu2':
self.clear()
#elif field_values['duid'] == 'tdu':
 #   self.clear()
#loop through all TextCtrl fields storing the key/value pairs in k, v
for k,v in self.fields.items():
# get the dict value for this TextCtrl
f = field_values.get(k, None)
# if the value is empty then set the new value
if f:
v.SetValue(f)

#sample output in a .txt file:

2013-12-27  12:07:331388164053.18
2013-12-27  12:07:331388164053.36
2013-12-27  12:07:331388164053.54
2013-12-27  12:07:331388164053.73
2013-12-27  12:07:331388164053.91
2013-12-27  12:07:341388164054.11
2013-12-27  12:07:341388164054.28
2013-12-27  12:07:341388164054.48
2013-12-27  12:07:341388164054.66
2013-12-27  12:07:341388164054.84
2013-12-27  12:07:371388164057.62
2013-12-27  12:07:371388164057.81
2013-12-27  12:07:371388164057.99
2013-12-27  12:07:381388164058.18
2013-12-27  12:07:381388164058.37
2013-12-27  12:07:381388164058.54
2013-12-27  12:07:381388164058.73
2013-12-27  12:07:381388164058.92

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Ned Batchelder

On 12/27/13 1:09 PM, [email protected] wrote:

On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:

In article <[email protected]>,

  [email protected] wrote:




I am on Ubuntu 12.10.   I am still working with the 2 decimal places.



Sometime ago i had this issue and I forget how i solved it. maybe i used



datetime? thanks!




That's strange.  Linux should give you time to the microsecond, or

something in that range.



Please post the *exact* code you're running.  The code you posted

earlier is obviously only a fragment of some larger program, so we can

only guess what's happening.  Assuming your program is in a file called

"prog.py", run the following commands and copy-paste the output:



i cant run it that way.  i tried using the python prompt in terminal but got 
nothing.  but here is all the code relevant to this issue:
#all the imports
import sys
import posixpath
import time
from time import strftime
from datetime import datetime
import os
import wx
import cPickle as pickle
import gnuradio.gr.gr_threading as _threading


#the function that writes the time values
  def update(self, field_values):

 now = datetime.now()

 #logger ---
 #  new line to write on
 self.logfile.write('\n')
 #  write date, time, and seconds from the epoch
 self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
 self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
 self.logfile.write('%s\t'%(time.time()))
 # list to store dictionary keys in tis order
 keys = ["duid", "nac",  "tgid", "source", "algid", "kid"]
 # loop through the keys in the right order
 for k in keys:
 #  get the value of the current key
 f = field_values.get(k, None)
 # if data unit has value...
 if f:
 #  output the value with trailing tab
 self.logfile.write('%s\t'%(str(f)))
 # if data unit doesnt have this value print a tab
 else:
 self.logfile.write('\t')
 #end logger 

 #if the field 'duid' == 'hdu', then clear fields
 if field_values['duid'] == 'hdu':
 self.clear()
 elif field_values['duid'] == 'ldu1':
 self.clear()
 elif field_values['duid'] == 'ldu2':
 self.clear()
 #elif field_values['duid'] == 'tdu':
  #   self.clear()
 #loop through all TextCtrl fields storing the key/value pairs in k, v
 for k,v in self.fields.items():
 # get the dict value for this TextCtrl
 f = field_values.get(k, None)
 # if the value is empty then set the new value
 if f:
 v.SetValue(f)

#sample output in a .txt file:

2013-12-27  12:07:331388164053.18
2013-12-27  12:07:331388164053.36
2013-12-27  12:07:331388164053.54
2013-12-27  12:07:331388164053.73
2013-12-27  12:07:331388164053.91
2013-12-27  12:07:341388164054.11
2013-12-27  12:07:341388164054.28
2013-12-27  12:07:341388164054.48
2013-12-27  12:07:341388164054.66
2013-12-27  12:07:341388164054.84
2013-12-27  12:07:371388164057.62
2013-12-27  12:07:371388164057.81
2013-12-27  12:07:371388164057.99
2013-12-27  12:07:381388164058.18
2013-12-27  12:07:381388164058.37
2013-12-27  12:07:381388164058.54
2013-12-27  12:07:381388164058.73
2013-12-27  12:07:381388164058.92

Thanks!



Instead of:

"%s" % time.time()

try:

"%.6f" % time.time()

%.6f is a formatting code meaning, floating-point number, 6 decimal places.

--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article <[email protected]>,
 [email protected] wrote:

> > Please post the *exact* code you're running.  The code you posted 
> > earlier is obviously only a fragment of some larger program, so we can 
> > only guess what's happening.  Assuming your program is in a file called 
> > "prog.py", run the following commands and copy-paste the output:
> > 
> i cant run it that way.  i tried using the python prompt in terminal but got 
> nothing.

Why can't you run it that way?  What does "got nothing" mean?  Did you 
just get another shell prompt back with no output?  Did your shell 
window close?  Did the machine crash?

I asked you to run these commands:

> cat /etc/lsb-release
> 
> uname -a
> 
> python --version

Did you run them?  What output did you get?  I know it seems silly, but 
it really is important that people know exactly what your environment 
is.  The less information we have, the harder it is to figure out what's 
going on.

> but here is all the code relevant to this issue:

Well, you've got a lot of code there.  What you want to do is reduce 
this down to the smallest possible amount of code which demonstrates the 
problem.

I can't even begin to run your code here because I don't have gnuradio 
installed.  It's almost certainly not necessary to demonstrate the 
problem (nor are posixpath, cPickle, wx, etc), but I can already see 
that as soon as I delete those, I'll run up against the next problem, 
which is that update() is a method of a class and I don't have the rest 
of that class.

Let's take this one step at a time.  You've got:

self.logfile.write('%s\t'%(time.time()))

which is apparently causing, "1388164053.18", to end up in your output 
file.  The question is, why are there only two digits after the decimal 
place?  Possible causes:

1) Your version of time.time() is returning a float which is only 
precise to the centisecond.

2) Your version of string's %s operator is only converting floats to two 
decimal places.

3) Your self.logfile.write() method is taking the string it was given 
and stripping off all the digits beyond two after the decimal point.

All of those seem about equally unlikely, so just start to eliminate 
them one by one.  What happens if you do:

self.logfile.write("1388164053.183454")

What happens if you do:

t = time.time()
self.logfile.write("str=%s, repr=%s", (str(t), repr(t)))

what happens if you get rid of the whole self.logfile.write() thing and 
just use print?  If you're working in some environment where stdout gets 
redirected somewhere that you can't find, bypass stdout completely:

my_file = open("/tmp/foo", "w")
print >> my_file, time.time()

and then go look and see what got dropped into /tmp/foo.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article ,
 Roy Smith  wrote:

> self.logfile.write("str=%s, repr=%s", (str(t), repr(t)))

Ugh, make that:

> self.logfile.write("str=%s, repr=%s" % ((str(t), repr(t)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Brython (Python in the browser)

2013-12-27 Thread billy . earney
Awesome..  Wonderful work!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python in the news

2013-12-27 Thread Larry Martell
John D. MacDonald fan?

On Friday, December 27, 2013, Travis McGee wrote:

> From Twitter:
>
> RT @cjbrummitt Python kills security guard at Sanur Hyatt, Bali (Ind).
> bit.ly/1fLCWvn < bad coding has CONSEQUENCES, ppl!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT]Royal pardon for codebreaker Turing

2013-12-27 Thread Tim Delaney
On 28 December 2013 04:34, Mark Lawrence  wrote:

>
>> Personally, I think that people ought to throw a party celebrating
>> Turing's rehabilitation, and do it right outside the Russian Embassy.
>>
>>
> Any particular reason for the restriction to Russian Embassy?


I suspect it's in reference to the difficulties homosexuals are likely to
face when attending or competing in the 2014 Winter Olympic and Paralympic
Games at Sochi. Adam Hills in particular has had a real go about it on his
UK show "The Last Leg" where he decided to turn Vladimir Putin into a
homosexual icon (search "last leg sochi" without the quotes).

Tim Delaney
-- 
https://mail.python.org/mailman/listinfo/python-list


eclipse+pyDev code complete problem

2013-12-27 Thread zhaoyunsong
dear all,
I am trying to configure eclipse + pydev as my ide, but there seems to be some 
problem on code complete.
the attached is the case when code complete does not work. any suggestions? 
Thanks!


my system is win 64bit
pyhon 3.3 64bit
eclipse kepler-SR1
pydev 3.1
I downloaded pillow from this website:http://www.lfd.uci.edu/~gohlke/pythonlibs/


Yunsong Zhao<>-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-27 Thread Chris Angelico
On Sat, Dec 28, 2013 at 3:42 AM, Roy Smith  wrote:
> Keeping a bunch of clocks on a network in sync is a solved problem.  The
> world really needs to move on to new problems like how to deal with more
> than 2^32 devices on a network.  Or how to deal with languages where 26
> letters isn't enough.

*clap* Very tidy, finding two examples that were both solved in 1996. I like.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Variables in a loop, Newby question

2013-12-27 Thread vanommen . robert
Op dinsdag 24 december 2013 17:23:43 UTC+1 schreef Jean-Michel Pichavant:
> - Original Message -
> > Hello, for the first time I'm trying te create a little Python
> > program. (on a raspberri Pi)
> > 
> > I don't understand the handling of variables in a loop with Python.
> > 
> > 
> > Lets say i want something like this.
> > 
> > x = 1
> > while x <> 10
> > var x = x
> > x = x + 1
> > 
> > The results must be:
> > 
> > var1 = 1
> > var2 = 2
> > 
> > enz. until var9 = 9
> > 
> > How do i program this in python?
> 
> Short story, cause it's almost xmas eve :D:
> 
> python 2.5:
> 
> var = {}
> for i in range(10):
>   var[i] = i
> 
> print var[1]
> print var[2]
> print var
> 
> var here is a dictionary. I suggest that you read through the python tutorial 
> :)
> 
> JM
> 
> 
> -- IMPORTANT NOTICE: 
> 
> The contents of this email and any attachments are confidential and may also 
> be privileged. If you are not the intended recipient, please notify the 
> sender immediately and do not disclose the contents to any other person, use 
> it for any purpose, or store or copy the information in any medium. Thank you.

This was the information I was looking for and what my first question was 
about. Got this working, Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-27 Thread pecore
Roy Smith  writes:

> Or how to deal with languages where 26 letters isn't enough.

English! that is, imvho
English is in sore need
of some more letters[*]
and of diacriticals too
  g
[*] unable to quantify!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Cameron Simpson
On 27Dec2013 07:40, [email protected]  
wrote:
> I am on Ubuntu 12.10.   I am still working with the 2 decimal
> places. Sometime ago i had this issue and I forget how i solved it.
> maybe i used datetime? thanks!

Repeatedly people have asked you to show your exact code. Still nothing.

Here's a clue, from a Gentoo box running kernel 3.2.1-gentoo-r2:

  $ python
  Python 2.7.2 (default, Feb  9 2012, 18:40:46)
  [GCC 4.5.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import time; print time.time()
  1388190100.44
  >>> import time; time.time()
  1388190102.795531
  >>>

Please show us _exactly_ what you're doing. I'm guessing that print
is confusing you.

Cheers,
-- 
Cameron Simpson 

Try moving off NT easily.  You can move from Solaris to HP/UX to AIX or
DEC easily-- relative to moving off of NT, which is like a Roach
Motel.  Once you check in, you never check out.
- Scott McNealy, Sun Microsystems
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
[email protected] wrote:
> I need to print the time in seconds from the epoch with 
> millisecond precision.  

I wrote:

> What happens if you do:
> 
> t = time.time()
> self.logfile.write("str=%s, repr=%s", (str(t), repr(t)))

At the time I originally posted that, I was baffled as to what was going 
on and was simply feeding you suggestions for how to go about debugging 
the problem logically.

However, I have since figured out exactly what's going on.  I'm going to 
do you a favor and NOT tell you what I've figured out (because you won't 
learn anything that way), but I will give you a hint.  The hint is that 
if you run the two lines of code I suggested above, the answer should be 
obvious.

And, once you do that, please report your findings back to us, because 
it's a fun little quirk of Python and one that I suspect has tripped up 
more than a few people over time.  In fact, I seem to recall being 
mystified by this myself once.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Ned Batchelder

On 12/27/13 7:25 PM, Cameron Simpson wrote:

On 27Dec2013 07:40, [email protected]  
wrote:

I am on Ubuntu 12.10.   I am still working with the 2 decimal
places. Sometime ago i had this issue and I forget how i solved it.
maybe i used datetime? thanks!


Repeatedly people have asked you to show your exact code. Still nothing.


Is something wrong with the connectivity of this list?  Matt posted his 
code about six hours before your message.


--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Steven D'Aprano
On Fri, 27 Dec 2013 21:10:49 -0500, Ned Batchelder wrote:

> On 12/27/13 7:25 PM, Cameron Simpson wrote:
>> On 27Dec2013 07:40, [email protected]
>>  wrote:
>>> I am on Ubuntu 12.10.   I am still working with the 2 decimal places.
>>> Sometime ago i had this issue and I forget how i solved it. maybe i
>>> used datetime? thanks!
>>
>> Repeatedly people have asked you to show your exact code. Still
>> nothing.
> 
> Is something wrong with the connectivity of this list?  Matt posted his
> code about six hours before your message.

Methinks too many people have been hitting the Christmas eggnog a little 
harder than is wise...

:-)




-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT]Royal pardon for codebreaker Turing

2013-12-27 Thread Steven D'Aprano
On Sat, 28 Dec 2013 07:30:34 +1100, Tim Delaney wrote:

> On 28 December 2013 04:34, Mark Lawrence 
> wrote:
> 
> 
>>> Personally, I think that people ought to throw a party celebrating
>>> Turing's rehabilitation, and do it right outside the Russian Embassy.
>>>
>>>
>> Any particular reason for the restriction to Russian Embassy?
> 
> 
> I suspect it's in reference to the difficulties homosexuals are likely
> to face when attending or competing in the 2014 Winter Olympic and
> Paralympic Games at Sochi.

I don't care about the Olympians. Their presence in Russia is voluntary, 
and so long as they keep it in their pants for a few weeks (or at least 
don't get caught) they get to go home again a few weeks later. Have a 
thought for those who don't get to go home again. I'm talking about the 
situation in Russia, where the government is engaging in 1930s-style 
scape-goating and oppression of homosexuals. They haven't quite reached 
the level of Kristallnacht or concentration camps, but the rhetoric and 
laws coming out of the Kremlin are just like that coming out of the 
Reichstag in the thirties.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT]Royal pardon for codebreaker Turing

2013-12-27 Thread Tim Delaney
On 28 December 2013 15:16, Steven D'Aprano  wrote:

> I don't care about the Olympians. Their presence in Russia is voluntary,
> and so long as they keep it in their pants for a few weeks (or at least
> don't get caught) they get to go home again a few weeks later. Have a
> thought for those who don't get to go home again. I'm talking about the
> situation in Russia, where the government is engaging in 1930s-style
> scape-goating and oppression of homosexuals. They haven't quite reached
> the level of Kristallnacht or concentration camps, but the rhetoric and
> laws coming out of the Kremlin are just like that coming out of the
> Reichstag in the thirties.


You are of course correct - I was still groggy from waking up when I
replied, and focused on the element that I had been most exposed to.

Tim Delaney
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unicode to human readable format

2013-12-27 Thread wxjmfauth
Le vendredi 27 décembre 2013 12:37:17 UTC+1, Steven D'Aprano a écrit :
> [email protected] wrote:
> 
> 
> 
> > hello,
> 
> > can I ask you for help? when I try to print s[0] i vane the message:
> 
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1:
> 
> > ordinal not in range(128). how to solve my problem, please?
> 
> 
> 
> What version of Python?
> 
> 
> 
> What operating system?
> 
> 
> 
> What environment are you running in? IDLE? The shell or cmd.exe? Powershell?
> 
> xterm? Something else?
> 
> 
> 
> Please copy and paste the complete traceback, starting from the line
> 
> 
> 
> Traceback (most recent call last):
> 
> 
> 
> to the end.
> 
> 
> 
> Please print repr(s[0]) and show us the output.
> 
> 


What do you expect?
The representation is - and should be -

>>> print repr(s[0])
u'\u0105\u017c\u0119\u0142\u0144'

independently of the tool one uses to process such
a code.


Now, if one prints s[0], the result may be - and should be -
different from the tool.


win console, cp850

>>> print s[0]
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python27\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 0-4: cha
racter maps to 
>>>


win console, cp1252

>>> print s[0]
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python27\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-4: cha
racter maps to 
>>>

win console, cp1250

>>> s = [u'\u0105\u017c\u0119\u0142\u0144']
>>> print s[0]
ążęłń
>>>


SciTE editor, output pane "locale", cp1252 for me.

Traceback (most recent call last):
  File "utrick.py", line 18, in 
print u'\u0105\u017c\u0119\u0142\u0144'
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: 
ordinal not in range(128)
>Exit code: 1


SciTE editor, output pane 65001

Traceback (most recent call last):
  File "utrick.py", line 18, in 
print u'\u0105\u017c\u0119\u0142\u0144'
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: 
ordinal not in range(128)
>Exit code: 1


Now in IDLE, Western European version of Windows, 
one get this

>>> print s[0]
ążęłń

Note, by chance it is printing something. It may
come it does not print, understand, render chars
at all. *This is wrong*.



My interactive interpreter I wrote for Py2.*
(full of dirty tricks).

>>> print repr(s[0])
u'\u0105\u017c\u0119\u0142\u0144'
>>> print s[0]
?

*This is correct*, it is an expected result and it
works for all chars.



A (the) correct way to print s[0] with a console (all
platforms).

>>> print s[0].encode(sys.stdout.encoding, 'replace')
?
>>>


See the another thread about printing repr().


jmf
-- 
https://mail.python.org/mailman/listinfo/python-list