Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread 88888 Dihedral
Carlos Nepomuceno於 2013年5月22日星期三UTC+8上午11時38分45秒寫道:
> 
> > From: steve+comp.lang.pyt...@pearwood.info
> > Subject: Re: PEP 378: Format Specifier for Thousands Separator
> > Date: Wed, 22 May 2013 03:08:54 +
> > To: python-list@python.org
> [...]
> >> So, the only alternative to have "'%,d' % x" rendering the thousands
> >> separator output would a C source code modification?
> >
> > That's one alternative. But the language you would be then running will
> > no longer be Python.
> >
> > Another alternative would be to write a pre-processor that parses your
> > Python source code, extracts any reference to the above, and replaces it
> > with a call to the appropriate format call. But not only is that a lot of
> > work for very little gain, but it's also more or less impossible to do in
> > full generality. And again, what you are running will be something
> > different than Python, it will be Python plus a pre-processor.
> >
> >
> > Don't fight the language. You will lose.
> 
> Not fighting the language. In fact it's not even a language issue.
> All I need is a standard library[1] improvement: "%,d"! That's all!
> 
> Just to put in perspective the performance difference of str.__mod__() and 
> str.format():
> 
> C:\Python27>python -m timeit -cv -n1000 "'%d'%12345"
> raw times: 0.386 0.38 0.373
> 1000 loops, best of 3: 0.0373 usec per loop
> 
> C:\Python27>python -m timeit -cv -n1000 "'{:d}'.format(12345)"
> raw times: 7.91 7.89 7.98
> 1000 loops, best of 3: 0.789 usec per loop
> 
> C:\Python27>python -m timeit -cv -n1000 "'{:,d}'.format(12345)"
> raw times: 8.7 8.67 8.78
> 1000 loops, best of 3: 0.867 usec per loop
> 
> That shows str.format() is 20 times slower than str.__mod__() for a simple 
> decimal integer literal formatting.
> And it's additionally 10% slower if the thousands separator format specifier 
> (',') is used.
> 
> [1] I think that translates to Python source code in 'Objects/stringobject.c' 
> and maybe 'Objects/unicodeobject.c'
> 
> >
> >
> > --
> > Steven
> > --
> > http://mail.python.org/mailman/listinfo/python-list

The conversions of the  32 bit integers and 64 bit floats
 to the strings of the  base 10 digits require an 
efficint div and mod normally in the low level.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Chris Angelico
On Wed, May 22, 2013 at 4:52 PM, Kevin Xi  wrote:
> On Wednesday, May 22, 2013 2:23:15 PM UTC+8, C. N. Desrosiers wrote:
>> age=raw_input('Enter your age: ')
>> if age > 18:
>
> You can either use `raw_input` to read data and convert it to right type, or 
> use `input` to get an integer directly. Read this: 
> http://docs.python.org/2/library/functions.html#raw_input
> http://docs.python.org/2/library/functions.html#input

No! No, please do NOT use input()! It does not return an integer; it
*evaluates* (that is, executes) the input.

>>> input('Enter your age: ')
Enter your age: 18
18
>>> input('Enter your age: ')
Enter your age: 1+2+4+5+6
18
>>> input('Enter your age: ')
Enter your age: sys.stdout.write("Hello, world!\n") or 18
Hello, world!
18
>>> input('Enter your age: ')
Enter your age: sys.exit(0)

This is almost certainly NOT what you want to have in your script. If
you want an integer, just pass it through int() as Fabio suggested.

Please do not use, or advocate using, this steam-powered Izzet goblin
hammer for cracking walnuts.

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


Diagnosing socket "Connection reset by peer"

2013-05-22 Thread loial
I have a sockets client that is connecting to a printer and occassionally 
getting the error "104 Connection reset by peer"

I have not been able to diagnose what is causing this. Is there any additional 
traceing I can do(either within my python code or on the network) to establish 
what is causing this error?

Currently I am simply trapping socket.erruor 

Python version is 2.6






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


Re: More general way of generating PyODBC queries as a dict?

2013-05-22 Thread stackoverflowuser95
On Wednesday, May 22, 2013 9:33:18 AM UTC+10, Dennis Lee Bieber wrote:
> On Tue, 21 May 2013 10:27:07 -0700 (PDT), stackoverflowuse...@gmail.com
> 
> declaimed the following in gmane.comp.python.general:
> 
> 
> 
> > 
> 
> > For example, when multiple tables are queried; some hackish lambdas are 
> > required to generate the resulting dictionary.
> 
> > 
> 
> > Can you think of some more general methods?
> 
> >
> 
>   What about using the information from 
> 
> 
> 
>   cursor.description
> 
> 
> 
> You did state PyODBC, did you not?
> 
> 
> 
> """
> 
> description
> 
> 
> 
> This read-only attribute is a list of 7-item tuples, each containing
> 
> (name, type_code, display_size, internal_size, precision, scale,
> 
> null_ok). pyodbc only provides values for name, type_code,
> 
> internal_size, and null_ok. The other values are set to None.  
> 
> """
> 
> -- 
> 
>   Wulfraed Dennis Lee Bieber AF6VN
> 
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

YAY: `[{c[0]: v for (c, v) in zip(row.cursor_description, row)} for row in 
self.cursor.fetchall()]`
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-22 Thread Skip Montanaro
>> Is this tutorial outdated or this still an issue?
>>
>> [1]
>> http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
>
>
> That tutorial is out of date.  %-formatting isn't being removed.

OTOH, PEP 3101 also mentions deprecation, at the very end: "... both
systems can co-exist until it comes time to deprecate the older
system."

I have been operating under the assumption since the days of that PEP
that %-style formatting would eventually disappear, dreading the day
when I'd have to learn the str.format language.  I apologize for
(inadvertently) spreading FUD.

It does seem like the documentation should be updated in a few places.
 If the decision has been made to not remove the older system, it
might be worthwhile to mention that somewhere.  Clearly the tutorial
and PEP 3101 should be updated.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Skip Montanaro
 Please stop perpetuating this myth, see
 http://mail.python.org/pipermail/python-dev/2012-February/116789.html
 and http://bugs.python.org/issue14123

>>> What myth?
>>
>> The myth that % string formatting is deprecated. It is not deprecated.
> Skip didn't say that it was deprecated.

I didn't mean to create a tempest in a teapot.  I was away from
comp.lang.python, python-bugs, and python-dev for a few years.  In
particular, I didn't ever see the aforementioned thread from Feb 2012.
 Had I known of that thread I would have worded the sentence which
shall not be repeated differently.

My apologies...

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static Maps from Lat Long data in XLS file

2013-05-22 Thread kobewka
On Tuesday, May 21, 2013 11:27:42 AM UTC-4, Tim Daneliuk wrote:
> On 05/21/2013 08:12 AM, @gmail.com wrote:
> 
> > Hello,
> 
> >
> 
> > I'm new to Python, but I think it can solve my problem and I am looking for 
> > a someone to point me to tutorial or give me some tips here.
> 
> >
> 
> > I have an xls file that has about 1,000 latitude and longitude points. I 
> > want to do one of two things: 1) Save a static maps and street view image 
> > from the coordinates, or 2) create an html file with the map and street 
> > view image side by side.
> 
> >
> 
> > I need the urls to look like this:
> 
> >
> 
> > Map with a pin in the centre:
> 
> > http://maps.googleapis.com/maps/api/staticmap?center=43.65162,-79.40571&zoom=16&size=600x600&markers=color:blue%7Clabel:S%7C43.65162,-79.40571&sensor=false
> 
> >
> 
> > Image:
> 
> > http://maps.googleapis.com/maps/api/streetview?location=43.65162,%20-79.40571&size=600x600&sensor=false
> 
> >
> 
> > I am not sure if option 1 will work because the url doesn't actually lead 
> > to an image, but rather Google returns an image when that url is used.
> 
> >
> 
> > Any tips or pointers are much appreciated!
> 
> >
> 
> 
> 
> 
> 
> https://pypi.python.org/pypi/xlrd
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> ---
> 
> Tim Daneliuk

Thanks Tim.

Scott
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static Maps from Lat Long data in XLS file

2013-05-22 Thread kobewka
Thanks Ken. I'll have a closer look at those links. I also found Motionless, 
which creates a static map HTML file. Combined with what you said, I should be 
able to get what I need.

https://github.com/ryancox/motionless

Scott



On Tuesday, May 21, 2013 9:58:25 AM UTC-4, Ken Bolton wrote:
> On Tue, May 21, 2013 at 9:12 AM,   wrote:
> 
> 
> Hello,
> 
> 
> 
> I'm new to Python, but I think it can solve my problem and I am looking for a 
> someone to point me to tutorial or give me some tips here.
> 
>  
> Hi! I am a first-time poster to python-list, but I think I can help you.
> 
> 
>  
> I have an xls file that has about 1,000 latitude and longitude points. I want 
> to do one of two things: 1) Save a static maps and street view image from the 
> coordinates, or 2) create an html file with the map and street view image 
> side by side.
> 
> 
> 
> 
> If you save your xls file as a csv (comma-separated values), you can use 
> python's built-in csv module, documented here - 
> http://docs.python.org/2/library/csv.html, to read the file line by line. 
> Store the values and substitute the strings into a new list of URLs.
> 
> 
>  
> I need the urls to look like this:
> 
> 
> 
> Map with a pin in the centre:
> 
> http://maps.googleapis.com/maps/api/staticmap?center=43.65162,-79.40571&zoom=16&size=600x600&markers=color:blue%7Clabel:S%7C43.65162,-79.40571&sensor=false
> 
> 
> 
> 
> 
> Image:
> 
> http://maps.googleapis.com/maps/api/streetview?location=43.65162,%20-79.40571&size=600x600&sensor=false
> 
> 
> 
> 
> I was able to use curl to grab the images you linked. I believe you can use 
> urllib (or, better, requests - http://docs.python-requests.org/en/latest/) to 
> get and save the images.
> 
> 
> 
> 
> hth.
> 
> 
> best,
> ken
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Ned Batchelder


On 5/21/2013 11:38 PM, Carlos Nepomuceno wrote:

From:steve+comp.lang.pyt...@pearwood.info
>Subject: Re: PEP 378: Format Specifier for Thousands Separator
>Date: Wed, 22 May 2013 03:08:54 +
>To:python-list@python.org

[...]

>>So, the only alternative to have "'%,d' % x" rendering the thousands
>>separator output would a C source code modification?

>
>That's one alternative. But the language you would be then running will
>no longer be Python.
>
>Another alternative would be to write a pre-processor that parses your
>Python source code, extracts any reference to the above, and replaces it
>with a call to the appropriate format call. But not only is that a lot of
>work for very little gain, but it's also more or less impossible to do in
>full generality. And again, what you are running will be something
>different than Python, it will be Python plus a pre-processor.
>
>
>Don't fight the language. You will lose.

Not fighting the language. In fact it's not even a language issue.
All I need is a standard library[1] improvement: "%,d"! That's all!


You have to keep in mind that 2.7 is not getting any new features, no 
matter how small they seem.  If you create a patch that implements the 
comma flag in %-formatting, it *might* go into 3.x, but it will not go 
into 2.7.


--Ned.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Matt Jones
This typically indicates that the "peer" at the other end of the tcp
connection severed the session without the typical FIN packet.  If you're
treating the printer as a "blackbox" then there really isn't anything you
can do here except catch the exception and attempt to reconnect.

*Matt Jones*


On Wed, May 22, 2013 at 3:46 AM, loial  wrote:

> I have a sockets client that is connecting to a printer and occassionally
> getting the error "104 Connection reset by peer"
>
> I have not been able to diagnose what is causing this. Is there any
> additional traceing I can do(either within my python code or on the
> network) to establish what is causing this error?
>
> Currently I am simply trapping socket.erruor
>
> Python version is 2.6
>
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> Date: Wed, 22 May 2013 07:25:13 -0400
> From: n...@nedbatchelder.com
[...]
> You have to keep in mind that 2.7 is not getting any new features, no
> matter how small they seem. If you create a patch that implements the
> comma flag in %-formatting, it *might* go into 3.x, but it will not go
> into 2.7.
>
> --Ned.

No problem. I have just discovered i was measuring the wrong thing.

My test case is been optimized at compile time by CPython that treats "'%d' % 
12345" as a constant.
My use case is different because I almost have no literals been used with % 
operator.

So my gain isn't that great. In fact it's faster with str.format() than %, and 
it's even faster if I use the default format specifier.

C:\Python27>python -m timeit -cv -n1000 -s"v=12345" "'%d'%v"
raw times: 10.5 10.7 10.7
1000 loops, best of 3: 1.05 usec per loop

C:\Python27>python -m timeit -cv -n1000 -s"v=12345" "'{:d}'.format(v)"
raw times: 8.11 8.09 8.02
1000 loops, best of 3: 0.802 usec per loop

C:\Users\Josue\Documents\Python>python -m timeit -cv -n1000 -s"v=12345" 
"'{}'.format(v)"
raw times: 5.3 5.5 5.62
1000 loops, best of 3: 0.53 usec per loop

Using variables (100% of cases) makes str.format() 50% faster than %.   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Windows release and encoding

2013-05-22 Thread Absalom K.
Hi, I am working on Linux; a friend of mine sends to me python files from
his Windows release. He uses the editor coming with the release; he runs
his code from the editor by using a menu (or some F5 key I think).

He doesn't declare any encoding in his source file; when I want to try
his code, I have an error since he obviously uses non-ascii characters.
As far as I can see, he uses utf8 without knowing it. I add the UTF8
declaration, run the code, and everything is fine.

Then I tell him to add the utf-8 declaration; but now he has an error
when running his file from the Windows editor.

Finally, he told me he could run the file by declaring the latin-1
encoding.

But I want to understand exactly:
  a) what is the encoding used by the editor coming in the Windows release?
  b) why doesn't he need to declare the encoding (I need it on Linux for
 the very same files)?

Best regards, ak.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Windows release and encoding

2013-05-22 Thread Peter Otten
Absalom K. wrote:

> Hi, I am working on Linux; a friend of mine sends to me python files from
> his Windows release. He uses the editor coming with the release; he runs
> his code from the editor by using a menu (or some F5 key I think).
> 
> He doesn't declare any encoding in his source file; when I want to try
> his code, I have an error since he obviously uses non-ascii characters.
> As far as I can see, he uses utf8 without knowing it. I add the UTF8
> declaration, run the code, and everything is fine.
> 
> Then I tell him to add the utf-8 declaration; but now he has an error
> when running his file from the Windows editor.
> 
> Finally, he told me he could run the file by declaring the latin-1
> encoding.
> 
> But I want to understand exactly:
>   a) what is the encoding used by the editor coming in the Windows
>   release? b) why doesn't he need to declare the encoding (I need it on
>   Linux for
>  the very same files)?
> 
> Best regards, ak.

Your friend may be using an old version of Python. Quoting



"""
For backwards-compatibility with existing code which currently
uses non-ASCII in string literals without declaring an encoding,
the implementation will be introduced in two phases:

1. Allow non-ASCII in string literals and comments, by internally
   treating a missing encoding declaration as a declaration of
   "iso-8859-1". This will cause arbitrary byte strings to
   correctly round-trip between step 2 and step 5 of the
   processing, and provide compatibility with Python 2.2 for
   Unicode literals that contain non-ASCII bytes.

   A warning will be issued if non-ASCII bytes are found in the
   input, once per improperly encoded input file.

2. Remove the warning, and change the default encoding to "ascii".

[...]

Implementation of steps 1 and 2 above were completed in 2.3,
except for changing the default encoding to "ascii".

The default encoding was set to "ascii" in version 2.5.
 """

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


Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Dave Angel

On 05/22/2013 04:46 AM, loial wrote:

   

 Is there any additional traceing I can do(either within my python code or 
on the network) to establish what is causing this error?




Try using Wireshark.  It can do a remarkable job of filtering, 
capturing, and analyzing packets.  It can also read and write pcap 
files, which you could either save for later analysis, or send to 
someone who might help.  (Note - unfiltered pcap files can be very large 
on a busy network, but if you can quiet other traffic, you may not need 
to filter at all.)



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-22 Thread Tim Chase
On 2013-05-22 16:39, Chris Angelico wrote:
> On Wed, May 22, 2013 at 12:32 PM, Tim Chase
>  wrote:
> > On 2013-05-22 01:15, i...@databaseprograms.biz wrote:
> >> A computer programmer, web developer and network administrator
> >
> > ...walk into a bar...
> >
> > So what's the punchline?
> 
> ;steps up to the mike
> 
> So yeah, as I was saying, a programmer, a web dev, and a BOFH walk
> into a bar. The other two buy the BOFH a drink, because they're not
> stupid, and anyway, so this luser walks up to them with a resume in
> his hand.
> 
> "," says the luser.
> 
> "So what's the punchline?" says the computer programmer.
> 
> The stand-up comic steps up to the mike, and he says, "So yeah, as I
> was saying, a programmer, a web dev, and a BOFH walk into a stable
> time loop..."

So a pirate programmer walks into a bar with a bird on his shoulder.
The bird repeatedly squawks "pieces of nine! pieces of nine!".  The
bartender looks at him and asks "what's up with the bird?" to which
the pirate says "Arrr, he's got a parroty error."  The bartender
replies, "Ah, I thought he was a bit off."

-tkc



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


Re: What was the project that made you feel skilled in Python?

2013-05-22 Thread Ben Finney
Ned Batchelder  writes:

> as you moved from exercises like those in Learn Python the Hard Way,
> up to your own self-guided work on small projects, what project were
> you working on that made you feel independent and skilled?  What
> program first felt like your own work rather than an exercise the
> teacher had assigned?

I wanted to simulate a particular board game, and had others in mind
with some common mechanics.

This resulted in a library for rolling dice in different combinations,
and looking up result tables https://pypi.python.org/pypi/alea>.

Eventually I wanted to extend it to know about custom decks of cards,
and the different ways those are handled in board games.

The unifying theme was a library of routines for simulating the random
elements (dice, cards, tables, spinners, etc.) in any board game.

A little over-engineered, I'll freely admit. But it did give me a sense
of being at home in Python and knowing that this is a good language for
getting things done the right way.

-- 
 \ “Creativity can be a social contribution, but only in so far as |
  `\society is free to use the results.” —Richard Stallman |
_o__)  |
Ben Finney

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


Re: A computer programmer, web developer and network admin resume

2013-05-22 Thread Harry Percival
oh wow.  great one, thanks for that tim :)


On 22 May 2013 14:03, Tim Chase  wrote:

> On 2013-05-22 16:39, Chris Angelico wrote:
> > On Wed, May 22, 2013 at 12:32 PM, Tim Chase
> >  wrote:
> > > On 2013-05-22 01:15, i...@databaseprograms.biz wrote:
> > >> A computer programmer, web developer and network administrator
> > >
> > > ...walk into a bar...
> > >
> > > So what's the punchline?
> >
> > ;steps up to the mike
> >
> > So yeah, as I was saying, a programmer, a web dev, and a BOFH walk
> > into a bar. The other two buy the BOFH a drink, because they're not
> > stupid, and anyway, so this luser walks up to them with a resume in
> > his hand.
> >
> > "," says the luser.
> >
> > "So what's the punchline?" says the computer programmer.
> >
> > The stand-up comic steps up to the mike, and he says, "So yeah, as I
> > was saying, a programmer, a web dev, and a BOFH walk into a stable
> > time loop..."
>
> So a pirate programmer walks into a bar with a bird on his shoulder.
> The bird repeatedly squawks "pieces of nine! pieces of nine!".  The
> bartender looks at him and asks "what's up with the bird?" to which
> the pirate says "Arrr, he's got a parroty error."  The bartender
> replies, "Ah, I thought he was a bit off."
>
> -tkc
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
Harry J.W. Percival
--
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype: harry.percival
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread Wolfgang Keller
>  Do you think tkinter is going to be the standard python built-in
>  gui solution as long as python exists?
> >>>
> >>> AT the moment, there is nothing really comparable that is a
> >>> realistic candidate to replace tkinter.
> >>
> >> FLTK? (http://www.fltk.org/index.php)
> >
> > tkinter is the Python wrapper of the tk library, just as wxpython
> > is the python wrapper of the wx library. I do not see a py-fltk
> > wrapper.
> 
> It exists, but it's really old.
> 
> http://pyfltk.sourceforge.net/

And it's imho definitely not "native" (in terms of "look and feel") on
*any* operating system, not even on Linux.

In fact it's SGI's Irix Forms re-implemented, afaik.

Sincerely,

Wolfgang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread Wolfgang Keller
> I know this may sound a silly question because no one can see the
> future. But ...
> Do you think tkinter is going to be the standard python built-in gui
> solution as long as python exists?

"Standard built-in" maybe, but by far most people who need a GUI for an
actual application will keep using something else.
 
> I couldn't help but wonder if wx or PySide receives better py2 and py3
> support, or anything else that prevent
> them from getting into the standard python distributions, whether or
> not this scene could start to shift ...

Didn't Pyside have serious trouble recently, requiring a reanimation of
the project?
 
> I believe this "which one of tkinter, wx, qt, is the best gui toolkit
> for python" flame war has been going on
> for ages. 

If (Py)Qt wasn't so freaking fat, it might be the best.
If wxPython had a more pythonic (and stable?) API, it might be the best.
If PyGTK was more native on Windows and native at all on MacOS X, it
might be the best.
If PyGUI was more extensive, it might be the best.

> This worries me very much about whether I should start a gui app
> using python.

What other open-source cross-platform programming language choices do yo
have.

Java? For GUIs? Excuse me while I vomit.

C++? As a language for human beings? Oops, I have to throw up again.

Sincerely,

Wolfgang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread Chris Angelico
On Wed, May 22, 2013 at 11:42 PM, Wolfgang Keller  wrote:
> What other open-source cross-platform programming language choices do yo
> have.
>
> Java? For GUIs? Excuse me while I vomit.
>
> C++? As a language for human beings? Oops, I have to throw up again.

I personally like using Pike and GTK, so if I were to try a
cross-platform Python GUI project, I'd probably give PyGTK a shot. But
there's another option that is available to every platform and
(practially) every high level language: the web browser. Make your app
serve HTTP and do up your UI in HTML5/CSS3 - your facilities are
pretty extensive. Plus you get networking support for free! Obviously
this option isn't for everyone, but don't discount it out of hand.

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


Re: Translation API in Python

2013-05-22 Thread Chris Angelico
On Wed, May 22, 2013 at 8:16 AM, Hala Gamal  wrote:
> ok MR,
> I have searched before asking here,but i didn't find thing

Your post doesn't demonstrate that. When you ask a question like this,
it's helpful to give at least some indication of what you've tried and
what you haven't. Also, I strongly suspect that #4 is going to turn
something up; though of course people who read this post now have no
idea what I'm talking about, because you're responding to last week's
post without a shred of context.

Here are some tips that might help you:

http://www.catb.org/esr/faqs/smart-questions.html

ChrisA
PS. I say "might" only because they can't help if they're not followed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-22 Thread Denis McMahon
On Tue, 21 May 2013 23:26:58 -0400, Ned Batchelder wrote:

> On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:

>> "Since str.format() is quite new, a lot of Python code still uses the %
>> operator. However, because this old style of formatting will eventually
>> be removed from the language, str.format() should generally be used."

>> Is this tutorial outdated or this still an issue?

> That tutorial is out of date.  %-formatting isn't being removed.

Indeed, removing %-formatting could break a substantial amount of live 
code, with potentially significant maintenance effort in the user 
community simply to make existing code work with the new interpreter. The 
effect of this on corporations using python code translates into 
"business risk", and the next step is "we can avoid the business risk by 
migrating our python scripts to some other language."

For the designers and maintainers of any language to arbitrarily[1] (in 
the eyes of the user base) remove a widely used feature that would have a 
major effect on the user base could kill off a language, simply because 
many users will not want to take the risk of it happening again, even if 
they can easily automate the upgrade from removed obsolete language 
feature to new shiny language feature.

[1] Some portion of the user base will always consider any such change 
that causes them headaches and additional effort as having been 
arbitrary, no matter how well the language designers and maintainers 
explain the need to break the old scripts.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What was the project that made you feel skilled in Python?

2013-05-22 Thread Chris Angelico
On Wed, May 22, 2013 at 11:05 PM, Ben Finney  wrote:
> I wanted to simulate a particular board game, and had others in mind
> with some common mechanics.
>
> This resulted in a library for rolling dice in different combinations,
> and looking up result tables https://pypi.python.org/pypi/alea>.

Fun fun! Of course, when I hear "rolling dice in different
combinations", my mind immediately turns to Dungeons and Dragons,
where it's plausible to roll d20+7, then roll 2d8+d6+12 to figure out
how much damage you did...

But the hard part of board games is usually the board. I used to spend
ages trying to draw up a half-decent board, and ended up giving up. By
"simulate", I'm guessing you mean that you didn't actually draw
anything of the sort?

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Steven D'Aprano
On Wed, 22 May 2013 05:45:12 -0500, Skip Montanaro wrote:

> I didn't mean to create a tempest in a teapot.  I was away from
> comp.lang.python, python-bugs, and python-dev for a few years.  In
> particular, I didn't ever see the aforementioned thread from Feb 2012.
>  Had I known of that thread I would have worded the sentence which
> shall not be repeated differently.
> 
> My apologies...

No problem, it's not about you specifically, it's just that some of us 
fans of % formatting can be a tad sensitive about it, especially since 
the idea that it has been deprecated (or soon will be deprecated, or one 
day will be deprecated, and therefore code using it is bad) is relatively 
widespread on the Internet.

Glad to have you back here!



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


subclassing from unittest

2013-05-22 Thread Charles Smith
Hi,

I'd like to subclass from unittest.TestCase.  I observed something
interesting and wonder if anyone can explain what's going on... some
subclasses create  null tests.

I can create this subclass and the test works:

  class StdTestCase (unittest.TestCase):
  blahblah

and I can create this subsubclass and the test works:

  class aaaTestCase (StdTestCase):
  moreblahblah

but if I create this subsubclass (or any where the first letter is
capital):

  class AaaTestCase (StdTestCase):
  differentblahblah

the test completes immediately without any work being done.

I suspect that the answer is in the prefix printed out by the test.  I
have diffed both the long output (tests works, on the left) and the
short output (null test, on the right):

test
(TC_02.TestCase_F__ULLA05__AM_Tx) ...  <
test suite has  ,   test suite has  ,
 
>,
 ]><
 
>   -->  test_api_socket:the address specified is:  127.0.0.1
 
>
 
>
 
>
 
>
--
 
>   Ran 0 tests in 0.000s
 
>
 
>   OK


I see an empty test somehow gets sorted to the beginning of the list.
How could that be a result of whether the first letter of the class is
capitalized or not?

Thanks in advance...
cts


http://www.creative-telcom-solutions.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subclassing from unittest

2013-05-22 Thread Charles Smith
On 22 Mai, 17:32, Charles Smith  wrote:
> Hi,
>
> I'd like to subclass from unittest.TestCase.  I observed something
> interesting and wonder if anyone can explain what's going on... some
> subclasses create  null tests.
>
> I can create this subclass and the test works:
>
>   class StdTestCase (unittest.TestCase):
>       blahblah
>
> and I can create this subsubclass and the test works:
>
>   class aaaTestCase (StdTestCase):
>       moreblahblah
>
> but if I create this subsubclass (or any where the first letter is
> capital):
>
>   class AaaTestCase (StdTestCase):
>       differentblahblah
>
> the test completes immediately without any work being done.
>
> I suspect that the answer is in the prefix printed out by the test.  I
> have diffed both the long output (tests works, on the left) and the
> short output (null test, on the right):
>
> test
> (TC_02.TestCase_F__ULLA05__AM_Tx) ...                  <
> test suite has   tests=[]>,       test suite has   tests=[,
>
> >    ,
>
>   tests=[    tests=[    tests=[    tests=[    tests=[    tests=[    tests=[]>]>                                        <
>
> >   -->  test_api_socket:the address specified is:  127.0.0.1
>
> --
>
> >   Ran 0 tests in 0.000s
>
> >   OK
>
> I see an empty test somehow gets sorted to the beginning of the list.
> How could that be a result of whether the first letter of the class is
> capitalized or not?
>
> Thanks in advance...
> cts
>
> http://www.creative-telcom-solutions.de


Unfortunately, the side-by-side diff didn't come out so well  ...

---
http://www.creative-telcom-solutions.de
-- 
http://mail.python.org/mailman/listinfo/python-list


file I/O and arithmetic calculation

2013-05-22 Thread Keira Wilson
Dear all,

I would appreciate if someone could write a simple python code for the
purpose below:

I have five text files each of 10 columns by 10 rows as follows:

file_one = 'C:/test/1.txt'
file_two = 'C:/test/2.txt' . . .
file_five = 'C:/test/5.txt'

 I want to calculate the mean of first row (10 elements) for each file (5
files), if mean of first column (10 elements) of each file (5 files) is 50.

Thank you in advance.

Keira
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file I/O and arithmetic calculation

2013-05-22 Thread Mark Lawrence

On 22/05/2013 17:13, Keira Wilson wrote:

Dear all,

I would appreciate if someone could write a simple python code for the
purpose below:

I have five text files each of 10 columns by 10 rows as follows:


|file_one=  'C:/test/1.txt'
file_two=  'C:/test/2.txt'
.  .  .
file_five=  'C:/test/5.txt'|

I want to calculate the mean of first row (10 elements) for each file (5
files), if mean of first column (10 elements) of each file (5 files) is 50.

Thank you in advance.

Keira



Sorry but we don't do homework.

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Ned Batchelder


On 5/22/2013 10:58 AM, Steven D'Aprano wrote:

On Wed, 22 May 2013 05:45:12 -0500, Skip Montanaro wrote:


I didn't mean to create a tempest in a teapot.  I was away from
comp.lang.python, python-bugs, and python-dev for a few years.  In
particular, I didn't ever see the aforementioned thread from Feb 2012.
  Had I known of that thread I would have worded the sentence which
shall not be repeated differently.

My apologies...

No problem, it's not about you specifically, it's just that some of us
fans of % formatting can be a tad sensitive about it, especially since
the idea that it has been deprecated (or soon will be deprecated, or one
day will be deprecated, and therefore code using it is bad) is relatively
widespread on the Internet.


Seems like maybe this should become a question in the Python FAQ.

--Ned.



Glad to have you back here!





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


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-22 Thread Terry Jan Reedy

On 5/22/2013 10:24 AM, Denis McMahon wrote:


Indeed, removing %-formatting could break a substantial amount of live
code, with potentially significant maintenance effort in the user


While I would like to see % formatting go away everntually*, other 
developers would not. In any case, I agree that it should not disappear 
until there is a foolproof conversion tool, probably custom written. I 
am working on other things.


* perhaps in 10 years?, when all 2.x code that is going to be converted 
has been converted


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


Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Jorgen Grahn
On Wed, 2013-05-22, Dave Angel wrote:
> On 05/22/2013 04:46 AM, loial wrote:
>>
>>
>>  Is there any additional traceing I can do(either within my
>> python code or on the network) to establish what is causing this
>> error?
>
> Try using Wireshark.  It can do a remarkable job of filtering, 
> capturing, and analyzing packets.  It can also read and write pcap 
> files, which you could either save for later analysis, or send to 
> someone who might help.

Or use tcpdump, which has a text interface so you can show the problem
in a text medium like Usenet.

> (Note - unfiltered pcap files can be very large 
> on a busy network, but if you can quiet other traffic, you may not need 
> to filter at all.)

Or simply filter.  It's not hard -- the capture filter
"host my-printer-hostname-or-address" is enough.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-22 Thread nn
On May 22, 6:35 am, Skip Montanaro  wrote:
> >> Is this tutorial outdated or this still an issue?
>
> >> [1]
> >>http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
>
> > That tutorial is out of date.  %-formatting isn't being removed.
>
> OTOH, PEP 3101 also mentions deprecation, at the very end: "... both
> systems can co-exist until it comes time to deprecate the older
> system."
>
> I have been operating under the assumption since the days of that PEP
> that %-style formatting would eventually disappear, dreading the day
> when I'd have to learn the str.format language.  I apologize for
> (inadvertently) spreading FUD.
>
> It does seem like the documentation should be updated in a few places.
>  If the decision has been made to not remove the older system, it
> might be worthwhile to mention that somewhere.  Clearly the tutorial
> and PEP 3101 should be updated.
>
> Skip

I was of the impression that deprecating % was still planned for Py4k,
whenever that is. I personally believe that eliminating % formatting
would reduce bugs and generally make code clearer, but I realize that
breaking backward compatibility has a high price.

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


Re: What was the project that made you feel skilled in Python?

2013-05-22 Thread Terry Jan Reedy

On 5/22/2013 9:05 AM, Ben Finney wrote:


I wanted to simulate a particular board game, and had others in mind
with some common mechanics.

This resulted in a library for rolling dice in different combinations,
and looking up result tables https://pypi.python.org/pypi/alea>.


Have you cosidered adding a description so it can be found be a search?
A 3.3 version?

"Simulate game randomizers and lookup: dice rolls, card drawing, 
spinners, ...



Eventually I wanted to extend it to know about custom decks of cards,
and the different ways those are handled in board games.

The unifying theme was a library of routines for simulating the random
elements (dice, cards, tables, spinners, etc.) in any board game.

A little over-engineered, I'll freely admit. But it did give me a sense
of being at home in Python and knowing that this is a good language for
getting things done the right way.




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


Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Jorgen Grahn
On Wed, 2013-05-22, Matt Jones wrote:
> On Wed, May 22, 2013 at 3:46 AM, loial  wrote:
>
>> I have a sockets client that is connecting to a printer and occassionally
>> getting the error "104 Connection reset by peer"
>>
>> I have not been able to diagnose what is causing this. Is there any
>> additional traceing I can do(either within my python code or on the
>> network) to establish what is causing this error?
>>
>> Currently I am simply trapping socket.erruor
>>
>> Python version is 2.6

> This typically indicates that the "peer" at the other end of the tcp
> connection severed the session without the typical FIN packet.

I.e. by sending a RST (reset) instead.  Yes, that's what "Connection
reset by peer" means.  I don't think there are any other causes for
this signal.

A server application can cause a reset explicitly, or if it crashes
the OS will send one for it, as part of the resource cleanup.

Also, if you're behind a cheap NATing gateway, I think it may send
fake RSTs if it has lost track of the TCP session.

> If you're
> treating the printer as a "blackbox" then there really isn't anything you
> can do here except catch the exception and attempt to reconnect.

Yes.  Note that there *may* be some uncertainty re: "did the printer
process the last request before the reset or not?" E.g. I wouldn't
endlessly retry printing a 100-page document in that case.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diagnosing socket "Connection reset by peer"

2013-05-22 Thread Grant Edwards
On 2013-05-22, Jorgen Grahn  wrote:
> On Wed, 2013-05-22, Dave Angel wrote:
>> On 05/22/2013 04:46 AM, loial wrote:
>>>
>>>
>>>  Is there any additional traceing I can do(either within my
>>> python code or on the network) to establish what is causing this
>>> error?
>>
>> Try using Wireshark.  It can do a remarkable job of filtering, 
>> capturing, and analyzing packets.  It can also read and write pcap 
>> files, which you could either save for later analysis, or send to 
>> someone who might help.
>
> Or use tcpdump, which has a text interface so you can show the problem
> in a text medium like Usenet.

There's also tshark, which is sort of a command-line version of
wireshark.

http://www.wireshark.org/docs/man-pages/tshark.html

>> (Note - unfiltered pcap files can be very large on a busy network,
>> but if you can quiet other traffic, you may not need to filter at
>> all.)
>
> Or simply filter.  It's not hard -- the capture filter "host
> my-printer-hostname-or-address" is enough.

Indeed.  Even a simple filter can make life several orders of
magnitude easier.  If filtering by IP address isn't enough, the next
step is usually to add a port number filter...

-- 
Grant Edwards   grant.b.edwardsYow! Of course, you
  at   UNDERSTAND about the PLAIDS
  gmail.comin the SPIN CYCLE --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread nn
On May 22, 2:30 pm, Ned Batchelder  wrote:
> On 5/22/2013 10:58 AM, Steven D'Aprano wrote:
>
> > On Wed, 22 May 2013 05:45:12 -0500, Skip Montanaro wrote:
>
> >> I didn't mean to create a tempest in a teapot.  I was away from
> >> comp.lang.python, python-bugs, and python-dev for a few years.  In
> >> particular, I didn't ever see the aforementioned thread from Feb 2012.
> >>   Had I known of that thread I would have worded the sentence which
> >> shall not be repeated differently.
>
> >> My apologies...
> > No problem, it's not about you specifically, it's just that some of us
> > fans of % formatting can be a tad sensitive about it, especially since
> > the idea that it has been deprecated (or soon will be deprecated, or one
> > day will be deprecated, and therefore code using it is bad) is relatively
> > widespread on the Internet.
>
> Seems like maybe this should become a question in the Python FAQ.
>
> --Ned.
>
>
>
>
>
>
>
>
>
> > Glad to have you back here!

Maybe a cformat(formatstring, variables)  function should be created
in the string module so people who prefer that can use it. I don't
mind the C formatting syntax but I don't like the fact that the %
operator does something totally different when the first variable is
an integer and the fact that it misbehaves if the second variable is a
tuple.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
Funny! I made a lot of assumptions regarding your requirements specification. 
Let me know if it isn't what you need:

### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
#    '10,11,12,13,14,15,16,17,18,19\n' \
#    '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0]   : file '1.txt'
# contents[1][2]    : 3rd row of file '2.txt'
# contents[3][4][5] : 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4])  : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'

filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents  = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] 
for x in filenames]
s1c  = [sum([r[0] for r in f]) for f in contents]
a1r  = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join([x for x in ['File "{}" has 1st row average = 
{:.2f}'.format(n,a1r[i]) if s1c[i]==50 else '' for i,n in enumerate(filenames)] 
if x])



> From: wilke...@gmail.com 
> Date: Thu, 23 May 2013 01:13:19 +0900 
> Subject: file I/O and arithmetic calculation 
> To: python-list@python.org 
>  
>  
> Dear all, 
>  
> I would appreciate if someone could write a simple python code for the  
> purpose below: 
>  
> I have five text files each of 10 columns by 10 rows as follows: 
>  
>  
>  
> file_one = 'C:/test/1.txt' 
> file_two = 'C:/test/2.txt' 
> . . . 
> file_five = 'C:/test/5.txt' 
>  
> I want to calculate the mean of first row (10 elements) for each file  
> (5 files), if mean of first column (10 elements) of each file (5  
> files) is 50. 
>  
> Thank you in advance. 
>  
> Keira 
>  
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subclassing from unittest

2013-05-22 Thread Terry Jan Reedy

On 5/22/2013 11:32 AM, Charles Smith wrote:

Have you red this? I will suggest some specifics.
http://www.catb.org/esr/faqs/smart-questions.html


I'd like to subclass from unittest.TestCase.


What version of Python.

> I observed something interesting and wonder if anyone can explain 
what's going on... some

subclasses create  null tests.

I can create this subclass and the test works:


What does 'works' mean?


   class StdTestCase (unittest.TestCase):
   blahblah


I bet that this (and the rest of your 'code' is not what you actually 
ran. Unless blahblah is bound (to what?), this fails with NameError.

Give us what you ran so we can run it too, and modify it.


and I can create this subsubclass and the test works:

   class aaaTestCase (StdTestCase):
   moreblahblah

but if I create this subsubclass (or any where the first letter is
capital):

   class AaaTestCase (StdTestCase):
   differentblahblah

the test completes immediately without any work being done.


What does this mean? I see no difference with the following

import unittest
class StdTestCase (unittest.TestCase): pass
class lowerSub(StdTestCase): pass
class UpperSub(StdTestCase): pass

unittest.main(verbosity=2, exit=False)

# prints (3.3)
--
Ran 0 tests in 0.000s

OK

Same as before the subclasses were added.

--
Terry Jan Reedy


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


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> Date: Wed, 22 May 2013 13:26:23 -0700
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> From: prueba...@latinmail.com
> To: python-list@python.org
[...]
>
> Maybe a cformat(formatstring, variables) function should be created
> in the string module so people who prefer that can use it. I don't
> mind the C formatting syntax but I don't like the fact that the %
> operator does something totally different when the first variable is
> an integer and the fact that it misbehaves if the second variable is a
> tuple.
> --
> http://mail.python.org/mailman/listinfo/python-list

I still don't understand why % benefits from literals optimization 
("'%d'%12345") while '{:d}'.format(12345) doesn't.

What "totally different" you talking about? Please give me an example.  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Alister
On Tue, 21 May 2013 23:52:30 -0700, Kevin Xi wrote:

> On Wednesday, May 22, 2013 2:23:15 PM UTC+8, C. N. Desrosiers wrote:
>> Hi,
>> 
> Hi,
>> 
>> I'm just starting out with Python and to practice I am trying to write
>> a script that can have a simple conversation with the user.
>> 
> So you may want to search the doc before you ask: http://docs.python.org
>> 
>> When I run the below code, it always ends up printing response to "if
>> age > 18:" -- even if I enter a value below 18.
>> 
>> 
>> 
>> Can anyone point me to what I am doing wrong?  Many thanks in advance.
>> 
>> 
>> 
>> age=raw_input('Enter your age: ')
>> 
>> if age > 18:
>> 
>> print ('Wow, %s. You can buy cigarettes.' % age)
>> 
>> else:
>> 
>> print ('You are a young grasshopper.')
> 
> You can either use `raw_input` to read data and convert it to right
> type, or use `input` to get an integer directly. Read this:
> http://docs.python.org/2/library/functions.html#raw_input
> http://docs.python.org/2/library/functions.html#input
> 
>  
Kevin

Please write out 1000 time (without using any form of loop)

"NEVER use input in python <3.0 it is EVIL"*

as Chris A point out it executes user input an can cause major damage 
(reformatting the hard disk is not impossible!)


-- 
Quality Control, n.:
The process of testing one out of every 1,000 units coming off
a production line to make sure that at least one out of 100 works.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Carlos Nepomuceno

> From: alister.w...@ntlworld.com
[...]
> Kevin
>
> Please write out 1000 time (without using any form of loop)
>
> "NEVER use input in python <3.0 it is EVIL"*
>
> as Chris A point out it executes user input an can cause major damage
> (reformatting the hard disk is not impossible!)
>

Indeed! input is eval(raw_input())! lol 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-22 Thread Gregory Ewing

Tim Chase wrote:

So a pirate programmer walks into a bar with a bird on his shoulder.
The bird repeatedly squawks "pieces of nine! pieces of nine!".  The
bartender looks at him and asks "what's up with the bird?" to which
the pirate says "Arrr, he's got a parroty error."


No, he's just using half-open ranges.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 22:05, Carlos Nepomuceno  wrote:
>
> filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
> contents  = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] 
> for x in filenames]
> s1c  = [sum([r[0] for r in f]) for f in contents]
> a1r  = [sum(f[0])/float(len(f[0])) for f in contents]
> print '\n'.join([x for x in ['File "{}" has 1st row average = 
> {:.2f}'.format(n,a1r[i]) if s1c[i]==50 else '' for i,n in 
> enumerate(filenames)] if x])

Do you find this code easy to read? I wouldn't write something like
this and I certainly wouldn't use it when explaining something to a
beginner.

Rather than repeated list comprehensions you should consider using a
single loop e.g.:

for filename in filenames:
# process each file

This will make the code a lot simpler.


Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
[...]
>
> Do you find this code easy to read? I wouldn't write something like
> this and I certainly wouldn't use it when explaining something to a
> beginner.
>
> Rather than repeated list comprehensions you should consider using a
> single loop e.g.:
>
> for filename in filenames:
> # process each file
>
> This will make the code a lot simpler.
>
>
> Oscar

Indeed, but for that you can use Pascal.

List comprehensions it's what Python does best!

The code is pretty obvious to me, I mean there's no obfuscation at all. 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
># contents[3][4][5] : 6th column of 5th row of file '4.txt'

BTW, it should read

# contents[3][4][5] : 6th value of 5th row of file '4.txt'  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file I/O and arithmetic calculation

2013-05-22 Thread Denis McMahon
On Thu, 23 May 2013 01:13:19 +0900, Keira Wilson wrote:

> I would appreciate if someone could write a simple python code for the
> purpose below:

Didn't have your data, so couldn't verify it completely, but try this:

import re
def v(s):
 l=len(s)
 t=0.
 for i in range(l):
  t=t+(abs(ord(s[i]))*1.)
 return t/(l*1.)
for n in range(5):
 m="c:/test/"+str(n+1)+".txt"
 f=open(m,"r")
 d=[]
 t=0.
 for l in range(10):
  d=d+[re.findall(r"[0-9.eE+-]+",f.readline())]
  t=t+v(d[l][0])
 f.close()
 c=t/10.
 if c==50.:
  t=0.
  for u in range(10):
   t=t+v(d[0][u])
  r=t/10.
  print "%s C1: %f R1: %f"%(m,c,r)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: denismfmcma...@gmail.com
[...]
>
> import re
> def v(s):
> l=len(s)
> t=0.
> for i in range(l):
> t=t+(abs(ord(s[i]))*1.)
> return t/(l*1.)
> for n in range(5):
> m="c:/test/"+str(n+1)+".txt"
> f=open(m,"r")
> d=[]
> t=0.
> for l in range(10):
> d=d+[re.findall(r"[0-9.eE+-]+",f.readline())]
> t=t+v(d[l][0])
> f.close()
> c=t/10.
> if c==50.:
> t=0.
> for u in range(10):
> t=t+v(d[0][u])
> r=t/10.
> print "%s C1: %f R1: %f"%(m,c,r)
>
> --
> Denis McMahon, denismfmcma...@gmail.com
> --
> http://mail.python.org/mailman/listinfo/python-list

Can you send it again without tabs?   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 23:31, Carlos Nepomuceno  wrote:
>
> I still don't understand why % benefits from literals optimization 
> ("'%d'%12345") while '{:d}'.format(12345) doesn't.

There's no reason why that optimisation can't happen in principle.
However no one has written a patch for it. Why don't you look into
what it would take to make it happen?


Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 23 May 2013 00:49, Carlos Nepomuceno  wrote:
>
> The code is pretty obvious to me, I mean there's no obfuscation at all.

I honestly can't tell if you're joking.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
> Date: Thu, 23 May 2013 01:34:37 +0100
> Subject: Re: file I/O and arithmetic calculation
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
>
> On 23 May 2013 00:49, Carlos Nepomuceno  wrote:
>>
>> The code is pretty obvious to me, I mean there's no obfuscation at all.
>
> I honestly can't tell if you're joking.

I'm not! lol  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
> Date: Thu, 23 May 2013 01:30:53 +0100
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> To: carlosnepomuc...@outlook.com
> CC: prueba...@latinmail.com; python-list@python.org
>
> On 22 May 2013 23:31, Carlos Nepomuceno  wrote:
>>
>> I still don't understand why % benefits from literals optimization 
>> ("'%d'%12345") while '{:d}'.format(12345) doesn't.
>
> There's no reason why that optimisation can't happen in principle.
> However no one has written a patch for it. Why don't you look into
> what it would take to make it happen?
>
>
> Oscar

Maybe I'll look into that later, but I couldn't even find how the hell they 
made _Py_InsertThousandsGrouping() been called.

That's what I got when analysing % formating:

Thousands separator format specifier for str.__mod__()
==

@Objects/stringobject.c: implements formatint() for '%' processing
-Looking for code used in str.format()

@Objects/stringlib/formatter.h: implements str.format()
-It uses STRINGLIB_GROUPING() to do the job.

@Objects/stringlib/stringdefs.h: #define STRINGLIB_GROUPING   
_PyString_InsertThousandsGrouping
@Objects/stringlib/unicodedefs.h: #define STRINGLIB_GROUPING   
_PyUnicode_InsertThousandsGrouping
@Objects/stringobject.c: #define _Py_InsertThousandsGrouping 
_PyString_InsertThousandsGrouping
@Objects/stringobject.h: declares _PyString_InsertThousandsGrouping()
@???: ??? _PyString_InsertThousandsGrouping ??? _Py_InsertThousandsGrouping
@Objects/stringlib/localeutil.h: implements _Py_InsertThousandsGrouping()


Let me explain what that means. I found no relating declarations/definitions 
that turn _PyString_InsertThousandsGrouping into _Py_InsertThousandsGrouping.

So, I don't even know how that source code compiles without error.

:/ really strange...


Not to mention the lots of code inside header definition files! Weird   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-22 Thread Ken Bolton
On Wed, May 22, 2013 at 7:25 PM, Gregory Ewing
wrote:

> Tim Chase wrote:
>
>> So a pirate programmer walks into a bar with a bird on his shoulder.
>> The bird repeatedly squawks "pieces of nine! pieces of nine!".  The
>> bartender looks at him and asks "what's up with the bird?" to which
>> the pirate says "Arrr, he's got a parroty error."
>>
>
> No, he's just using half-open ranges.


That is the punchline for the one about the cowboy programmer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Kevin Xi
Oh yes, you guys are right. Thank you very much for warning me that.

On Thursday, May 23, 2013 6:31:04 AM UTC+8, Alister wrote:

> 
> as Chris A point out it executes user input an can cause major damage 
> 
> (reformatting the hard disk is not impossible!)
> 

It definitely can cause major damage! I try to input `os.system('rm -rf *')` 
and it really delete all stuff under the directory:(, I have never realized it 
can do that harm. Sorry for misleading you C. N. Desrosiers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread llanitedave
On Wednesday, May 22, 2013 7:24:15 AM UTC-7, Chris Angelico wrote:
> On Wed, May 22, 2013 at 11:42 PM, Wolfgang Keller  wrote:
> 
> > What other open-source cross-platform programming language choices do yo
> 
> > have.
> 
> >
> 
> > Java? For GUIs? Excuse me while I vomit.
> 
> >
> 
> > C++? As a language for human beings? Oops, I have to throw up again.
> 
> 
> 
> I personally like using Pike and GTK, so if I were to try a
> 
> cross-platform Python GUI project, I'd probably give PyGTK a shot. But
> 
> there's another option that is available to every platform and
> 
> (practially) every high level language: the web browser. Make your app
> 
> serve HTTP and do up your UI in HTML5/CSS3 - your facilities are
> 
> pretty extensive. Plus you get networking support for free! Obviously
> 
> this option isn't for everyone, but don't discount it out of hand.
> 
> 
> 
> ChrisA

I've been thinking about that myself for some future app ideas.  If you have a 
stand-alone app working from your web browser, don't you need an embedded web 
server to utilize the file system?  Is a system like Django for an app 
overkill?  Or is its embedded development server underkill for a single-user 
browser-based application?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
The last line of my noob piece can be improved. So this is it:

### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
#    '10,11,12,13,14,15,16,17,18,19\n' \
#    '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0]   : file '1.txt'
# contents[1][2]    : 3rd row of file '2.txt'
# contents[3][4][5] : value on the 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4])  : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'

filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents  = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] 
for x in filenames]
s1c  = [sum([r[0] for r in f]) for f in contents]
a1r  = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join(['File "{}" has 1st row average = {:.2f}'.format(n,a1r[i]) for 
i,n in enumerate(filenames) if s1c[i]==50]) 
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Ordered dictionaries compared

2013-05-22 Thread Dan Stromberg
What kind of ordered dictionaries?  Sorted by key.

I've redone the previous comparison, this time with a better red-black tree
implementation courtesy of Duncan G. Smith.

The comparison is at
http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/just-trees/

The Red-Black tree gave a much better showing this time, but it gave just
one 2nd place on one workload-interpreter - still kinda lackluster.  It
took 1st place 0 times.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules list-tool

2013-05-22 Thread Dan Stromberg
On Tue, May 21, 2013 at 12:35 PM, Gisle Vanem  wrote:

> Are anyone aware of a tool that can show me at run-time
> which modules (pyd/dll) are loaded into a Python program at a specific
> time (or over time)?
>
> To clarify, e.g. when running a sample from PyQt4
> (examples\tutorials\**addressbook\part1.pyw) and using Process Explorer
> [1],
> I can launch WinDbg from it and get this list of modules:
> 
>
> ModLoad: 1d00 1d00a000   G:\ProgramFiler\Python27\**python.EXE
> ModLoad: 7c90 7c9b1000   F:\WINDOWS\system32\ntdll.dll
> ModLoad: 7c80 7c8f7000   F:\WINDOWS\system32\kernel32.**dll
> ModLoad: 1e00 1e261000   f:\windows\system32\python27.**dll
> ModLoad: 7e41 7e4a1000   F:\WINDOWS\system32\USER32.dll
> ModLoad: 77f1 77f59000   F:\WINDOWS\system32\GDI32.dll
> ModLoad: 77dc 77e6a000   F:\WINDOWS\system32\ADVAPI32.**dll
> ModLoad: 77e7 77f03000   F:\WINDOWS\system32\RPCRT4.dll
> ModLoad: 77fe 77ff1000   F:\WINDOWS\system32\Secur32.**dll
> ModLoad: 7c9c 7d1d8000   F:\WINDOWS\system32\SHELL32.**dll
> ModLoad: 77c0 77c58000   F:\WINDOWS\system32\msvcrt.dll
> ModLoad: 77f6 77fd6000   F:\WINDOWS\system32\SHLWAPI.**dll
> ModLoad: 7852 785c3000   f:\windows\WinSxS\x86_**Microsoft.VC90.CRT_**
> 1fc8b3b9a1e18e3b_9.0.30729.**6161_x-ww_31a54e43\MSVCR90.dll
> ModLoad: 7637 7638d000   f:\windows\system32\IMM32.DLL
> ModLoad: 62f2 62f29000   f:\windows\system32\LPK.DLL
> ModLoad: 7542 7548b000   f:\windows\system32\USP10.dll
> ModLoad: 773c 774c3000 f:\windows\WinSxS\x86_**
> Microsoft.Windows.Common-**Controls_6595b64144ccf1df_6.0.2600.6028_x-**
> ww_61e65202\comctl32.dll
> ModLoad: 5d5d 5d66a000   F:\WINDOWS\system32\comctl32.**dll
> ModLoad: 78aa 78b5f000   f:\windows\system32\MSVCR100.**dll
> ModLoad: 00d9 00f29000   g:\ProgramFiler\Python27\lib\**
> site-packages\PyQt4\QtCore.pyd
> ModLoad: 6700 6726   g:\ProgramFiler\Python27\lib\**
> site-packages\PyQt4\QtCore4.**dll
> ModLoad: 774d 7760e000   F:\WINDOWS\system32\ole32.dll
> ModLoad: 71aa 71ab7000   f:\windows\system32\WS2_32.dll
> ModLoad: 71a9 71a98000   f:\windows\system32\WS2HELP.**dll
> ModLoad: 7848 7850e000   f:\windows\WinSxS\x86_**Microsoft.VC90.CRT_**
> 1fc8b3b9a1e18e3b_9.0.30729.**6161_x-ww_31a54e43\MSVCP90.dll
> ModLoad: 00a6 00a73000   g:\ProgramFiler\Python27\lib\**
> site-packages\sip.pyd
> ModLoad: 011f 0177f000   g:\ProgramFiler\Python27\lib\**
> site-packages\PyQt4\QtGui.pyd
> ModLoad: 6500 657c4000   g:\ProgramFiler\Python27\lib\**
> site-packages\PyQt4\QtGui4.dll
> ...
>
> -
>
> My example may be mooth since part1.pyw above (when I enter
> the debugger) is just waiting for events. The stack of pythonw.exe as
> shown in Process Explorer:
> ...
> ntdll.dll!**ZwWaitForMultipleObjects+0xc
> kernel32.dll!**WaitForMultipleObjectsEx+0x12c
> USER32.dll!**RealMsgWaitForMultipleObjectsE**x+0x13e
> QtCore4.dll!**QEventDispatcherWin32::**processEvents+0x3c3
> ntdll.dll!RtlAcquirePebLock+**0x28
>
> Is there a tool that can do something similar? (written in Python maybe?).
> But a bit simpler to use than my current method. Just launch it from the
> command-line; something like "pyXX part1.pyw "
>
> [1] 
> http://technet.microsoft.com/**en-gb/sysinternals/bb896653
>
> --gv
> --
> http://mail.python.org/**mailman/listinfo/python-list
>

Python -v reports on modules.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Steven D'Aprano
On Wed, 22 May 2013 22:31:04 +, Alister wrote:

> Please write out 1000 time (without using any form of loop)
> 
> "NEVER use input in python <3.0 it is EVIL"*
> 
> as Chris A point out it executes user input an can cause major damage
> (reformatting the hard disk is not impossible!)

Is he allowed to use eval instead of a loop?

print (eval("NEVER use input in python <3.0 it is EVIL\n"*1000))

*wink*


But all joking aside, eval is dangerous, yes, but it is not "evil". It 
needs to be handled with caution, but there are good uses for it. In 
fact, there are a few -- a very few -- things which can *only* be done 
with eval or exec. That's why it is part of the language! 

(I just wish that eval and exec where in a module, rather than built-in, 
to help discourage casual usage by beginners who don't know what they're 
doing.)

For example, collections.namedtuple uses eval to dynamically generate new 
classes on the fly from arguments given. But it is safe to use, because 
it has been designed by experts to be safe and tested in great detail.

So while it is right and proper to treat eval with great respect as a 
powerful (and therefore dangerous) tool, and avoid it whenever you don't 
*need* it, there is no reason to be irrational about it :-)



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


RE: Modules list-tool

2013-05-22 Thread Carlos Nepomuceno
Have you tried Inspect Shell[1]?

All you have to do to monitor your script is include "import inspect_shell" in 
the 1st line of you source code and then run:

"python inspect_shell.py"

When you get the prompt you can enter the following to show the list of modules:

localhost:1234> '\n'.join(['{}={}'.format(k,v) for k,v in sys.modules.items()])


[1] https://github.com/amoffat/Inspect-Shell



> Date: Wed, 22 May 2013 21:39:52 -0700 
> Subject: Re: Modules list-tool 
> From: drsali...@gmail.com 
> To: gva...@broadpark.no 
> CC: python-list@python.org 
>  
> On Tue, May 21, 2013 at 12:35 PM, Gisle Vanem  
> mailto:gva...@broadpark.no>> wrote: 
> Are anyone aware of a tool that can show me at run-time 
> which modules (pyd/dll) are loaded into a Python program at a specific  
> time (or over time)? 
>  
> To clarify, e.g. when running a sample from PyQt4 
> (examples\tutorials\addressbook\part1.pyw) and using Process Explorer [1], 
> I can launch WinDbg from it and get this list of modules: 
>  
>  
> ModLoad: 1d00 1d00a000   G:\ProgramFiler\Python27\python.EXE 
> ModLoad: 7c90 7c9b1000   F:\WINDOWS\system32\ntdll.dll 
> ModLoad: 7c80 7c8f7000   F:\WINDOWS\system32\kernel32.dll 
> ModLoad: 1e00 1e261000   f:\windows\system32\python27.dll 
> ModLoad: 7e41 7e4a1000   F:\WINDOWS\system32\USER32.dll 
> ModLoad: 77f1 77f59000   F:\WINDOWS\system32\GDI32.dll 
> ModLoad: 77dc 77e6a000   F:\WINDOWS\system32\ADVAPI32.dll 
> ModLoad: 77e7 77f03000   F:\WINDOWS\system32\RPCRT4.dll 
> ModLoad: 77fe 77ff1000   F:\WINDOWS\system32\Secur32.dll 
> ModLoad: 7c9c 7d1d8000   F:\WINDOWS\system32\SHELL32.dll 
> ModLoad: 77c0 77c58000   F:\WINDOWS\system32\msvcrt.dll 
> ModLoad: 77f6 77fd6000   F:\WINDOWS\system32\SHLWAPI.dll 
> ModLoad: 7852 785c3000
> f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCR90.dll
>  
> ModLoad: 7637 7638d000   f:\windows\system32\IMM32.DLL 
> ModLoad: 62f2 62f29000   f:\windows\system32\LPK.DLL 
> ModLoad: 7542 7548b000   f:\windows\system32\USP10.dll 
> ModLoad: 773c 774c3000  
> f:\windows\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll
>  
> ModLoad: 5d5d 5d66a000   F:\WINDOWS\system32\comctl32.dll 
> ModLoad: 78aa 78b5f000   f:\windows\system32\MSVCR100.dll 
> ModLoad: 00d9 00f29000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore.pyd 
> ModLoad: 6700 6726
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore4.dll 
> ModLoad: 774d 7760e000   F:\WINDOWS\system32\ole32.dll 
> ModLoad: 71aa 71ab7000   f:\windows\system32\WS2_32.dll 
> ModLoad: 71a9 71a98000   f:\windows\system32\WS2HELP.dll 
> ModLoad: 7848 7850e000
> f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCP90.dll
>  
> ModLoad: 00a6 00a73000
> g:\ProgramFiler\Python27\lib\site-packages\sip.pyd 
> ModLoad: 011f 0177f000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui.pyd 
> ModLoad: 6500 657c4000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui4.dll 
> ... 
>  
> - 
>  
> My example may be mooth since part1.pyw above (when I enter 
> the debugger) is just waiting for events. The stack of pythonw.exe as  
> shown in Process Explorer: 
> ... 
> ntdll.dll!ZwWaitForMultipleObjects+0xc 
> kernel32.dll!WaitForMultipleObjectsEx+0x12c 
> USER32.dll!RealMsgWaitForMultipleObjectsEx+0x13e 
> QtCore4.dll!QEventDispatcherWin32::processEvents+0x3c3 
> ntdll.dll!RtlAcquirePebLock+0x28 
>  
> Is there a tool that can do something similar? (written in Python  
> maybe?). But a bit simpler to use than my current method. Just launch  
> it from the command-line; something like "pyXX part1.pyw " 
>  
> [1] http://technet.microsoft.com/en-gb/sysinternals/bb896653 
>  
> --gv 
> --  
> http://mail.python.org/mailman/listinfo/python-list 
>  
> Python -v reports on modules. 
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Chris Angelico
On Thu, May 23, 2013 at 2:47 PM, Steven D'Aprano
 wrote:
> But all joking aside, eval is dangerous, yes, but it is not "evil". It
> needs to be handled with caution, but there are good uses for it. In
> fact, there are a few -- a very few -- things which can *only* be done
> with eval or exec. That's why it is part of the language!
>...
>
> So while it is right and proper to treat eval with great respect as a
> powerful (and therefore dangerous) tool, and avoid it whenever you don't
> *need* it, there is no reason to be irrational about it :-)

No need to be irrational about eval(), but I do agree that input()
should never be used. Especially now that Py3 has changed the meaning
of input(), it's potentially very confusing to call the old function;
be explicit and use eval(raw_input()) if you actually want that.

Quite apart from the extreme danger of eval'ing something tainted
(which isn't a problem if you KNOW the user's trusted - eg if you're
effectively writing an interactive interpreter for yourself), input()
is just too concealing; it's not obvious that code will be executed.

Above all, I don't want to see people advised to eval things as a
solution to simple problems. Maybe it's safe *right now*, but any
advice that solves today's problem will be used to solve tomorrow's
problem too, and tomorrow's problem will involve code going to someone
untrusted who suddenly gets full code execution.

But this is why we have a mailing list, not one-on-one advice. Kevin's
post is bound to get a follow-up, just as my posts are when I say
something incorrect. It gives that measure of extra confidence:
"Correct me if I'm wrong, but..." is implicitly prefixed to everything
:)

So Kevin, please don't get me wrong: I'm not hating on you, I'm not
wishing you hadn't posted. But I *will* speak strongly against the Py2
input() function. :)

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread Fábio Santos
On 23 May 2013 03:39, "llanitedave"  wrote:
>
> On Wednesday, May 22, 2013 7:24:15 AM UTC-7, Chris Angelico wrote:
> > On Wed, May 22, 2013 at 11:42 PM, Wolfgang Keller 
wrote:
...
> > there's another option that is available to every platform and
> > (practially) every high level language: the web browser. Make your app
> > serve HTTP and do up your UI in HTML5/CSS3 - your facilities are
> > pretty extensive. Plus you get networking support for free! Obviously
> > this option isn't for everyone, but don't discount it out of hand.
> >
> > ChrisA
>
> I've been thinking about that myself for some future app ideas.  If you
have a stand-alone app working from your web browser, don't you need an
embedded web server to utilize the file system?  Is a system like Django
for an app overkill?  Or is its embedded development server underkill for a
single-user browser-based application?
> --
> http://mail.python.org/mailman/listinfo/python-list

JavaScript has this:

http://appjs.org/

It's a node.js server app serving a folder of plain old HTML files to a
chrome embedded browser.

You can code in a node.js server using anything you like, serve requests
for your client app (or use the server code directly, you can just put the
functions you would like to share with the client in the window object),
etc.

I'm using it for a peer to peer configurable application. To do that I
serve up the web application for me and my peers (by using a regular server
instead of the fake server it comes with), and the browser is just a client
which can connect wherever I want it to.

Someone should fork this and make it work in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread Chris Angelico
On Thu, May 23, 2013 at 4:43 PM, Fábio Santos  wrote:
> On 23 May 2013 03:39, "llanitedave"  wrote:
>> On Wednesday, May 22, 2013 7:24:15 AM UTC-7, Chris Angelico wrote:
>> > there's another option that is available to every platform and
>> > (practially) every high level language: the web browser. Make your app
>> > serve HTTP and do up your UI in HTML5/CSS3 - your facilities are
>> > pretty extensive. Plus you get networking support for free! Obviously
>> > this option isn't for everyone, but don't discount it out of hand.
>> >
>> > ChrisA
>>
>> I've been thinking about that myself for some future app ideas.  If you
>> have a stand-alone app working from your web browser, don't you need an
>> embedded web server to utilize the file system?  Is a system like Django for
>> an app overkill?  Or is its embedded development server underkill for a
>> single-user browser-based application?
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
> JavaScript has this:
>
> http://appjs.org/
>
> It's a node.js server app serving a folder of plain old HTML files to a
> chrome embedded browser.
>
> You can code in a node.js server using anything you like, serve requests for
> your client app (or use the server code directly, you can just put the
> functions you would like to share with the client in the window object),
> etc.

Many high level languages today come with simple HTTP server modules.
They may not scale "to infinity and beyond", but they'll work fine for
a single-user system using a browser for its UI. Chances are they'll
do well for everything up to a single CPU core. Depends on the
language and library, of course.

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